buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int k = int.Parse(str[1]); var list = new SortedDictionary<int, int>(); for (int i = 0; i < n; i++) { string[] strer = Console.ReadLine().Split(' '); int key = int.Parse(strer[0]); int vla = int.Parse(strer[1]); if (list.ContainsKey(key)) { list[key] += vla; } else { list[key] = vla; } } int u = 0; foreach (var s in list) { u = s.Value; if (u >= k) { Console.WriteLine(s.Key); break; } else { k -= u; } } } } }
using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); long k = long.Parse(str[1]); var list = new SortedDictionary<int, long>(); for (int i = 0; i < n; i++) { string[] strer = Console.ReadLine().Split(' '); int key = int.Parse(strer[0]); int vla = int.Parse(strer[1]); if (list.ContainsKey(key)) { list[key] += vla; } else { list[key] = vla; } } long u = 0; foreach (var s in list) { u = s.Value; if (u >= k) { Console.WriteLine(s.Key); break; } else { k -= u; } } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
220
8
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { class Entity : IComparable<Entity> { public int number; public int count; public int CompareTo(Entity e) { return number.CompareTo(e.number); } } static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); List<Entity> l = new List<Entity>(); for (int i = 0; i < N; i++) { s = Console.ReadLine().Split(' '); Entity e = new Entity(); e.number = int.Parse(s[0]); e.count = int.Parse(s[1]); l.Add(e); } l.Sort(); int total = 0; for (int i = 0; i < l.Count; i++) { total += l[i].count; if (M <= total) { Console.WriteLine(l[i].number); break; } } } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { class Entity : IComparable<Entity> { public int number; public int count; public int CompareTo(Entity e) { return number.CompareTo(e.number); } } static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); long M = long.Parse(s[1]); List<Entity> l = new List<Entity>(); for (int i = 0; i < N; i++) { s = Console.ReadLine().Split(' '); Entity e = new Entity(); e.number = int.Parse(s[0]); e.count = int.Parse(s[1]); l.Add(e); } l.Sort(); long total = 0; for (int i = 0; i < l.Count; i++) { total += l[i].count; if (M <= total) { Console.WriteLine(l[i].number); break; } } } } }
[["-", 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
272
6
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC061C { class Program { static void Solve(Input input) { var n = input.NextInt(); var k = input.NextInt(); var a = new int[n]; var b = new int[n]; for (int i = 0; i < n; i++) { a[i] = input.NextInt(); b[i] = input.NextInt(); } Array.Sort(a, b); var sum = 0L; for (int i = 0; i < n; i++) { sum += b[i]; if (sum >= k) { Console.WriteLine(a[i]); return; } } } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC061C { class Program { static void Solve(Input input) { var n = input.NextInt(); var k = input.NextLong(); var a = new int[n]; var b = new int[n]; for (int i = 0; i < n; i++) { a[i] = input.NextInt(); b[i] = input.NextInt(); } Array.Sort(a, b); var sum = 0L; for (int i = 0; i < n; i++) { sum += b[i]; if (sum >= k) { Console.WriteLine(a[i]); return; } } } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
1,245
2
using System; using System.Linq; namespace ABC061_C { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var ar = new int [N][]; for (int i = 0; i < N; i++) { ar[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); } ar = ar.OrderBy(x => x[0]).ToArray(); long n = 0; for (int i = 0; i < N; i++) { n += ar[i][1]; if (n >= K) { Console.WriteLine(ar[i][0]); break; } } } } }
using System; using System.Linq; namespace ABC061_C { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var ar = new int [N][]; for (int i = 0; i < N; i++) { ar[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); } ar = ar.OrderBy(x => x[0]).ToArray(); long n = 0; for (int i = 0; i < N; i++) { n += ar[i][1]; if (n >= K) { Console.WriteLine(ar[i][0]); break; } } } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
192
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = line[0]; var K = line[1]; var list = new List<int[]>(); for (int i = 0; i < N; ++i) { var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); list.Add(new int[] { ab[0], ab[1] }); } var orderList = list.OrderBy(x => x[0]); var ans = 0; foreach (var l in orderList) { K -= l[1]; if (K <= 0) { ans = l[0]; break; } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var N = line[0]; var K = line[1]; var list = new List<long[]>(); for (var i = 0; i < N; ++i) { var ab = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); list.Add(new long[] { ab[0], ab[1] }); } var orderList = list.OrderBy(x => x[0]); var ans = 0L; foreach (var l in orderList) { K -= l[1]; if (K <= 0) { ans = l[0]; break; } } Console.WriteLine(ans); } }
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 22], ["-", 0, 230, 39, 236, 237, 238, 0, 224, 39, 199], ["+", 0, 230, 39, 236, 237, 238, 0, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 3, 4, 0, 28, 0, 227, 39, 224, 39, 199], ["+", 3, 4, 0, 28, 0, 227, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
216
12
using System; using System.Linq; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); ulong K = ulong.Parse(s[1]); var array = Enumerable.Repeat((ulong)0, AMAX + 1).ToArray(); for (int i = 0; i < N; i++) { string[] ss = Console.ReadLine().Split(' '); int a = int.Parse(ss[0]); int b = int.Parse(ss[1]); array[a] += (ulong)b; } ulong itemNum = 0; for (int i = 1; i <= N; i++) { if (K <= array[i]) { Console.WriteLine(i); return; } K -= array[i]; } } public const int AMAX = 100000; }
using System; using System.Linq; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); ulong K = ulong.Parse(s[1]); var array = Enumerable.Repeat((ulong)0, AMAX + 1).ToArray(); for (int i = 0; i < N; i++) { string[] ss = Console.ReadLine().Split(' '); int a = int.Parse(ss[0]); int b = int.Parse(ss[1]); array[a] += (ulong)b; } ulong itemNum = 0; for (int i = 1; i <= AMAX; i++) { if (K <= array[i]) { Console.WriteLine(i); return; } K -= array[i]; } } public const int AMAX = 100000; }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
213
2
using System; using System.Collections.Generic; using System.Text; using System.Linq; using static System.Math; class Program { static int n; static int k; static int[] a; static int[] b; static int[] count; // count[i] : iが配列に何個含まれるか static void Main() { /* 入力の受取 */ string[] input = Console.ReadLine().Split(); n = int.Parse(input[0]); k = int.Parse(input[1]); a = new int[n]; b = new int[n]; for (int i = 0; i < n; i++) { input = Console.ReadLine().Split(); a[i] = int.Parse(input[0]); b[i] = int.Parse(input[1]); } /* countを計算 */ count = new int[a.Max() + 1]; for (int i = 0; i < n; i++) //各挿入操作を処理 count[a[i]] += b[i]; /* 答えの計算 */ int index = 0; for (int i = 0; i < count.Length; i++) { index += count[i]; if (index >= k) { Console.WriteLine(i); return; } } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; using static System.Math; class Program { static int n; static long k; static int[] a; static int[] b; static long[] count; // count[i] : iが配列に何個含まれるか static void Main() { /* 入力の受取 */ string[] input = Console.ReadLine().Split(); n = int.Parse(input[0]); k = long.Parse(input[1]); a = new int[n]; b = new int[n]; for (int i = 0; i < n; i++) { input = Console.ReadLine().Split(); a[i] = int.Parse(input[0]); b[i] = int.Parse(input[1]); } /* countを計算 */ count = new long[a.Max() + 1]; for (int i = 0; i < n; i++) //各挿入操作を処理 count[a[i]] += b[i]; /* 答えの計算 */ long index = 0; for (int i = 0; i < count.Length; i++) { index += count[i]; if (index >= k) { Console.WriteLine(i); return; } } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
269
10
using System; class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var n = int.Parse(nm[0]); var m = int.Parse(nm[1]); var d = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { var ab = Console.ReadLine().Split(' '); d[i] = Tuple.Create(int.Parse(ab[0]), int.Parse(ab[1])); } Array.Sort(d, (x, y) => x.Item1 - y.Item1); var sum = 0L; for (int i = 0; i < n; i++) { sum += d[i].Item2; if (m <= sum) { Console.WriteLine(d[i].Item1); return; } } } }
using System; class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var n = long.Parse(nm[0]); var m = long.Parse(nm[1]); var d = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { var ab = Console.ReadLine().Split(' '); d[i] = Tuple.Create(int.Parse(ab[0]), int.Parse(ab[1])); } Array.Sort(d, (x, y) => x.Item1 - y.Item1); var sum = 0L; for (int i = 0; i < n; i++) { sum += d[i].Item2; if (m <= sum) { Console.WriteLine(d[i].Item1); return; } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
209
4
using System; using System.Collections.Generic; using System.Linq; public static partial class Program { public static void Main() { var nk = CRL().SpTInts(); var n = nk[0]; var k = nk[1]; var array = new List<KeyValuePair<int, int>>(); for (int i = 0; i < n; i++) { var ab = CRL().SpTInts(); var a = ab[0]; var b = ab[1]; array.Add(new KeyValuePair<int, int>(a, b)); } array = array.OrderBy(x => x.Key).ToList(); for (int i = 0; i < array.Count; i++) { k -= array[i].Value; if (k <= 0) { CWL(array[i].Key); return; } } } } public static partial class Program { //テンプレここから private static int ToInt(this string str) => int.Parse(str); private static long ToLong(this string str) => long.Parse(str); private static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray(); private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); public static int[] SpTInts(this string str, char opr = ' ') => str.Split(opr).ToInt(); public static long[] SpTLongs(this string str, char opr = ' ') => str.Split(opr).ToLong(); public static string CRL() => Console.ReadLine(); public static void CWL(object obj) => Console.WriteLine(obj); public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static int Sign(this int i) => Math.Sign(i); public static bool IsEven(this int i) => i % 2 == 0; public static int[] dx = new int[] { 0, -1, 0, 1 }; public static int[] dy = new int[] { -1, 0, 1, 0 }; public static long mod = 1000000007; public static string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static int ToInt(this char c) => c.ToString().ToInt(); public static long ToLong(this char c) => c.ToString().ToLong(); //テンプレここまで }
using System; using System.Collections.Generic; using System.Linq; public static partial class Program { public static void Main() { var nk = CRL().SpTLongs(); var n = nk[0]; var k = nk[1]; var array = new List<KeyValuePair<int, int>>(); for (int i = 0; i < n; i++) { var ab = CRL().SpTInts(); var a = ab[0]; var b = ab[1]; array.Add(new KeyValuePair<int, int>(a, b)); } array = array.OrderBy(x => x.Key).ToList(); for (int i = 0; i < n; i++) { k -= array[i].Value; if (k <= 0) { CWL(array[i].Key); return; } } } } public static partial class Program { //テンプレここから private static int ToInt(this string str) => int.Parse(str); private static long ToLong(this string str) => long.Parse(str); private static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray(); private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); public static int[] SpTInts(this string str, char opr = ' ') => str.Split(opr).ToInt(); public static long[] SpTLongs(this string str, char opr = ' ') => str.Split(opr).ToLong(); public static string CRL() => Console.ReadLine(); public static void CWL(object obj) => Console.WriteLine(obj); public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static int Sign(this int i) => Math.Sign(i); public static bool IsEven(this int i) => i % 2 == 0; public static int[] dx = new int[] { 0, -1, 0, 1 }; public static int[] dy = new int[] { -1, 0, 1, 0 }; public static long mod = 1000000007; public static string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static int ToInt(this char c) => c.ToString().ToInt(); public static long ToLong(this char c) => c.ToString().ToLong(); //テンプレここまで }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
597
6
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); var N = NK[0]; var K = NK[1]; var array = new List<KeyValuePair<long, long>>(); for (var i = 0; i < N; i++) { var ab = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); array.Add(new KeyValuePair<long, long>(ab[0], ab[1])); } array.OrderBy(s => s.Key); var tmpK = K; for (var i = 0; i < N; i++) { tmpK -= array[i].Value; if (tmpK < 1) { Console.WriteLine(array[i].Key); return; } } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); var N = NK[0]; var K = NK[1]; var array = new List<KeyValuePair<long, long>>(); for (var i = 0; i < N; i++) { var ab = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); array.Add(new KeyValuePair<long, long>(ab[0], ab[1])); } array = array.OrderBy(s => s.Key).ToList(); var tmpK = K; for (var i = 0; i < N; i++) { tmpK -= array[i].Value; if (tmpK < 1) { Console.WriteLine(array[i].Key); return; } } } }
[["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24]]
8
229
6
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var nk = Array.ConvertAll(ReadLine().Split(' '), long.Parse); var dic = new SortedDictionary<long, int>(); for (var i = 0; i < nk[0]; i++) { var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse); if (dic.ContainsKey(input[0])) dic[input[0]] += input[1]; else dic[input[0]] = input[1]; } var sum = 0; foreach (var pair in dic) { sum += pair.Value; if (sum >= nk[1]) { WriteLine(pair.Key); return; } } } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var nk = Array.ConvertAll(ReadLine().Split(' '), long.Parse); var dic = new SortedDictionary<long, long>(); for (var i = 0; i < nk[0]; i++) { var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse); if (dic.ContainsKey(input[0])) dic[input[0]] += input[1]; else dic[input[0]] = input[1]; } var sum = 0L; foreach (var pair in dic) { sum += pair.Value; if (sum >= nk[1]) { WriteLine(pair.Key); return; } } } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
221
4
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; using static System.Console; class Program { static Scanner sc = new Scanner(); class ab { public int a { get; set; } public int b { get; set; } } internal static void Main(string[] args) { var N = sc.nextInt(); var K = sc.nextInt(); var lst = new List<ab>(); for (int i = 0; i < N; i++) { lst.Add(new ab() { a = sc.nextInt(), b = sc.nextInt() }); } lst = lst.OrderBy(hoge => hoge.a).ToList(); long sum = 0; for (int i = 0; i < N; i++) { sum += lst[i].b; if (sum >= K) { WriteLine(lst[i].a); return; } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; using static System.Console; class Program { static Scanner sc = new Scanner(); class ab { public int a { get; set; } public int b { get; set; } } internal static void Main(string[] args) { var N = sc.nextInt(); var K = sc.nextLong(); var lst = new List<ab>(); for (int i = 0; i < N; i++) { lst.Add(new ab() { a = sc.nextInt(), b = sc.nextInt() }); } lst = lst.OrderBy(hoge => hoge.a).ToList(); long sum = 0; for (int i = 0; i < N; i++) { sum += lst[i].b; if (sum >= K) { WriteLine(lst[i].a); return; } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
562
2
using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); var d = new Dictionary<long, long>(); for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); var a = long.Parse(line[0]); var b = long.Parse(line[1]); if (d.ContainsKey(a)) d[a] += b; else d[a] = b; } var total = 0L; foreach (var x in d.OrderBy(y => y.Key)) { total += x.Value; if (total >= k) { Console.WriteLine(x.Key); break; } } } }
using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = long.Parse(line[1]); var d = new Dictionary<int, long>(); for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = long.Parse(line[1]); if (d.ContainsKey(a)) d[a] += b; else d[a] = b; } var total = 0L; foreach (var x in d.OrderBy(y => y.Key)) { total += x.Value; if (total >= k) { Console.WriteLine(x.Key); break; } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
222
6
using System; using System.Linq; using System.Collections.Generic; using System.Runtime.InteropServices; class P { static void Main() { int[] NK = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int[][] ab = new int[NK[0]][] .Select(_ => Console.ReadLine() .Split() .Select(x => int.Parse(x)) .ToArray()) .OrderBy(x => x[0]) .ToArray(); long nowindex = 0; for (int i = 0; i < ab.Length; i++) { nowindex += ab[i][1]; if (nowindex >= NK[1]) { Console.WriteLine(ab[i][0]); break; } } } }
using System; using System.Linq; using System.Collections.Generic; using System.Runtime.InteropServices; class P { static void Main() { long[] NK = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); int[][] ab = new int[NK[0]][] .Select(_ => Console.ReadLine() .Split() .Select(x => int.Parse(x)) .ToArray()) .OrderBy(x => x[0]) .ToArray(); long nowindex = 0; for (int i = 0; i < ab.Length; i++) { nowindex += ab[i][1]; if (nowindex >= NK[1]) { Console.WriteLine(ab[i][0]); break; } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199]]
8
186
4
using System; using System.Collections.Generic; namespace C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int K = int.Parse(input[1]); var data = new long[int.Parse(Math.Pow(10, 5).ToString()) + 1]; for (var i = 0; i < int.Parse(Math.Pow(10, 5).ToString()) + 1; i++) { data[i] = 0; } for (var i = 0; i < N; i++) { input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); data[a] = data[a] + b; } long p = 0; int r = 0; for (var i = 0; i < int.Parse(Math.Pow(10, 5).ToString()) + 1; i++) { p = p + data[i]; if (p >= K) { r = i; break; } } Console.WriteLine(r); // Console.ReadKey(); } } }
using System; using System.Collections.Generic; namespace C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); long K = long.Parse(input[1]); var data = new long[int.Parse(Math.Pow(10, 5).ToString()) + 1]; for (var i = 0; i < int.Parse(Math.Pow(10, 5).ToString()) + 1; i++) { data[i] = 0; } for (var i = 0; i < N; i++) { input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); data[a] = data[a] + b; } long p = 0; int r = 0; for (var i = 0; i < int.Parse(Math.Pow(10, 5).ToString()) + 1; i++) { p = p + data[i]; if (p >= K) { r = i; break; } } Console.WriteLine(r); // Console.ReadKey(); } } }
[["-", 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
283
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long K = long.Parse(str[1]); long[] cnt = new long[100000 + 1]; for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); int A, B; A = int.Parse(str[0]); B = int.Parse(str[1]); cnt[A] += B; } for (int i = 1; i < 100000; i++) { if (K <= cnt[i]) { Console.WriteLine(i); break; } K -= cnt[i]; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long K = long.Parse(str[1]); long[] cnt = new long[100000 + 1]; for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); int A, B; A = int.Parse(str[0]); B = int.Parse(str[1]); cnt[A] += B; } for (int i = 1; i <= 100000; i++) { if (K <= cnt[i]) { Console.WriteLine(i); break; } K -= cnt[i]; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
202
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061C { class Program { class Number { public int a, b; } static void Main(string[] args) { int N; long K; string[] vals = Console.ReadLine().Split(' '); N = int.Parse(vals[0]); K = long.Parse(vals[1]); List<Number> list = new List<Number>(); for (int i = 0; i < N; i++) { vals = Console.ReadLine().Split(' '); Number n = new Number(); n.a = int.Parse(vals[0]); n.b = int.Parse(vals[1]); list.Add(n); } list.Sort((n, m) => n.a - n.b); long count = 0; foreach (var n in list) { count += n.b; if (K <= count) { Console.WriteLine(n.a); return; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061C { class Program { class Number { public int a, b; } static void Main(string[] args) { int N; long K; string[] vals = Console.ReadLine().Split(' '); N = int.Parse(vals[0]); K = long.Parse(vals[1]); List<Number> list = new List<Number>(); for (int i = 0; i < N; i++) { vals = Console.ReadLine().Split(' '); Number n = new Number(); n.a = int.Parse(vals[0]); n.b = int.Parse(vals[1]); list.Add(n); } list.Sort((n, m) => n.a - m.a); long count = 0; foreach (var n in list) { count += n.b; if (K <= count) { Console.WriteLine(n.a); return; } } } } }
[["-", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22]]
8
250
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Hello { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = nk[0], k = nk[1]; var pair = new KeyValuePair<int, int>[n]; for (int i = 0; i < pair.Length; i++) { var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = ab[0], b = ab[1]; pair[i] = new KeyValuePair<int, int>(a, b); } var sortPair = pair.OrderBy(e => e.Key); ulong sum = 0; int ans = -1; foreach (var _pair in sortPair) { sum += (ulong)_pair.Value; if (sum >= (ulong)k) { ans = _pair.Key; break; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Hello { static void Main() { var nk = Console.ReadLine().Split().Select(ulong.Parse).ToArray(); ulong n = nk[0], k = nk[1]; var pair = new KeyValuePair<int, int>[n]; for (int i = 0; i < pair.Length; i++) { var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = ab[0], b = ab[1]; pair[i] = new KeyValuePair<int, int>(a, b); } var sortPair = pair.OrderBy(e => e.Key); ulong sum = 0; int ans = -1; foreach (var _pair in sortPair) { sum += (ulong)_pair.Value; if (sum >= k) { ans = _pair.Key; break; } } Console.WriteLine(ans); } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25]]
8
228
7
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { long n = Cin.Ni(); long k = Cin.Ni(); SortedDictionary<long, long> dic = new SortedDictionary<long, long>(); for (int i = 0; i < n; i++) { long a = Cin.Ni(); long b = Cin.Ni(); if (dic.ContainsKey(a)) { dic[a] += b; } else { dic[a] = b; } } foreach (var item in dic) { k -= item.Value; if (k <= 0) { Console.WriteLine(item.Key); return; } } } } public class Cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next(); } public static int Ni() { return int.Parse(Next()); } public static long NextLong() { return long.Parse(Next()); } public static double NextDouble() { return double.Parse(Next()); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { long n = Cin.Ni(); long k = Cin.NextLong(); SortedDictionary<long, long> dic = new SortedDictionary<long, long>(); for (int i = 0; i < n; i++) { long a = Cin.Ni(); long b = Cin.Ni(); if (dic.ContainsKey(a)) { dic[a] += b; } else { dic[a] = b; } } foreach (var item in dic) { k -= item.Value; if (k <= 0) { Console.WriteLine(item.Key); return; } } } } public class Cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next(); } public static int Ni() { return int.Parse(Next()); } public static long NextLong() { return long.Parse(Next()); } public static double NextDouble() { return double.Parse(Next()); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
327
2
using System; using System.Linq; namespace AtCoder { static class Solver { static IO io = new IO(); public static void Solve() { io.ReadSplit(); int N = io.Int(); long K = io.Long(); P[] plist = new P[N]; for (int i = 0; i < N; ++i) { io.ReadSplit(); plist[i].a = io.Int(); plist[i].b = io.Int(); } plist.OrderBy(p => p.a); for (int i = 0; i < N; ++i) { if (K - plist[i].b <= 0) { io.WriteLine(plist[i].a.ToString()); break; } else { K -= plist[i].b; } } } } public struct P { public int a; public int b; } } namespace AtCoder { class Program { static void Main(string[] args) { Solver.Solve(); } } class IO { private string[] _Inputs; private int _Index; public void Read() { _Inputs = new string[1]; _Inputs[0] = Console.ReadLine(); _Index = 0; } public void ReadSplit() { _Inputs = Console.ReadLine().Split(' '); _Index = 0; } public string String() { return _Inputs[_Index++]; } public string[] String(int xCount) { string[] rv = new string[xCount]; Array.Copy(_Inputs, _Index, rv, 0, xCount); _Index += xCount; return rv; } public int Int() { return int.Parse(_Inputs[_Index++]); } public int[] Int(int xCount) { int[] rv = new int[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = int.Parse(_Inputs[_Index++]); } return rv; } public long Long() { return long.Parse(_Inputs[_Index++]); } public long[] Long(int xCount) { long[] rv = new long[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = long.Parse(_Inputs[_Index++]); } return rv; } public void Write(string xStr) { Console.Write(xStr); } public void WriteLine(string xStr) { Console.WriteLine(xStr); } } }
using System; using System.Linq; namespace AtCoder { static class Solver { static IO io = new IO(); public static void Solve() { io.ReadSplit(); int N = io.Int(); long K = io.Long(); P[] plist = new P[N]; for (int i = 0; i < N; ++i) { io.ReadSplit(); plist[i].a = io.Int(); plist[i].b = io.Int(); } plist = plist.OrderBy(p => p.a).ToArray(); for (int i = 0; i < N; ++i) { if (K - plist[i].b <= 0) { io.WriteLine(plist[i].a.ToString()); break; } else { K -= plist[i].b; } } } } public struct P { public int a; public int b; } } namespace AtCoder { class Program { static void Main(string[] args) { Solver.Solve(); } } class IO { private string[] _Inputs; private int _Index; public void Read() { _Inputs = new string[1]; _Inputs[0] = Console.ReadLine(); _Index = 0; } public void ReadSplit() { _Inputs = Console.ReadLine().Split(' '); _Index = 0; } public string String() { return _Inputs[_Index++]; } public string[] String(int xCount) { string[] rv = new string[xCount]; Array.Copy(_Inputs, _Index, rv, 0, xCount); _Index += xCount; return rv; } public int Int() { return int.Parse(_Inputs[_Index++]); } public int[] Int(int xCount) { int[] rv = new int[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = int.Parse(_Inputs[_Index++]); } return rv; } public long Long() { return long.Parse(_Inputs[_Index++]); } public long[] Long(int xCount) { long[] rv = new long[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = long.Parse(_Inputs[_Index++]); } return rv; } public void Write(string xStr) { Console.Write(xStr); } public void WriteLine(string xStr) { Console.WriteLine(xStr); } } }
[["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24]]
8
539
6
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int K = int.Parse(str[1]); int[] A = new int[N]; int[] B = new int[N]; for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); A[i] = int.Parse(str[0]); B[i] = int.Parse(str[1]); } Array.Sort(A, B); for (int i = 0; i < N; i++) { if (B[i] >= K) { sb.Append(A[i] + "\n"); break; } K -= B[i]; } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long K = long.Parse(str[1]); int[] A = new int[N]; int[] B = new int[N]; for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); A[i] = int.Parse(str[0]); B[i] = int.Parse(str[1]); } Array.Sort(A, B); for (int i = 0; i < N; i++) { if (B[i] >= K) { sb.Append(A[i] + "\n"); break; } K -= B[i]; } } }
[["-", 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
273
4
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = System.Int64; using static System.Math; namespace Program { public class Solver { public void Solve() { var n = ri; var m = ri; var G = Enumerate(n, x => new List<Edge>()); for (int i = 0; i < m; i++) { var a = ri - 1; var b = ri - 1; var c = -ri; Debug.WriteLine("{0} {1} {2}", a, b, c); G[a].Add(new Edge(b, c)); } var dist = new long[n]; G.BellmanFord(0, out dist); if (dist[n - 1] != -1L << 60) IO.Printer.Out.WriteLine(-dist[n - 1]); else IO.Printer.Out.WriteLine("inf"); } int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<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; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public 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) return 0; 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) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion #region Edge public struct Edge : IComparable<Edge> { public int from, to, id; public long cost; public Edge(int f, int t) : this() { from = f; to = t; cost = 0; id = -1; } public Edge(int f, int t, long v) : this() { from = f; to = t; cost = v; id = -1; } public Edge(int f, int t, long v, int idx) : this() { from = f; to = t; cost = v; id = idx; } public override string ToString() { return string.Format("{0}->{1}:{2} id:{3}", from, to, cost, id); } public int CompareTo(Edge other) { var cmp = cost.CompareTo(other.cost); if (cmp != 0) return cmp; cmp = to.CompareTo(other.to); if (cmp != 0) return cmp; cmp = from.CompareTo(other.from); return id.CompareTo(other.id); } } #endregion #region bellman_ford static partial class Graph { // O(|V||E|) static public bool BellmanFord(this List<Edge>[] graph, int s, out long[] dist, out int[] prev) { const long max = 1L << 60; var n = graph.Length; dist = new long[n]; prev = new int[n]; for (int i = 0; i < n; i++) { dist[i] = max; prev[i] = -1; } dist[s] = 0; var negCycle = false; for (int i = 0; i < n; i++) for (int v = 0; v < n; v++) foreach (var np in graph[v]) { if (dist[np.to] <= np.cost + dist[v]) continue; dist[np.to] = np.cost + dist[v]; prev[np.to] = v; if (i != n - 1) continue; dist[np.to] = -max; negCycle = true; } return negCycle; } } static partial class Graph { static public bool BellmanFord(this List<Edge>[] graph, int s, out long[] dist) { const long max = 1L << 60; var n = graph.Length; dist = new long[n]; for (int i = 0; i < n; i++) dist[i] = max; dist[s] = 0; var negCycle = false; for (int i = 0; i < n; i++) for (int v = 0; v < n; v++) foreach (var np in graph[v]) { if (dist[np.to] <= np.cost + dist[v]) continue; dist[np.to] = np.cost + dist[v]; if (i != n - 1) continue; dist[np.to] = -max; negCycle = true; } return negCycle; } } static partial class Graph { static public void BellmanFord(this Edge[] edges, int s, long[] dist) { const long max = 1L << 60; var n = dist.Length; for (int i = 0; i < n; i++) dist[i] = max; dist[s] = 0; while (true) { var update = false; foreach (var e in edges) { if (dist[e.from] + e.cost < dist[e.to]) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) break; } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = System.Int64; using static System.Math; namespace Program { public class Solver { public void Solve() { var n = ri; var m = ri; var G = Enumerate(n, x => new List<Edge>()); for (int i = 0; i < m; i++) { var a = ri - 1; var b = ri - 1; var c = -ri; Debug.WriteLine("{0} {1} {2}", a, b, c); G[a].Add(new Edge(a, b, c)); } var dist = new long[n]; G.BellmanFord(0, out dist); if (dist[n - 1] != -1L << 60) IO.Printer.Out.WriteLine(-dist[n - 1]); else IO.Printer.Out.WriteLine("inf"); } int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<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; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public 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) return 0; 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) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion #region Edge public struct Edge : IComparable<Edge> { public int from, to, id; public long cost; public Edge(int f, int t) : this() { from = f; to = t; cost = 0; id = -1; } public Edge(int f, int t, long v) : this() { from = f; to = t; cost = v; id = -1; } public Edge(int f, int t, long v, int idx) : this() { from = f; to = t; cost = v; id = idx; } public override string ToString() { return string.Format("{0}->{1}:{2} id:{3}", from, to, cost, id); } public int CompareTo(Edge other) { var cmp = cost.CompareTo(other.cost); if (cmp != 0) return cmp; cmp = to.CompareTo(other.to); if (cmp != 0) return cmp; cmp = from.CompareTo(other.from); return id.CompareTo(other.id); } } #endregion #region bellman_ford static partial class Graph { // O(|V||E|) static public bool BellmanFord(this List<Edge>[] graph, int s, out long[] dist, out int[] prev) { const long max = 1L << 60; var n = graph.Length; dist = new long[n]; prev = new int[n]; for (int i = 0; i < n; i++) { dist[i] = max; prev[i] = -1; } dist[s] = 0; var negCycle = false; for (int i = 0; i < n; i++) for (int v = 0; v < n; v++) foreach (var np in graph[v]) { if (dist[np.to] <= np.cost + dist[v]) continue; dist[np.to] = np.cost + dist[v]; prev[np.to] = v; if (i != n - 1) continue; dist[np.to] = -max; negCycle = true; } return negCycle; } } static partial class Graph { static public bool BellmanFord(this List<Edge>[] graph, int s, out long[] dist) { const long max = 1L << 60; var n = graph.Length; dist = new long[n]; for (int i = 0; i < n; i++) dist[i] = max; dist[s] = 0; var negCycle = false; for (int i = 0; i < n; i++) for (int v = 0; v < n; v++) foreach (var np in graph[v]) { if (dist[np.to] <= np.cost + dist[v]) continue; dist[np.to] = np.cost + dist[v]; if (i != n - 1) continue; dist[np.to] = -max; negCycle = true; } return negCycle; } } static partial class Graph { static public void BellmanFord(this Edge[] edges, int s, long[] dist) { const long max = 1L << 60; var n = dist.Length; for (int i = 0; i < n; i++) dist[i] = max; dist[s] = 0; while (true) { var update = false; foreach (var e in edges) { if (dist[e.from] + e.cost < dist[e.to]) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) break; } } } #endregion
[["+", 0, 28, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 21]]
8
2,100
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class44 { static void Main() { var abc = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = abc[0], b = abc[1], c = abc[2]; if (!check(a, b, c)) { Console.WriteLine(1); return; } if (a == b && b == c) { Console.WriteLine(-1); return; } int count = 0; while (check(a, b, c)) { int d = a, e = b, f = c; a = (e + f) / 2; b = (d + f) / 2; c = (d + e) / 2; count++; } Console.WriteLine(count); } static bool check(int a, int b, int c) { bool ans = false; if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) ans = true; return ans; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class44 { static void Main() { var abc = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = abc[0], b = abc[1], c = abc[2]; if (!check(a, b, c)) { Console.WriteLine(0); return; } if (a == b && b == c) { Console.WriteLine(-1); return; } int count = 0; while (check(a, b, c)) { int d = a, e = b, f = c; a = (e + f) / 2; b = (d + f) / 2; c = (d + e) / 2; count++; } Console.WriteLine(count); } static bool check(int a, int b, int c) { bool ans = false; if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) ans = true; return ans; } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
251
2
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = l[0], B = l[1], C = l[2]; if (A == B && B == C && A == C) { Console.WriteLine(-1); return; } var count = 0; while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) { count++; var a = A / 2; var b = B / 2; var c = C / 2; A = b + c; B = a + c; C = a + b; } Console.WriteLine(count); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = l[0], B = l[1], C = l[2]; if (A % 2 == 0 && A == B && B == C && A == C) { Console.WriteLine(-1); return; } var count = 0; while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) { count++; var a = A / 2; var b = B / 2; var c = C / 2; A = b + c; B = a + c; C = a + b; } Console.WriteLine(count); } } }
[["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22]]
8
182
6
using System; class program { static long ans = 0; static void solv(long A, long B, long C) { long p, q, r; while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) { ans++; p = (B + C) / 2; q = (C + A) / 2; r = (A + B) / 2; A = p; B = q; C = r; } return; } static void Main(string[] args) { string[] inputs = Console.ReadLine().Split(); long A = long.Parse(inputs[0]); long B = long.Parse(inputs[1]); long C = long.Parse(inputs[2]); if (A == B && B == C) Console.WriteLine(-1); else { solv(A, B, C); Console.WriteLine(ans); } } }
using System; class program { static long ans = 0; static void solv(long A, long B, long C) { long p, q, r; while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) { ans++; p = (B + C) / 2; q = (C + A) / 2; r = (A + B) / 2; A = p; B = q; C = r; } return; } static void Main(string[] args) { string[] inputs = Console.ReadLine().Split(); long A = long.Parse(inputs[0]); long B = long.Parse(inputs[1]); long C = long.Parse(inputs[2]); if (A == B && B == C && A % 2 == 0) Console.WriteLine(-1); else { solv(A, B, C); Console.WriteLine(ans); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
206
6
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 inputs = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Console.WriteLine(CookieExchanges(inputs)); } public static int CookieExchanges(int[] inputs) { int count = -1; int sum = inputs.Sum(); count = 0; while (!inputs.Any(x => x % 2 != 0)) { if (inputs[0] == inputs[1] && inputs[0] == inputs[2] && inputs[0] % 2 == 0) { return -1; } for (int i = 0; i < inputs.Length; i++) { inputs[i] = (sum - inputs[i]) / 2; } count++; } return count; } } }
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 inputs = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); Console.WriteLine(CookieExchanges(inputs)); } public static long CookieExchanges(long[] inputs) { int count = -1; long sum = inputs.Sum(); count = 0; while (!inputs.Any(x => x % 2 != 0)) { if (inputs[0] == inputs[1] && inputs[0] == inputs[2] && inputs[0] % 2 == 0) { return -1; } for (int i = 0; i < inputs.Length; i++) { inputs[i] = (sum - inputs[i]) / 2; } count++; } return count; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
207
8
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NM = Sarray(); var N = NM[0]; var M = NM[1]; var nums = new long[N]; for (var i = 0L; i < M; ++i) { var ab = Sarray(); var a = ab[0] - 1; var b = ab[1] - 1; ++nums[a]; ++nums[b]; } if (nums.Any(n => n % 2 == 1)) WriteLine("No"); else WriteLine("Yes"); Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NM = Sarray(); var N = NM[0]; var M = NM[1]; var nums = new long[N]; for (var i = 0L; i < M; ++i) { var ab = Sarray(); var a = ab[0] - 1; var b = ab[1] - 1; ++nums[a]; ++nums[b]; } if (nums.Any(n => n % 2 == 1)) WriteLine("NO"); else WriteLine("YES"); Out.Flush(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
267
4
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long m = long.Parse(input[1]); long[] usedCount = new long[n]; bool answer = true; long[,] vertexes = new long[n, 2]; //ここに受け取る for (long i = 0; i < n; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); //1行ごとに受け取る usedCount[nums[0] - 1]++; usedCount[nums[1] - 1]++; } for (int i = 0; i < n; i++) { if (usedCount[i] % 2 == 1) answer = false; } Console.WriteLine((answer) ? "YES" : "NO"); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long m = long.Parse(input[1]); long[] usedCount = new long[n]; bool answer = true; long[,] vertexes = new long[n, 2]; //ここに受け取る for (long i = 0; i < m; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); //1行ごとに受け取る usedCount[nums[0] - 1]++; usedCount[nums[1] - 1]++; } for (int i = 0; i < n; i++) { if (usedCount[i] % 2 == 1) answer = false; } Console.WriteLine((answer) ? "YES" : "NO"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
223
2
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Linq; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int A, B, C; public void Solve() { var Map = new Dictionary<int, int>(); int N, M; var line = Console.ReadLine().Split(' '); N = int.Parse(line[0]); M = int.Parse(line[1]); for (int i = 0; i < M; i++) { line = Console.ReadLine().Split(' '); int a = int.Parse(line[0]); int b = int.Parse(line[1]); int d; if (Map.TryGetValue(a, out d)) Map[a] = 0; if (Map.TryGetValue(b, out d)) Map[b] = 0; Map[a]++; Map[b]++; } foreach (var i in Map) { if (i.Value % 2 == 1) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Linq; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int A, B, C; public void Solve() { var Map = new Dictionary<int, int>(); int N, M; var line = Console.ReadLine().Split(' '); N = int.Parse(line[0]); M = int.Parse(line[1]); for (int i = 0; i < M; i++) { line = Console.ReadLine().Split(' '); int a = int.Parse(line[0]); int b = int.Parse(line[1]); int d; if (!Map.TryGetValue(a, out d)) Map[a] = 0; if (!Map.TryGetValue(b, out d)) Map[b] = 0; Map[a]++; Map[b]++; } foreach (var i in Map) { if (i.Value % 2 == 1) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } }
[["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111]]
8
292
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] a = new int[n[0]]; for (int i = 0; i < n[1]; i++) { int[] s = Read.Ints(); a[s[0]]++; a[s[1]]++; } bool f = true; for (int i = 0; i < n[0]; i++) { if (a[i] % 2 != 0) { f = false; break; } } Console.WriteLine(f ? "YES" : "NO"); } public static Boolean uso() { return false; } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (int i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] Ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] a = new int[n[0]]; for (int i = 0; i < n[1]; i++) { int[] s = Read.Ints(); a[s[0] - 1]++; a[s[1] - 1]++; } bool f = true; for (int i = 0; i < n[0]; i++) { if (a[i] % 2 != 0) { f = false; break; } } Console.WriteLine(f ? "YES" : "NO"); } public static Boolean uso() { return false; } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (int i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] Ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
366
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); int m = sc.nextInt(); int[] ls = new int[n]; for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; ls[a]++; ls[b]++; } int odd = 0; for (int i = 0; i < n; i++) { if (ls[i] % 2 == 1) odd++; } if (odd > 0 || m % 2 == 1) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); int m = sc.nextInt(); int[] ls = new int[n]; for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; ls[a]++; ls[b]++; } int odd = 0; for (int i = 0; i < n; i++) { if (ls[i] % 2 == 1) odd++; } if (odd > 0) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
1,313
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int M = cin.nextInt(); int[] num = new int[N]; for (int i = 0; i < N; i++) { int a = cin.nextInt() - 1; int b = cin.nextInt() - 1; num[a]++; num[b]++; } for (int i = 0; i < N; i++) { if (num[i] % 2 == 1) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int M = cin.nextInt(); int[] num = new int[N]; for (int i = 0; i < M; i++) { int a = cin.nextInt() - 1; int b = cin.nextInt() - 1; num[a]++; num[b]++; } for (int i = 0; i < N; i++) { if (num[i] % 2 == 1) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
380
2
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); int mod = 1000000000 + 7; var dp = new long[n]; dp[0] = n % mod; long sum = n - 1; for (int i = 1; i < n; i++) { long val = 0; // (>=2,>=2) val += 1L * (n - 1) * (n - 1); val %= mod; // (>=2,1...) #if false for (int j = 2; j <= n; j++) { val += (i - j >= 0) ? dp[i - j] : 1; val %= mod; } #else if (i - 2 >= 0) { sum += dp[i - 2]; } else { sum++; } if (i - n - 1 >= 0) { sum += mod - dp[i - n - 1]; } else { sum += mod - 1; } sum %= mod; val += sum; val %= mod; #endif // (1) val += dp[i - 1]; val %= mod; dp[i] = val % mod; } cout.WriteLine(dp[n - 1]); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); int mod = 1000000000 + 7; var dp = new long[n]; dp[0] = n % mod; long sum = n - 1; for (int i = 1; i < n; i++) { long val = 0; // (>=2,>=2) val += 1L * (n - 1) * (n - 1); val %= mod; // (>=2,1...) #if false for (int j = 2; j <= n; j++) { val += (i - j >= 0) ? dp[i - j] : 1; val %= mod; } #else // 2 -> 1 2 2 if (i - 3 >= 0) { sum += dp[i - 3]; } else { sum++; } if (i - n - 2 >= 0) { sum += mod - dp[i - n - 2]; } else { sum += mod - 1; } sum %= mod; val += sum; val %= mod; #endif // (1) val += dp[i - 1]; val %= mod; dp[i] = val % mod; } cout.WriteLine(dp[n - 1]); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
1,151
8
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = ModInteger; using System.Numerics; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var ep = new ModInteger[n + 1]; var cum = new ModInteger[n + 1]; for (int i = 0; i <= n; i++) ep[i].num = -1; ep[0] = 1; ep[1] = n; Func<int, ModInteger> dfs = null; dfs = m => { // Debug.WriteLine(m); if (m < 0) return 1; if (ep[m].num != -1) return ep[m]; ModInteger ret = 0; for (int i = 1; i <= n; i++) { // 1 if (i == 1) ret += dfs(m - i); else ret += dfs(m - i - 1); if (i != 1) ret += n - 1; } return ep[m] = ret; }; dfs(2); // Debug.WriteLine(dfs(n)); ep[0] = 1; ep[1] = n; cum[0] = ep[0]; cum[1] = ep[0] + ep[1]; cum[2] = cum[1] + ep[2]; for (int m = 3; m <= n; m++) { ModInteger ret = 0; ret += ep[m - 1]; ret += cum[m - 3]; ret += n - m + 1; ModInteger val = n - 1; val *= n - 1; ret += val; ep[m] = ret; cum[m] = cum[m - 1] + ep[m]; } // Debug.WriteLine(ep.AsJoinedString()); IO.Printer.Out.WriteLine(ep[n]); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<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; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public 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) return 0; 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) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion #region ModNumber public partial struct ModInteger { public const long Mod = (long)1e9 + 7; public long num; public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; } public override string ToString() { return num.ToString(); } public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); } public static implicit operator ModInteger(long n) { return new ModInteger(n); } public static ModInteger Pow(ModInteger v, long k) { ModInteger ret = 1; var n = k; for (; n > 0; n >>= 1, v *= v) { if ((n & 1) == 1) ret = ret * v; } return ret; } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = ModInteger; using System.Numerics; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var ep = new ModInteger[n + 50]; var cum = new ModInteger[n + 50]; for (int i = 0; i <= n; i++) ep[i].num = -1; ep[0] = 1; ep[1] = n; Func<int, ModInteger> dfs = null; dfs = m => { // Debug.WriteLine(m); if (m < 0) return 1; if (ep[m].num != -1) return ep[m]; ModInteger ret = 0; for (int i = 1; i <= n; i++) { // 1 if (i == 1) ret += dfs(m - i); else ret += dfs(m - i - 1); if (i != 1) ret += n - 1; } return ep[m] = ret; }; dfs(2); // Debug.WriteLine(dfs(n)); ep[0] = 1; ep[1] = n; cum[0] = ep[0]; cum[1] = ep[0] + ep[1]; cum[2] = cum[1] + ep[2]; for (int m = 3; m <= n; m++) { ModInteger ret = 0; ret += ep[m - 1]; ret += cum[m - 3]; ret += n - m + 1; ModInteger val = n - 1; val *= n - 1; ret += val; ep[m] = ret; cum[m] = cum[m - 1] + ep[m]; } // Debug.WriteLine(ep.AsJoinedString()); IO.Printer.Out.WriteLine(ep[n]); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<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; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public 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) return 0; 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) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion #region ModNumber public partial struct ModInteger { public const long Mod = (long)1e9 + 7; public long num; public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; } public override string ToString() { return num.ToString(); } public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); } public static implicit operator ModInteger(long n) { return new ModInteger(n); } public static ModInteger Pow(ModInteger v, long k) { ModInteger ret = 1; var n = k; for (; n > 0; n >>= 1, v *= v) { if ((n & 1) == 1) ret = ret * v; } return ret; } } #endregion
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
1,728
4
using System; using System.Linq; namespace ProgramingStydying { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(long.Parse).ToList(); a.Sort(); long ans = 0; for (int i = n; i < 2 * n; i++) { ans += a[i]; } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace ProgramingStydying { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(long.Parse).ToList(); a.Sort(); long ans = 0; for (int i = n; i < 3 * n; i += 2) { ans += a[i]; } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203]]
8
108
5
using System; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Array.Sort(a); long ans = 0; for (int i = 0; i < n; i++) { ans += a[2 * (n - i)]; } Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Array.Sort(a); long ans = 0; for (int i = 0; i < n; i++) { ans += a[3 * n - 2 * (n - i)]; } Console.WriteLine(ans); } }
[["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33]]
8
112
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ long n; Lib_IO.rm(out n); ll[] a; ra(out a); Array.Sort(a); long ans = 0; for (int i = (int)n; i < 2*n; i++) { ans+=a[i]; } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ long n; Lib_IO.rm(out n); ll[] a; ra(out a); Array.Sort(a); long ans = 0; for (int i = (int)n; i < 3*n; i+=2) { ans+=a[i]; } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 0, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 0, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 0, 287, 0, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 287, 0, 196, 0, 7, 26, 11, 12, 203]]
8
2,942
5
public class Hello { public static void Main() { // Your code here! int n = int.Parse(System.Console.ReadLine()); string[] s = System.Console.ReadLine().Split(' '); long[] a = new long[3 * n]; for (int i = 0; i < n * 3; i++) a[i] = System.Int64.Parse(s[i]); System.Array.Sort(a); long ans = 0; for (int i = 0; i < n; i++) { ans += a[3 * n - 2 - 1 * 2]; } System.Console.WriteLine(ans.ToString()); } }
public class Hello { public static void Main() { // Your code here! int n = int.Parse(System.Console.ReadLine()); string[] s = System.Console.ReadLine().Split(' '); long[] a = new long[3 * n]; for (int i = 0; i < n * 3; i++) a[i] = System.Int64.Parse(s[i]); System.Array.Sort(a); long ans = 0; for (int i = 0; i < n; i++) { ans += a[3 * n - 2 - i * 2]; } System.Console.WriteLine(ans.ToString()); } }
[["-", 206, 207, 0, 28, 0, 16, 12, 16, 31, 203], ["+", 206, 207, 0, 28, 0, 16, 12, 16, 31, 22]]
8
154
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 N = cin.ReadInt; var a = cin.ReadIntArray(3 * N); Array.Sort(a); var ans = 0; for (int i = 0; i < N; i++) { ans += a[3 * N - 2 - (i * 2)]; } WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var N = cin.ReadInt; var a = cin.ReadLongArray(3 * N); Array.Sort(a); long ans = 0; for (int i = 0; i < N; i++) { ans += a[3 * N - 2 - (i * 2)]; } WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
494
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AGC012A { class Program { static void Solve(Input input) { var n = input.NextInt(); var a = input.NextInt(n * 3); Array.Sort(a); int top = a.Length - 1; long sum = 0; for (int i = 0; i < n; i++) { sum += a[top - 1]; top -= 2; } Console.WriteLine(sum); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する static readonly char[] separator = { ' ', '\r', '\n' }; public bool IsEof { get; set; } List<string> q { get; set; } int index; StreamReader sr; public Input(string path = "") { IsEof = false; q = new List<string>(); index = 0; if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; q.AddRange( s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries)); return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; q.AddRange( s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries)); if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (index >= q.Count()) { if (!read()) { IsEof = true; return ""; } index = 0; } return q[index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public string[] Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToArray(); public int[] NextInt(int n, int offset = 0) => Enumerable.Range(0, n) .Select(_ => int.Parse(Next()) + offset) .ToArray(); public long[] NextLong(int n, long offset = 0) => Enumerable.Range(0, n) .Select(_ => long.Parse(Next()) + offset) .ToArray(); public double[] NextDouble(int n, double offset = 0.0) => Enumerable.Range(0, n) .Select(_ => double.Parse(Next()) + offset) .ToArray(); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AGC012A { class Program { static void Solve(Input input) { var n = input.NextInt(); var a = input.NextInt(n * 3); Array.Sort(a); int top = a.Length - 1; long sum = 0; for (int i = 0; i < n; i++) { sum += a[top - 1]; top -= 2; } Console.WriteLine(sum); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する static readonly char[] separator = { ' ', '\r', '\n' }; public bool IsEof { get; set; } List<string> q { get; set; } int index; StreamReader sr; public Input(string path = "") { IsEof = false; q = new List<string>(); index = 0; if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; q.AddRange( s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries)); return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; q.Clear(); q.AddRange( s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries)); if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (index >= q.Count()) { if (!read()) { IsEof = true; return ""; } index = 0; } return q[index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public string[] Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToArray(); public int[] NextInt(int n, int offset = 0) => Enumerable.Range(0, n) .Select(_ => int.Parse(Next()) + offset) .ToArray(); public long[] NextLong(int n, long offset = 0) => Enumerable.Range(0, n) .Select(_ => long.Parse(Next()) + offset) .ToArray(); public double[] NextDouble(int n, double offset = 0.0) => Enumerable.Range(0, n) .Select(_ => double.Parse(Next()) + offset) .ToArray(); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131]]
8
1,085
6
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { var n = ReadInt(); var a = ReadLongArray(); Array.Sort(a); long ans = 0; for (int i = n; i < 2 * n; i++) { ans += a[i]; } WriteAnswer(ans); } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { var n = ReadInt(); var a = ReadLongArray(); Array.Sort(a); long ans = 0; for (int i = n; i < 3 * n; i += 2) { ans += a[i]; } WriteAnswer(ans); } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203]]
8
746
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { long ans = 0; long N = long.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); Array.Sort(a); for (long i = N; i < 2 * N; i++) { ans += a[i]; } Console.WriteLine(ans.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { long ans = 0; long N = long.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); Array.Sort(a); for (long i = N; i < 3 * N - 1; i += 2) { ans += a[i]; } Console.WriteLine(ans.ToString()); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203]]
8
130
7
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { Array.Sort(A); long sum = 0; for (int i = N; i < N + N; i++) sum += A[i]; Console.WriteLine(sum); } int N; long[] A; public Sol() { N = ri(); A = rla(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { Array.Sort(A); long sum = 0; for (int i = N; i < 3 * N; i += 2) { sum += A[i]; } Console.WriteLine(sum); } int N; long[] A; public Sol() { N = ri(); A = rla(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
350
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.AGC_Challenge { class _012_B { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int[] nm = ReadInts(); int n = nm[0]; int m = nm[1]; var graph = new List<int>[n]; for (int i = 0; i < n; i++) { graph[i] = new List<int>(); } for (int i = 0; i < m; i++) { int[] ab = ReadInts(); int a = ab[0] - 1; int b = ab[1] - 1; graph[a].Add(b); graph[b].Add(a); } int q = ReadInt(); int[][] vdcs = new int [q][]; for (int i = 0; i < q; i++) { vdcs[i] = ReadInts(); } var coloredTimes = new int[n, 10]; for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { coloredTimes[i, j] = -1; } } for (int i = q - 1; i >= 0; i--) { int v = vdcs[i][0] - 1; int d = vdcs[i][1]; Queue<int[]> queue = new Queue<int[]>(); queue.Enqueue(new int[2] { v, d }); while (queue.Count > 0) { int[] val = queue.Dequeue(); if (coloredTimes[val[0], val[1]] != -1) continue; for (int j = val[1]; j >= 0; j--) { if (coloredTimes[val[0], j] != -1) break; coloredTimes[val[0], j] = i; } if (val[1] == 0) continue; for (int j = 0; j < graph[val[0]].Count; j++) { queue.Enqueue(new int[2] { graph[val[0]][j], val[1] - 1 }); } } } for (int i = 0; i < n; i++) { if (coloredTimes[i, 0] == -1) { WriteLine(0); } else { WriteLine(vdcs[coloredTimes[i, 0]][2]); } } } private static string Read() { return ReadLine(); } 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.AGC_Challenge { class _012_B { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int[] nm = ReadInts(); int n = nm[0]; int m = nm[1]; var graph = new List<int>[n]; for (int i = 0; i < n; i++) { graph[i] = new List<int>(); } for (int i = 0; i < m; i++) { int[] ab = ReadInts(); int a = ab[0] - 1; int b = ab[1] - 1; graph[a].Add(b); graph[b].Add(a); } int q = ReadInt(); int[][] vdcs = new int [q][]; for (int i = 0; i < q; i++) { vdcs[i] = ReadInts(); } var coloredTimes = new int[n, 11]; for (int i = 0; i < n; i++) { for (int j = 0; j < 11; j++) { coloredTimes[i, j] = -1; } } for (int i = q - 1; i >= 0; i--) { int v = vdcs[i][0] - 1; int d = vdcs[i][1]; Queue<int[]> queue = new Queue<int[]>(); queue.Enqueue(new int[2] { v, d }); while (queue.Count > 0) { int[] val = queue.Dequeue(); if (coloredTimes[val[0], val[1]] != -1) continue; for (int j = val[1]; j >= 0; j--) { if (coloredTimes[val[0], j] != -1) break; coloredTimes[val[0], j] = i; } if (val[1] == 0) continue; for (int j = 0; j < graph[val[0]].Count; j++) { queue.Enqueue(new int[2] { graph[val[0]][j], val[1] - 1 }); } } } for (int i = 0; i < n; i++) { if (coloredTimes[i, 0] == -1) { WriteLine(0); } else { WriteLine(vdcs[coloredTimes[i, 0]][2]); } } } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203]]
8
739
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; // using System.Numerics; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; List<int>[] G; int N, M, Q; int[] v, d, c; int[] A; int[] color; void dfs(int u, int dis, int c) { if (dis <= A[u]) return; A[u] = dis; if (color[u] == 0) color[u] = c; foreach (var v in G[u]) { if (dis - 1 <= A[v]) continue; dfs(v, dis - 1, c); } } void Solve() { N = cin.Nextint; M = cin.Nextint; G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray(); for (int i = 0; i < M; i++) { int a = cin.Nextint - 1; int b = cin.Nextint - 1; G[a].Add(b); G[b].Add(a); } Q = cin.Nextint; v = new int[N]; d = new int[N]; c = new int[N]; for (int i = 0; i < Q; i++) { v[i] = cin.Nextint - 1; d[i] = cin.Nextint; c[i] = cin.Nextint; } A = Enumerable.Repeat(-1, N).ToArray(); color = new int[N]; for (int i = Q - 1; i >= 0; i--) { // dfs(v[i], d[i], c[i]); var X = new Queue<int>(); var Y = new Queue<int>(); X.Enqueue(v[i]); Y.Enqueue(d[i]); while (X.Any()) { int u = X.Dequeue(); int dis = Y.Dequeue(); if (dis <= A[u]) continue; A[u] = dis; if (color[u] == 0) color[u] = c[i]; foreach (var k in G[u]) { X.Enqueue(k); Y.Enqueue(dis - 1); } } } foreach (var k in color) { WriteLine(k); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] Scan { get { return ReadLine().Split(); } } public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } } public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } } public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } } public string Next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next; } } public int Nextint { get { return int.Parse(Next); } } public long Nextlong { get { return long.Parse(Next); } } public double Nextdouble { get { return double.Parse(Next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; // using System.Numerics; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; List<int>[] G; int N, M, Q; int[] v, d, c; int[] A; int[] color; void dfs(int u, int dis, int c) { if (dis <= A[u]) return; A[u] = dis; if (color[u] == 0) color[u] = c; foreach (var v in G[u]) { if (dis - 1 <= A[v]) continue; dfs(v, dis - 1, c); } } void Solve() { N = cin.Nextint; M = cin.Nextint; G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray(); for (int i = 0; i < M; i++) { int a = cin.Nextint - 1; int b = cin.Nextint - 1; G[a].Add(b); G[b].Add(a); } Q = cin.Nextint; v = new int[Q]; d = new int[Q]; c = new int[Q]; for (int i = 0; i < Q; i++) { v[i] = cin.Nextint - 1; d[i] = cin.Nextint; c[i] = cin.Nextint; } A = Enumerable.Repeat(-1, N).ToArray(); color = new int[N]; for (int i = Q - 1; i >= 0; i--) { // dfs(v[i], d[i], c[i]); var X = new Queue<int>(); var Y = new Queue<int>(); X.Enqueue(v[i]); Y.Enqueue(d[i]); while (X.Any()) { int u = X.Dequeue(); int dis = Y.Dequeue(); if (dis <= A[u]) continue; A[u] = dis; if (color[u] == 0) color[u] = c[i]; foreach (var k in G[u]) { X.Enqueue(k); Y.Enqueue(dis - 1); } } } foreach (var k in color) { WriteLine(k); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] Scan { get { return ReadLine().Split(); } } public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } } public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } } public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } } public string Next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next; } } public int Nextint { get { return int.Parse(Next); } } public long Nextlong { get { return long.Parse(Next); } } public double Nextdouble { get { return double.Parse(Next); } } }
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22]]
8
878
6
using System; using System.Collections.Generic; using System.Linq; namespace AGC012 { public class B { private void Run() { var input = Console.ReadLine().Trim().Split(); var N = int.Parse(input[0]); var M = int.Parse(input[1]); var edges = Enumerable.Range(0, N).Select(_ => new List<int>()).ToArray(); while (M-- > 0) { input = Console.ReadLine().Trim().Split(); var a = int.Parse(input[0]) - 1; var b = int.Parse(input[1]) - 1; edges[a].Add(b); edges[b].Add(a); } var Q = int.Parse(Console.ReadLine().Trim()); var queries = new List<Tuple<int, int, int>>(); while (Q-- > 0) { input = Console.ReadLine().Trim().Split(); var v = int.Parse(input[0]) - 1; var d = int.Parse(input[1]); var c = int.Parse(input[2]); queries.Add(Tuple.Create(v, d, c)); } var color = new int[N]; var maxUsedDistance = new int[N]; foreach (var query in queries.AsEnumerable().Reverse()) { var v = query.Item1; var d = query.Item2; var c = query.Item3; var q = new Queue<Tuple<int, int>>(); q.Enqueue(Tuple.Create(v, d)); while (q.Count > 0) { var t = q.Dequeue(); var index = t.Item1; var rest = t.Item2; if (color[index] == 0) { color[index] = c; } if (rest == 0) { continue; } if (maxUsedDistance[index] >= rest) { continue; } maxUsedDistance[index] = rest; foreach (var edge in edges[index]) { if (maxUsedDistance[edge] >= rest - 1) { continue; } q.Enqueue(Tuple.Create(edge, rest - 1)); } } } Console.WriteLine(string.Join(Environment.NewLine, color)); } public static void Main() { var old = Console.Out; using (var writer = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Console.SetOut(writer); new B().Run(); Console.Out.Flush(); Console.SetOut(old); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AGC012 { public class B { private void Run() { var input = Console.ReadLine().Trim().Split(); var N = int.Parse(input[0]); var M = int.Parse(input[1]); var edges = Enumerable.Range(0, N).Select(_ => new List<int>()).ToArray(); while (M-- > 0) { input = Console.ReadLine().Trim().Split(); var a = int.Parse(input[0]) - 1; var b = int.Parse(input[1]) - 1; edges[a].Add(b); edges[b].Add(a); } var Q = int.Parse(Console.ReadLine().Trim()); var queries = new List<Tuple<int, int, int>>(); while (Q-- > 0) { input = Console.ReadLine().Trim().Split(); var v = int.Parse(input[0]) - 1; var d = int.Parse(input[1]); var c = int.Parse(input[2]); queries.Add(Tuple.Create(v, d, c)); } var color = new int[N]; var maxUsedDistance = new int[N]; foreach (var query in queries.AsEnumerable().Reverse()) { var v = query.Item1; var d = query.Item2; var c = query.Item3; var q = new Queue<Tuple<int, int>>(); q.Enqueue(Tuple.Create(v, d)); while (q.Count > 0) { var t = q.Dequeue(); var index = t.Item1; var rest = t.Item2; if (color[index] == 0) { color[index] = c; } if (rest == 0) { continue; } if (maxUsedDistance[index] >= rest) { continue; } maxUsedDistance[index] = rest; foreach (var edge in edges[index]) { if (maxUsedDistance[edge] > rest - 1) { continue; } q.Enqueue(Tuple.Create(edge, rest - 1)); } } } Console.WriteLine(string.Join(Environment.NewLine, color)); } public static void Main() { var old = Console.Out; using (var writer = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Console.SetOut(writer); new B().Run(); Console.Out.Flush(); Console.SetOut(old); } } } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47]]
8
594
2
using System; using System.IO; using System.Collections.Generic; using System.Linq; namespace AtCoder.Contest.A { static class Program { public static void Solve(Scanner cin) { var (a, b) = cin.ReadValue<int, int>(); var ans = (a + b) / 24; Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; namespace AtCoder.Contest.A { static class Program { public static void Solve(Scanner cin) { var (a, b) = cin.ReadValue<int, int>(); var ans = (a + b) % 24; Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109]]
8
2,451
2
using System; namespace ABC_057_A_Csharp_ver { class Program { static void Main(string[] args) { var word = Console.ReadLine().Split(' '); int A = int.Parse(word[0]); int B = int.Parse(word[1]); if (A + B > 24) { Console.WriteLine(A + B - 24); } else { Console.WriteLine(A + B); } Console.ReadKey(); } } }
using System; namespace ABC_057_A_Csharp_ver { class Program { static void Main(string[] args) { var word = Console.ReadLine().Split(' '); int A = int.Parse(word[0]); int B = int.Parse(word[1]); if (A + B >= 24) { Console.WriteLine(A + B - 24); } else { Console.WriteLine(A + B); } Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
103
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var A = inputLongArray[0]; var B = inputLongArray[1]; var ANS = A + B; if (ANS > 24) { ANS -= 24; } Console.WriteLine(ANS); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var A = inputLongArray[0]; var B = inputLongArray[1]; var ANS = A + B; if (ANS >= 24) { ANS -= 24; } Console.WriteLine(ANS.ToString()); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
125
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC057A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = a + b; if (c <= 24) Console.WriteLine(c); else Console.WriteLine(c - 24); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC057A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = a + b; if (c < 24) Console.WriteLine(c); else Console.WriteLine(c - 24); Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
128
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace AtCoder { class Program { static void Main() { var A = ReadIntArray(); if (A[0] + A[1] <= 24) { Console.WriteLine(A[0] + A[1]); } else { Console.WriteLine(A[0] + A[1] - 24); } } //ここからテンプレート // 1行に1入力 private static string ReadString() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(ReadString()); } private static long ReadLong() { return long.Parse(ReadString()); } private static double ReadDouble() { return double.Parse(ReadString()); } // 1行に複数入力(配列で取得) private static string[] ReadStringArray() { return ReadString().Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); } private static int[] ReadIntArray() { return ReadStringArray().Select(int.Parse).ToArray(); } private static long[] ReadLongArray() { return ReadStringArray().Select(long.Parse).ToArray(); } private static double[] ReadDoubleArray() { return ReadStringArray().Select(double.Parse).ToArray(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace AtCoder { class Program { static void Main() { var A = ReadIntArray(); if (A[0] + A[1] < 24) { Console.WriteLine(A[0] + A[1]); } else { Console.WriteLine(A[0] + A[1] - 24); } } //ここからテンプレート // 1行に1入力 private static string ReadString() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(ReadString()); } private static long ReadLong() { return long.Parse(ReadString()); } private static double ReadDouble() { return double.Parse(ReadString()); } // 1行に複数入力(配列で取得) private static string[] ReadStringArray() { return ReadString().Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); } private static int[] ReadIntArray() { return ReadStringArray().Select(int.Parse).ToArray(); } private static long[] ReadLongArray() { return ReadStringArray().Select(long.Parse).ToArray(); } private static double[] ReadDoubleArray() { return ReadStringArray().Select(double.Parse).ToArray(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
281
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var input = ReadInts(); if (input[0] + input[1] > 24) { WriteLine(input[0] + input[1] - 24); } else { WriteLine(input[0] + input[1]); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var input = ReadInts(); if (input[0] + input[1] > 23) { WriteLine(input[0] + input[1] - 24); } else { WriteLine(input[0] + input[1]); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
277
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine(input[0] + input[1] % 24); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine((input[0] + input[1]) % 24); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
95
2
using System; class Program { static void Main(string[] args) { var ab = Console.ReadLine().Split(); Console.WriteLine(int.Parse(ab[0]) + int.Parse(ab[1]) % 24); } }
using System; class Program { static void Main(string[] args) { var ab = Console.ReadLine().Split(); Console.WriteLine((int.Parse(ab[0]) + int.Parse(ab[1])) % 24); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
58
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrrr { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int ans = a + b; Console.WriteLine(ans > 24 ? ans - 24 : ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrrr { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int ans = a + b; Console.WriteLine(ans >= 24 ? ans - 24 : ans); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
112
2
using System; using System.Linq; namespace _057 { class Program { static void Main(string[] args) { // A - Remaining Time var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = line[0]; var b = line[1]; Console.WriteLine(a + b <= 24 ? a + b : a + b - 24); } } }
using System; using System.Linq; namespace _057 { class Program { static void Main(string[] args) { // A - Remaining Time var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = line[0]; var b = line[1]; Console.WriteLine(a + b < 24 ? a + b : a + b - 24); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18]]
8
97
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp38 { class Program { static void Main(string[] args) { string[] time = Console.ReadLine().Split(' '); int a = int.Parse(time[0]); int b = int.Parse(time[1]); int c = a + b; if (c < 24) { Console.WriteLine(c); } else if (c > 24) { int d = c % 24; Console.WriteLine(d); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp38 { class Program { static void Main(string[] args) { string[] time = Console.ReadLine().Split(' '); int a = int.Parse(time[0]); int b = int.Parse(time[1]); int c = a + b; if (c < 24) { Console.WriteLine(c); } else if (c >= 24) { int d = c % 24; Console.WriteLine(d); } } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20]]
8
135
2
// Rextester.Program.Main is the entry point for your code. Don't change it. // Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Your code goes here var input = Console.ReadLine(); var inputs = input.Split(' '); var a = Int32.Parse(inputs[0]); var b = Int32.Parse(inputs[1]); var startTime = a + b; if (startTime >= 24) ; { Console.WriteLine(startTime - 24); return; } Console.WriteLine(startTime); } } }
// Rextester.Program.Main is the entry point for your code. Don't change it. // Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Your code goes here var input = Console.ReadLine(); var inputs = input.Split(' '); var a = Int32.Parse(inputs[0]); var b = Int32.Parse(inputs[1]); var startTime = a + b; if (startTime >= 24) { Console.WriteLine(startTime - 24); return; } Console.WriteLine(startTime); } } }
[["-", 0, 195, 8, 196, 0, 57, 64, 260, 0, 35]]
8
127
1
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class CODEFORCES2 { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var M = NN; var abList = Repeat(0, N).Select(_ => new { a = NN, b = NN }).ToArray(); var cdList = Repeat(0, M).Select(_ => new { c = NN, d = NN }).ToArray(); foreach (var item in abList) { var tgt = -1; var dist = long.MaxValue; for (var i = 0; i < M; i++) { var dista = Abs(item.a - cdList[i].c) + Abs(item.b - cdList[i].d); if (dist > dista) { dist = dista; tgt = i; } } Console.WriteLine(tgt); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static byte[] NNList(long N) => Repeat(0, N).Select(_ => (byte)NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } 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++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class CODEFORCES2 { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var M = NN; var abList = Repeat(0, N).Select(_ => new { a = NN, b = NN }).ToArray(); var cdList = Repeat(0, M).Select(_ => new { c = NN, d = NN }).ToArray(); foreach (var item in abList) { var tgt = -1; var dist = long.MaxValue; for (var i = 0; i < M; i++) { var dista = Abs(item.a - cdList[i].c) + Abs(item.b - cdList[i].d); if (dist > dista) { dist = dista; tgt = i; } } Console.WriteLine(tgt + 1); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static byte[] NNList(long N) => Repeat(0, N).Select(_ => (byte)NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } 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++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,568
2
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); long n = cin.nextLong(); long m = cin.nextLong(); var p = new List<Tuple<long, long>>(); for (long i = 0; i < n; i++) { long a = cin.nextLong(); long b = cin.nextLong(); p.Add(Tuple.Create(a, b)); } var ck = new List<Tuple<long, long>>(); for (long i = 0; i < n; i++) { var c = cin.nextLong(); var d = cin.nextLong(); ck.Add(Tuple.Create(c, d)); } foreach (var pp in p) { long ans = 0; long ii = 1; long i = long.MaxValue; foreach (var c in ck) { long d = Math.Abs(pp.Item1 - c.Item1) + Math.Abs(pp.Item2 - c.Item2); if (d < i) { i = d; ans = ii; } ii++; } Console.WriteLine(ans); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); long n = cin.nextLong(); long m = cin.nextLong(); var p = new List<Tuple<long, long>>(); for (long i = 0; i < n; i++) { long a = cin.nextLong(); long b = cin.nextLong(); p.Add(Tuple.Create(a, b)); } var ck = new List<Tuple<long, long>>(); for (long i = 0; i < m; i++) { var c = cin.nextLong(); var d = cin.nextLong(); ck.Add(Tuple.Create(c, d)); } foreach (var pp in p) { long ans = 0; long ii = 1; long i = long.MaxValue; foreach (var c in ck) { long d = Math.Abs(pp.Item1 - c.Item1) + Math.Abs(pp.Item2 - c.Item2); if (d < i) { i = d; ans = ii; } ii++; } Console.WriteLine(ans); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
775
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int m = sc.NextInt(); Tuple<long, long>[] members = new Tuple<long, long>[n]; Tuple<long, long>[] points = new Tuple<long, long>[m]; for (int i = 0; i < n; i++) { members[i] = Tuple.Create(sc.NextLong(), sc.NextLong()); } for (int i = 0; i < m; i++) { points[i] = Tuple.Create(sc.NextLong(), sc.NextLong()); } for (int i = 0; i < n; i++) { var member = members[i]; long minDist = long.MaxValue; int minPoint = 0; for (int j = 0; j < m; j++) { var point = points[j]; long dist = Math.Abs(member.Item1 + point.Item1) + Math.Abs(member.Item2 + point.Item2); if (dist < minDist) { minDist = dist; minPoint = j + 1; } } Console.WriteLine(minPoint); } } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int m = sc.NextInt(); Tuple<long, long>[] members = new Tuple<long, long>[n]; Tuple<long, long>[] points = new Tuple<long, long>[m]; for (int i = 0; i < n; i++) { members[i] = Tuple.Create(sc.NextLong(), sc.NextLong()); } for (int i = 0; i < m; i++) { points[i] = Tuple.Create(sc.NextLong(), sc.NextLong()); } for (int i = 0; i < n; i++) { var member = members[i]; long minDist = long.MaxValue; int minPoint = 0; for (int j = 0; j < m; j++) { var point = points[j]; long dist = Math.Abs(member.Item1 - point.Item1) + Math.Abs(member.Item2 - point.Item2); if (dist < minDist) { minDist = dist; minPoint = j + 1; } } Console.WriteLine(minPoint); } } 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(); } }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
584
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp7 { class Program { static void Main(string[] args) { int[] param = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int studentNum = param[0]; int checkPointNum = param[1]; List<List<int>> student = new List<List<int>>(); List<List<int>> checkPoint = new List<List<int>>(); for (int index = 0; index < studentNum; index++) { student.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToList()); } for (int index = 0; index < studentNum; index++) { checkPoint.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToList()); } // search most near check point foreach (var s in student) { var distances = checkPoint.Select(v => Math.Abs(v[0] - s[0]) + Math.Abs(v[1] - s[1])) .ToList(); Console.WriteLine(1 + distances.IndexOf(distances.Min())); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp7 { class Program { static void Main(string[] args) { int[] param = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int studentNum = param[0]; int checkPointNum = param[1]; List<List<int>> student = new List<List<int>>(); List<List<int>> checkPoint = new List<List<int>>(); for (int index = 0; index < studentNum; index++) { student.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToList()); } for (int index = 0; index < checkPointNum; index++) { checkPoint.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToList()); } // search most near check point foreach (var s in student) { var distances = checkPoint.Select(v => Math.Abs(v[0] - s[0]) + Math.Abs(v[1] - s[1])) .ToList(); Console.WriteLine(1 + distances.IndexOf(distances.Min())); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
293
2
using System; namespace ABC057_B { class Program { static void Main(string[] args) { var sss = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = sss[0]; var M = sss[1]; var x = new int[N]; var y = new int[N]; var px = new int[M]; var py = new int[M]; var ans = new int[N]; for (var i = 0; i < N; i++) { var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); x[i] = xy[0]; y[i] = xy[1]; } for (var i = 0; i < M; i++) { var point = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); px[i] = point[0]; py[i] = point[1]; } for (var i = 0; i < N; i++) { var min = 30000000; for (var j = M - 1; j >= 0; j--) { var dist = Math.Abs(x[i] - px[j]) + Math.Abs(y[i] - py[j]); if (dist <= min) { min = dist; ans[i] = j + 1; } } } foreach (var ch in ans) { Console.WriteLine(ch); } } } }
using System; namespace ABC057_B { class Program { static void Main(string[] args) { var sss = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = sss[0]; var M = sss[1]; var x = new int[N]; var y = new int[N]; var px = new int[M]; var py = new int[M]; var ans = new int[N]; for (var i = 0; i < N; i++) { var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); x[i] = xy[0]; y[i] = xy[1]; } for (var i = 0; i < M; i++) { var point = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); px[i] = point[0]; py[i] = point[1]; } for (var i = 0; i < N; i++) { var min = 900000000; for (var j = M - 1; j >= 0; j--) { var dist = Math.Abs(x[i] - px[j]) + Math.Abs(y[i] - py[j]); if (dist <= min) { min = dist; ans[i] = j + 1; } } } foreach (var ch in ans) { Console.WriteLine(ch); } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
339
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string[] buf = Console.ReadLine().Split(' '); int N = int.Parse(buf[0]); int M = int.Parse(buf[1]); int mcp = 0; int min = 99999999; int[] pX = new int[N]; int[] pY = new int[N]; for (int i = 0; i < N; i++) { buf = Console.ReadLine().Split(' '); pX[i] = int.Parse(buf[0]); pY[i] = int.Parse(buf[1]); } int[] cX = new int[M]; int[] cY = new int[M]; for (int i = 0; i < M; i++) { buf = Console.ReadLine().Split(' '); cX[i] = int.Parse(buf[0]); cY[i] = int.Parse(buf[1]); } for (int i = 0; i < N; i++) { min = 99999999; mcp = 0; for (int j = 0; j < M; j++) { int kyori = Math.Abs(pX[i] - cX[j]) + Math.Abs(pY[i] - cY[j]); if (kyori < min) { min = kyori; mcp = j + 1; } } Console.WriteLine(mcp); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string[] buf = Console.ReadLine().Split(' '); int N = int.Parse(buf[0]); int M = int.Parse(buf[1]); int mcp = 0; int min = 999999999; int[] pX = new int[N]; int[] pY = new int[N]; for (int i = 0; i < N; i++) { buf = Console.ReadLine().Split(' '); pX[i] = int.Parse(buf[0]); pY[i] = int.Parse(buf[1]); } int[] cX = new int[M]; int[] cY = new int[M]; for (int i = 0; i < M; i++) { buf = Console.ReadLine().Split(' '); cX[i] = int.Parse(buf[0]); cY[i] = int.Parse(buf[1]); } for (int i = 0; i < N; i++) { min = 999999999; mcp = 0; for (int j = 0; j < M; j++) { int kyori = Math.Abs(pX[i] - cX[j]) + Math.Abs(pY[i] - cY[j]); if (kyori < min) { min = kyori; mcp = j + 1; } } Console.WriteLine(mcp); } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
359
4
using System; public class P { public int x { get; set; } public int y { get; set; } } public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var std = new P[n]; var cp = new P[m]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); std[i] = new P { x = a, y = b }; } for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); var c = int.Parse(line[0]); var d = int.Parse(line[1]); cp[i] = new P { x = c, y = d }; } for (int i = 0; i < n; i++) Console.WriteLine(getCp(cp, std[i]) + 1); } public static int getCp(P[] cp, P a) { var ret = 999999999; var reti = -1; for (int i = 0; i < cp.Length; i++) { var w = Math.Abs(a.x - cp[i].x) + Math.Abs(a.y - cp[i].y); if (w < ret) { ret = w; reti = i; } } return reti; } }
using System; public class P { public int x { get; set; } public int y { get; set; } } public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var std = new P[n]; var cp = new P[m]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); std[i] = new P { x = a, y = b }; } for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var c = int.Parse(line[0]); var d = int.Parse(line[1]); cp[i] = new P { x = c, y = d }; } for (int i = 0; i < n; i++) Console.WriteLine(getCp(cp, std[i]) + 1); } public static int getCp(P[] cp, P a) { var ret = 999999999; var reti = -1; for (int i = 0; i < cp.Length; i++) { var w = Math.Abs(a.x - cp[i].x) + Math.Abs(a.y - cp[i].y); if (w < ret) { ret = w; reti = i; } } return reti; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
390
2
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { int[] n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int N = n[0]; int M = n[1]; int[,] st = new int[N, 2]; for (int i = 0; i < N; i++) { n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); st[i, 0] = n[0]; st[i, 1] = n[1]; } int[,] points = new int[M, 2]; for (int i = 0; i < M; i++) { n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); points[i, 0] = n[0]; points[i, 1] = n[1]; } int add = 0; int min = 10000000; int box = 0; for (int i = 0; i < N; i++) { min = 10000000; add = 0; for (int j = 0; j < M; j++) { box = Math.Abs(st[i, 0] - points[j, 0]) + Math.Abs(st[i, 1] - points[j, 1]); if (min > box) { min = box; add = j + 1; } } Console.WriteLine(add); } } }
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { int[] n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int N = n[0]; int M = n[1]; int[,] st = new int[N, 2]; for (int i = 0; i < N; i++) { n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); st[i, 0] = n[0]; st[i, 1] = n[1]; } int[,] points = new int[M, 2]; for (int i = 0; i < M; i++) { n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); points[i, 0] = n[0]; points[i, 1] = n[1]; } int add = 0; int min = 2147483647; int box = 0; for (int i = 0; i < N; i++) { min = 2147483647; add = 0; for (int j = 0; j < M; j++) { box = Math.Abs(st[i, 0] - points[j, 0]) + Math.Abs(st[i, 1] - points[j, 1]); if (min > box) { min = box; add = j + 1; } } Console.WriteLine(add); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
368
4
using System; using System.Linq; namespace _057 { class Program { static void Main(string[] args) { // B - Checkpoints var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = line[0]; var m = line[1]; var ab = new long[n, 2]; var cd = new long[m, 2]; var ans = new int[n]; for (int i = 0; i < n; i++) { var line2 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); ab[i, 0] = line2[0]; ab[i, 1] = line2[1]; } for (int i = 0; i < m; i++) { var line2 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); cd[i, 0] = line2[0]; cd[i, 1] = line2[1]; } for (int i = 0; i < n; i++) { long min = 100000000; for (int j = 0; j < m; j++) { var w = Math.Abs(ab[i, 0] - cd[j, 0]) + Math.Abs(ab[i, 1] - cd[j, 1]); if (w < min) { min = w; ans[i] = j; } } } for (int i = 0; i < n; i++) { Console.WriteLine(ans[i] + 1); } } } }
using System; using System.Linq; namespace _057 { class Program { static void Main(string[] args) { // B - Checkpoints var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = line[0]; var m = line[1]; var ab = new long[n, 2]; var cd = new long[m, 2]; var ans = new int[n]; for (int i = 0; i < n; i++) { var line2 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); ab[i, 0] = line2[0]; ab[i, 1] = line2[1]; } for (int i = 0; i < m; i++) { var line2 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); cd[i, 0] = line2[0]; cd[i, 1] = line2[1]; } for (int i = 0; i < n; i++) { long min = 10000000000; for (int j = 0; j < m; j++) { var w = Math.Abs(ab[i, 0] - cd[j, 0]) + Math.Abs(ab[i, 1] - cd[j, 1]); if (w < min) { min = w; ans[i] = j; } } } for (int i = 0; i < n; i++) { Console.WriteLine(ans[i] + 1); } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
376
2
using System; using System.Collections.Generic; namespace atcode { class MainClass { class Point { public int x; public int y; public Point() { x = 0; y = 0; } public double getDistTo(Point p) { return (Math.Abs(x - p.x) + Math.Abs(y - p.y)); } }; static void Main(string[] args) { string[] firstLine = Console.ReadLine().Split(' '); int studentNum = int.Parse(firstLine[0]); int checkPointNum = int.Parse(firstLine[1]); if (studentNum < 1 || checkPointNum < 1) return; if (studentNum > 50 || checkPointNum > 50) return; List<Point> studentPoints = new List<Point>(); List<Point> checkPoints = new List<Point>(); for (int i = 0; i < studentNum; i++) { string[] line = Console.ReadLine().Split(' '); Point p = new Point(); p.x = int.Parse(line[0]); p.y = int.Parse(line[1]); studentPoints.Add(p); } for (int i = 0; i < checkPointNum; i++) { string[] line = Console.ReadLine().Split(' '); Point p = new Point(); p.x = int.Parse(line[0]); p.y = int.Parse(line[1]); checkPoints.Add(p); } foreach (Point p in studentPoints) { double minDist = double.MaxValue; int minDistIndex = 1; int index = 1; foreach (Point p2 in checkPoints) { double dist = p.getDistTo(p2); if (dist < minDist) { minDist = dist; minDistIndex = index; } index++; } Console.WriteLine(minDist.ToString()); } } } }
using System; using System.Collections.Generic; namespace atcode { class MainClass { class Point { public int x; public int y; public Point() { x = 0; y = 0; } public double getDistTo(Point p) { return (Math.Abs(x - p.x) + Math.Abs(y - p.y)); } }; static void Main(string[] args) { string[] firstLine = Console.ReadLine().Split(' '); int studentNum = int.Parse(firstLine[0]); int checkPointNum = int.Parse(firstLine[1]); if (studentNum < 1 || checkPointNum < 1) return; if (studentNum > 50 || checkPointNum > 50) return; List<Point> studentPoints = new List<Point>(); List<Point> checkPoints = new List<Point>(); for (int i = 0; i < studentNum; i++) { string[] line = Console.ReadLine().Split(' '); Point p = new Point(); p.x = int.Parse(line[0]); p.y = int.Parse(line[1]); studentPoints.Add(p); } for (int i = 0; i < checkPointNum; i++) { string[] line = Console.ReadLine().Split(' '); Point p = new Point(); p.x = int.Parse(line[0]); p.y = int.Parse(line[1]); checkPoints.Add(p); } foreach (Point p in studentPoints) { double minDist = double.MaxValue; int minDistIndex = 1; int index = 1; foreach (Point p2 in checkPoints) { double dist = p.getDistTo(p2); if (dist < minDist) { minDist = dist; minDistIndex = index; } index++; } Console.WriteLine(minDistIndex.ToString()); } } } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
415
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { for (int i = 0; i < N; i++) { int min = (int)1e9; int idx = -1; for (int j = 0; j < M; j++) { if (Dist(A[i], B[i], C[j], D[j]) < min) { min = Dist(A[i], B[i], C[j], D[j]); idx = j; } } Console.WriteLine(idx + 1); } } static int Dist(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } int N, M; int[] A, B, C, D; public Sol() { var d = ria(); N = d[0]; M = d[1]; A = new int[N]; B = new int[N]; for (int i = 0; i < N; i++) { d = ria(); A[i] = d[0]; B[i] = d[1]; } C = new int[N]; D = new int[N]; for (int i = 0; i < M; i++) { d = ria(); C[i] = d[0]; D[i] = d[1]; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { for (int i = 0; i < N; i++) { int min = (int)1e9; int idx = -1; for (int j = 0; j < M; j++) { if (Dist(A[i], B[i], C[j], D[j]) < min) { min = Dist(A[i], B[i], C[j], D[j]); idx = j; } } Console.WriteLine(idx + 1); } } static int Dist(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } int N, M; int[] A, B, C, D; public Sol() { var d = ria(); N = d[0]; M = d[1]; A = new int[N]; B = new int[N]; for (int i = 0; i < N; i++) { d = ria(); A[i] = d[0]; B[i] = d[1]; } C = new int[M]; D = new int[M]; for (int i = 0; i < M; i++) { d = ria(); C[i] = d[0]; D[i] = d[1]; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22]]
8
591
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0031 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); double pN = Math.Sqrt((double)N); long result = long.MaxValue; for (long i = 1; i < pN; i++) { if (N % i == 0) { long tmp = 0; var n = N / i; if (n.ToString().Length <= i.ToString().Length) { tmp = i.ToString().Length; } else { tmp = n.ToString().Length; } if (result > tmp) { result = tmp; } } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0031 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); double pN = Math.Sqrt((double)N); long result = long.MaxValue; for (long i = 1; i <= pN; i++) { if (N % i == 0) { long tmp = 0; var n = N / i; if (n.ToString().Length <= i.ToString().Length) { tmp = i.ToString().Length; } else { tmp = n.ToString().Length; } if (result > tmp) { result = tmp; } } } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
180
2
using System; namespace ProgramingStydying { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var ans = 20; for (long a = 1; a < Math.Sqrt(n); a++) { if (n % a != 0) { continue; } else { var b = n / a; if (F(a, b) < ans) { ans = F(a, b); } } } Console.WriteLine(ans); } public static int F(long a, long b) { return Math.Max(DigitFinder(a), DigitFinder(b)); } public static int DigitFinder(long x) { var digit = 0; while (x > 0) { x /= 10; digit++; } return digit; } } }
using System; namespace ProgramingStydying { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var ans = 20; for (long a = 1; a <= Math.Sqrt(n); a++) { if (n % a != 0) { continue; } else { var b = n / a; if (F(a, b) < ans) { ans = F(a, b); } } } Console.WriteLine(ans); } public static int F(long a, long b) { return Math.Max(DigitFinder(a), DigitFinder(b)); } public static int DigitFinder(long x) { var digit = 0; while (x > 0) { x /= 10; digit++; } return digit; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
175
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 N = cin.ReadLong; var ans = long.MaxValue; for (long i = 1; i * i < N; i++) { if (N % i == 0) { var f = Max(i.ToString().Length, (N / i).ToString().Length); if (f < ans) ans = f; } } WriteLine(ans); } } 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; } } struct ModInt { const int M = 1000000007; public long V; public ModInt(long v) { V = (v %= M) < 0 ? v + M : v; } public static implicit operator ModInt(long v) => new ModInt(v); public static ModInt operator +(ModInt x) => x; public static ModInt operator -(ModInt x) => -x.V; public static ModInt operator +(ModInt x, ModInt y) => x.V + y.V; public static ModInt operator -(ModInt x, ModInt y) => x.V - y.V; public static ModInt operator *(ModInt x, ModInt y) => x.V * y.V; public static ModInt operator /(ModInt x, ModInt y) => x.V * y.Inv(); public ModInt Pow(int i) => MPow(V, i); public ModInt Inv() => MPow(V, M - 2); public override string ToString() => $"{V}"; static long MPow(long b, int i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } public static long MFactorial(int n) { for (long x = 1, i = 1;; x = x * ++i % M) if (i >= n) return x; } public static long MNpr(int n, int r) { if (n < r) return 0; for (long x = 1, i = n - r;; x = x * ++i % M) if (i >= n) return x; } public static ModInt MNcr(int n, int r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (ModInt)MNpr(n, r) / MFactorial(r); } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var ans = long.MaxValue; for (long i = 1; i * i <= N; i++) { if (N % i == 0) { var f = Max(i.ToString().Length, (N / i).ToString().Length); if (f < ans) ans = f; } } WriteLine(ans); } } 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; } } struct ModInt { const int M = 1000000007; public long V; public ModInt(long v) { V = (v %= M) < 0 ? v + M : v; } public static implicit operator ModInt(long v) => new ModInt(v); public static ModInt operator +(ModInt x) => x; public static ModInt operator -(ModInt x) => -x.V; public static ModInt operator +(ModInt x, ModInt y) => x.V + y.V; public static ModInt operator -(ModInt x, ModInt y) => x.V - y.V; public static ModInt operator *(ModInt x, ModInt y) => x.V * y.V; public static ModInt operator /(ModInt x, ModInt y) => x.V * y.Inv(); public ModInt Pow(int i) => MPow(V, i); public ModInt Inv() => MPow(V, M - 2); public override string ToString() => $"{V}"; static long MPow(long b, int i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } public static long MFactorial(int n) { for (long x = 1, i = 1;; x = x * ++i % M) if (i >= n) return x; } public static long MNpr(int n, int r) { if (n < r) return 0; for (long x = 1, i = n - r;; x = x * ++i % M) if (i >= n) return x; } public static ModInt MNcr(int n, int r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (ModInt)MNpr(n, r) / MFactorial(r); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
918
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static List<long[]> list = new List<long[]>(); public static void Answer() { long N = IO.RLong; var last = list.Last(); int a1 = Keta(last[0]); int a2 = Keta(last[1]); WriteLine(Max(a2, a1)); } public static void Yakusu(long N) { for (int i = 1; i <= Sqrt(N); i++) { if (N % i == 0) list.Add(new long[] { i, N / i }); } } public static int Keta(long N) { int cnt = 1; while (true) { N /= 10; if (N != 0) cnt++; else break; } return cnt; } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static List<long[]> list = new List<long[]>(); public static void Answer() { long N = IO.RLong; Yakusu(N); var last = list.Last(); int a1 = Keta(last[0]); int a2 = Keta(last[1]); WriteLine(Max(a2, a1)); } public static void Yakusu(long N) { for (int i = 1; i <= Sqrt(N); i++) { if (N % i == 0) list.Add(new long[] { i, N / i }); } } public static int Keta(long N) { int cnt = 1; while (true) { N /= 10; if (N != 0) cnt++; else break; } return cnt; } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
626
5
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { public static void Main() { long read = rlong(); double root = Sqrt((double)read); long max = 1; for (int i = 1; i < root; i++) { if (read % i == 0) { max = i; } } max = Max(max, read / max); int ans = 0; while (max > 0) { max /= 10; ans++; } WriteLine(ans); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // A/B小数点以下切上 static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // スタック -> 深さ優先 ???
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { public static void Main() { long read = rlong(); double root = Sqrt((double)read); long max = 1; for (int i = 1; i <= root; i++) { if (read % i == 0) { max = i; } } max = Max(max, read / max); int ans = 0; while (max > 0) { max /= 10; ans++; } WriteLine(ans); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // A/B小数点以下切上 static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // スタック -> 深さ優先 ???
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
657
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { long N = int.Parse(Console.ReadLine()); long A = 1; long i = 1; while (i <= N / i) { if (N % i == 0) { A = i; } i++; } long B = N / A; long judger = B / 10; long counter = 1; while (judger > 0) { judger = judger / 10; counter++; } Console.WriteLine(counter); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long A = 1; long i = 1; while (i <= N / i) { if (N % i == 0) { A = i; } i++; } long B = N / A; long judger = B / 10; long counter = 1; while (judger > 0) { judger = judger / 10; counter++; } Console.WriteLine(counter); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
140
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { readonly static long mod = 1000000000 + 7; static void Main(string[] args) { long n = long.Parse(ReadLine()); var ans = Digits(n); for (int i = 2; i < (int)Sqrt(n); i++) { if (n % i == 0) { ans = Min(ans, Digits(n / i)); } } WriteLine(ans); } static int Digits(long a) { return (a == 0) ? 1 : ((int)Log10(a) + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { readonly static long mod = 1000000000 + 7; static void Main(string[] args) { long n = long.Parse(ReadLine()); var ans = Digits(n); for (int i = 1; i <= (int)Sqrt(n); i++) { if (n % i == 0) { ans = Min(ans, Digits(n / i)); } } WriteLine(ans); } static int Digits(long a) { return (a == 0) ? 1 : ((int)Log10(a) + 1); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
166
4
using System; namespace ABC057 { class C { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long min = long.MaxValue; long B = 0; for (long i = 1; i < Math.Sqrt(N); i++) { if (N % i == 0) { B = N / i; min = Math.Min(min, CalculateTheNumberOfRows(B)); } } Console.WriteLine(min); } static long CalculateTheNumberOfRows(long x) { long count = 0; while (0 < x) { x /= 10; count++; } return count; } } }
using System; namespace ABC057 { class C { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long min = long.MaxValue; long B = 0; for (long i = 1; i <= Math.Sqrt(N); i++) { if (N % i == 0) { B = N / i; min = Math.Min(min, CalculateTheNumberOfRows(B)); } } Console.WriteLine(min); } static long CalculateTheNumberOfRows(long x) { long count = 0; while (0 < x) { x /= 10; count++; } return count; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
138
2
using System; class Program { static void Main(string[] args) { ulong N = ulong.Parse(Console.ReadLine()); ulong A = 1; for (ulong i = 1; i < Math.Sqrt(N); i++) { if (N % i == 0) { A = i; } } Console.WriteLine((N / A).ToString().Length); } }
using System; class Program { static void Main(string[] args) { ulong N = ulong.Parse(Console.ReadLine()); ulong A = 1; for (ulong i = 1; i * i <= N; i++) { if (N % i == 0) { A = i; } } Console.WriteLine((N / A).ToString().Length); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25]]
8
89
9
using System; class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var ans = long.MaxValue; for (long i = 1; i * i < n; i++) { if (n % i == 0) { ans = Math.Min(ans, Math.Max(f(i), f(n / i))); } } Console.WriteLine(ans); } static long f(long x) { var ans = 0; while (x != 0) { ans++; x /= 10; } return ans; } }
using System; class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var ans = long.MaxValue; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ans = Math.Min(ans, Math.Max(f(i), f(n / i))); } } Console.WriteLine(ans); } static long f(long x) { var ans = 0; while (x != 0) { ans++; x /= 10; } return ans; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
132
2
using System; namespace ABC057_C { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var min = int.MaxValue; for (long i = 1; i * i < N; i++) { if (N % i != 0) continue; var B = N / i; var F = Math.Max(i.ToString().Length, B.ToString().Length); min = Math.Min(min, F); } Console.WriteLine(min); } } }
using System; namespace ABC057_C { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var min = int.MaxValue; for (long i = 1; i * i <= N; i++) { if (N % i != 0) continue; var B = N / i; var F = Math.Max(i.ToString().Length, B.ToString().Length); min = Math.Min(min, F); } Console.WriteLine(min); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
120
2
using System; namespace ABC057_C_Digits_in_Multiplication { internal class Program { public static void Main(string[] args) { long n = long.Parse(Console.ReadLine()); long a; long b; int resultLength = n.ToString().Length; for (long i = 1; i < Math.Sqrt(n); i++) { if (n % i == 0) { a = i; b = n / i; int length; if (a.ToString().Length <= b.ToString().Length) length = b.ToString().Length; else length = a.ToString().Length; if (resultLength > length) resultLength = length; } } Console.WriteLine(resultLength); } } }
using System; namespace ABC057_C_Digits_in_Multiplication { internal class Program { public static void Main(string[] args) { long n = long.Parse(Console.ReadLine()); long a; long b; int resultLength = n.ToString().Length; for (long i = 1; i <= Math.Sqrt(n); i++) { if (n % i == 0) { a = i; b = n / i; int length; if (a.ToString().Length <= b.ToString().Length) length = b.ToString().Length; else length = a.ToString().Length; if (resultLength > length) resultLength = length; } } Console.WriteLine(resultLength); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
155
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static List<int[]> list = new List<int[]>(); static int[] yMove = new int[] { -1, 1, 0, 0 }; static int[] xMove = new int[] { 0, 0, -1, 1 }; static bool[,] miz; static int cnt = 0; static long abs = int.MaxValue; static long _A = 0; static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; // var N = int.Parse(Console.ReadLine()); // char[] mozi = new char[N]; // long[] MARCH = new long[5]; // long cnt = 0; // for (int i = 0; i < N; i++) //{ // mozi[i] = Console.ReadLine().ToCharArray()[0]; //} // MARCH[0] = mozi.Where(n => n == 'M').Count(); // MARCH[1] = mozi.Where(n => n == 'A').Count(); // MARCH[2] = mozi.Where(n => n == 'R').Count(); // MARCH[3] = mozi.Where(n => n == 'C').Count(); // MARCH[4] = mozi.Where(n => n == 'H').Count(); // for (int i = 0; i < 3; i++) //{ // for (int j = i + 1; j < 4; j++) // { // for (int k = j + 1; k < 5; k++) // { // cnt += MARCH[i] * MARCH[j] * MARCH[k]; // } // } //} // Console.WriteLine(cnt); // var N = int.Parse(Console.ReadLine()); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int candy = 0; // int MAX = 0; // for (int i = 0; i < N; i++) //{ // for (int k = 0; k <= i; k++) // { // candy += line1[k]; // } // for (int j = N - 1; j >= i; j--) // { // candy += line2[j]; // } // MAX = Math.Max(candy,MAX); // candy = 0; //} // Console.WriteLine(MAX); // var N = int.Parse(Console.ReadLine()); // List<int[]> list = new List<int[]>(); // int t = 0; // int x = 0; // int y = 0; // for (int i = 0; i < N; i++) //{ // var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // list.Add(txy); //} // foreach (var item in list) //{ // if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) // { // if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 1) || // ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 0)) // { // t = item[0]; // x = item[1]; // y = item[2]; // } // else // { // Console.WriteLine("No"); // return; // } // } // else // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // if (line1[1] >= 10000) //{ // for (int i = 0; i <= line1[1]/10000; i++) // { // for (int j = 0; j <= line1[1] / 5000; j++) // { // if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 == // line1[1] && line1[0] - i - j >= 0) // { // Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j); // return; // } // } // } //} // else //{ // for (int i = 0; i < 2; i++) // { // for (int j = 0; j <= 9; j++) // { // if (5000 * i + 1000 * j == line1[1] && i + j == line1[0]) // { // Console.WriteLine("{0} {1} {2}", 0, i, j); // return; // } // } // } //} // Console.WriteLine("{0} {1} {2}", -1, -1, -1); // var N = int.Parse(Console.ReadLine()); // int[,] station = new int[N,3]; // long sum = 0; // for (int i = 0; i < N - 1; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // station[i, 0] = line[0]; // station[i, 1] = line[1]; // station[i, 2] = line[2]; //} // for (int j = 0; j < N -1; j++) //{ // for (int i = j; i < N - 1; i++) // { // var F = station[i, 2]; // var S = station[i, 1]; // if (i == j) // { // sum += station[i, 0] + station[i, 1]; // } // else // { // if (sum < S) // { // sum = S + station[i, 0]; // } // else if (sum % F == 0) // { // sum += station[i, 0]; // } // else // { // sum += F - (sum % F) + station[i, 0]; // } // } // } // Console.WriteLine(sum); // sum = 0; //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long A = line[0]; // int i = 0; // while (A <= line[1]) //{ // A *=2; // i++; //} // Console.WriteLine(i); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // Dictionary<long, long> dic = new Dictionary<long, long>(); // long sum = 0; // for (int i = 0; i < N; i++) //{ // if (dic.ContainsKey(line[i])) // { // dic[line[i]]++; // } // else // { // dic.Add(line[i], 1); // } //} // foreach (var item in dic) //{ // if (item.Key == item.Value) // { // } // else if (item.Key < item.Value) // { // sum += item.Value - item.Key; // } // else // { // sum += item.Value; // } //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // var N = line[0]; // var K = line[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long cnt = 0; // long sum = 0; // long[] lngarray = new long[N]; // for (int i = 0; i < N; i++) //{ // lngarray[line2[i]-1]++; //} // if (lngarray.Where(n => n !=0).Count() <= K) //{ // Console.WriteLine(0); // return; //} // var orderlng = lngarray.Where(n => n != 0).OrderBy(n => n).ToArray(); // for (int i = 0; i < orderlng.Length; i++) //{ // if (cnt == orderlng.Length - K) // { // Console.WriteLine(sum); // return; // } // else // { // sum += orderlng[i]; // cnt++; // } //} // int soe = 0; // saiki(soe, new int[10]); // var N = int.Parse(Console.ReadLine()); // var F = new List<int[]>(); // var P = new List<int[]>(); // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // F.Add(line); //} // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // P.Add(line); //} // int sum = int.MinValue; // list.RemoveAt(0); // foreach (var item in list) //{ // int tmpsum = 0; // for (int i = 0; i < N; i++) // { // int c = 0; // for (int j = 0; j < 10; j++) // { // if (item[j] == 1 && F[i][j] == 1) // { // c++; // } // } // tmpsum += P[i][c]; // } // sum = Math.Max(sum, tmpsum); //} // Console.WriteLine(sum); // var line = Console.ReadLine().ToCharArray(); // int[] hai = new int[7]; // hai[0] = int.Parse(line[0].ToString()); // hai[2] = int.Parse(line[1].ToString()); // hai[4] = int.Parse(line[2].ToString()); // hai[6] = int.Parse(line[3].ToString()); // saikiseven(1,0, hai); // string ope1 = list[0][1] == 0 ? "+" : "-"; // string ope2 = list[0][3] == 0 ? "+" : "-"; // string ope3 = list[0][5] == 0 ? "+" : "-"; // Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7", list[0][0],ope1, list[0][2], // ope2,list[0][4], ope3,list[0][6]); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long[] A = new long[N]; // for (int i = 0; i < N; i++) //{ // A[i] = Math.Abs(i - (N - i -1)); //} // var tmp1 = line.OrderBy(n => n).ToArray(); // var tmp2 = A.OrderBy(n => n).ToArray(); // for (int i = 0; i < N; i++) //{ // if (tmp1[i] != tmp2[i]) // { // Console.WriteLine(0); // return; // } //} // long X = 1; // for (int i = 0; i < N/2; i++) //{ // X *= 2; // X %= 1000000007; //} // Console.WriteLine(X); // var line =Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var sx = line[0]; // var sy = line[1]; // var tx = line[2]; // var ty = line[3]; // var path1 = new string('U', ty - sy) + new string('R',tx - sx); // var path2 = new string('D', ty - sy) + new string('L', tx - sx); // var path3 = new string('L', 1) + new string('U', ty - sy + 1) + new // string('R', tx - sx + 1) + new string('D', 1); var path4 = new string('R', // 1) + new string('D', ty - sy + 1) + new string('L', tx - sx + 1) + new // string('U', 1); Console.WriteLine(path1 + path2 + path3 + path4); int[] // sosuu = new int[1000]; // var N = int.Parse(Console.ReadLine()); // int[] sosuu = new int[1001]; // long ans = 1; // for (int i = 1; i < N + 1; i++) //{ // PrimeFactors(i, sosuu); //} // for (int i = 2; i < N + 1; i++) //{ // ans *= sosuu[i] + 1; // ans %= 1000000007; //} // Console.WriteLine(ans); // var N = long.Parse(Console.ReadLine()); // long X = 0; // long Y = 0; // X = N / 11; // if ((N - (11 * X)) == 0) //{ // Y = 0; //} // else if ((N - (11 * X)) <= 6) //{ // Y = 1; //} // else //{ // Y = 2; //} // Console.WriteLine(X * 2 + Y); // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var N = line[0]; // var M = line[1]; // int[,] RL = new int[N, N]; // for (int i = 0; i < M; i++) //{ // var tmp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // RL[tmp[0]-1, tmp[1]-1] = 1; // RL[tmp[1]-1, tmp[0]-1] = 1; //} // bool[] visit = new bool[N]; // DFSgraph(RL,visit,0); // Console.WriteLine(cnt); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line[0]; // var M = line[1]; // if (N * 2 < M) //{ // Console.WriteLine(N + (M - 2 * N) /4); //} // else //{ // Console.WriteLine(M/2); //} // var N = int.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int[,] dp = new int[N + 1, 10001]; ////for (int i = 0; i < N; i++) ////{ //// dp[0, line[0]] = line[i]; ////} // for (int i = 0; i < N; i++) //{ // for (int j = 0; j < 10001; j++) // { // dp[i + 1, line[i]] = line[i]; // if (dp[i,j] != 0) // { // dp[i + 1, j] = dp[i, j]; // dp[i + 1, dp[i, j] + line[i]] = line[i] + dp[i, j]; // } // } //} // long ans = 0; // for (int i = 0; i < 10001; i++) //{ // if (dp[N,i] != 0) // { // ans++; // } //} // Console.WriteLine(ans + 1); // var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var A = line[0]; // var B = line[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line3 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int[] a = new int[A]; // int[] b = new int[B]; // for (int i = 0; i < A; i++) //{ // a[i] = line2[i]; //} // for (int i = 0; i < B; i++) //{ // b[i] = line3[i]; //} // int AB = A + B; // int[,] dp = new int[A + 1, B + 1]; // for (int i = 1; i <= A; i++) //{ // if ((AB - i) % 2 == 0) // { // dp[i, 0] = dp[i - 1, 0] + a[A - i]; // } // else // { // dp[i, 0] = dp[i - 1, 0]; // } //} // for (int i = 1; i <= B; i++) //{ // if ((AB - i) % 2 == 0) // { // dp[0, i] = dp[0, i -1] + b[B - i]; // } // else // { // dp[0, i] = dp[0, i -1]; // } //} // for (int i = 1; i <= A; i++) //{ // for (int j = 1; j <= B; j++) // { // if ((AB - i - j) % 2 == 0) // { // dp[i, j] = Math.Max(dp[i -1,j] + a[A - i],dp[i,j-1] + b[B - // j]); // } // else // { // dp[i, j] = Math.Min(dp[i - 1, j] , dp[i, j - 1]); // } // } //} // Console.WriteLine(dp[A,B]); // var N = int.Parse(Console.ReadLine()); // int[] dp = new int[N + 1]; // for (int i = 1; i <= N; i++) //{ // dp[i] = i; //} // List<int> hai = new List<int>(); // int loop = 6; // while (N>=loop) //{ // hai.Add(loop); // loop *= 6; //} // loop = 9; // while (N >= loop) //{ // hai.Add(loop); // loop *= 9; //} // var hai2 = hai.OrderBy(n => n).ToArray(); // foreach (var item in hai) //{ // for (int i = 0; i < N; i++) // { // if (i + item <= N) // { // dp[i + item] = Math.Min(dp[i + item], dp[i] + 1); // } // } //} // Console.WriteLine(dp[N]); // var N = int.Parse(Console.ReadLine()); // if (N == 1) //{ // Console.WriteLine(1); // return; //} // for (int i = 1; i <= N; i++) //{ // if (2 * N > i * (i + 1)) // { // continue; // } // else // { // Console.WriteLine(i); // return; // } //} var N = long.Parse(Console.ReadLine()); var yaku = getPrime(N).ToArray(); yakusu(N, 0, 1, yaku); var min = Math.Max(_A.ToString().Length, (N / _A).ToString().Length); Console.WriteLine(min); } public static List<long> getPrime(long n) { long i = 2; long tmp = n; List<long> listp = new List<long>(); while (i * i <= n) { if (tmp % i == 0) { tmp /= i; listp.Add(i); } else { i++; } } if (tmp != 1) listp.Add(tmp); return listp; } public static void yakusu(long N, long num, long A, long[] arr) { if (num == arr.Length) { if (Math.Abs(A - N / A) < abs) { abs = Math.Min(Math.Abs(A - N / A), abs); _A = A; } return; } for (int i = 0; i < 2; i++) { if (i == 0) yakusu(N, num + 1, A, arr); if (i == 1) yakusu(N, num + 1, A * arr[num], arr); } } public static void DFSgraph(int[,] RL, bool[] visit, int v) { visit[v] = true; if (visit.Where(n => n == true).Count() == visit.Length) { cnt++; return; } for (int i = 0; i < visit.Length; i++) { if (RL[v, i] == 0) continue; if (visit[i]) continue; bool[] tmpvisit = new bool[visit.Length]; visit.CopyTo(tmpvisit, 0); DFSgraph(RL, tmpvisit, i); } } public static void PrimeFactors(int n, int[] sosuu) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; sosuu[i]++; } else { i++; } } if (tmp != 1) sosuu[tmp]++; } public static void DFSzahyo(int x, int y, int[] s, int[] g) { if (x == g[0] && y == g[1]) { return; } miz[x, y] = true; for (int i = 0; i < 4; i++) { if (miz[x + xMove[i], y + yMove[i]] != true) { DFSzahyo(x + xMove[i], y + yMove[i], s, g); } } } public static void saikiseven(int ope, int sum, int[] hairetui) { if (ope == 1) { sum = hairetui[ope - 1]; } if (ope == 7 && sum == 7) { int[] dummy = new int[ope]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } else if (ope == 7 && sum != 7) { return; } for (int i = 0; i < 2; i++) { if (i == 0) { sum += hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); sum -= hairetui[ope + 1]; } else { sum -= hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); } } return; } public static void saiki(int soezi, int[] hairetui) { if (soezi == 10) { int[] dummy = new int[soezi]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } for (int j = 0; j < 2; j++) { hairetui[soezi] = j; saiki(soezi + 1, hairetui); } return; } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } /// <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<ComparablePair<int, // int>>(maxIndex); priorityQueue.Push(new ComparablePair<int, int>(0, // s)); // while (priorityQueue.Count() > 0) // { // var costDestinationPair = priorityQueue.Pop(); // 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.Push(new ComparablePair<int, // int>(newCostToi, i)); // } // } // } // return cost[t]; // } //} // public class ComparablePair<T, U> : IComparable where T : IComparable<T> //{ // public readonly T Item1; // public readonly U Item2; // public int CompareTo(object obj) // { // ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj; // return this.Item1.CompareTo(castedObj.Item1); // } // public ComparablePair(T t, U u) // { // Item1 = t; // Item2 = u; // } //} }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static List<int[]> list = new List<int[]>(); static int[] yMove = new int[] { -1, 1, 0, 0 }; static int[] xMove = new int[] { 0, 0, -1, 1 }; static bool[,] miz; static int cnt = 0; static long abs = long.MaxValue; static long _A = 0; static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; // var N = int.Parse(Console.ReadLine()); // char[] mozi = new char[N]; // long[] MARCH = new long[5]; // long cnt = 0; // for (int i = 0; i < N; i++) //{ // mozi[i] = Console.ReadLine().ToCharArray()[0]; //} // MARCH[0] = mozi.Where(n => n == 'M').Count(); // MARCH[1] = mozi.Where(n => n == 'A').Count(); // MARCH[2] = mozi.Where(n => n == 'R').Count(); // MARCH[3] = mozi.Where(n => n == 'C').Count(); // MARCH[4] = mozi.Where(n => n == 'H').Count(); // for (int i = 0; i < 3; i++) //{ // for (int j = i + 1; j < 4; j++) // { // for (int k = j + 1; k < 5; k++) // { // cnt += MARCH[i] * MARCH[j] * MARCH[k]; // } // } //} // Console.WriteLine(cnt); // var N = int.Parse(Console.ReadLine()); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int candy = 0; // int MAX = 0; // for (int i = 0; i < N; i++) //{ // for (int k = 0; k <= i; k++) // { // candy += line1[k]; // } // for (int j = N - 1; j >= i; j--) // { // candy += line2[j]; // } // MAX = Math.Max(candy,MAX); // candy = 0; //} // Console.WriteLine(MAX); // var N = int.Parse(Console.ReadLine()); // List<int[]> list = new List<int[]>(); // int t = 0; // int x = 0; // int y = 0; // for (int i = 0; i < N; i++) //{ // var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // list.Add(txy); //} // foreach (var item in list) //{ // if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) // { // if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 1) || // ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 0)) // { // t = item[0]; // x = item[1]; // y = item[2]; // } // else // { // Console.WriteLine("No"); // return; // } // } // else // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // if (line1[1] >= 10000) //{ // for (int i = 0; i <= line1[1]/10000; i++) // { // for (int j = 0; j <= line1[1] / 5000; j++) // { // if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 == // line1[1] && line1[0] - i - j >= 0) // { // Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j); // return; // } // } // } //} // else //{ // for (int i = 0; i < 2; i++) // { // for (int j = 0; j <= 9; j++) // { // if (5000 * i + 1000 * j == line1[1] && i + j == line1[0]) // { // Console.WriteLine("{0} {1} {2}", 0, i, j); // return; // } // } // } //} // Console.WriteLine("{0} {1} {2}", -1, -1, -1); // var N = int.Parse(Console.ReadLine()); // int[,] station = new int[N,3]; // long sum = 0; // for (int i = 0; i < N - 1; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // station[i, 0] = line[0]; // station[i, 1] = line[1]; // station[i, 2] = line[2]; //} // for (int j = 0; j < N -1; j++) //{ // for (int i = j; i < N - 1; i++) // { // var F = station[i, 2]; // var S = station[i, 1]; // if (i == j) // { // sum += station[i, 0] + station[i, 1]; // } // else // { // if (sum < S) // { // sum = S + station[i, 0]; // } // else if (sum % F == 0) // { // sum += station[i, 0]; // } // else // { // sum += F - (sum % F) + station[i, 0]; // } // } // } // Console.WriteLine(sum); // sum = 0; //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long A = line[0]; // int i = 0; // while (A <= line[1]) //{ // A *=2; // i++; //} // Console.WriteLine(i); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // Dictionary<long, long> dic = new Dictionary<long, long>(); // long sum = 0; // for (int i = 0; i < N; i++) //{ // if (dic.ContainsKey(line[i])) // { // dic[line[i]]++; // } // else // { // dic.Add(line[i], 1); // } //} // foreach (var item in dic) //{ // if (item.Key == item.Value) // { // } // else if (item.Key < item.Value) // { // sum += item.Value - item.Key; // } // else // { // sum += item.Value; // } //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // var N = line[0]; // var K = line[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long cnt = 0; // long sum = 0; // long[] lngarray = new long[N]; // for (int i = 0; i < N; i++) //{ // lngarray[line2[i]-1]++; //} // if (lngarray.Where(n => n !=0).Count() <= K) //{ // Console.WriteLine(0); // return; //} // var orderlng = lngarray.Where(n => n != 0).OrderBy(n => n).ToArray(); // for (int i = 0; i < orderlng.Length; i++) //{ // if (cnt == orderlng.Length - K) // { // Console.WriteLine(sum); // return; // } // else // { // sum += orderlng[i]; // cnt++; // } //} // int soe = 0; // saiki(soe, new int[10]); // var N = int.Parse(Console.ReadLine()); // var F = new List<int[]>(); // var P = new List<int[]>(); // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // F.Add(line); //} // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // P.Add(line); //} // int sum = int.MinValue; // list.RemoveAt(0); // foreach (var item in list) //{ // int tmpsum = 0; // for (int i = 0; i < N; i++) // { // int c = 0; // for (int j = 0; j < 10; j++) // { // if (item[j] == 1 && F[i][j] == 1) // { // c++; // } // } // tmpsum += P[i][c]; // } // sum = Math.Max(sum, tmpsum); //} // Console.WriteLine(sum); // var line = Console.ReadLine().ToCharArray(); // int[] hai = new int[7]; // hai[0] = int.Parse(line[0].ToString()); // hai[2] = int.Parse(line[1].ToString()); // hai[4] = int.Parse(line[2].ToString()); // hai[6] = int.Parse(line[3].ToString()); // saikiseven(1,0, hai); // string ope1 = list[0][1] == 0 ? "+" : "-"; // string ope2 = list[0][3] == 0 ? "+" : "-"; // string ope3 = list[0][5] == 0 ? "+" : "-"; // Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7", list[0][0],ope1, list[0][2], // ope2,list[0][4], ope3,list[0][6]); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long[] A = new long[N]; // for (int i = 0; i < N; i++) //{ // A[i] = Math.Abs(i - (N - i -1)); //} // var tmp1 = line.OrderBy(n => n).ToArray(); // var tmp2 = A.OrderBy(n => n).ToArray(); // for (int i = 0; i < N; i++) //{ // if (tmp1[i] != tmp2[i]) // { // Console.WriteLine(0); // return; // } //} // long X = 1; // for (int i = 0; i < N/2; i++) //{ // X *= 2; // X %= 1000000007; //} // Console.WriteLine(X); // var line =Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var sx = line[0]; // var sy = line[1]; // var tx = line[2]; // var ty = line[3]; // var path1 = new string('U', ty - sy) + new string('R',tx - sx); // var path2 = new string('D', ty - sy) + new string('L', tx - sx); // var path3 = new string('L', 1) + new string('U', ty - sy + 1) + new // string('R', tx - sx + 1) + new string('D', 1); var path4 = new string('R', // 1) + new string('D', ty - sy + 1) + new string('L', tx - sx + 1) + new // string('U', 1); Console.WriteLine(path1 + path2 + path3 + path4); int[] // sosuu = new int[1000]; // var N = int.Parse(Console.ReadLine()); // int[] sosuu = new int[1001]; // long ans = 1; // for (int i = 1; i < N + 1; i++) //{ // PrimeFactors(i, sosuu); //} // for (int i = 2; i < N + 1; i++) //{ // ans *= sosuu[i] + 1; // ans %= 1000000007; //} // Console.WriteLine(ans); // var N = long.Parse(Console.ReadLine()); // long X = 0; // long Y = 0; // X = N / 11; // if ((N - (11 * X)) == 0) //{ // Y = 0; //} // else if ((N - (11 * X)) <= 6) //{ // Y = 1; //} // else //{ // Y = 2; //} // Console.WriteLine(X * 2 + Y); // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var N = line[0]; // var M = line[1]; // int[,] RL = new int[N, N]; // for (int i = 0; i < M; i++) //{ // var tmp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // RL[tmp[0]-1, tmp[1]-1] = 1; // RL[tmp[1]-1, tmp[0]-1] = 1; //} // bool[] visit = new bool[N]; // DFSgraph(RL,visit,0); // Console.WriteLine(cnt); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line[0]; // var M = line[1]; // if (N * 2 < M) //{ // Console.WriteLine(N + (M - 2 * N) /4); //} // else //{ // Console.WriteLine(M/2); //} // var N = int.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int[,] dp = new int[N + 1, 10001]; ////for (int i = 0; i < N; i++) ////{ //// dp[0, line[0]] = line[i]; ////} // for (int i = 0; i < N; i++) //{ // for (int j = 0; j < 10001; j++) // { // dp[i + 1, line[i]] = line[i]; // if (dp[i,j] != 0) // { // dp[i + 1, j] = dp[i, j]; // dp[i + 1, dp[i, j] + line[i]] = line[i] + dp[i, j]; // } // } //} // long ans = 0; // for (int i = 0; i < 10001; i++) //{ // if (dp[N,i] != 0) // { // ans++; // } //} // Console.WriteLine(ans + 1); // var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var A = line[0]; // var B = line[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line3 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int[] a = new int[A]; // int[] b = new int[B]; // for (int i = 0; i < A; i++) //{ // a[i] = line2[i]; //} // for (int i = 0; i < B; i++) //{ // b[i] = line3[i]; //} // int AB = A + B; // int[,] dp = new int[A + 1, B + 1]; // for (int i = 1; i <= A; i++) //{ // if ((AB - i) % 2 == 0) // { // dp[i, 0] = dp[i - 1, 0] + a[A - i]; // } // else // { // dp[i, 0] = dp[i - 1, 0]; // } //} // for (int i = 1; i <= B; i++) //{ // if ((AB - i) % 2 == 0) // { // dp[0, i] = dp[0, i -1] + b[B - i]; // } // else // { // dp[0, i] = dp[0, i -1]; // } //} // for (int i = 1; i <= A; i++) //{ // for (int j = 1; j <= B; j++) // { // if ((AB - i - j) % 2 == 0) // { // dp[i, j] = Math.Max(dp[i -1,j] + a[A - i],dp[i,j-1] + b[B - // j]); // } // else // { // dp[i, j] = Math.Min(dp[i - 1, j] , dp[i, j - 1]); // } // } //} // Console.WriteLine(dp[A,B]); // var N = int.Parse(Console.ReadLine()); // int[] dp = new int[N + 1]; // for (int i = 1; i <= N; i++) //{ // dp[i] = i; //} // List<int> hai = new List<int>(); // int loop = 6; // while (N>=loop) //{ // hai.Add(loop); // loop *= 6; //} // loop = 9; // while (N >= loop) //{ // hai.Add(loop); // loop *= 9; //} // var hai2 = hai.OrderBy(n => n).ToArray(); // foreach (var item in hai) //{ // for (int i = 0; i < N; i++) // { // if (i + item <= N) // { // dp[i + item] = Math.Min(dp[i + item], dp[i] + 1); // } // } //} // Console.WriteLine(dp[N]); // var N = int.Parse(Console.ReadLine()); // if (N == 1) //{ // Console.WriteLine(1); // return; //} // for (int i = 1; i <= N; i++) //{ // if (2 * N > i * (i + 1)) // { // continue; // } // else // { // Console.WriteLine(i); // return; // } //} var N = long.Parse(Console.ReadLine()); var yaku = getPrime(N).ToArray(); yakusu(N, 0, 1, yaku); var min = Math.Max(_A.ToString().Length, (N / _A).ToString().Length); Console.WriteLine(min); } public static List<long> getPrime(long n) { long i = 2; long tmp = n; List<long> listp = new List<long>(); while (i * i <= n) { if (tmp % i == 0) { tmp /= i; listp.Add(i); } else { i++; } } if (tmp != 1) listp.Add(tmp); return listp; } public static void yakusu(long N, long num, long A, long[] arr) { if (num == arr.Length) { if (Math.Abs(A - N / A) < abs) { abs = Math.Min(Math.Abs(A - N / A), abs); _A = A; } return; } for (int i = 0; i < 2; i++) { if (i == 0) yakusu(N, num + 1, A, arr); if (i == 1) yakusu(N, num + 1, A * arr[num], arr); } } public static void DFSgraph(int[,] RL, bool[] visit, int v) { visit[v] = true; if (visit.Where(n => n == true).Count() == visit.Length) { cnt++; return; } for (int i = 0; i < visit.Length; i++) { if (RL[v, i] == 0) continue; if (visit[i]) continue; bool[] tmpvisit = new bool[visit.Length]; visit.CopyTo(tmpvisit, 0); DFSgraph(RL, tmpvisit, i); } } public static void PrimeFactors(int n, int[] sosuu) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; sosuu[i]++; } else { i++; } } if (tmp != 1) sosuu[tmp]++; } public static void DFSzahyo(int x, int y, int[] s, int[] g) { if (x == g[0] && y == g[1]) { return; } miz[x, y] = true; for (int i = 0; i < 4; i++) { if (miz[x + xMove[i], y + yMove[i]] != true) { DFSzahyo(x + xMove[i], y + yMove[i], s, g); } } } public static void saikiseven(int ope, int sum, int[] hairetui) { if (ope == 1) { sum = hairetui[ope - 1]; } if (ope == 7 && sum == 7) { int[] dummy = new int[ope]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } else if (ope == 7 && sum != 7) { return; } for (int i = 0; i < 2; i++) { if (i == 0) { sum += hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); sum -= hairetui[ope + 1]; } else { sum -= hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); } } return; } public static void saiki(int soezi, int[] hairetui) { if (soezi == 10) { int[] dummy = new int[soezi]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } for (int j = 0; j < 2; j++) { hairetui[soezi] = j; saiki(soezi + 1, hairetui); } return; } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } /// <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<ComparablePair<int, // int>>(maxIndex); priorityQueue.Push(new ComparablePair<int, int>(0, // s)); // while (priorityQueue.Count() > 0) // { // var costDestinationPair = priorityQueue.Pop(); // 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.Push(new ComparablePair<int, // int>(newCostToi, i)); // } // } // } // return cost[t]; // } //} // public class ComparablePair<T, U> : IComparable where T : IComparable<T> //{ // public readonly T Item1; // public readonly U Item2; // public int CompareTo(object obj) // { // ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj; // return this.Item1.CompareTo(castedObj.Item1); // } // public ComparablePair(T t, U u) // { // Item1 = t; // Item2 = u; // } //} }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
8
1,964
2
using System.Linq; using System.Collections.Generic; using System; public class P { public int x { get; set; } public int y { get; set; } } public class Hello { public static void Main() { var alist = new List<long>(); var n = long.Parse(Console.ReadLine().Trim()); var n2 = (long)Math.Sqrt(n + 1); for (long i = 2; i <= n2; i++) if (n % i == 0) alist.Add(getF(i, n / i)); Console.WriteLine(alist.Min()); } public static long getF(long a, long b) { var wa = a.ToString().Length; var wb = b.ToString().Length; if (wa >= wb) return wa; else return wb; } }
using System.Linq; using System.Collections.Generic; using System; public class P { public int x { get; set; } public int y { get; set; } } public class Hello { public static void Main() { var alist = new List<long>(); var n = long.Parse(Console.ReadLine().Trim()); var n2 = (long)Math.Sqrt(n + 1); for (long i = 1; i <= n2; i++) if (n % i == 0) alist.Add(getF(i, n / i)); Console.WriteLine(alist.Min()); } public static long getF(long a, long b) { var wa = a.ToString().Length; var wb = b.ToString().Length; if (wa >= wb) return wa; else return wb; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
190
2
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { // C#7.0 long N; void Solve() { io.i(out N); Mathf mat = new Mathf(); long min = mat.Digit(N); for (long A = 1; A * A < N; A++) { if (N % A != 0) continue; long B = N / A; long cur = mat.Max(mat.Digit(A), mat.Digit(B)); if (min > cur) min = cur; } io.o(min); } public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public char nextChar() { return char.Parse(next()); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public string[] array() { return Console.ReadLine().Split(' '); } public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); } public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); } public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); } public double[] arrayDouble() { return Array.ConvertAll(array(), double.Parse); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } public void i<T>(out T v) { v = suitType<T>(next()); } public void i<T, U>(out T v1, out U v2) { var a = array(); v1 = suitType<T>(a[0]); v2 = suitType<U>(a[1]); } public void i<T, U, V>(out T v1, out U v2, out V v3) { var a = array(); v1 = suitType<T>(a[0]); v2 = suitType<U>(a[1]); v3 = suitType<V>(a[2]); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { var a = array(); v1 = suitType<T>(a[0]); v2 = suitType<U>(a[1]); v3 = suitType<V>(a[2]); v4 = suitType<W>(a[3]); } public void ini(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt(); } public void ini(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt(); a2[i] = nextInt(); } } public void ini(out string[] a, int size) { a = new string[size]; for (int i = 0; i < size; i++) a[i] = next(); } public void inii(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt() - 1; } public void inii(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt() - 1; a2[i] = nextInt() - 1; } } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { foreach (T v in a) Console.WriteLine(v); } public void o<T>(List<T> l) { foreach (T v in l) sw.WriteLine(v); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { foreach (T v in a) Console.Write(v + " "); Console.WriteLine(""); } public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); } public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); } public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); } public void writeFlush() { Console.Out.Flush(); } } class Mathf { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long Sum(params long[] a) { return a.Aggregate((v, next) => (v % mod + next) % mod); } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } } } class BucketSort { public int[] bucket; public void Init(int[] a) { bucket = new int[a.Max() + 1]; for (int i = 0; i < a.Length; ++i) ++bucket[a[i]]; for (int i = 0, j = 0; j < bucket.Length; ++j) for (int k = bucket[j]; k != 0; --k, ++i) a[i] = j; } } static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { // C#7.0 long N; void Solve() { io.i(out N); Mathf mat = new Mathf(); long min = mat.Digit(N); for (long A = 1; A * A <= N; A++) { if (N % A != 0) continue; long B = N / A; long cur = mat.Max(mat.Digit(A), mat.Digit(B)); if (min > cur) min = cur; } io.o(min); } public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public char nextChar() { return char.Parse(next()); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public string[] array() { return Console.ReadLine().Split(' '); } public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); } public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); } public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); } public double[] arrayDouble() { return Array.ConvertAll(array(), double.Parse); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } public void i<T>(out T v) { v = suitType<T>(next()); } public void i<T, U>(out T v1, out U v2) { var a = array(); v1 = suitType<T>(a[0]); v2 = suitType<U>(a[1]); } public void i<T, U, V>(out T v1, out U v2, out V v3) { var a = array(); v1 = suitType<T>(a[0]); v2 = suitType<U>(a[1]); v3 = suitType<V>(a[2]); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { var a = array(); v1 = suitType<T>(a[0]); v2 = suitType<U>(a[1]); v3 = suitType<V>(a[2]); v4 = suitType<W>(a[3]); } public void ini(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt(); } public void ini(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt(); a2[i] = nextInt(); } } public void ini(out string[] a, int size) { a = new string[size]; for (int i = 0; i < size; i++) a[i] = next(); } public void inii(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt() - 1; } public void inii(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt() - 1; a2[i] = nextInt() - 1; } } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { foreach (T v in a) Console.WriteLine(v); } public void o<T>(List<T> l) { foreach (T v in l) sw.WriteLine(v); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { foreach (T v in a) Console.Write(v + " "); Console.WriteLine(""); } public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); } public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); } public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); } public void writeFlush() { Console.Out.Flush(); } } class Mathf { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long Sum(params long[] a) { return a.Aggregate((v, next) => (v % mod + next) % mod); } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } } } class BucketSort { public int[] bucket; public void Init(int[] a) { bucket = new int[a.Max() + 1]; for (int i = 0; i < a.Length; ++i) ++bucket[a[i]]; for (int i = 0, j = 0; j < bucket.Length; ++j) for (int k = bucket[j]; k != 0; --k, ++i) a[i] = j; } } static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
2,073
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { void Calc() { var sc = new Scanner(); int N = sc.NextInt(); double root = Math.Sqrt(N); double roottt = Math.Floor(root); int ret3 = (int)roottt; for (int i = ret3; i > 0; i--) { if (N % i == 0) { int l = N / i; string a = l.ToString(); Console.WriteLine(a.Length); break; } } } static void Main() { new Program().Calc(); } class Scanner { string[] s = new string[0]; int i = 0; char[] cs = new char[] { ' ' }; public string Next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { void Calc() { var sc = new Scanner(); long N = sc.NextLong(); double root = Math.Sqrt(N); double roottt = Math.Floor(root); int root3 = (int)roottt; for (int i = root3; i > 0; i--) { if (N % i == 0) { long l = N / i; string a = l.ToString(); Console.WriteLine(a.Length); break; } } } static void Main() { new Program().Calc(); } class Scanner { string[] s = new string[0]; int i = 0; char[] cs = new char[] { ' ' }; public string Next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199]]
8
280
10
using System; using System.Collections.Generic; class P { static void Main(string[] _) { decimal n = decimal.Parse(Console.ReadLine()); int result = int.MaxValue; List<int> l = new List<int>(); for (decimal i = 2; i <= (decimal)Math.Sqrt((double)n); i++) { if (n % i == 0) { result = Math.Min( result, Math.Max(i.ToString().Length, (n / i).ToString().Length)); } } if (result == int.MinValue) { Console.WriteLine(result); } else { Console.WriteLine(n.ToString().Length); } } }
using System; using System.Collections.Generic; class P { static void Main(string[] _) { decimal n = decimal.Parse(Console.ReadLine()); int result = int.MaxValue; List<int> l = new List<int>(); for (decimal i = 2; i <= (decimal)Math.Sqrt((double)n); i++) { if (n % i == 0) { result = Math.Min( result, Math.Max(i.ToString().Length, (n / i).ToString().Length)); } } if (result != int.MaxValue) { Console.WriteLine(result); } else { Console.WriteLine(n.ToString().Length); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22]]
8
164
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { var firstLine = Console.ReadLine() .Split(' ') .Select(value => long.Parse(value)) .ToList(); var n = firstLine[0]; var a = firstLine[1]; var b = firstLine[2]; var values = Console.ReadLine() .Split(' ') .Select(value => long.Parse(value)) .ToList(); var valueDp = new double[n + 1, b + 1]; var combinationDp = new long[n + 1, b + 1]; for (var i = 0; i <= n; i++) { for (var j = 0; j <= b; j++) { valueDp[i, j] = 0; combinationDp[i, j] = 0; } } for (var i = 0; i <= n; i++) { combinationDp[i, 0] = 1; } for (var i = 1; i <= n; i++) { for (var j = 1; j <= b; j++) { if (i < j) { continue; } var notSelectedValue = valueDp[i - 1, j]; var selectedValue = valueDp[i - 1, j - 1] + values[i - 1]; if (notSelectedValue < selectedValue) { valueDp[i, j] = selectedValue; combinationDp[i, j] = combinationDp[i - 1, j - 1]; } else if (notSelectedValue == selectedValue) { valueDp[i, j] = selectedValue; combinationDp[i, j] = combinationDp[i - 1, j] + combinationDp[i - 1, j - 1]; } else { valueDp[i, j] = notSelectedValue; combinationDp[i, j] = combinationDp[i - 1, j]; } } } var maxValue = double.MinValue; long maxCombination = 0; for (var i = a; i <= b; i++) { valueDp[n, i] /= i; if (valueDp[n, i] > maxValue) { maxValue = valueDp[n, i]; } } for (var i = a; i <= b; i++) { if (valueDp[n, i] == maxValue) { maxCombination += combinationDp[n, i]; } } Console.WriteLine("{0:f6}", maxValue); Console.WriteLine(maxCombination); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { var firstLine = Console.ReadLine() .Split(' ') .Select(value => long.Parse(value)) .ToList(); var n = firstLine[0]; var a = firstLine[1]; var b = firstLine[2]; var values = Console.ReadLine() .Split(' ') .Select(value => long.Parse(value)) .ToList(); var valueDp = new decimal[n + 1, b + 1]; var combinationDp = new long[n + 1, b + 1]; for (var i = 0; i <= n; i++) { for (var j = 0; j <= b; j++) { valueDp[i, j] = 0; combinationDp[i, j] = 0; } } for (var i = 0; i <= n; i++) { combinationDp[i, 0] = 1; } for (var i = 1; i <= n; i++) { for (var j = 1; j <= b; j++) { if (i < j) { continue; } var notSelectedValue = valueDp[i - 1, j]; var selectedValue = valueDp[i - 1, j - 1] + values[i - 1]; if (notSelectedValue < selectedValue) { valueDp[i, j] = selectedValue; combinationDp[i, j] = combinationDp[i - 1, j - 1]; } else if (notSelectedValue == selectedValue) { valueDp[i, j] = selectedValue; combinationDp[i, j] = combinationDp[i - 1, j] + combinationDp[i - 1, j - 1]; } else { valueDp[i, j] = notSelectedValue; combinationDp[i, j] = combinationDp[i - 1, j]; } } } var maxValue = decimal.MinValue; long maxCombination = 0; for (var i = a; i <= b; i++) { valueDp[n, i] /= i; if (valueDp[n, i] > maxValue) { maxValue = valueDp[n, i]; } } for (var i = a; i <= b; i++) { if (valueDp[n, i] == maxValue) { maxCombination += combinationDp[n, i]; } } Console.WriteLine("{0:f6}", maxValue); Console.WriteLine(maxCombination); } } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
8
530
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var nab = Array.ConvertAll(ReadLine().Split(' '), int.Parse); var ar = Array.ConvertAll(ReadLine().Split(' '), long.Parse); ar = ar.OrderByDescending(v => v).ToArray(); var max = ar.Take(nab[1]).Average(v => (double)v); WriteLine(max.ToString("0.#######")); var ct = ar.Count(v => v == ar[nab[1] - 1]); var ctf = ar.Take(nab[1]).Count(v => v == ar[nab[1] - 1]); if (ctf != nab[1]) { var res = (long)ct; for (var i = 0; i < ctf; i++) { res *= ct - (i + 1); res /= (i + 2); } WriteLine(res); return; } var r = 0L; for (var i = ctf; i <= Min(nab[2], ct); i++) { var pro = (long)ct; for (var j = 1; j < i; j++) { pro *= ct - j; pro /= (j + 1); } r += pro; } WriteLine(r); } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var nab = Array.ConvertAll(ReadLine().Split(' '), int.Parse); var ar = Array.ConvertAll(ReadLine().Split(' '), long.Parse); ar = ar.OrderByDescending(v => v).ToArray(); var max = ar.Take(nab[1]).Average(v => (double)v); WriteLine(max.ToString("0.#######")); var ct = ar.Count(v => v == ar[nab[1] - 1]); var ctf = ar.Take(nab[1]).Count(v => v == ar[nab[1] - 1]); if (ctf != nab[1]) { var res = (long)ct; for (var i = 0; i < ctf - 1; i++) { res *= ct - (i + 1); res /= (i + 2); } WriteLine(res); return; } var r = 0L; for (var i = ctf; i <= Min(nab[2], ct); i++) { var pro = (long)ct; for (var j = 1; j < i; j++) { pro *= ct - j; pro /= (j + 1); } r += pro; } WriteLine(r); } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
[["+", 64, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
349
2
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); int a = cin.Int() - 1; int b = cin.Int() - 1; var vs = cin.ArrayLong(n); Array.Sort(vs); Array.Reverse(vs); long val = vs[a]; int preCount = 0; int postCount = 0; for (int i = a - 1; i >= 0; i--) { if (vs[i] == val) { preCount++; } else { break; } } for (int i = a + 1; i < n; i++) { if (vs[i] == val) { postCount++; } else { break; } } int count = preCount + 1; int allCount = preCount + 1 + postCount; bool isAll = true; long first = vs[0]; for (int i = 0; i <= a + postCount; i++) { if (first != vs[i]) { isAll = false; break; } } long ans = 0; PascalTriangle.Initialize(50); if (isAll) { for (int i = a; i <= allCount; i++) { ans += PascalTriangle.Combination(allCount, i + 1); } } else { ans = PascalTriangle.Combination(allCount, count); } double ave = vs.Where((x, index) => index <= a).Select(x => (double)x).Average(); Console.WriteLine(ave.ToString("f6")); Console.WriteLine(ans); } } public static class PascalTriangle { private static long[,] c_; public static void Initialize(int n) { c_ = new long[n + 1, n + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || i == j) { c_[i, j] = 1; } else { c_[i, j] = (c_[i - 1, j - 1] + c_[i - 1, j]); } } } } public static long Combination(long n, long k) { if (n < k || (n < 0 || k < 0)) { return 0; } return c_[n, k]; } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); int a = cin.Int() - 1; int b = cin.Int() - 1; var vs = cin.ArrayLong(n); Array.Sort(vs); Array.Reverse(vs); long val = vs[a]; int preCount = 0; int postCount = 0; for (int i = a - 1; i >= 0; i--) { if (vs[i] == val) { preCount++; } else { break; } } for (int i = a + 1; i < n; i++) { if (vs[i] == val) { postCount++; } else { break; } } int count = preCount + 1; int allCount = preCount + 1 + postCount; bool isAll = true; long first = vs[0]; for (int i = 0; i <= a + postCount; i++) { if (first != vs[i]) { isAll = false; break; } } long ans = 0; PascalTriangle.Initialize(50); if (isAll) { for (int i = a; i <= b; i++) { ans += PascalTriangle.Combination(allCount, i + 1); } } else { ans = PascalTriangle.Combination(allCount, count); } double ave = vs.Where((x, index) => index <= a).Select(x => (double)x).Average(); Console.WriteLine(ave.ToString("f6")); Console.WriteLine(ans); } } public static class PascalTriangle { private static long[,] c_; public static void Initialize(int n) { c_ = new long[n + 1, n + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || i == j) { c_[i, j] = 1; } else { c_[i, j] = (c_[i - 1, j - 1] + c_[i - 1, j]); } } } } public static long Combination(long n, long k) { if (n < k || (n < 0 || k < 0)) { return 0; } return c_[n, k]; } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22]]
8
1,001
2
using System; namespace ABC057D { class Program { static void Main(string[] args) { string[] bufs = Console.ReadLine().Split(' '); int N = Int32.Parse(bufs[0]); int A = Int32.Parse(bufs[1]); int B = Int32.Parse(bufs[2]); long[] v = new long[N]; bufs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = Int64.Parse(bufs[i]); } Array.Sort(v); double max = 0.0; for (int i = 1; i <= A; i++) { max += v[N - i]; } Console.WriteLine((max / A).ToString("F6")); // Max of average long res = 0; long cur = v[N - A]; int same = 1; int right = 1; int j = N - A - 1; while (j >= 0 && cur == v[j]) // Left { same++; j--; } j = N - A + 1; while (j < N && cur == v[j]) // Right { same++; right++; j++; } int term = N - (A - right); res = Combination(same, right); A++; while ((N >= A) && (v[N - A] == v[N - 1])) { res += Combination(same, A); A++; } Console.WriteLine(res); } static long Combination(int tot, int num) { long res = 1; int tmp = 1; if ((tot / 2) < num) { num = tot - num; } for (int i = 0; i < num; i++) { res = res * tot / tmp; tot--; tmp++; } return res; } } }
using System; namespace ABC057D { class Program { static void Main(string[] args) { string[] bufs = Console.ReadLine().Split(' '); int N = Int32.Parse(bufs[0]); int A = Int32.Parse(bufs[1]); int B = Int32.Parse(bufs[2]); long[] v = new long[N]; bufs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = Int64.Parse(bufs[i]); } Array.Sort(v); double max = 0.0; for (int i = 1; i <= A; i++) { max += v[N - i]; } Console.WriteLine((max / A).ToString("F6")); // Max of average long res = 0; long cur = v[N - A]; int same = 1; int right = 1; int j = N - A - 1; while (j >= 0 && cur == v[j]) // Left { same++; j--; } j = N - A + 1; while (j < N && cur == v[j]) // Right { same++; right++; j++; } int term = N - (A - right); res = Combination(same, right); A++; while ((N >= A) && (B >= A) && (v[N - A] == v[N - 1])) { res += Combination(same, A); A++; } Console.WriteLine(res); } static long Combination(int tot, int num) { long res = 1; int tmp = 1; if ((tot / 2) < num) { num = tot - num; } for (int i = 0; i < num; i++) { res = res * tot / tmp; tot--; tmp++; } return res; } } }
[["+", 15, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 20], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 52, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 8, 196, 0, 52, 15, 16, 12, 23, 0, 24]]
8
422
6
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] nab = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] v = Console.ReadLine() .Split() .Select(long.Parse) .OrderByDescending(x => x) .ToArray(); long[] take = v.Take(nab[1]).ToArray(); Console.WriteLine(take.Average().ToString("G20")); long res = 0; long last = take.Last(); if (take.Distinct().Count() != 1) { res = combination(v.Count(x => x == last), take.Count(x => x == last)); } else { long lastcount = v.Count(x => x == last); for (int i = nab[1]; i <= Math.Max(lastcount, nab[2]); i++) { res += combination(v.Length, i); } } Console.WriteLine(res); } static long combination(int n, int r) { long res = 1; for (int i = 1; i <= r; i++) { res *= (n - i + 1); res /= i; } return res; } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] nab = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] v = Console.ReadLine() .Split() .Select(long.Parse) .OrderByDescending(x => x) .ToArray(); long[] take = v.Take(nab[1]).ToArray(); Console.WriteLine(take.Average().ToString("G20")); long res = 0; long last = take.Last(); if (take.Distinct().Count() != 1) { res = combination(v.Count(x => x == last), take.Count(x => x == last)); } else { int lastcount = v.Count(x => x == last); for (int i = nab[1]; i <= Math.Min(lastcount, nab[2]); i++) { res += combination(lastcount, i); } } Console.WriteLine(res); } static long combination(int n, int r) { long res = 1; for (int i = 1; i <= r; i++) { res *= (n - i + 1); res /= i; } return res; } }
[["-", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
293
8
// optional using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; public static class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var ab = ReadLib.ReadAsStringArray(); Console.WriteLine(ab[0] == "H" ^ ab[1] == "H" ? "H" : "D"); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static char[][] ReadNTimesAsCharArray(int n) { return Enumerable.Range(1, n) .Select(i => Console.ReadLine().ToArray()) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } namespace Heaps { /// <summary>優先度付きキュー</summary> public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T> where T : IComparable<T> { public List<T> HeapArray { get; } public T NIL { get; } public bool IsMax { get; } public int Count => HeapArray.Count; /// <param name="heapArray">ヒープ</param> /// <param name="NIL">NILの値</param> /// <param /// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param> public PriorityQueue(T NIL, IEnumerable<T> heapArray = null, bool IsMax = true) { this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList(); this.NIL = NIL; this.IsMax = IsMax; Update(); } /// <summary>KeyのValueを取得</summary> public T this[int id] { get { if (id <= 0 || id > HeapArray.Count) { return NIL; } return HeapArray[id - 1]; } } class Node { public int Key { get; } public T Value => outer[Key]; readonly PriorityQueue<T> outer; public Node(int key, PriorityQueue<T> outer) { Key = key; this.outer = outer; } public Node Left { get { var leftKey = 2 * Key; return new Node(leftKey, outer); } } public Node Right { get { var rightkey = 2 * Key + 1; return new Node(rightkey, outer); } } public Node Parent { get { var parentKey = Key / 2; return new Node(parentKey, outer); } } } private Node GetNode(int key) { return new Node(key, this); } /// <summary>max Heap木とする O(N)</summary> public void Update() { var n = HeapArray.Count() / 2; /// <summary>葉から順に処理を行う</summary> for (int i = n; i >= 1; i--) { Heapify(i); } } /// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary> private void Heapify(int key) { var current = GetNode(key); var left = current.Left; var right = current.Right; var largest = current; var sign = IsMax ? 1 : -1; if (left.Value.CompareTo(NIL) != 0 && left.Value.CompareTo(current.Value) * sign > 0) { largest = left; } if (right.Value.CompareTo(NIL) != 0 && right.Value.CompareTo(largest.Value) * sign > 0) { largest = right; } if (largest.Key != key) { HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする Heapify( largest .Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。 } } /// <summary>keyの値を挿入する</summary> public void Enqueue(T value) { HeapArray.Add(value); var inserted = GetNode(HeapArray.Count); // 末尾に挿入 var parent = inserted.Parent; var sign = IsMax ? 1 : -1; // 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換 while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) { HeapArray.Swap(inserted.Key - 1, parent.Key - 1); inserted = parent; parent = inserted.Parent; } } public T Dequeue() { if (HeapArray.Count == 0) { return NIL; } var popVal = HeapArray.First(); var newRootVal = HeapArray.Last(); // 新しい根となる。 HeapArray.RemoveAt(HeapArray.Count - 1); // del last if (HeapArray.Count > 0) { HeapArray[0] = newRootVal; Heapify(1); } return popVal; } public T Peek() { return HeapArray.First(); } public IEnumerator<T> GetEnumerator() { while (HeapArray.Count > 0) { yield return Dequeue(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Clear() { HeapArray.Clear(); } public bool Contains(T val) { return HeapArray.Contains(val); } public PriorityQueue<T> Clone() { return new PriorityQueue<T>(NIL, HeapArray.DeepCopy()); } } } /// <summary>拡張メソッドs</summary> static class MyExtention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } public static void Swap<T>(this List<T> list, int i, int j) { var buf = list[i]; list[i] = list[j]; list[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } public static int Find<T>(this T[] array, T obj) { return Array.IndexOf(array, obj); } public static int LastFind<T>(this T[] array, T obj) { return Array.LastIndexOf(array, obj); } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[] array, T value) { for (int i = 0; i < array.Length; i++) { array[i] = value; } } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[,] array, T value) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = value; } } } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(long a, long n, int mod = 1000000007) { long res = 1; long pow = a; while (n > 0) { if ((n & 1) == 1) { res = (pow * res) % mod; // resにaをかける } pow = (pow * pow) % mod; // 次のaはa^2 n >>= 1; } return (int)res; } /// <summary>約数を列挙</summary> public static long[] Divisors(long n) { var ret = new List<long>(); var sqrt = Math.Ceiling(Math.Sqrt(n)); for (long i = 1; i <= sqrt; i++) { if (i * i > n) { continue; } if (n % i != 0) { continue; } ret.Add(i); if (n / i == i) { continue; } ret.Add(n / i); } return ret.ToArray(); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] InducesOfValue<T>(this T[] arr, T searchValue) { return arr.Select((v, i) => new { v, i }) .Where(o => searchValue.Equals(o.v)) .Select(o => o.i) .ToArray(); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) { return arr.ToArray().InducesOfValue(searchValue); } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } // optional namespace Graph { /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>有向グラフの隣接行列表現</summary> class AdjacencyMatrixCreator { public int[][] Matrix { get; } public AdjacencyMatrixCreator(int[][] matrix) { this.Matrix = matrix; } /// <summary>ノード数nの隣接行列表現を生成.1オリジン</summary> public AdjacencyMatrixCreator(int n, int defaultVal = 0) { Matrix = new int [n + 1][]; for (int i = 0; i <= n; i++) { Matrix[i] = new int[n + 1]; for (int j = 0; j <= n; j++) { Matrix[i][j] = defaultVal; } } } /// <summary> /// 辺の追加 (行列に1を足す) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void AddEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 1; } } /// <summary> /// 辺の削除 (行列を0にする) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void DelEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 0; } } } } namespace Sort { static class MergeSort { /// <summary>ソートを行う(mutable)</summary> public static void Sort(long[] arr) { Sort(arr, 0, arr.Count()); } private static void Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; Sort(sArr, left, mid); // left ~ mid-1をソート Sort(sArr, mid, right); // mid ~ rightをソート Merge(sArr, left, mid, right); // 昇順に並んだ2つの列を結合する。 } } // arrのleftとrightは昇順に並ぶのでO(n1+n2) private static void Merge(long[] arr, int left, int mid, int right) { var lArr = new long[mid - left + 1]; var rArr = new long[right - mid + 1]; for (int i = 0; i < mid - left; i++) { lArr[i] = arr[left + i]; } lArr[mid - left] = long.MaxValue; for (int i = 0; i < right - mid; i++) { rArr[i] = arr[mid + i]; } rArr[right - mid] = long.MaxValue; int l = 0, r = 0; // arrを並び替える for (int i = left; i < right; i++) { if (lArr[l] > rArr[r]) { arr[i] = rArr[r]; r++; } else { arr[i] = lArr[l]; l++; } } } } static class QuickSort { internal static void Sort(int[] ts) { Sort(ts, 0, ts.Count() - 1); } /// <summary>Quickソート</summary> private static void Sort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); Sort(ts, p, q - 1); Sort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } /// <summary>計数ソート</summary> static class CountingSort { public static int[] Sort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } } namespace Tree { /// <summary>UnionFind木</summary> public class UnionFind { Dictionary<int, int> nodeToRoot; Dictionary<int, int> rank; // その根が配下に何個nodeがぶら下がっているか public UnionFind(int n, int startAt = 0) { nodeToRoot = Enumerable.Range(startAt, n) .ToDictionary(i => i, i => i); // n個根を作る rank = Enumerable.Range(startAt, n).ToDictionary(i => i, i => 0); } /// <summary>根を得る</summary> public int GetRoot(int x) { if (nodeToRoot[x] == x) { // 渡されたノードが根 return x; } nodeToRoot[x] = GetRoot(nodeToRoot[x]); // parentの根を得てset。調べるたびに最適化。 return nodeToRoot[x]; } /// <summary>xとyの木を併合 => 根を同一にする</summary> public void Unite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) { return; // pass } if (rank[rootX] < rank[rootY]) { // yをxへ併合 nodeToRoot[rootX] = nodeToRoot[rootY]; } else { nodeToRoot[rootX] = nodeToRoot[rootY]; if (rank[rootX] == rank[rootY]) { rank[rootX]++; // yの下に配下が1つ追加される。 } } } public bool AreSameRoot(int x, int y) { return GetRoot(x) == GetRoot(y); } } /// <summary>根付き木</summary> public class RootedTree { readonly Dictionary<int, Node> nodes; const int NIL = -1; int startAt; int nNode; class Node { /// <summary>親のID</summary> public int Parent { get; set; } /// <summary>子の最左端</summary> public int LeftChild { get; set; } /// <summary>右の兄弟</summary> public int RightBrother { get; set; } /// <summary>深さ</summary> public int Depth { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightBrother = NIL; Depth = 0; } } /// <summary>根付き木</summary> public RootedTree(int n, int startAt = 0) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary>Nodeに子を追加</summary> public void SetChilds(int id, int[] childs) { if (childs.Length == 0) { return; } nodes[id].LeftChild = childs.First(); for (int i = 0; i < childs.Length - 1; i++) { int childId = childs[i]; nodes[childId].Parent = id; nodes[childId].RightBrother = childs[i + 1]; } nodes[childs.Last()].Parent = id; } /// <summary>親Idを取得</summary> public int GetParentId(int id) { return nodes[id].Parent; } /// <summary>子のidを取得</summary> public int[] GetChilds(int id) { var childs = new List<int>(); var child = nodes[id].LeftChild; while (child != NIL) { childs.Add(child); child = nodes[child].RightBrother; } return childs.ToArray(); } int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; // 何でもいい var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } bool isSetedDepth = false; /// <summary>深さを取得</summary> public int GetDepth(int id) { if (!isSetedDepth) { var root = GetRoot(); SetDepth(root, depth: 0); isSetedDepth = true; } var current = id; var parent = nodes[id].Parent; var depth = 0; while (parent != NIL) { current = parent; parent = nodes[current].Parent; depth++; } return depth; } private void SetDepth(int id, int depth) { var node = nodes[id]; node.Depth = depth; if (node.RightBrother != NIL) { SetDepth(node.RightBrother, depth); } if (node.LeftChild != NIL) { SetDepth(node.LeftChild, depth + 1); } } public int NodesCount() { return nodes.Count(); } } /// <summary>二分木</summary> public class BinaryTree { const int NIL = int.MinValue; readonly int startAt; readonly int nNode; class Node { public int Parent { get; set; } public int LeftChild { get; set; } public int RightChild { get; set; } public int Depth { get; set; } public int Height { get; set; } /// <summary>唯一の兄弟</summary> public int Sibling { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightChild = NIL; Sibling = NIL; Depth = 0; Height = 0; } } Dictionary<int, Node> nodes; public BinaryTree(int n, int startAt) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary> /// 子をセットする /// </summary> /// <param name="id">ノードのID</param> /// <param name="left">左子ID。存在しない場合は-1</param> /// <param name="right">右子ID。存在しない場合は-1</param> public void SetChilds(int id, int left, int right) { nodes[id].LeftChild = left; nodes[id].RightChild = right; if (left != NIL) { nodes[left].Parent = id; nodes[left].Sibling = right; } if (right != NIL) { nodes[right].Parent = id; nodes[right].Sibling = left; } } /// <summary>Root</summary> int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } #region Depth bool isSetDepth = false; public int GetDepth(int id) { if (!isSetDepth) { var root = GetRoot(); SetDepth(root, 0); isSetDepth = true; } return nodes[id].Depth; } private void SetDepth(int id, int depth) { nodes[id].Depth = depth; if (nodes[id].LeftChild != NIL) { SetDepth(nodes[id].LeftChild, depth + 1); } if (nodes[id].RightChild != NIL) { SetDepth(nodes[id].RightChild, depth + 1); } } #endregion #region Height bool isSetHeight = false; /// <summary>高さを得る</summary> public int GetHeight(int id) { if (!isSetHeight) { var root = GetRoot(); SetHeight(root); isSetHeight = true; } return nodes[id].Height; } public int SetHeight(int id) { var node = nodes[id]; int hLeft = 0; int hRight = 0; if (node.LeftChild != NIL) { hLeft = SetHeight(node.LeftChild) + 1; } if (node.RightChild != NIL) { hRight = SetHeight(node.RightChild) + 1; } node.Height = Math.Max(hLeft, hRight); return node.Height; } #endregion /// <summary>兄弟を得る</summary> public int GetSibling(int id) { return nodes[id].Sibling; } /// <summary>親IDを得る</summary> public int GetParent(int id) { return nodes[id].Parent; } public int[] GetChilds(int id) { var ids = new List<int>(); if (nodes[id].LeftChild != NIL) { ids.Add(nodes[id].LeftChild); } if (nodes[id].RightChild != NIL) { ids.Add(nodes[id].RightChild); } return ids.ToArray(); } /// <summary>左子を取得。存在しない時はint.MinValue</summary> public int GetLeft(int id) { return nodes[id].LeftChild; } /// <summary>右子を取得。存在しない時はint.MinValue</summary> public int GetRight(int id) { return nodes[id].RightChild; } public int NodesCount() { return nodes.Count(); } #region 巡回 private enum OrderType { Pre, In, Post } /// <summary>先行順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPreOrder() { return Process(OrderType.Pre); } /// <summary>中間順巡回のNodeIdを取得</summary> public IEnumerable<int> GetInOrder() { return Process(OrderType.In); } /// <summary>後方順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPostOrder() { return Process(OrderType.Post); } /// <summary>巡回を出力。O(N)</summary> private IEnumerable<int> Process(OrderType orderType) { var order = new List<int>(); var stack = new Stack<int>(); var passed = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 巡回済 var orderAdded = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 処理済 Action<int> addOrder = id => { if (!orderAdded[id]) { order.Add(id); orderAdded[id] = true; } }; stack.Push(GetRoot()); while (stack.Count > 0) { var current = stack.First(); passed[current] = true; if (orderType == OrderType.Pre) { addOrder(current); // 先行順巡回 } int left = GetLeft(current); if (left != -1 && !passed[left]) { stack.Push(left); continue; } if (orderType == OrderType.In) { addOrder(current); // 中間順巡回 } int right = GetRight(current); if (right != -1 && !passed[right]) { stack.Push(right); continue; } if (orderType == OrderType.Post) { addOrder(current);   // 後方順巡回 } stack.Pop(); } return order; } #endregion } /// <summary>二分探索木</summary> public class BinarySearchTree { static readonly Node NIL = new Node(int.MinValue); class Node { public int Key { get; set; } public Node Parent { get; set; } public Node Left { get; set; } public Node Right { get; set; } public Node(int key) { this.Key = key; this.Parent = NIL; this.Left = NIL; this.Right = NIL; } } Node root = NIL; #region Operate public void Insert(int key) { var z = new Node(key); var y = NIL; // xの親 var x = root; // Treeの根 while (x != NIL) { y = x; if (z.Key < x.Key) { x = x.Left; } else { x = x.Right; } } z.Parent = y; if (y == NIL) { root = z; } else if (z.Key < y.Key) { y.Left = z; } else { y.Right = z; } } public bool Find(int key) { var nearLeaf = GetNearLeaf(key); return nearLeaf.Key == key; } private Node GetNearLeaf(int key) { var x = this.root; while (x != NIL && x.Key != key) { if (x.Key < key) { x = x.Right; } else { x = x.Left; } } return x; } public void Delete(int key) { var cand = GetNearLeaf(key); if (cand.Key != key) { throw new KeyNotFoundException(); } DeleteNode(cand); } private void DeleteNode(Node target) { // 削除対象ノードを選択 Node delTarget; if (target.Left == NIL || target.Right == NIL) { delTarget = target; } else { delTarget = NextInOrder(target); } // DelTargetの親の新規子を決める Node newChild; if (delTarget.Left != NIL) { newChild = delTarget.Left; } else { newChild = delTarget.Right; } // 新規子 => 親をつなぐ if (newChild != NIL) { newChild.Parent = delTarget.Parent; } // 親 => 新規子をつなぐ var parent = delTarget.Parent; if (parent == NIL) { root = newChild; } else if (parent.Left == delTarget) { parent.Left = newChild; } else if (parent.Right == delTarget) { parent.Right = newChild; } // 消したノードの値を渡されたNodeに入れる if (delTarget != target) { target.Key = delTarget.Key; } } /// <summary>次の中間順巡回のNodeを取得</summary> /// <returns>NILの時は木が空</returns> private Node NextInOrder(Node node) { if (node.Right == NIL) { var current = node; var parent = node.Parent; // 親をたどっていき、初めて左子となっているNodeを取得 while (parent != NIL && current == parent.Right) { current = parent; parent = current.Parent; } return node.Parent; } // 右部分木より最左を取得 var root = node.Right; while (root.Left != NIL) { root = root.Left; } return root; } /// <summary> /// targetの親の子を、新しい子につなぎ替える /// </summary> /// <param name="target">対象のTarget</param> /// <param name="newChild">つなぎ変えた先の子</param> private static void ChangeParentOfChild(Node target, Node newChild) { var parent = target.Parent; if (parent.Left == target) { parent.Left = newChild; } else if (parent.Right == target) { parent.Right = newChild; } else { throw new KeyNotFoundException(); } } #endregion #region Order public IEnumerable<int> GetInOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetInOrder(root); } public IEnumerable<int> GetPreOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetPreOrder(root); } class OrderGetter { private List<int> process = new List<int>(); public IEnumerable<int> GetInOrder(Node root) { SetInOrder(root); return process; } public IEnumerable<int> GetPreOrder(Node root) { SetPreOrder(root); return process; } private void SetInOrder(Node node) { if (node == NIL) { return; } SetInOrder(node.Left); process.Add(node.Key); SetInOrder(node.Right); } private void SetPreOrder(Node node) { if (node == NIL) { return; } process.Add(node.Key); SetPreOrder(node.Left); SetPreOrder(node.Right); } } #endregion } }
// optional using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; public static class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var ab = ReadLib.ReadAsStringArray(); Console.WriteLine(ab[0] == "H" ^ ab[1] == "H" ? "D" : "H"); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static char[][] ReadNTimesAsCharArray(int n) { return Enumerable.Range(1, n) .Select(i => Console.ReadLine().ToArray()) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } namespace Heaps { /// <summary>優先度付きキュー</summary> public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T> where T : IComparable<T> { public List<T> HeapArray { get; } public T NIL { get; } public bool IsMax { get; } public int Count => HeapArray.Count; /// <param name="heapArray">ヒープ</param> /// <param name="NIL">NILの値</param> /// <param /// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param> public PriorityQueue(T NIL, IEnumerable<T> heapArray = null, bool IsMax = true) { this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList(); this.NIL = NIL; this.IsMax = IsMax; Update(); } /// <summary>KeyのValueを取得</summary> public T this[int id] { get { if (id <= 0 || id > HeapArray.Count) { return NIL; } return HeapArray[id - 1]; } } class Node { public int Key { get; } public T Value => outer[Key]; readonly PriorityQueue<T> outer; public Node(int key, PriorityQueue<T> outer) { Key = key; this.outer = outer; } public Node Left { get { var leftKey = 2 * Key; return new Node(leftKey, outer); } } public Node Right { get { var rightkey = 2 * Key + 1; return new Node(rightkey, outer); } } public Node Parent { get { var parentKey = Key / 2; return new Node(parentKey, outer); } } } private Node GetNode(int key) { return new Node(key, this); } /// <summary>max Heap木とする O(N)</summary> public void Update() { var n = HeapArray.Count() / 2; /// <summary>葉から順に処理を行う</summary> for (int i = n; i >= 1; i--) { Heapify(i); } } /// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary> private void Heapify(int key) { var current = GetNode(key); var left = current.Left; var right = current.Right; var largest = current; var sign = IsMax ? 1 : -1; if (left.Value.CompareTo(NIL) != 0 && left.Value.CompareTo(current.Value) * sign > 0) { largest = left; } if (right.Value.CompareTo(NIL) != 0 && right.Value.CompareTo(largest.Value) * sign > 0) { largest = right; } if (largest.Key != key) { HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする Heapify( largest .Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。 } } /// <summary>keyの値を挿入する</summary> public void Enqueue(T value) { HeapArray.Add(value); var inserted = GetNode(HeapArray.Count); // 末尾に挿入 var parent = inserted.Parent; var sign = IsMax ? 1 : -1; // 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換 while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) { HeapArray.Swap(inserted.Key - 1, parent.Key - 1); inserted = parent; parent = inserted.Parent; } } public T Dequeue() { if (HeapArray.Count == 0) { return NIL; } var popVal = HeapArray.First(); var newRootVal = HeapArray.Last(); // 新しい根となる。 HeapArray.RemoveAt(HeapArray.Count - 1); // del last if (HeapArray.Count > 0) { HeapArray[0] = newRootVal; Heapify(1); } return popVal; } public T Peek() { return HeapArray.First(); } public IEnumerator<T> GetEnumerator() { while (HeapArray.Count > 0) { yield return Dequeue(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Clear() { HeapArray.Clear(); } public bool Contains(T val) { return HeapArray.Contains(val); } public PriorityQueue<T> Clone() { return new PriorityQueue<T>(NIL, HeapArray.DeepCopy()); } } } /// <summary>拡張メソッドs</summary> static class MyExtention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } public static void Swap<T>(this List<T> list, int i, int j) { var buf = list[i]; list[i] = list[j]; list[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } public static int Find<T>(this T[] array, T obj) { return Array.IndexOf(array, obj); } public static int LastFind<T>(this T[] array, T obj) { return Array.LastIndexOf(array, obj); } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[] array, T value) { for (int i = 0; i < array.Length; i++) { array[i] = value; } } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[,] array, T value) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = value; } } } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(long a, long n, int mod = 1000000007) { long res = 1; long pow = a; while (n > 0) { if ((n & 1) == 1) { res = (pow * res) % mod; // resにaをかける } pow = (pow * pow) % mod; // 次のaはa^2 n >>= 1; } return (int)res; } /// <summary>約数を列挙</summary> public static long[] Divisors(long n) { var ret = new List<long>(); var sqrt = Math.Ceiling(Math.Sqrt(n)); for (long i = 1; i <= sqrt; i++) { if (i * i > n) { continue; } if (n % i != 0) { continue; } ret.Add(i); if (n / i == i) { continue; } ret.Add(n / i); } return ret.ToArray(); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] InducesOfValue<T>(this T[] arr, T searchValue) { return arr.Select((v, i) => new { v, i }) .Where(o => searchValue.Equals(o.v)) .Select(o => o.i) .ToArray(); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) { return arr.ToArray().InducesOfValue(searchValue); } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } // optional namespace Graph { /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>有向グラフの隣接行列表現</summary> class AdjacencyMatrixCreator { public int[][] Matrix { get; } public AdjacencyMatrixCreator(int[][] matrix) { this.Matrix = matrix; } /// <summary>ノード数nの隣接行列表現を生成.1オリジン</summary> public AdjacencyMatrixCreator(int n, int defaultVal = 0) { Matrix = new int [n + 1][]; for (int i = 0; i <= n; i++) { Matrix[i] = new int[n + 1]; for (int j = 0; j <= n; j++) { Matrix[i][j] = defaultVal; } } } /// <summary> /// 辺の追加 (行列に1を足す) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void AddEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 1; } } /// <summary> /// 辺の削除 (行列を0にする) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void DelEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 0; } } } } namespace Sort { static class MergeSort { /// <summary>ソートを行う(mutable)</summary> public static void Sort(long[] arr) { Sort(arr, 0, arr.Count()); } private static void Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; Sort(sArr, left, mid); // left ~ mid-1をソート Sort(sArr, mid, right); // mid ~ rightをソート Merge(sArr, left, mid, right); // 昇順に並んだ2つの列を結合する。 } } // arrのleftとrightは昇順に並ぶのでO(n1+n2) private static void Merge(long[] arr, int left, int mid, int right) { var lArr = new long[mid - left + 1]; var rArr = new long[right - mid + 1]; for (int i = 0; i < mid - left; i++) { lArr[i] = arr[left + i]; } lArr[mid - left] = long.MaxValue; for (int i = 0; i < right - mid; i++) { rArr[i] = arr[mid + i]; } rArr[right - mid] = long.MaxValue; int l = 0, r = 0; // arrを並び替える for (int i = left; i < right; i++) { if (lArr[l] > rArr[r]) { arr[i] = rArr[r]; r++; } else { arr[i] = lArr[l]; l++; } } } } static class QuickSort { internal static void Sort(int[] ts) { Sort(ts, 0, ts.Count() - 1); } /// <summary>Quickソート</summary> private static void Sort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); Sort(ts, p, q - 1); Sort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } /// <summary>計数ソート</summary> static class CountingSort { public static int[] Sort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } } namespace Tree { /// <summary>UnionFind木</summary> public class UnionFind { Dictionary<int, int> nodeToRoot; Dictionary<int, int> rank; // その根が配下に何個nodeがぶら下がっているか public UnionFind(int n, int startAt = 0) { nodeToRoot = Enumerable.Range(startAt, n) .ToDictionary(i => i, i => i); // n個根を作る rank = Enumerable.Range(startAt, n).ToDictionary(i => i, i => 0); } /// <summary>根を得る</summary> public int GetRoot(int x) { if (nodeToRoot[x] == x) { // 渡されたノードが根 return x; } nodeToRoot[x] = GetRoot(nodeToRoot[x]); // parentの根を得てset。調べるたびに最適化。 return nodeToRoot[x]; } /// <summary>xとyの木を併合 => 根を同一にする</summary> public void Unite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) { return; // pass } if (rank[rootX] < rank[rootY]) { // yをxへ併合 nodeToRoot[rootX] = nodeToRoot[rootY]; } else { nodeToRoot[rootX] = nodeToRoot[rootY]; if (rank[rootX] == rank[rootY]) { rank[rootX]++; // yの下に配下が1つ追加される。 } } } public bool AreSameRoot(int x, int y) { return GetRoot(x) == GetRoot(y); } } /// <summary>根付き木</summary> public class RootedTree { readonly Dictionary<int, Node> nodes; const int NIL = -1; int startAt; int nNode; class Node { /// <summary>親のID</summary> public int Parent { get; set; } /// <summary>子の最左端</summary> public int LeftChild { get; set; } /// <summary>右の兄弟</summary> public int RightBrother { get; set; } /// <summary>深さ</summary> public int Depth { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightBrother = NIL; Depth = 0; } } /// <summary>根付き木</summary> public RootedTree(int n, int startAt = 0) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary>Nodeに子を追加</summary> public void SetChilds(int id, int[] childs) { if (childs.Length == 0) { return; } nodes[id].LeftChild = childs.First(); for (int i = 0; i < childs.Length - 1; i++) { int childId = childs[i]; nodes[childId].Parent = id; nodes[childId].RightBrother = childs[i + 1]; } nodes[childs.Last()].Parent = id; } /// <summary>親Idを取得</summary> public int GetParentId(int id) { return nodes[id].Parent; } /// <summary>子のidを取得</summary> public int[] GetChilds(int id) { var childs = new List<int>(); var child = nodes[id].LeftChild; while (child != NIL) { childs.Add(child); child = nodes[child].RightBrother; } return childs.ToArray(); } int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; // 何でもいい var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } bool isSetedDepth = false; /// <summary>深さを取得</summary> public int GetDepth(int id) { if (!isSetedDepth) { var root = GetRoot(); SetDepth(root, depth: 0); isSetedDepth = true; } var current = id; var parent = nodes[id].Parent; var depth = 0; while (parent != NIL) { current = parent; parent = nodes[current].Parent; depth++; } return depth; } private void SetDepth(int id, int depth) { var node = nodes[id]; node.Depth = depth; if (node.RightBrother != NIL) { SetDepth(node.RightBrother, depth); } if (node.LeftChild != NIL) { SetDepth(node.LeftChild, depth + 1); } } public int NodesCount() { return nodes.Count(); } } /// <summary>二分木</summary> public class BinaryTree { const int NIL = int.MinValue; readonly int startAt; readonly int nNode; class Node { public int Parent { get; set; } public int LeftChild { get; set; } public int RightChild { get; set; } public int Depth { get; set; } public int Height { get; set; } /// <summary>唯一の兄弟</summary> public int Sibling { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightChild = NIL; Sibling = NIL; Depth = 0; Height = 0; } } Dictionary<int, Node> nodes; public BinaryTree(int n, int startAt) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary> /// 子をセットする /// </summary> /// <param name="id">ノードのID</param> /// <param name="left">左子ID。存在しない場合は-1</param> /// <param name="right">右子ID。存在しない場合は-1</param> public void SetChilds(int id, int left, int right) { nodes[id].LeftChild = left; nodes[id].RightChild = right; if (left != NIL) { nodes[left].Parent = id; nodes[left].Sibling = right; } if (right != NIL) { nodes[right].Parent = id; nodes[right].Sibling = left; } } /// <summary>Root</summary> int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } #region Depth bool isSetDepth = false; public int GetDepth(int id) { if (!isSetDepth) { var root = GetRoot(); SetDepth(root, 0); isSetDepth = true; } return nodes[id].Depth; } private void SetDepth(int id, int depth) { nodes[id].Depth = depth; if (nodes[id].LeftChild != NIL) { SetDepth(nodes[id].LeftChild, depth + 1); } if (nodes[id].RightChild != NIL) { SetDepth(nodes[id].RightChild, depth + 1); } } #endregion #region Height bool isSetHeight = false; /// <summary>高さを得る</summary> public int GetHeight(int id) { if (!isSetHeight) { var root = GetRoot(); SetHeight(root); isSetHeight = true; } return nodes[id].Height; } public int SetHeight(int id) { var node = nodes[id]; int hLeft = 0; int hRight = 0; if (node.LeftChild != NIL) { hLeft = SetHeight(node.LeftChild) + 1; } if (node.RightChild != NIL) { hRight = SetHeight(node.RightChild) + 1; } node.Height = Math.Max(hLeft, hRight); return node.Height; } #endregion /// <summary>兄弟を得る</summary> public int GetSibling(int id) { return nodes[id].Sibling; } /// <summary>親IDを得る</summary> public int GetParent(int id) { return nodes[id].Parent; } public int[] GetChilds(int id) { var ids = new List<int>(); if (nodes[id].LeftChild != NIL) { ids.Add(nodes[id].LeftChild); } if (nodes[id].RightChild != NIL) { ids.Add(nodes[id].RightChild); } return ids.ToArray(); } /// <summary>左子を取得。存在しない時はint.MinValue</summary> public int GetLeft(int id) { return nodes[id].LeftChild; } /// <summary>右子を取得。存在しない時はint.MinValue</summary> public int GetRight(int id) { return nodes[id].RightChild; } public int NodesCount() { return nodes.Count(); } #region 巡回 private enum OrderType { Pre, In, Post } /// <summary>先行順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPreOrder() { return Process(OrderType.Pre); } /// <summary>中間順巡回のNodeIdを取得</summary> public IEnumerable<int> GetInOrder() { return Process(OrderType.In); } /// <summary>後方順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPostOrder() { return Process(OrderType.Post); } /// <summary>巡回を出力。O(N)</summary> private IEnumerable<int> Process(OrderType orderType) { var order = new List<int>(); var stack = new Stack<int>(); var passed = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 巡回済 var orderAdded = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 処理済 Action<int> addOrder = id => { if (!orderAdded[id]) { order.Add(id); orderAdded[id] = true; } }; stack.Push(GetRoot()); while (stack.Count > 0) { var current = stack.First(); passed[current] = true; if (orderType == OrderType.Pre) { addOrder(current); // 先行順巡回 } int left = GetLeft(current); if (left != -1 && !passed[left]) { stack.Push(left); continue; } if (orderType == OrderType.In) { addOrder(current); // 中間順巡回 } int right = GetRight(current); if (right != -1 && !passed[right]) { stack.Push(right); continue; } if (orderType == OrderType.Post) { addOrder(current);   // 後方順巡回 } stack.Pop(); } return order; } #endregion } /// <summary>二分探索木</summary> public class BinarySearchTree { static readonly Node NIL = new Node(int.MinValue); class Node { public int Key { get; set; } public Node Parent { get; set; } public Node Left { get; set; } public Node Right { get; set; } public Node(int key) { this.Key = key; this.Parent = NIL; this.Left = NIL; this.Right = NIL; } } Node root = NIL; #region Operate public void Insert(int key) { var z = new Node(key); var y = NIL; // xの親 var x = root; // Treeの根 while (x != NIL) { y = x; if (z.Key < x.Key) { x = x.Left; } else { x = x.Right; } } z.Parent = y; if (y == NIL) { root = z; } else if (z.Key < y.Key) { y.Left = z; } else { y.Right = z; } } public bool Find(int key) { var nearLeaf = GetNearLeaf(key); return nearLeaf.Key == key; } private Node GetNearLeaf(int key) { var x = this.root; while (x != NIL && x.Key != key) { if (x.Key < key) { x = x.Right; } else { x = x.Left; } } return x; } public void Delete(int key) { var cand = GetNearLeaf(key); if (cand.Key != key) { throw new KeyNotFoundException(); } DeleteNode(cand); } private void DeleteNode(Node target) { // 削除対象ノードを選択 Node delTarget; if (target.Left == NIL || target.Right == NIL) { delTarget = target; } else { delTarget = NextInOrder(target); } // DelTargetの親の新規子を決める Node newChild; if (delTarget.Left != NIL) { newChild = delTarget.Left; } else { newChild = delTarget.Right; } // 新規子 => 親をつなぐ if (newChild != NIL) { newChild.Parent = delTarget.Parent; } // 親 => 新規子をつなぐ var parent = delTarget.Parent; if (parent == NIL) { root = newChild; } else if (parent.Left == delTarget) { parent.Left = newChild; } else if (parent.Right == delTarget) { parent.Right = newChild; } // 消したノードの値を渡されたNodeに入れる if (delTarget != target) { target.Key = delTarget.Key; } } /// <summary>次の中間順巡回のNodeを取得</summary> /// <returns>NILの時は木が空</returns> private Node NextInOrder(Node node) { if (node.Right == NIL) { var current = node; var parent = node.Parent; // 親をたどっていき、初めて左子となっているNodeを取得 while (parent != NIL && current == parent.Right) { current = parent; parent = current.Parent; } return node.Parent; } // 右部分木より最左を取得 var root = node.Right; while (root.Left != NIL) { root = root.Left; } return root; } /// <summary> /// targetの親の子を、新しい子につなぎ替える /// </summary> /// <param name="target">対象のTarget</param> /// <param name="newChild">つなぎ変えた先の子</param> private static void ChangeParentOfChild(Node target, Node newChild) { var parent = target.Parent; if (parent.Left == target) { parent.Left = newChild; } else if (parent.Right == target) { parent.Right = newChild; } else { throw new KeyNotFoundException(); } } #endregion #region Order public IEnumerable<int> GetInOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetInOrder(root); } public IEnumerable<int> GetPreOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetPreOrder(root); } class OrderGetter { private List<int> process = new List<int>(); public IEnumerable<int> GetInOrder(Node root) { SetInOrder(root); return process; } public IEnumerable<int> GetPreOrder(Node root) { SetPreOrder(root); return process; } private void SetInOrder(Node node) { if (node == NIL) { return; } SetInOrder(node.Left); process.Add(node.Key); SetInOrder(node.Right); } private void SetPreOrder(Node node) { if (node == NIL) { return; } process.Add(node.Key); SetPreOrder(node.Left); SetPreOrder(node.Right); } } #endregion } }
[["-", 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
7,299
4
using System; class c { static void Main() { string s = Console.ReadLine(); string ans = "D"; if (s[0] - s[1] == 0) ans = "H"; Console.WriteLine(ans); } }
using System; class c { static void Main() { string s = Console.ReadLine(); string ans = "D"; if (s[0] - s[2] == 0) ans = "H"; Console.WriteLine(ans); } }
[["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
57
2
using System; namespace Sample1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string a = input.Split(' ')[0]; string b = input.Split(' ')[1]; if (a == b) { Console.WriteLine('H'); } else if (a == "H" && b == "D") { Console.WriteLine('D'); } else { Console.WriteLine('H'); } } } }
using System; namespace Sample1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string a = input.Split(' ')[0]; string b = input.Split(' ')[1]; if (a == b) { Console.WriteLine('H'); } else if (a == "H" & b == "D") { Console.WriteLine('D'); } else { Console.WriteLine('D'); } } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 67], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
116
4
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; using System.Text.RegularExpressions; namespace CsTest { class Program { static void Main() { int[] ab = AtCoder.ReadInt32Array(); int a = ab[0]; int b = ab[1]; Console.WriteLine(a == b ? 'H' : 'D'); } } public class AtCoder { public static string[] ReadStringArray() => Console.ReadLine().Split( Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); public static int[] ReadInt32Array() => ReadStringArray().Select(s => int.Parse(s)).ToArray(); public static long[] ReadInt64Array() => ReadStringArray().Select(s => long.Parse(s)).ToArray(); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; using System.Text.RegularExpressions; namespace CsTest { class Program { static void Main() { var ab = AtCoder.ReadStringArray(); var a = ab[0]; var b = ab[1]; Console.WriteLine(a == b ? 'H' : 'D'); } } public class AtCoder { public static string[] ReadStringArray() => Console.ReadLine().Split( Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); public static int[] ReadInt32Array() => ReadStringArray().Select(s => int.Parse(s)).ToArray(); public static long[] ReadInt64Array() => ReadStringArray().Select(s => long.Parse(s)).ToArray(); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
202
10
// Rextester.Program.Main is the entry point for your code. Don't change it. // Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Your code goes // var input = Console.ReadLine(); var input = "H H"; var array = input.Split(' '); var a = array[0]; var b = array[1]; if (a == "H") { Console.WriteLine(b); } else if ((a == "D") && (b == "H")) { Console.WriteLine('D'); } else { Console.WriteLine('H'); } } } }
// Rextester.Program.Main is the entry point for your code. Don't change it. // Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Your code goes var input = Console.ReadLine(); var array = input.Split(' '); var a = array[0]; var b = array[1]; if (a == "H") { Console.WriteLine(b); } else if ((a == "D") && (b == "H")) { Console.WriteLine('D'); } else { Console.WriteLine('H'); } } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
141
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int w = sc.NextInt(); int a = sc.NextInt(); int b = sc.NextInt(); int l = Math.Min(a, b); int r = Math.Max(a, b); int answer = Math.Max(0, l + w - r); Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int w = sc.NextInt(); int a = sc.NextInt(); int b = sc.NextInt(); int l = Math.Min(a, b); int r = Math.Max(a, b); int answer = Math.Max(0, r - (l + w)); Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
408
6
using System; namespace Sample1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int width = int.Parse(input.Split(' ')[0]); int a = int.Parse(input.Split(' ')[1]); int b = int.Parse(input.Split(' ')[2]); int answer = 0; // b- (w+a) if (b > a) { answer = b - (width + a); if (answer > 0) { Console.WriteLine(answer); } else { Console.WriteLine(0); } } else if (b < a) { answer = a - (width + b); if (answer > 0) { Console.WriteLine(answer); } else { Console.WriteLine(0); } } } } }
using System; namespace Sample1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int width = int.Parse(input.Split(' ')[0]); int a = int.Parse(input.Split(' ')[1]); int b = int.Parse(input.Split(' ')[2]); int answer = 0; // b- (w+a) if (b >= a) { answer = b - (width + a); if (answer > 0) { Console.WriteLine(answer); } else { Console.WriteLine(0); } } else if (b < a) { answer = a - (width + b); if (answer > 0) { Console.WriteLine(answer); } else { Console.WriteLine(0); } } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
184
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int answer = 1; int now = 0; while (true) { now += answer; answer++; if (now >= x) { break; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int answer = 1; int now = 0; while (true) { now += answer; if (now >= x) { break; } answer++; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 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], ["+", 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
383
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N = GetLong(); long sum = 0; long ans = 0; for (int i = 0; i < N; i++) { sum += i; if (sum >= N) { ans = i; break; } } 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; 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.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N = GetLong(); long sum = 0; long ans = 0; for (int i = 0; i < int.MaxValue; i++) { sum += i; if (sum >= N) { ans = i; break; } } 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; 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, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 199], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22]]
8
1,500
4