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; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200323D.Input; namespace Asakatsu20200323D { static class Input { private static Func<string, T[]> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray(); private static Func<string, T> Convert<T>() { Type t = typeof(T); if (t == typeof(string)) return _ => (T)(object)_; if (t == typeof(int)) return _ => (T)(object) int.Parse(_); if (t == typeof(long)) return _ => (T)(object) long.Parse(_); if (t == typeof(double)) return _ => (T)(object) double.Parse(_); if (t == typeof(string[])) return _ => (T)(object)Cast<string>()(_); if (t == typeof(int[])) return _ => (T)(object)Cast<int>()(_); if (t == typeof(long[])) return _ => (T)(object)Cast<long>()(_); if (t == typeof(double[])) return _ => (T)(object)Cast<double>()(_); throw new NotSupportedException(t + "is not supported."); } private static T Convert<T>(string s) => Convert<T>()(s); private static string String() => Console.ReadLine(); private static string[] String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToArray(); public static void Cin<T>(out T a) => a = Convert<T>(String()); public static void Cin<T1, T2>(out T1 a1, out T2 a2) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); } public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); } public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3, out T4 a4) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); } public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); } public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5, out T6 a6) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); set(v[5], out a6); } private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s); public static void Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray(); public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) { l1 = new T1[n]; l2 = new T2[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i]); } public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2, out T3[] l3) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i]); } public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2, out T3[] l3, out T4[] l4) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; l4 = new T4[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i], out l4[i]); } public static void Cin<T>(out T[] a) => a = Convert<T[]>(String()); public static void Cin<T>(long h, out T[][] map) => map = String(h).Select(Convert<T[]>()).ToArray(); } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); new Solver().Solve(); Console.Out.Flush(); } public static void Debug() { new Solver().Solve(); } } class Solver { private long N; private long M; private long[] A; private long[] B; private long[] C; public void Solve() { Cin(out N, out M); Cin(out A); Cin(M, out B, out C); var sd = new SortedDictionary<long, long>(new SortRule()); for (int i = 0; i < M; i++) { if (!sd.ContainsKey(C[i])) sd.Add(C[i], 0); sd[C[i]] += B[i]; } Array.Sort(A); Array.Reverse(A); return; long rest = N; long sum = 0; long index = 0; foreach (var v in sd) { if (rest <= 0) break; while (rest > 0 && A[index] > v.Key) { sum += A[index]; rest--; index++; } if (rest > v.Value) { rest -= v.Value; sum += v.Key * v.Value; continue; } sum += v.Key * rest; rest = 0; } while (rest > 0) { sum += A[index]; rest--; index++; } Console.WriteLine(sum); } } public sealed class SortRule : IComparer<long> { public int Compare(long x, long y) { return (int)y - (int)x; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200323D.Input; namespace Asakatsu20200323D { static class Input { private static Func<string, T[]> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray(); private static Func<string, T> Convert<T>() { Type t = typeof(T); if (t == typeof(string)) return _ => (T)(object)_; if (t == typeof(int)) return _ => (T)(object) int.Parse(_); if (t == typeof(long)) return _ => (T)(object) long.Parse(_); if (t == typeof(double)) return _ => (T)(object) double.Parse(_); if (t == typeof(string[])) return _ => (T)(object)Cast<string>()(_); if (t == typeof(int[])) return _ => (T)(object)Cast<int>()(_); if (t == typeof(long[])) return _ => (T)(object)Cast<long>()(_); if (t == typeof(double[])) return _ => (T)(object)Cast<double>()(_); throw new NotSupportedException(t + "is not supported."); } private static T Convert<T>(string s) => Convert<T>()(s); private static string String() => Console.ReadLine(); private static string[] String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToArray(); public static void Cin<T>(out T a) => a = Convert<T>(String()); public static void Cin<T1, T2>(out T1 a1, out T2 a2) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); } public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); } public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3, out T4 a4) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); } public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); } public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5, out T6 a6) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); set(v[5], out a6); } private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s); public static void Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray(); public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) { l1 = new T1[n]; l2 = new T2[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i]); } public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2, out T3[] l3) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i]); } public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2, out T3[] l3, out T4[] l4) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; l4 = new T4[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i], out l4[i]); } public static void Cin<T>(out T[] a) => a = Convert<T[]>(String()); public static void Cin<T>(long h, out T[][] map) => map = String(h).Select(Convert<T[]>()).ToArray(); } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); new Solver().Solve(); Console.Out.Flush(); } public static void Debug() { new Solver().Solve(); } } class Solver { private long N; private long M; private long[] A; private long[] B; private long[] C; public void Solve() { Cin(out N, out M); Cin(out A); Cin(M, out B, out C); var sd = new SortedDictionary<long, long>(new SortRule()); for (int i = 0; i < M; i++) { if (!sd.ContainsKey(C[i])) sd.Add(C[i], 0); sd[C[i]] += B[i]; } Array.Sort(A); Array.Reverse(A); long rest = N; long sum = 0; long index = 0; foreach (var v in sd) { if (rest <= 0) break; while (rest > 0 && A[index] > v.Key) { sum += A[index]; rest--; index++; } if (rest > v.Value) { rest -= v.Value; sum += v.Key * v.Value; continue; } sum += v.Key * rest; rest = 0; } while (rest > 0) { sum += A[index]; rest--; index++; } Console.WriteLine(sum); } } public sealed class SortRule : IComparer<long> { public int Compare(long x, long y) { return (int)y - (int)x; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
1,680
2
using System; using System.Collections.Generic; using System.Linq; namespace ABC127D { class Program { static void Main(string[] args) { long[] NM = CIN.LongArray(); long N = NM[0]; long M = NM[1]; long[] A = CIN.LongArray(); long[] B = new long[M]; long[] C = new long[M]; for (int i = 0; i < M; i++) { long[] BC = CIN.LongArray(); B[i] = BC[0]; C[i] = BC[1]; } Array.Sort(A); Array.Reverse(A); var make = new SortedDictionary<long, long>(new SortRule()); for (int i = 0; i < M; i++) { if (make.ContainsKey(C[i])) { make[C[i]] += B[i]; continue; } make.Add(C[i], B[i]); } long Count = 0; long Score = 0; long Index = 0; foreach (var VARIABLE in make) { if (Index > N - 1 || Count >= N) { break; } while (VARIABLE.Key <= A[Index]) { Score += A[Index]; Index++; Count++; if (Index > N - 1 || Count >= N) { break; } } if (Index > N - 1 || Count >= N) { break; } long rest = Math.Min(N - Index - 1, N - Count); Count += Math.Min(VARIABLE.Value, rest); Score += VARIABLE.Key * Math.Min(VARIABLE.Value, rest); } long res = Math.Min(N - Index, N - Count); for (int i = 0; i < res; i++) { Score += A[Index]; Index++; Count++; if (Index > N - 1 || Count >= N) { break; } } Console.WriteLine(Score); } } public sealed class SortRule : IComparer<long> { public int Compare(long x, long y) { return (int)y - (int)x; } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC127D { class Program { static void Main(string[] args) { long[] NM = CIN.LongArray(); long N = NM[0]; long M = NM[1]; long[] A = CIN.LongArray(); long[] B = new long[M]; long[] C = new long[M]; for (int i = 0; i < M; i++) { long[] BC = CIN.LongArray(); B[i] = BC[0]; C[i] = BC[1]; } Array.Sort(A); Array.Reverse(A); var make = new SortedDictionary<long, long>(new SortRule()); for (int i = 0; i < M; i++) { if (make.ContainsKey(C[i])) { make[C[i]] += B[i]; continue; } make.Add(C[i], B[i]); } long Count = 0; long Score = 0; long Index = 0; foreach (var VARIABLE in make) { if (Index > N - 1 || Count >= N) { break; } while (VARIABLE.Key <= A[Index]) { Score += A[Index]; Index++; Count++; if (Index > N - 1 || Count >= N) { break; } } if (Index > N - 1 || Count >= N) { break; } long rest = Math.Min(N - Index, N - Count); Count += Math.Min(VARIABLE.Value, rest); Score += VARIABLE.Key * Math.Min(VARIABLE.Value, rest); } long res = Math.Min(N - Index, N - Count); for (int i = 0; i < res; i++) { Score += A[Index]; Index++; Count++; if (Index > N - 1 || Count >= N) { break; } } Console.WriteLine(Score); } } public sealed class SortRule : IComparer<long> { public int Compare(long x, long y) { return (int)y - (int)x; } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
646
2
using System; using System.Linq; using System.Collections.Generic; public class P { public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = input[0]; var M = input[1]; var cards = new List<long>( Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse)); cards.Sort(); var cardArray = cards.ToArray(); List<change> changes = new List<change>(); for (int i = 0; i < M; i++) { changes.Add(new change( Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse))); } changes.Sort(); long cardCurrent = 0; long changeCurrent = 1; foreach (var tgt in changes) { changeCurrent = 1; cardCurrent = 0; while (cardCurrent < N && cardArray[cardCurrent] < tgt.power && changeCurrent <= tgt.lives) { cardArray[cardCurrent] = tgt.power; cardCurrent++; changeCurrent++; } } Console.WriteLine(cardArray.Sum()); } class change : IComparable<change> { public long power { get; set; } public long lives { get; set; } public change(long[] x) { power = x[1]; lives = x[0]; } public int CompareTo(change x) { return (x.power == this.power) ? 0 : (x.power - this.power < 0) ? -1 : 1; } } }
using System; using System.Linq; using System.Collections.Generic; public class P { public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = input[0]; var M = input[1]; var cards = new List<long>( Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse)); cards.Sort(); var cardArray = cards.ToArray(); List<change> changes = new List<change>(); for (int i = 0; i < M; i++) { changes.Add(new change( Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse))); } changes.Sort(); long cardCurrent = 0; long changeCurrent = 1; foreach (var tgt in changes) { changeCurrent = 1; while (cardCurrent < N && cardArray[cardCurrent] < tgt.power && changeCurrent <= tgt.lives) { cardArray[cardCurrent] = tgt.power; cardCurrent++; changeCurrent++; } } Console.WriteLine(cardArray.Sum()); } class change : IComparable<change> { public long power { get; set; } public long lives { get; set; } public change(long[] x) { power = x[1]; lives = x[0]; } public int CompareTo(change x) { return (x.power == this.power) ? 0 : (x.power - this.power < 0) ? -1 : 1; } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
349
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemD { class Program { static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = read[0]; var M = read[1]; var As = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); As.Sort(); var dictKeyCValueB = new List<KeyValuePair<int, int>>(); for (int i = 0; i < M; i++) { read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); dictKeyCValueB.Add(new KeyValuePair<int, int>(read[1], read[0])); } var decendingDict = dictKeyCValueB.OrderByDescending(kv => kv.Key).ToArray(); var Ds = new List<int>(); var L = dictKeyCValueB.Count(); for (int i = 0; i < dictKeyCValueB.Count(); i++) { Ds.AddRange(Enumerable.Repeat(dictKeyCValueB[i].Key, (int)dictKeyCValueB[i].Value)); if (Ds.Count() >= N) break; } long ret = 0; for (int i = 0; i < N; i++) { if (i < Ds.Count() && As[i] < Ds[i]) ret += (long)Ds[i]; else ret += (long)As[i]; } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemD { class Program { static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = read[0]; var M = read[1]; var As = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); As.Sort(); var dictKeyCValueB = new List<KeyValuePair<int, int>>(); for (int i = 0; i < M; i++) { read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); dictKeyCValueB.Add(new KeyValuePair<int, int>(read[1], read[0])); } var decendingDict = dictKeyCValueB.OrderByDescending(kv => kv.Key).ToArray(); var Ds = new List<int>(); var L = decendingDict.Count(); for (int i = 0; i < decendingDict.Count(); i++) { Ds.AddRange( Enumerable.Repeat(decendingDict[i].Key, (int)decendingDict[i].Value)); if (Ds.Count() >= N) break; } long ret = 0; for (int i = 0; i < N; i++) { if (i < Ds.Count() && As[i] < Ds[i]) ret += (long)Ds[i]; else ret += (long)As[i]; } Console.WriteLine(ret); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 214, 205, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 214, 205, 204, 205, 22], ["-", 0, 28, 0, 74, 51, 214, 205, 204, 205, 22], ["+", 0, 28, 0, 74, 51, 214, 205, 204, 205, 22]]
8
385
8
using System; using System.Collections.Generic; namespace ABC127 { struct Rule : IComparable<Rule> { public int b, c; public Rule(int i_b, int i_c) { b = i_b; c = i_c; } public int CompareTo(Rule other) { // intと降順と昇順を逆にしたいので工夫する int cCompareTo = this.c.CompareTo(other.c); if (cCompareTo != 0) { return -cCompareTo; } int bCompareTo = this.b.CompareTo(other.b); return -bCompareTo; } } class Program { static void Main(string[] args) { // 入力 int N, M; int[] firstArray = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); N = firstArray[0]; M = firstArray[1]; int[] secondArray = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); List<int> A = new List<int>(N); for (int i = 0; i < N; i++) { A.Add(secondArray[i]); } List<Rule> rules = new List<Rule>(M); for (int i = 0; i < M; i++) { int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); rules.Add(new Rule(array[0], array[1])); } // 処理・出力 /* 正攻法はこう - 0~M-1に対して以下の処理 - A[]をソート - A[0]~A[B[i]]のうち、C[i]以下のものをC[i]に書き換え(これのせいでO(n^2)となる) - これで最大の時の結果が出る。あとは和を求めればよい。 こいつの非効率なところは「同じ値を書き換えまくる」である。 A[i]は1回しか書き換えないようなアルゴリズムは、こう。 - A[]をソート - B[i],C[i]をC[i]が大きい順にソート - A[]を上から順に「B[i]個だけC[i]に書き換える、ただしA[j]>=C[i]となったらもう書き換えない」をする **/ // Aをソート A.Sort(); // B,Cをソート rules.Sort(); // Aを書き換え int rulesIndex = 0; int aIndex = 0; while (aIndex < N && rulesIndex < M) { for (int i = aIndex; i < aIndex + rules[rulesIndex].b; i++) { if (A[i] < rules[rulesIndex].c) { A[i] = rules[rulesIndex].c; } else { // 書き換え終了 aIndex = N; break; } if (i >= N) { break; } } aIndex += rules[rulesIndex].b; rulesIndex++; } // 合計値の計算 Int64 total = 0; for (int i = 0; i < N; i++) { total += A[i]; } Console.WriteLine(total); } } }
using System; using System.Collections.Generic; namespace ABC127 { class Program { struct Rule : IComparable<Rule> { public int b, c; public Rule(int i_b, int i_c) { b = i_b; c = i_c; } public int CompareTo(Rule other) { // intと降順と昇順を逆にしたいので工夫する int cCompareTo = this.c.CompareTo(other.c); if (cCompareTo != 0) { return -cCompareTo; } int bCompareTo = this.b.CompareTo(other.b); return -bCompareTo; } } static void Main(string[] args) { // 入力 int N, M; int[] firstArray = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); N = firstArray[0]; M = firstArray[1]; int[] secondArray = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); List<int> A = new List<int>(N); for (int i = 0; i < N; i++) { A.Add(secondArray[i]); } List<Rule> rules = new List<Rule>(M); for (int i = 0; i < M; i++) { int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); rules.Add(new Rule(array[0], array[1])); } // 処理・出力 /* 正攻法はこう - 0~M-1に対して以下の処理 - A[]をソート - A[0]~A[B[i]]のうち、C[i]以下のものをC[i]に書き換え(これのせいでO(n^2)となる) - これで最大の時の結果が出る。あとは和を求めればよい。 こいつの非効率なところは「同じ値を書き換えまくる」である。 A[i]は1回しか書き換えないようなアルゴリズムは、こう。 - A[]をソート - B[i],C[i]をC[i]が大きい順にソート - A[]を上から順に「B[i]個だけC[i]に書き換える、ただしA[j]>=C[i]となったらもう書き換えない」をする **/ // Aをソート A.Sort(); // B,Cをソート rules.Sort(); // Aを書き換え int rulesIndex = 0; int aIndex = 0; while (aIndex < N && rulesIndex < M) { for (int i = aIndex; i < aIndex + rules[rulesIndex].b; i++) { if (i >= N) { // 書き換え終了 aIndex = N; break; } if (A[i] < rules[rulesIndex].c) { A[i] = rules[rulesIndex].c; } else { // 書き換え終了 aIndex = N; break; } } aIndex += rules[rulesIndex].b; rulesIndex++; } // 合計値の計算 Int64 total = 0; for (int i = 0; i < N; i++) { total += A[i]; } Console.WriteLine(total); } } }
[["+", 0, 208, 0, 209, 8, 201, 0, 235, 0, 269], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 0, 209, 8, 201, 0, 235, 8, 201, 0, 45], ["-", 0, 208, 0, 209, 8, 201, 0, 235, 0, 269], ["-", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["-", 0, 209, 8, 201, 0, 235, 8, 201, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45]]
8
467
30
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { Console.WriteLine(Solve()); return; } public static string Solve() { int[] input = ReadInts(); int N = input[0]; int M = input[1]; long[] A = ReadLongs(); Array.Sort(A); List<long[]> bc = new List<long[]>(M); for (int i = 0; i < M; i++) { long[] tmp = ReadLongs(); bc.Add(new long[] { tmp[0], tmp[1] }); } bc.Sort((a, b) => Math.Sign(b[1] - a[1])); int cnt = 0; int k = 0; while (k < M || cnt < N) { long b = bc[k][0]; long c = bc[k][1]; k++; if (c < A[cnt]) break; while (b > 0 || cnt < N) { if (c > A[cnt]) A[cnt] = c; else break; b--; cnt++; } } long ans = A.Sum(); return ans.ToString(); } private static string Read() { return Console.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; class Program { static void Main() { Console.WriteLine(Solve()); return; } public static string Solve() { int[] input = ReadInts(); int N = input[0]; int M = input[1]; long[] A = ReadLongs(); Array.Sort(A); List<long[]> bc = new List<long[]>(M); for (int i = 0; i < M; i++) { long[] tmp = ReadLongs(); bc.Add(new long[] { tmp[0], tmp[1] }); } bc.Sort((a, b) => Math.Sign(b[1] - a[1])); int cnt = 0; int k = 0; while (k < M && cnt < N) { long b = bc[k][0]; long c = bc[k][1]; k++; if (c < A[cnt]) break; while (b > 0 && cnt < N) { if (c > A[cnt]) A[cnt] = c; else break; b--; cnt++; } } long ans = A.Sum(); return ans.ToString(); } private static string Read() { return Console.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, 195, 8, 196, 0, 52, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 52, 8, 196, 0, 52, 15, 16, 17, 106], ["+", 0, 52, 8, 196, 0, 52, 15, 16, 17, 98]]
8
441
4
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using static System.Math; class Program { static string l; static int n; static long mod = (long)1e9 + 7; static void Main() { l = Console.ReadLine(); n = l.Length; long[,] dp = new long[n, 2]; dp[0, 0] = 2; dp[0, 1] = 1; for (int i = 1; i < n; i++) { if (l[i] == '1') { dp[i, 0] = 2 * dp[i - 1, 0] % mod; dp[i, 1] = dp[i - 1, 0]; dp[i, 1] += 3 * dp[i - 1, 1] % mod; dp[i, 1] %= mod; continue; } dp[i, 0] = dp[i - 1, 0]; dp[i, 1] = 3 * dp[i - 1, 1] % mod; } Console.WriteLine(dp[n - 1, 0] + dp[n - 1, 1] % mod); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using static System.Math; class Program { static string l; static int n; static long mod = (long)1e9 + 7; static void Main() { l = Console.ReadLine(); n = l.Length; long[,] dp = new long[n, 2]; dp[0, 0] = 2; dp[0, 1] = 1; for (int i = 1; i < n; i++) { if (l[i] == '1') { dp[i, 0] = (2 * dp[i - 1, 0]) % mod; dp[i, 1] = dp[i - 1, 0]; dp[i, 1] += (3 * dp[i - 1, 1]) % mod; dp[i, 1] %= mod; continue; } dp[i, 0] = dp[i - 1, 0]; dp[i, 1] = 3 * dp[i - 1, 1] % mod; } Console.WriteLine((dp[n - 1, 0] + dp[n - 1, 1]) % mod); } }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
264
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; namespace Program { public static class ABC129F { static public void Solve() { var L = NextLong; var A = NextLong; var B = NextLong; var M = NextLong; Mod._mod = M; var lim = 1L; var ans = new Mat<Mod>(new Mod[,] { { 0, A, 1 } }); var totalN = 0L; for (int i = 0; i < 19; ++i) { lim *= 10; if (lim - A - 1 < B) continue; var n = (lim - A - 1) / B - totalN + 1; if (totalN + n >= L) n = L - totalN; totalN += n; var mat = new Mat<Mod>(new Mod[,] { { lim, 0, 0 }, { 1, 1, 0 }, { 0, B, 1 } }); mat = Pow(mat, n); ans *= mat; if (totalN == L) break; } Console.WriteLine(ans[0, 0]); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val %= x) < 0) _val += _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) { var t = x._val + y._val; return new Mod() { _val = t < _mod ? t : t - _mod }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, long y) => x._val + y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(long x, Mod y) => x + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) { var t = x._val - y._val; return new Mod() { _val = t < _mod ? t : t - _mod }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, long y) => x._val - y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(long x, Mod y) => x - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, long y) => x._val == y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(long x, Mod y) => x == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, long y) => x._val != y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(long x, Mod y) => x != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } class Mat<T> { private T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mod Pow(Mod x, long y) => Mod.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; namespace Program { public static class ABC129F { static public void Solve() { var L = NextLong; var A = NextLong; var B = NextLong; var M = NextLong; Mod._mod = M; var lim = 1L; var ans = new Mat<Mod>(new Mod[,] { { 0, A, 1 } }); var totalN = 0L; for (int i = 0; i < 19; ++i) { lim *= 10; if (lim - A - 1 < B) continue; var n = (lim - A - 1) / B - totalN + 1; if (totalN + n >= L) n = L - totalN; totalN += n; var mat = new Mat<Mod>(new Mod[,] { { lim, 0, 0 }, { 1, 1, 0 }, { 0, B, 1 } }); mat = Pow(mat, n); ans *= mat; if (totalN == L) break; } Console.WriteLine(ans[0, 0]); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) { var t = x._val + y._val; return new Mod() { _val = t < _mod ? t : t - _mod }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, long y) => x._val + y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(long x, Mod y) => x + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) { var t = x._val - y._val; return new Mod() { _val = t < _mod ? t : t - _mod }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, long y) => x._val - y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(long x, Mod y) => x - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, long y) => x._val == y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(long x, Mod y) => x == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, long y) => x._val != y; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(long x, Mod y) => x != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } class Mat<T> { private T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return new Mat<T>(tm); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mod Pow(Mod x, long y) => Mod.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
[["-", 15, 16, 31, 23, 0, 11, 0, 202, 0, 132], ["+", 15, 16, 31, 23, 0, 11, 0, 202, 0, 32], ["+", 15, 16, 31, 23, 0, 11, 12, 16, 17, 109], ["+", 15, 16, 31, 23, 0, 11, 12, 16, 12, 22]]
8
4,286
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var L = cin.nextlong; var A = cin.nextlong; var B = cin.nextlong; var M = cin.nextint; var cnt = new long[18]; var sum = new long[18]; //(k+1)桁について考える long BASE = 1; for (int k = 0; k < 18; k++, BASE *= 10) { if (BASE * 10 <= A) { continue; } if (A + B * (L - 1) < BASE) { break; } var left = (BASE - A + B - 1) / B; if (left < 0) left = 0; var right = (BASE * 10 - A - 1) / B; if (right >= L) right = L - 1; if (right < left) continue; cnt[k] = right - left + 1; //初項 var first = A + B * left; var last = A + B * right; sum[k] += first % M * F(cnt[k] - 1, BASE * 10 % M, M) % M; sum[k] += B % M * G(cnt[k] - 1, BASE * 10 % M, M) % M; sum[k] %= M; // WriteLine($"first={first} last={last} sum={sum[k]} cnt={cnt[k]}"); // WriteLine($"right={first % M * F(cnt[k] - 1, BASE * 10 % M, M) % M} F={ // F(cnt[k] - 1, BASE * 10 % M, M)}"); WriteLine($"left={B % M * G(cnt[k] - // 1, BASE * 10 % M, M) % M} G={ G(cnt[k] - 1, BASE * 10 % M, M)}"); } long ans = 0; long before = 1; for (int k = 18 - 1; k >= 0; k--) { ans += sum[k] * before % M; before = before * powmod(powmod(10, k + 1, M), cnt[k], M) % M; } WriteLine(ans % M); } long G(long L, long BASE, long mod) { if (L == 0) return 0; if (L % 2 == 1) { long g = G(L / 2, BASE, mod); long f = F(L / 2, BASE, mod); return (g * (powmod(BASE, L / 2 + 1, mod) + 1) + (L / 2 + 1) * f) % mod; } else { return (L + G(L - 1, BASE, mod) * BASE) % mod; } } long F(long L, long BASE, long mod) { if (L == 0) return 1; if (L % 2 == 1) { long d = F(L / 2, BASE, mod); return (d * powmod(BASE, L / 2 + 1, mod) + d) % mod; } else { return (BASE * F(L - 1, BASE, mod) + 1) % mod; } } // a^b(mod p) solution works in O(logb). long powmod(long a, long b, long p) { if (b == 0) return 1; if (b % 2 == 0) { long d = powmod(a, b / 2, p); return d * d % p; } else { return a * powmod(a, b - 1, p) % p; } } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => 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 => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var L = cin.nextlong; var A = cin.nextlong; var B = cin.nextlong; var M = cin.nextint; var cnt = new long[18]; var sum = new long[18]; //(k+1)桁について考える long BASE = 1; for (int k = 0; k < 18; k++, BASE *= 10) { if (BASE * 10 <= A) { continue; } if (A + B * (L - 1) < BASE) { break; } var left = (BASE - A + B - 1) / B; if (left < 0) left = 0; var right = (BASE * 10 - A - 1) / B; if (right >= L) right = L - 1; if (right < left) continue; cnt[k] = right - left + 1; //初項 var first = A + B * left; var last = A + B * right; sum[k] += first % M * F(cnt[k] - 1, BASE * 10 % M, M) % M; sum[k] += B % M * G(cnt[k] - 1, BASE * 10 % M, M) % M; sum[k] %= M; // WriteLine($"first={first} last={last} sum={sum[k]} cnt={cnt[k]}"); // WriteLine($"right={first % M * F(cnt[k] - 1, BASE * 10 % M, M) % M} F={ // F(cnt[k] - 1, BASE * 10 % M, M)}"); WriteLine($"left={B % M * G(cnt[k] - // 1, BASE * 10 % M, M) % M} G={ G(cnt[k] - 1, BASE * 10 % M, M)}"); } long ans = 0; long before = 1; for (int k = 18 - 1; k >= 0; k--) { ans += sum[k] * before % M; before = before * powmod(powmod(10, k + 1, M), cnt[k], M) % M; } WriteLine(ans % M); } long G(long L, long BASE, long mod) { if (L == 0) return 0; if (L % 2 == 1) { long g = G(L / 2, BASE, mod); long f = F(L / 2, BASE, mod); return (g * (powmod(BASE, L / 2 + 1, mod) + 1) + (L / 2 + 1) % mod * f) % mod; } else { return (L + G(L - 1, BASE, mod) * BASE) % mod; } } long F(long L, long BASE, long mod) { if (L == 0) return 1; if (L % 2 == 1) { long d = F(L / 2, BASE, mod); return (d * powmod(BASE, L / 2 + 1, mod) + d) % mod; } else { return (BASE * F(L - 1, BASE, mod) + 1) % mod; } } // a^b(mod p) solution works in O(logb). long powmod(long a, long b, long p) { if (b == 0) return 1; if (b % 2 == 0) { long d = powmod(a, b / 2, p); return d * d % p; } else { return a * powmod(a, b - 1, p) % p; } } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => 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 => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["+", 31, 23, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 12, 22]]
8
1,451
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; static class Program { static int mod; static void Main() { Sc sc = new Sc(); var s = sc.La; mod = (int)s[3]; long[][] b = new long[][] { new long[] { 0 }, new long[] { s[2] }, new long[] { s[1] } }; long k = 0, m = 0, p = 1; for (int i = 1; m < s[0]; i++) { p *= 10; k = (p - s[1]) / s[2] + ((p - s[1]) % s[2] == 0 ? 0 : 1); k = Min(k, s[0]); if (k < 1) { continue; } long[][] g = new long[][] { new long[] { (p % mod), 0, 1 }, new long[] { 0, 1, 0 }, new long[] { 0, 1, 1 } }; b = Mp(b, g, k - m); m = k; } Console.WriteLine("{0}", b[0][0]); } static long[][] Mp(long[][] r, long[][] x, long e) { while (e > 0) { if ((e & 1) > 0) { r = Mm(x, r); } x = Mm(x, x); e >>= 1; } return r; } static long[][] Mm(long[][] a, long[][] b) { long[][] q = new long [a.Length][]; for (int j = 0; j < a.Length; j++) { q[j] = new long[b[0].Length]; for (int i = 0; i < b[0].Length; i++) { for (int k = 0; k < a.Length; k++) { q[j][i] = (q[j][i] + a[j][k] * b[k][i]) % mod; } } } return q; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2(int b) { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } public int[] Ia3(int a, int b) { return Array.ConvertAll( ((a != 0 ? b.ToString() + " " : "") + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(int a, int b, int c, int d) { return Array.ConvertAll(((a != 0 ? b.ToString() + " " : "") + Console.ReadLine() + (c != 0 ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2(int b) { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } public long[] La3(int a, int b) { return Array.ConvertAll( ((a != 0 ? b.ToString() + " " : "") + Console.ReadLine()).Split(), long.Parse); } public long[] La3(int a, int b, int c, int d) { return Array.ConvertAll(((a != 0 ? b.ToString() + " " : "") + Console.ReadLine() + (c != 0 ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; static class Program { static int mod; static void Main() { Sc sc = new Sc(); var s = sc.La; mod = (int)s[3]; long[][] b = new long[][] { new long[] { 0 }, new long[] { s[2] % mod }, new long[] { s[1] % mod } }; long k = 0, m = 0, p = 1; for (int i = 1; m < s[0]; i++) { p *= 10; k = (p - s[1]) / s[2] + ((p - s[1]) % s[2] == 0 ? 0 : 1); k = Min(k, s[0]); if (k < 1) { continue; } long[][] g = new long[][] { new long[] { (p % mod), 0, 1 }, new long[] { 0, 1, 0 }, new long[] { 0, 1, 1 } }; b = Mp(b, g, k - m); m = k; } Console.WriteLine("{0}", b[0][0]); } static long[][] Mp(long[][] r, long[][] x, long e) { while (e > 0) { if ((e & 1) > 0) { r = Mm(x, r); } x = Mm(x, x); e >>= 1; } return r; } static long[][] Mm(long[][] a, long[][] b) { long[][] q = new long [a.Length][]; for (int j = 0; j < a.Length; j++) { q[j] = new long[b[0].Length]; for (int i = 0; i < b[0].Length; i++) { for (int k = 0; k < a.Length; k++) { q[j][i] = (q[j][i] + a[j][k] * b[k][i]) % mod; } } } return q; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2(int b) { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } public int[] Ia3(int a, int b) { return Array.ConvertAll( ((a != 0 ? b.ToString() + " " : "") + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(int a, int b, int c, int d) { return Array.ConvertAll(((a != 0 ? b.ToString() + " " : "") + Console.ReadLine() + (c != 0 ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2(int b) { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } public long[] La3(int a, int b) { return Array.ConvertAll( ((a != 0 ? b.ToString() + " " : "") + Console.ReadLine()).Split(), long.Parse); } public long[] La3(int a, int b, int c, int d) { return Array.ConvertAll(((a != 0 ? b.ToString() + " " : "") + Console.ReadLine() + (c != 0 ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 0, 229, 0, 227, 0, 229, 0, 16, 17, 109], ["+", 0, 229, 0, 227, 0, 229, 0, 16, 12, 22]]
8
1,369
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Ints; var N = o[0]; var A = o[1] - 1; var B = o[2] - 1; var C = o[3] - 1; var D = o[4] - 1; var S = Str; YN(f(N, A, B, C, D, S)); } bool f(int n, int a, int b, int c, int d, string s) { for (int i = 1; i < n; ++i) { if (a < i - 1 && i < c && s[i] == '#' && s[i - 1] == '#') { return false; } if (b < i - 1 && i < d && s[i] == '#' && s[i - 1] == '#') { return false; } } if (c < d) return true; if (c > d) { var last = 0; for (int i = b; i <= d; ++i) { if (s[i] == '.') ++last; else { last = 0; } if (last > 2) return true; } } return false; } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Ints; var N = o[0]; var A = o[1] - 1; var B = o[2] - 1; var C = o[3] - 1; var D = o[4] - 1; var S = Str; YN(f(N, A, B, C, D, S)); } bool f(int n, int a, int b, int c, int d, string s) { for (int i = 1; i < n; ++i) { if (a < i - 1 && i < c && s[i] == '#' && s[i - 1] == '#') { return false; } if (b < i - 1 && i < d && s[i] == '#' && s[i - 1] == '#') { return false; } } if (c < d) return true; if (c > d) { var last = 0; for (int i = b - 1; i <= d + 1; ++i) { if (s[i] == '.') ++last; else { last = 0; } if (last > 2) return true; } } return false; } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 64, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 64, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
1,290
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); double N = double.Parse(s[0]); double K = double.Parse(s[1]); double answer = 0; if (N >= K) { answer += (N - K + 1) / N; } for (int i = 1; i <= Math.Min(N, (int)K - 1); i++) { double score = i; double count = 0; while (K >= score) { score *= 2; count++; } answer += (1 / N) * Math.Pow(0.5, count); } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); double N = double.Parse(s[0]); double K = double.Parse(s[1]); double answer = 0; if (N >= K) { answer += (N - K + 1) / N; } for (int i = 1; i <= Math.Min(N, (int)K - 1); i++) { double score = i; double count = 0; while (K > score) { score *= 2; count++; } answer += (1 / N) * Math.Pow(0.5, count); } Console.WriteLine(answer); } } }
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 47]]
8
192
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); var N = NK[0]; var K = NK[1]; double count = 0; for (int i = 1; i <= N; i++) { if (i < K) { var jou = (int)Math.Ceiling(Math.Log(K / i, 2)); count += 1 / (N * Math.Pow(2, jou)); } else { count = 1 / N; } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); var N = NK[0]; var K = NK[1]; double count = 0; for (int i = 1; i <= N; i++) { if (i < K) { var jou = (int)Math.Ceiling(Math.Log(K / i, 2)); count += 1 / (N * Math.Pow(2, jou)); } else { count += 1 / N; } } Console.WriteLine(count); } } }
[["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
168
2
using System; using System.Collections.Generic; namespace ABC126_C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int n = int.Parse(input[0]); int k = int.Parse(input[1]); double ans = 0; for (int i = 1; i <= n; i++) { long numberOfKakeru = 0; long nowNumber = i; // if (i < k) Console.WriteLine(i); while (nowNumber < k) { nowNumber *= 2; numberOfKakeru++; } // Console.Write(numberOfKakeru); ans += Math.Pow(0.5, numberOfKakeru); } ans = ans / 3; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace ABC126_C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int n = int.Parse(input[0]); int k = int.Parse(input[1]); double ans = 0; for (int i = 1; i <= n; i++) { long numberOfKakeru = 0; long nowNumber = i; // if (i < k) Console.WriteLine(i); while (nowNumber < k) { nowNumber *= 2; numberOfKakeru++; } // Console.Write(numberOfKakeru); ans += Math.Pow(0.5, numberOfKakeru); } ans /= n; Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 90], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22]]
8
142
6
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = line[0]; var A = line[1]; var B = line[2]; var C = line[3]; var D = line[4]; var S = Console.ReadLine().ToCharArray(); var isGyaku = false; var startGyaku = 0; var endGyaku = N - 1; if (A < B && D < C) { isGyaku = true; startGyaku = Math.Max(A, B); endGyaku = Math.Min(C, D); } var isNotKasanari = false; var notKasanariStart = 0; var notKasanariEnd = 0; if (C < B) { isNotKasanari = true; notKasanariStart = C - 1; notKasanariEnd = B - 1; } var start = Math.Min(A, B); var end = Math.Max(C, D); var ans = "Yes"; var canGyaku = false; for (int i = 1; i < N; ++i) { if (isNotKasanari) { if (notKasanariStart < i && i < notKasanariEnd) continue; } if (start - 1 < i && i < end) { if (S[i - 1] == '#' && S[i] == '#') { ans = "No"; break; } } if (isGyaku && !canGyaku) { if (startGyaku - 1 < i && i < endGyaku - 1) { if (i < N - 1 && S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') { canGyaku = true; } } } } if (isGyaku) if (canGyaku == false) ans = "No"; Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = line[0]; var A = line[1]; var B = line[2]; var C = line[3]; var D = line[4]; var S = Console.ReadLine().ToCharArray(); var isGyaku = false; var startGyaku = 0; var endGyaku = N - 1; if (A < B && D < C) { isGyaku = true; startGyaku = Math.Max(A, B); endGyaku = Math.Min(C, D); } var isNotKasanari = false; var notKasanariStart = 0; var notKasanariEnd = 0; if (C < B) { isNotKasanari = true; notKasanariStart = C - 1; notKasanariEnd = B - 1; } var start = Math.Min(A, B); var end = Math.Max(C, D); var ans = "Yes"; var canGyaku = false; for (int i = 1; i < N; ++i) { if (isNotKasanari) { if (notKasanariStart < i && i < notKasanariEnd) continue; } if (start - 1 < i && i < end) { if (S[i - 1] == '#' && S[i] == '#') { ans = "No"; break; } } if (isGyaku && !canGyaku) { if (startGyaku - 2 < i && i < endGyaku) { if (i < N - 1 && S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') { canGyaku = true; } } } } if (isGyaku) { if (canGyaku == false) ans = "No"; } Console.WriteLine(ans); } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
414
6
using System; using static System.Console; class Program { public static void Main() { string t = ReadLine(); int n = t.Length; char[] s = new char[n]; for (int i = 0; i < n; i++) s[i] = t[i]; long ans = 0; int foundA = -1; for (int i = 0; i < n - 1; i++) { if (foundA < 0) { if (s[i] == 'A') { foundA = i; } } else if (s[i] == 'A') { continue; } else if (s[i] == 'B' && s[i + 1] == 'C') { s[i] = s[i + 1] = 'A'; s[foundA] = 'B'; s[foundA + 1] = 'C'; ans += i - foundA; foundA = -1; // WriteLine($"{i} {ans}"); // for (int k = 0; k < n; k++) Write(s[k]); // WriteLine(""); } else { foundA = -1; } } WriteLine(ans); } }
using System; using static System.Console; class Program { public static void Main() { string t = ReadLine(); int n = t.Length; char[] s = new char[n]; for (int i = 0; i < n; i++) s[i] = t[i]; long ans = 0; int foundA = -1; for (int i = 0; i < n - 1; i++) { if (foundA < 0) { if (s[i] == 'A') { foundA = i; } } else if (s[i] == 'A') { continue; } else if (s[i] == 'B' && s[i + 1] == 'C') { s[i] = s[i + 1] = 'A'; s[foundA] = 'B'; s[foundA + 1] = 'C'; ans += i - foundA; foundA += 2; i++; } else { foundA = -1; } } WriteLine(ans); } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
8
228
8
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const int M2 = 998244353; const long LM = 1L << 60; const double eps = 1e-11; static void Main(string[] args) { var s = sc.Str; long ans = 0; int a = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'A') { ++a; } else if (i + 1 < s.Length && s[i] == 'B' && s[i + 1] == 'C') { ans += a; i += 2; } else { a = 0; } } Prt(ans); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } public static bool operator>(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator<(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator >=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) >= 0; public static bool operator <=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) <= 0; } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; static readonly string dstring = "RDLU"; public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static pair<P, char>[] adjacents_with_str(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .ToArray(); public static pair<P, char>[] adjacents_with_str(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .Where(p => inside(p.v1.v1, p.v1.v2, h, w)) .ToArray(); public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static void Assert(bool cond) { if (!cond) throw new Exception(); } public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const int M2 = 998244353; const long LM = 1L << 60; const double eps = 1e-11; static void Main(string[] args) { var s = sc.Str; long ans = 0; int a = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'A') { ++a; } else if (i + 1 < s.Length && s[i] == 'B' && s[i + 1] == 'C') { ans += a; ++i; } else { a = 0; } } Prt(ans); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } public static bool operator>(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator<(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator >=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) >= 0; public static bool operator <=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) <= 0; } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; static readonly string dstring = "RDLU"; public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static pair<P, char>[] adjacents_with_str(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .ToArray(); public static pair<P, char>[] adjacents_with_str(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .Where(p => inside(p.v1.v1, p.v1.v2, h, w)) .ToArray(); public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static void Assert(bool cond) { if (!cond) throw new Exception(); } public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } }
[["+", 75, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
2,486
3
using System; using System.Collections.Generic; using System.Text; namespace atcoder { class ac { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int ans = 180 * n - 2; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; namespace atcoder { class ac { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int ans = 180 * (n - 2); Console.WriteLine(ans); } } }
[["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
8
81
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { new Program().Solve(); } void Solve() { Scanner cin = new Scanner(); int n = cin.NextInt(); Console.WriteLine(180 * n); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public char[] ArrayChar() { return Next().ToCharArray(); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { new Program().Solve(); } void Solve() { Scanner cin = new Scanner(); int n = cin.NextInt(); Console.WriteLine(180 * (n - 2)); } } 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 char[] ArrayChar() { return Next().ToCharArray(); } 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; } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
451
4
using System; namespace AtCoder20190601 { class ProgramA { static void Main(string[] args) { int N = int.Parse(args[0]); A(N); } static void A(int N) { Console.WriteLine((N - 2) * 180); } } }
using System; namespace AtCoder20190601 { class ProgramA { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); A(N); } static void A(int N) { Console.WriteLine((N - 2) * 180); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
62
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); string s = sc.Next(); bool ok = s.Where(c => c == 'x').Count() <= 8; string answer = ok ? "YES" : "NO"; 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(); string s = sc.Next(); bool ok = s.Where(c => c == 'x').Count() <= 7; string answer = ok ? "YES" : "NO"; 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, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
385
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()); Out.Flush(); } } } public class Solve { static List<string> lis = new List<string>(); static long N; public static void Answer() { var s = ReadLine(); int ng = s.Where(c => c == 'x').Count(); IO.WriteLineYES_or_NO(ng >= 8); } } 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()); Out.Flush(); } } } public class Solve { static List<string> lis = new List<string>(); static long N; public static void Answer() { var s = ReadLine(); int ng = s.Where(c => c == 'x').Count(); IO.WriteLineYES_or_NO(ng < 8); } } 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, 213, 3, 4, 0, 28, 0, 16, 17, 20], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 18]]
8
525
2
using System; namespace B___Sumo { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var count = 0; foreach (var p in s) { if (p == 'o') count++; } if (count + 15 - s.Length >= 8) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; namespace B___Sumo { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var count = 0; foreach (var p in s) { if (p == 'o') count++; } if (count + 15 - s.Length >= 8) Console.WriteLine("YES"); else Console.WriteLine("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
87
4
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> s = new List<int>(); static List<int> t = new List<int>(); static decimal result; static int N, K, M; static string a; static void Main() { Read2(); for (int i = 0; i < a.Length; i++) { if (a[i] == 'x') { result++; } } if (result < 8) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static void Read1() { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read2() { a = Console.ReadLine(); } }
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> s = new List<int>(); static List<int> t = new List<int>(); static decimal result; static int N, K, M; static string a; static void Main() { Read2(); for (int i = 0; i < a.Length; i++) { if (a[i] == 'x') { result++; } } if (result < 8) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } static void Read1() { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read2() { a = Console.ReadLine(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
191
4
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string S = Console.ReadLine(); int lose = 0; string ans = "YES"; for (int i = 0; i < S.Length; i++) { if (S[i] == 'x') { lose++; } } if (lose > 8) { ans = "NO"; } Console.WriteLine(ans); } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string S = Console.ReadLine(); int lose = 0; string ans = "YES"; for (int i = 0; i < S.Length; i++) { if (S[i] == 'x') { lose++; } } if (lose > 7) { ans = "NO"; } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
128
2
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var s = rs; var ans = 0; for (int i = 0; i < 15; i++) { if (i < s.Length) { if (s[i] == 'o') ans++; } else ans++; } if (ans >= 8) Console.WriteLine("Yes"); else Console.WriteLine("No"); } const long INF = 1L << 60; 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 IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++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(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } 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; 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 != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var s = rs; var ans = 0; for (int i = 0; i < 15; i++) { if (i < s.Length) { if (s[i] == 'o') ans++; } else ans++; } if (ans >= 8) Console.WriteLine("YES"); else Console.WriteLine("NO"); } const long INF = 1L << 60; 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 IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++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(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } 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; 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 != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
882
4
using System; public class Test { public static void Main() { // your code goes here string s = Console.ReadLine(); int k = s.Length; int win = 0, lose = 0; for (int i = 0; i < k; i++) { if (s[i] == 'o') win++; else lose++; } if (win + (15 - k) >= 8) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; public class Test { public static void Main() { // your code goes here string s = Console.ReadLine(); int k = s.Length; int win = 0, lose = 0; for (int i = 0; i < k; i++) { if (s[i] == 'o') win++; else lose++; } if (win + (15 - k) >= 8) Console.WriteLine("YES"); else Console.WriteLine("NO"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
107
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); string S = cin.next(); string ans = "Yes"; int count = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == 'x') count++; } if (count >= 8) ans = "No"; 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 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; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); string S = cin.next(); string ans = "YES"; int count = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == 'x') count++; } if (count >= 8) ans = "NO"; 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 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; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222]]
8
758
4
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string s = Console.ReadLine(); Console.WriteLine(s.Length - s.Replace("o", "").Length < 8 ? "NO" : "YES"); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string s = Console.ReadLine(); Console.WriteLine(s.Replace("o", "").Length >= 8 ? "NO" : "YES"); } }
[["-", 0, 41, 15, 16, 31, 16, 31, 214, 141, 22], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 33], ["-", 31, 16, 12, 214, 205, 213, 63, 214, 205, 22], ["-", 31, 16, 12, 214, 205, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
72
6
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var S = cin.next(); var o = S.Count(s => s == 'o'); var x = S.Count(s => s == 'x'); if (x >= 8) { // lose Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } public static class ListExtensions { public static T Dequeue<T>(this IList<T> self) { var result = self[0]; self.RemoveAt(0); return result; } public static void Enqueue<T>(this IList<T> self, T item) { self.Add(item); } public static T Peek<T>(this IList<T> self) { return self[0]; } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var S = cin.next(); var o = S.Count(s => s == 'o'); var x = S.Count(s => s == 'x'); if (x >= 8) { // lose Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } public static class ListExtensions { public static T Dequeue<T>(this IList<T> self) { var result = self[0]; self.RemoveAt(0); return result; } public static void Enqueue<T>(this IList<T> self, T item) { self.Add(item); } public static T Peek<T>(this IList<T> self) { return self[0]; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
554
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { string S = Console.ReadLine(); int winNum = S.Count(c => c == 'o'); var remain = 15 - S.Length; if (winNum + remain >= 8) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { string S = Console.ReadLine(); int winNum = S.Count(c => c == 'o'); var remain = 15 - S.Length; if (winNum + remain >= 8) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
115
4
using AtCoderBeginnerContest126.Questions; using AtCoderBeginnerContest126.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest126.Questions { public class QuestionE : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nm = inputStream.ReadIntArray(); var n = nm[0]; var m = nm[1]; var cards = Enumerable.Range(0, n) .Select(_ => new UnionFindNode<bool>(false)) .ToArray(); for (int i = 0; i < m; i++) { var xyz = inputStream.ReadIntArray(); var x = xyz[0] - 1; var y = xyz[1] - 1; cards[x].Unite(cards[y]); } var roots = new HashSet<UnionFindNode<bool>>(); foreach (var card in cards) { roots.Add(card.Parent); } yield return roots.Count; } // See https://kumikomiya.com/competitive-programming-with-c-sharp/ public class UnionFindNode<T> : IEquatable<UnionFindNode<T>> { private int _height; // rootのときのみ有効 private int _groupSize; // 同上 private UnionFindNode<T> _parent; private readonly Guid _id = Guid.NewGuid(); public T Item { get; set; } public UnionFindNode<T> Parent => _parent; public UnionFindNode(T item) { _height = 0; _groupSize = 1; _parent = this; Item = item; } private UnionFindNode<T> FindRoot() { if (_parent != this) // not ref equals { var root = _parent.FindRoot(); _parent = root; } return _parent; } public int GetGroupSize() => FindRoot()._groupSize; public void Unite(UnionFindNode<T> other) { var thisRoot = this.FindRoot(); var otherRoot = other.FindRoot(); if (thisRoot == otherRoot) { return; } if (thisRoot._height < otherRoot._height) { thisRoot._parent = otherRoot; otherRoot._groupSize += thisRoot._groupSize; otherRoot._height = Math.Max(thisRoot._height + 1, otherRoot._height); } else { otherRoot._parent = thisRoot; thisRoot._groupSize += otherRoot._groupSize; thisRoot._height = Math.Max(otherRoot._height + 1, thisRoot._height); } } public bool IsInSameGroup(UnionFindNode<T> other) => this.FindRoot() == other.FindRoot(); public override string ToString() => $"{Item} root:{FindRoot().Item}"; public bool Equals(UnionFindNode<T> other) => _id == other._id; public override bool Equals(object obj) => Equals(obj as UnionFindNode<T>); public override int GetHashCode() => _id.GetHashCode(); } } } namespace AtCoderBeginnerContest126 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest126.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest126.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using AtCoderBeginnerContest126.Questions; using AtCoderBeginnerContest126.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest126.Questions { public class QuestionE : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nm = inputStream.ReadIntArray(); var n = nm[0]; var m = nm[1]; var cards = Enumerable.Range(0, n) .Select(_ => new UnionFindNode<bool>(false)) .ToArray(); for (int i = 0; i < m; i++) { var xyz = inputStream.ReadIntArray(); var x = xyz[0] - 1; var y = xyz[1] - 1; cards[x].Unite(cards[y]); } var roots = new HashSet<UnionFindNode<bool>>(); foreach (var card in cards) { roots.Add(card.FindRoot()); } yield return roots.Count; } // See https://kumikomiya.com/competitive-programming-with-c-sharp/ public class UnionFindNode<T> : IEquatable<UnionFindNode<T>> { private int _height; // rootのときのみ有効 private int _groupSize; // 同上 private UnionFindNode<T> _parent; private readonly Guid _id = Guid.NewGuid(); public T Item { get; set; } public UnionFindNode<T> Parent => _parent; public UnionFindNode(T item) { _height = 0; _groupSize = 1; _parent = this; Item = item; } public UnionFindNode<T> FindRoot() { if (_parent != this) // not ref equals { var root = _parent.FindRoot(); _parent = root; } return _parent; } public int GetGroupSize() => FindRoot()._groupSize; public void Unite(UnionFindNode<T> other) { var thisRoot = this.FindRoot(); var otherRoot = other.FindRoot(); if (thisRoot == otherRoot) { return; } if (thisRoot._height < otherRoot._height) { thisRoot._parent = otherRoot; otherRoot._groupSize += thisRoot._groupSize; otherRoot._height = Math.Max(thisRoot._height + 1, otherRoot._height); } else { otherRoot._parent = thisRoot; thisRoot._groupSize += otherRoot._groupSize; thisRoot._height = Math.Max(otherRoot._height + 1, thisRoot._height); } } public bool IsInSameGroup(UnionFindNode<T> other) => this.FindRoot() == other.FindRoot(); public override string ToString() => $"{Item} root:{FindRoot().Item}"; public bool Equals(UnionFindNode<T> other) => _id == other._id; public override bool Equals(object obj) => Equals(obj as UnionFindNode<T>); public override int GetHashCode() => _id.GetHashCode(); } } } namespace AtCoderBeginnerContest126 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest126.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest126.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 261], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259]]
8
953
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var A = Ints; Write(A[1] - A[0] + 1); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var A = Ints; Write(A[0] - A[1] + 1); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
1,048
4
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; partial class Solver { public void Run() { var N = ni(); var M = ni(); var A = ni(N); var B = new int[M]; var C = new int[M]; for (int i = 0; i < M; i++) { B[i] = ni(); C[i] = ni(); } Array.Sort(A); var actions = B.Zip(C, (Count, ToNum) => new { Count, ToNum }) .OrderByDescending(a => a.ToNum) .ToArray(); int current = 0; foreach (var a in actions) { if (current == A.Length) break; int count = a.Count; while (A[current] < a.ToNum && count > 0) { A[current++] = a.ToNum; count--; } } cout.WriteLine(A.Sum(x => (long)x)); } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { new Solver(Console.In, Console.Out).Run(); } TextReader cin; TextWriter cout; public Solver(TextReader reader, TextWriter writer) : base(reader) { this.cin = reader; this.cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} public int ni() { return NextInt(); } public int[] ni(int n) { return NextIntArray(n); } public long nl() { return NextLong(); } public long[] nl(int n) { return NextLongArray(n); } public double nd() { return NextDouble(); } public string ns() { return Next(); } } public class Scanner { private TextReader Reader; private Queue<String> TokenQueue = new Queue<string>(); private CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { this.Reader = reader; } public int NextInt() { return Int32.Parse(Next(), ci); } public long NextLong() { return Int64.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); 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 bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; partial class Solver { public void Run() { var N = ni(); var M = ni(); var A = ni(N); var B = new int[M]; var C = new int[M]; for (int i = 0; i < M; i++) { B[i] = ni(); C[i] = ni(); } Array.Sort(A); var actions = B.Zip(C, (Count, ToNum) => new { Count, ToNum }) .OrderByDescending(a => a.ToNum) .ToArray(); int current = 0; foreach (var a in actions) { if (current == A.Length) break; int count = a.Count; while (current < A.Length && A[current] < a.ToNum && count > 0) { A[current++] = a.ToNum; count--; } } cout.WriteLine(A.Sum(x => (long)x)); } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { new Solver(Console.In, Console.Out).Run(); } TextReader cin; TextWriter cout; public Solver(TextReader reader, TextWriter writer) : base(reader) { this.cin = reader; this.cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} public int ni() { return NextInt(); } public int[] ni(int n) { return NextIntArray(n); } public long nl() { return NextLong(); } public long[] nl(int n) { return NextLongArray(n); } public double nd() { return NextDouble(); } public string ns() { return Next(); } } public class Scanner { private TextReader Reader; private Queue<String> TokenQueue = new Queue<string>(); private CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { this.Reader = reader; } public int NextInt() { return Int32.Parse(Next(), ci); } public long NextLong() { return Int64.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); 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 bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
[["+", 0, 52, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 52, 15, 16, 31, 16, 31, 16, 17, 18], ["+", 15, 16, 31, 16, 31, 16, 12, 214, 205, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 214, 0, 131], ["+", 15, 16, 31, 16, 31, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 98]]
8
802
6
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; namespace AtCoder_Beginner_Contest_127 { class Program { public class Combination { readonly long mod; readonly long[] fac, finv, inv; public Combination(long n, long mod = 1000000007) { long max = n + 1; this.mod = mod; fac = new long[max]; finv = new long[max]; inv = new long[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; ++i) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } public long com(int n, int k) { if (n < k) return 0; if (n < 0 | k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } } static public List<int> SIn() { return ReadLine().Split().Select(int.Parse).ToList(); } static void Main(string[] args) { var NMK = SIn(); var N = NMK[0]; // N行 var M = NMK[1]; // M列 var K = NMK[2]; // K個 long mod = 1000000000 + 7; long nsum = 0; for (int i = 1; i <= N - 1; ++i) { nsum = nsum + i * (N - i) % mod; nsum %= mod; } long msum = 0; for (int i = 1; i <= M - 1; ++i) { msum = msum + i * (M - i) % mod; msum %= mod; } long sum = (nsum * (M * M % mod)) % mod + (msum * (N * N % mod)) % mod; sum %= mod; var cmb = new Combination(N * M - 2, mod); sum = sum * cmb.com(N * M - 2, K - 2) % mod; WriteLine(sum); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; namespace AtCoder_Beginner_Contest_127 { class Program { public class Combination { readonly long mod; readonly long[] fac, finv, inv; public Combination(long n, long mod = 1000000007) { long max = n + 1; this.mod = mod; fac = new long[max]; finv = new long[max]; inv = new long[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; ++i) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } public long com(int n, int k) { if (n < k) return 0; if (n < 0 | k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } } static public List<int> SIn() { return ReadLine().Split().Select(int.Parse).ToList(); } static void Main(string[] args) { var NMK = SIn(); var N = NMK[0]; // N行 var M = NMK[1]; // M列 var K = NMK[2]; // K個 long mod = 1000000000 + 7; long nsum = 0; for (int i = 1; i <= N - 1; ++i) { nsum = nsum + (long)i * (N - i) % mod; nsum %= mod; } long msum = 0; for (int i = 1; i <= M - 1; ++i) { msum = msum + (long)i * (M - i) % mod; msum %= mod; } long sum = (nsum * (M * M % mod)) % mod + (msum * (N * N % mod)) % mod; sum %= mod; var cmb = new Combination(N * M - 2, mod); sum = sum * cmb.com(N * M - 2, K - 2) % mod; WriteLine(sum); } } }
[["+", 12, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 12, 16, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 12, 16, 12, 16, 31, 16, 31, 74, 0, 25]]
8
506
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { struct mint : IEquatable<mint> { // static uint mod = 998244353; static uint mod = 1000000007; uint _v; public mint(long v) : this((uint)(v % mod + mod)) {} private mint(uint v) { _v = v < mod ? v : (v - mod); } public static void SetMod(uint p) { mod = p; } public static mint operator +(mint lhs, mint rhs) { return new mint(lhs._v + rhs._v); } public static mint operator -(mint lhs, mint rhs) { return new mint(lhs._v + mod - rhs._v); } public static mint operator *(mint lhs, mint rhs) { return new mint((uint)((ulong)lhs._v * rhs._v % mod)); } public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); } public static mint operator ^(mint x, int n) { return Pow(x, n); } public static bool operator ==(mint l, mint r) { return l._v == r._v; } public static bool operator !=(mint l, mint r) { return !(l == r); } public static bool operator<(mint l, mint r) { return l._v < r._v; } public static bool operator>(mint l, mint r) { return l._v > r._v; } public static mint Pow(mint x, int n) { var r = new mint(1); while (n > 0) { if ((n & 1) > 0) r *= x; x *= x; n >>= 1; } return r; } public mint Pow(int n) { return Pow(this, n); } public mint Inv() { return Pow((int)mod - 2); } public bool Equals(mint o) { return this == o; } public override bool Equals(object obj) { if (obj is mint) return this == (mint)obj; else return false; } public override int GetHashCode() { return _v.GetHashCode(); } public override string ToString() { return _v.ToString(); } public static implicit operator mint(int i) { return new mint(i); } public static implicit operator mint(long i) { return new mint(i); } private static mint[] _fact; public static void SetFact(int n) { _fact = new mint[n + 1]; _fact[0] = 1; for (int i = 1; i < n + 1; i++) { _fact[i] = _fact[i - 1] * i; } } public static mint Fact(int n) { if (_fact == null || _fact.Length < n) { SetFact(n * 2); } return _fact[n]; } public static mint Combination(int n, int r) { return Fact(n) / (Fact(n - r) * Fact(r)); } } static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class MinHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MinHeap() : this(0) {} public MinHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c < 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) { j++; } if (_comp.Compare(_list[i], _list[j]) > 0) { Swap(i, j); i = j; } else { return result; } } } public MinHeap<T> Copy(Comparison<T> comp = null) { var c = new MinHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MinHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMul(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMul(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMul(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static List<T> NewList<T>(T template) { return new List<T>(); } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nmk = ReadIntArray(); var n = nmk[0]; var m = nmk[1]; var k = nmk[2]; var result = new mint(0); var comb = mint.Combination(n * m - 2, k - 2); for (int i = 1; i < m; i++) { result += i * (m - i) * mint.Pow(n, 2); } for (int i = 1; i < n; i++) { result += i * (n - i) * mint.Pow(m, 2); } result *= comb; Console.WriteLine(result); //↑ } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { struct mint : IEquatable<mint> { // static uint mod = 998244353; static uint mod = 1000000007; uint _v; public mint(long v) : this((uint)(v % mod + mod)) {} private mint(uint v) { _v = v < mod ? v : (v - mod); } public static void SetMod(uint p) { mod = p; } public static mint operator +(mint lhs, mint rhs) { return new mint(lhs._v + rhs._v); } public static mint operator -(mint lhs, mint rhs) { return new mint(lhs._v + mod - rhs._v); } public static mint operator *(mint lhs, mint rhs) { return new mint((uint)((ulong)lhs._v * rhs._v % mod)); } public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); } public static mint operator ^(mint x, int n) { return Pow(x, n); } public static bool operator ==(mint l, mint r) { return l._v == r._v; } public static bool operator !=(mint l, mint r) { return !(l == r); } public static bool operator<(mint l, mint r) { return l._v < r._v; } public static bool operator>(mint l, mint r) { return l._v > r._v; } public static mint Pow(mint x, int n) { var r = new mint(1); while (n > 0) { if ((n & 1) > 0) r *= x; x *= x; n >>= 1; } return r; } public mint Pow(int n) { return Pow(this, n); } public mint Inv() { return Pow((int)mod - 2); } public bool Equals(mint o) { return this == o; } public override bool Equals(object obj) { if (obj is mint) return this == (mint)obj; else return false; } public override int GetHashCode() { return _v.GetHashCode(); } public override string ToString() { return _v.ToString(); } public static implicit operator mint(int i) { return new mint(i); } public static implicit operator mint(long i) { return new mint(i); } private static mint[] _fact; public static void SetFact(int n) { _fact = new mint[n + 1]; _fact[0] = 1; for (int i = 1; i < n + 1; i++) { _fact[i] = _fact[i - 1] * i; } } public static mint Fact(int n) { if (_fact == null || _fact.Length < n) { SetFact(n * 2); } return _fact[n]; } public static mint Combination(int n, int r) { return Fact(n) / (Fact(n - r) * Fact(r)); } } static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class MinHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MinHeap() : this(0) {} public MinHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c < 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) { j++; } if (_comp.Compare(_list[i], _list[j]) > 0) { Swap(i, j); i = j; } else { return result; } } } public MinHeap<T> Copy(Comparison<T> comp = null) { var c = new MinHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MinHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMul(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMul(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMul(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static List<T> NewList<T>(T template) { return new List<T>(); } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nmk = ReadIntArray(); var n = nmk[0]; var m = nmk[1]; var k = nmk[2]; var result = new mint(0); var comb = mint.Combination(n * m - 2, k - 2); for (int i = 1; i < m; i++) { result += (mint)i * (m - i) * mint.Pow(n, 2); } for (int i = 1; i < n; i++) { result += (mint)i * (n - i) * mint.Pow(m, 2); } result *= comb; Console.WriteLine(result); //↑ } } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
3,422
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { var n = Read; var pq1 = new C.PriorityQueue<long, long>(x => x); var pq2 = new C.PriorityQueue<long, long>(x => x, true); var min = 0L; foreach (var i in C.Loop(n)) { var q = Read; if (q == 1) { var a = Read; var b = Read; if (pq1.Count > 0) { var a1 = pq1.Top; var a2 = pq2.Top; if (a < a1) { min += a1 - a; } else if (a < a2) { } else { min += a - a2; } } min += b; pq1.Enqueue(a); pq2.Enqueue(a); if (pq1.Top != pq2.Top) { var x1 = pq1.Dequeue(); var x2 = pq2.Dequeue(); pq1.Enqueue(x2); pq2.Enqueue(x1); } } else { Write($"{pq2.Top} {min}"); } } // Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; return 0; } public bool SolveBool() { var n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { var n = Read; var pq1 = new C.PriorityQueue<long, long>(x => x); var pq2 = new C.PriorityQueue<long, long>(x => x, true); var min = 0L; foreach (var i in C.Loop(n)) { var q = Read; if (q == 1) { var a = Read; var b = Read; if (pq1.Count > 0) { var aMax = pq1.Top; var aMin = pq2.Top; if (a < aMin) { min += aMin - a; } else if (a < aMax) { } else { min += a - aMax; } } min += b; pq1.Enqueue(a); pq2.Enqueue(a); if (pq1.Top != pq2.Top) { var x1 = pq1.Dequeue(); var x2 = pq2.Dequeue(); pq1.Enqueue(x2); pq2.Enqueue(x1); } } else { Write($"{pq2.Top} {min}"); } } // Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; return 0; } public bool SolveBool() { var n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["-", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
8,334
12
using System; using System.Collections.Generic; using System.IO; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { new Program().Solve(); } public void Solve() { var sc = new Scanner(); var sb = new StringBuilder(); long bSum = 0; int Q = sc.NextInt(); var set = new Set<long>(); set.IsMultiSet = true; long l = int.MinValue, r = int.MaxValue; long min = 0; for (int i = 0; i < Q; i++) { int type = sc.NextInt(); if (type == 1) { int a = sc.NextInt(); int b = sc.NextInt(); bSum += b; set.Add(a); if (l <= a && a <= r) { min += 0; l = a; r = a; } else { if (r < a) { min += a - r; } if (a < l) { min += l - a; } if (set.Count % 2 == 0) { l = set[set.Count / 2 - 1]; r = set[set.Count / 2]; } else { r = set[set.Count - 1]; l = r; } } } else if (type == 2) { sb.AppendLine($"{l} {min + bSum}"); } } Console.Write(sb.ToString()); } } } #region Set public class Set<T> { Node root; readonly IComparer<T> comparer; readonly Node nil; public bool IsMultiSet { get; set; } public Set(IComparer<T> comparer) { nil = new Node(default(T)); root = nil; this.comparer = comparer; } public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison)) {} public Set() : this(Comparer<T>.Default) {} public bool Add(T v) { return insert(ref root, v); } public bool Remove(T v) { return remove(ref root, v); } public T this[int index] { get { return find(root, index); } } public int Count { get { return root.Count; } } public void RemoveAt(int k) { if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException(); removeAt(ref root, k); } public T[] Items { get { var ret = new T[root.Count]; var k = 0; walk(root, ret, ref k); return ret; } } void walk(Node t, T[] a, ref int k) { if (t.Count == 0) return; walk(t.lst, a, ref k); a[k++] = t.Key; walk(t.rst, a, ref k); } bool insert(ref Node t, T key) { if (t.Count == 0) { t = new Node(key); t.lst = t.rst = nil; t.Update(); return true; } var cmp = comparer.Compare(t.Key, key); bool res; if (cmp > 0) res = insert(ref t.lst, key); else if (cmp == 0) { if (IsMultiSet) res = insert(ref t.lst, key); else return false; } else res = insert(ref t.rst, key); balance(ref t); return res; } bool remove(ref Node t, T key) { if (t.Count == 0) return false; var cmp = comparer.Compare(key, t.Key); bool ret; if (cmp < 0) ret = remove(ref t.lst, key); else if (cmp > 0) ret = remove(ref t.rst, key); else { ret = true; var k = t.lst.Count; if (k == 0) { t = t.rst; return true; } if (t.rst.Count == 0) { t = t.lst; return true; } t.Key = find(t.lst, k - 1); removeAt(ref t.lst, k - 1); } balance(ref t); return ret; } void removeAt(ref Node t, int k) { var cnt = t.lst.Count; if (cnt < k) removeAt(ref t.rst, k - cnt - 1); else if (cnt > k) removeAt(ref t.lst, k); else { if (cnt == 0) { t = t.rst; return; } if (t.rst.Count == 0) { t = t.lst; return; } t.Key = find(t.lst, k - 1); removeAt(ref t.lst, k - 1); } balance(ref t); } void balance(ref Node t) { var balance = t.lst.Height - t.rst.Height; if (balance == -2) { if (t.rst.lst.Height - t.rst.rst.Height > 0) { rotR(ref t.rst); } rotL(ref t); } else if (balance == 2) { if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst); rotR(ref t); } else t.Update(); } T find(Node t, int k) { if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException(); for (;;) { if (k == t.lst.Count) return t.Key; else if (k < t.lst.Count) t = t.lst; else { k -= t.lst.Count + 1; t = t.rst; } } } public int LowerBound(T v) { var k = 0; var t = root; for (;;) { if (t.Count == 0) return k; if (comparer.Compare(v, t.Key) <= 0) t = t.lst; else { k += t.lst.Count + 1; t = t.rst; } } } public int UpperBound(T v) { var k = 0; var t = root; for (;;) { if (t.Count == 0) return k; if (comparer.Compare(t.Key, v) <= 0) { k += t.lst.Count + 1; t = t.rst; } else t = t.lst; } } void rotR(ref Node t) { var l = t.lst; t.lst = l.rst; l.rst = t; t.Update(); l.Update(); t = l; } void rotL(ref Node t) { var r = t.rst; t.rst = r.lst; r.lst = t; t.Update(); r.Update(); t = r; } class Node { public Node(T key) { Key = key; } public int Count { get; private set; } public sbyte Height { get; private set; } public T Key { get; set; } public Node lst, rst; public void Update() { Count = 1 + lst.Count + rst.Count; Height = (sbyte)(1 + Math.Max(lst.Height, rst.Height)); } public override string ToString() { return string.Format("Count = {0}, Key = {1}", Count, Key); } } } #endregion class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; } const char Separator = ' '; private readonly StreamReader _stream; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { new Program().Solve(); } public void Solve() { var sc = new Scanner(); var sb = new StringBuilder(); long bSum = 0; int Q = sc.NextInt(); var set = new Set<long>(); set.IsMultiSet = true; long l = int.MinValue, r = int.MaxValue; long min = 0; for (int i = 0; i < Q; i++) { int type = sc.NextInt(); if (type == 1) { int a = sc.NextInt(); int b = sc.NextInt(); bSum += b; set.Add(a); if (l <= a && a <= r) { min += 0; l = a; r = a; } else { if (r < a) { min += a - r; } if (a < l) { min += l - a; } if (set.Count % 2 == 0) { l = set[set.Count / 2 - 1]; r = set[set.Count / 2]; } else { r = set[set.Count / 2]; l = r; } } } else if (type == 2) { sb.AppendLine($"{l} {min + bSum}"); } } Console.Write(sb.ToString()); } } } #region Set public class Set<T> { Node root; readonly IComparer<T> comparer; readonly Node nil; public bool IsMultiSet { get; set; } public Set(IComparer<T> comparer) { nil = new Node(default(T)); root = nil; this.comparer = comparer; } public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison)) {} public Set() : this(Comparer<T>.Default) {} public bool Add(T v) { return insert(ref root, v); } public bool Remove(T v) { return remove(ref root, v); } public T this[int index] { get { return find(root, index); } } public int Count { get { return root.Count; } } public void RemoveAt(int k) { if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException(); removeAt(ref root, k); } public T[] Items { get { var ret = new T[root.Count]; var k = 0; walk(root, ret, ref k); return ret; } } void walk(Node t, T[] a, ref int k) { if (t.Count == 0) return; walk(t.lst, a, ref k); a[k++] = t.Key; walk(t.rst, a, ref k); } bool insert(ref Node t, T key) { if (t.Count == 0) { t = new Node(key); t.lst = t.rst = nil; t.Update(); return true; } var cmp = comparer.Compare(t.Key, key); bool res; if (cmp > 0) res = insert(ref t.lst, key); else if (cmp == 0) { if (IsMultiSet) res = insert(ref t.lst, key); else return false; } else res = insert(ref t.rst, key); balance(ref t); return res; } bool remove(ref Node t, T key) { if (t.Count == 0) return false; var cmp = comparer.Compare(key, t.Key); bool ret; if (cmp < 0) ret = remove(ref t.lst, key); else if (cmp > 0) ret = remove(ref t.rst, key); else { ret = true; var k = t.lst.Count; if (k == 0) { t = t.rst; return true; } if (t.rst.Count == 0) { t = t.lst; return true; } t.Key = find(t.lst, k - 1); removeAt(ref t.lst, k - 1); } balance(ref t); return ret; } void removeAt(ref Node t, int k) { var cnt = t.lst.Count; if (cnt < k) removeAt(ref t.rst, k - cnt - 1); else if (cnt > k) removeAt(ref t.lst, k); else { if (cnt == 0) { t = t.rst; return; } if (t.rst.Count == 0) { t = t.lst; return; } t.Key = find(t.lst, k - 1); removeAt(ref t.lst, k - 1); } balance(ref t); } void balance(ref Node t) { var balance = t.lst.Height - t.rst.Height; if (balance == -2) { if (t.rst.lst.Height - t.rst.rst.Height > 0) { rotR(ref t.rst); } rotL(ref t); } else if (balance == 2) { if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst); rotR(ref t); } else t.Update(); } T find(Node t, int k) { if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException(); for (;;) { if (k == t.lst.Count) return t.Key; else if (k < t.lst.Count) t = t.lst; else { k -= t.lst.Count + 1; t = t.rst; } } } public int LowerBound(T v) { var k = 0; var t = root; for (;;) { if (t.Count == 0) return k; if (comparer.Compare(v, t.Key) <= 0) t = t.lst; else { k += t.lst.Count + 1; t = t.rst; } } } public int UpperBound(T v) { var k = 0; var t = root; for (;;) { if (t.Count == 0) return k; if (comparer.Compare(t.Key, v) <= 0) { k += t.lst.Count + 1; t = t.rst; } else t = t.lst; } } void rotR(ref Node t) { var l = t.lst; t.lst = l.rst; l.rst = t; t.Update(); l.Update(); t = l; } void rotL(ref Node t) { var r = t.rst; t.rst = r.lst; r.lst = t; t.Update(); r.Update(); t = r; } class Node { public Node(T key) { Key = key; } public int Count { get; private set; } public sbyte Height { get; private set; } public T Key { get; set; } public Node lst, rst; public void Update() { Count = 1 + lst.Count + rst.Count; Height = (sbyte)(1 + Math.Max(lst.Height, rst.Height)); } public override string ToString() { return string.Format("Count = {0}, Key = {1}", Count, Key); } } } #endregion class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; } const char Separator = ' '; private readonly StreamReader _stream; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 85], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
2,072
4
using System; using System.Collections.Generic; using System.IO; using System.Text; class ChokudaiSpeedRun002 { static int __cnt = 0; #if LOCAL_ENVIRONMENT static string __mark = "@@@"; #endif static void Main(string[] args) { #if LOCAL_ENVIRONMENT StreamReader __sr = new StreamReader("stdin.txt"); string __str = __sr.ReadToEnd(); __sr.Close(); int __index = __str.IndexOf(__mark, 0); while (__index != -1) { __index = __str.IndexOf(__mark, __index + __mark.Length); __cnt++; } if (__cnt > 0) { Console.Write("Eenter test data no(1-{0})? ", __cnt); Console.Out.Flush(); if (!int.TryParse(Console.ReadLine(), out __cnt)) __cnt = 1; Console.WriteLine("Select/Default test data: {0}", __cnt); } var stdin = new System.IO.StreamReader("stdin.txt"); Console.SetIn(stdin); #endif SimpleScanner sc = new SimpleScanner(__cnt); int Q = sc.NextInt(); var q1 = new PriorityQueue<long>((a, b) => (int)(b - a)); var q2 = new PriorityQueue<long>((a, b) => (int)(a - b)); long s1 = 0, s2 = 0, B = 0; for (var n = 0; n < Q; n++) { int t = sc.NextInt(); if (t == 1) { long a = sc.NextLong(), b = sc.NextLong(); B += b; q1.Enqueue(a); q2.Enqueue(a); long l = q1.Peek(), r = q2.Peek(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine($"L:{l}, R:{r}, B:{B}"); #endif if (l > r) { q1.Dequeue(); q1.Enqueue(r); q2.Dequeue(); q2.Enqueue(l); s1 += r; s2 += l; } else { s1 += l; s2 += r; } #if LOCAL_ENVIRONMENT Console.Error.WriteLine($"s1:{s1}, s2:{s2}, B:{B}"); Console.Error.WriteLine($"q1:{q1.ToString()}"); Console.Error.WriteLine($"q2:{q2.ToString()}"); #endif } else { long a = q1.Peek(); Console.WriteLine($"{a} {s1 + s2 + B}"); } } } // Main class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Empty() { return this.Count < 1; } public bool Any() { return size > 0; } public override string ToString() { return this.heap.ToArray().ToStringA(); } } public static int LowerBound<T>(T[] array, int start, int end, T value, IComparer<T> comparer) { int low = start, high = end, mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(array[mid], value) < 0) low = mid + 1; else high = mid; } #if LOCAL_ENVIRONMENT Console.Error.WriteLine($"LowerBound(array:{array.ToStringA()}"); Console.Error.WriteLine( $"LowerBound(start:{start}, end:{end}, value:{value.ToString()}) return:{low}"); #endif return low; } public static int LowerBound<T>(T[] array, T value) where T : IComparable { return LowerBound(array, 0, array.Length, value, Comparer<T>.Default); } public class BIT { int n; int[] data; public BIT(int size) { n = size + 1; data = new int[n]; } public void add(int i, int x) { while (i < n) { data[i] += x; i += i & -i; } } public int sum(int i) { int ret = 0; while (i > 0) { ret += data[i]; i -= i & -i; } return ret; } } public class Item : IEquatable<Item>, IComparable<Item> { public long value { get; set; } public long count { get; set; } public Item(long count, long value) { this.value = value; this.count = count; } public override string ToString() { return $"[value:{this.value}, count:{this.count}]"; } public bool Equals(Item other) { if (other == null) return false; return this.value == other.value && this.count == other.count; } public override bool Equals(Object obj) { if (obj == null) return false; Item item = obj as Item; if (item == null) return false; else return Equals(item); } public override int GetHashCode() { long hc = this.value * this.count; return hc.GetHashCode(); } public int CompareTo(Item other) { if (other == null) return -1; if (this.value == other.value) return this.count.CompareTo(other.count); else return -1 * this.value.CompareTo(other.value); } public int Compare(Item x, Item y) { if (x == null) return 1; else return x.CompareTo(y); } } public class SimpleScanner { private int cnt; private string[] items; public SimpleScanner(int cnt = 0) { this.cnt = 0; var sb = new StringBuilder(); var s = Console.ReadLine(); while (s != null) { sb.Append(s + " "); s = Console.ReadLine(); } this.items = sb.ToString().Split(' '); #if LOCAL_ENVIRONMENT if (cnt > 0) { int index = Array.IndexOf(this.items, __mark + cnt.ToString()); this.cnt = index + 1; } Console.Error.WriteLine("SimpleScanner.cnt: {0}", this.cnt); Console.Error.WriteLine("SimpleScanner.items: {0}", this.items.ToStringA()); #endif } public void SetCnt(int n) { this.cnt = n; } public int NextInt() { return int.Parse(this.items[this.cnt++]); } public long NextLong() { return long.Parse(this.items[this.cnt++]); } public string NextString() { return this.items[this.cnt++]; } public int[] NextIntArray(int n) { if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); var result = new int[n]; for (var i = 0; i < n; i++) result[i] = this.NextInt(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine("{0}", result.ToStringA()); #endif return result; } public long[] NextLongArray(int n) { if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); var result = new long[n]; for (var i = 0; i < n; i++) result[i] = this.NextLong(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine("{0}", result.ToStringA()); #endif return result; } public string[] NextStringArray(int n) { if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); var result = new string[n]; for (var i = 0; i < n; i++) result[i] = this.NextString(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine("{0}", result.ToStringA()); #endif return result; } public int[][] NextInt2Col(int n) { const int M = 2; if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); int[][] result = new int [M][] { new int[n], new int[n], }; for (var i = 0; i < n; i++) { result[0][i] = this.NextInt(); result[1][i] = this.NextInt(); } #if LOCAL_ENVIRONMENT Console.Error.WriteLine("NextInt2Col: ["); for (var i = 0; i < M; i++) Console.Error.WriteLine(" {0},", result[i].ToStringA()); Console.Error.WriteLine("]"); #endif return result; } } } static class Extensions { public static string ToStringA<T>(this T[] array, string separator = ", ", string braces = "[]") { string bL = braces.Length > 0 ? braces[0].ToString() : ""; string bR = braces.Length > 1 ? braces[1].ToString() : ""; return bL + String.Join(separator, array) + bR; } }
using System; using System.Collections.Generic; using System.IO; using System.Text; class ChokudaiSpeedRun002 { static int __cnt = 0; #if LOCAL_ENVIRONMENT static string __mark = "@@@"; #endif static void Main(string[] args) { #if LOCAL_ENVIRONMENT StreamReader __sr = new StreamReader("stdin.txt"); string __str = __sr.ReadToEnd(); __sr.Close(); int __index = __str.IndexOf(__mark, 0); while (__index != -1) { __index = __str.IndexOf(__mark, __index + __mark.Length); __cnt++; } if (__cnt > 0) { Console.Write("Eenter test data no(1-{0})? ", __cnt); Console.Out.Flush(); if (!int.TryParse(Console.ReadLine(), out __cnt)) __cnt = 1; Console.WriteLine("Select/Default test data: {0}", __cnt); } var stdin = new System.IO.StreamReader("stdin.txt"); Console.SetIn(stdin); #endif SimpleScanner sc = new SimpleScanner(__cnt); int Q = sc.NextInt(); var q1 = new PriorityQueue<long>((a, b) => (int)(b - a)); var q2 = new PriorityQueue<long>((a, b) => (int)(a - b)); long s1 = 0, s2 = 0, B = 0; for (var n = 0; n < Q; n++) { int t = sc.NextInt(); if (t == 1) { long a = sc.NextLong(), b = sc.NextLong(); B += b; q1.Enqueue(a); q2.Enqueue(a); long l = q1.Peek(), r = q2.Peek(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine($"L:{l}, R:{r}, B:{B}"); #endif if (l > r) { q1.Dequeue(); q1.Enqueue(r); q2.Dequeue(); q2.Enqueue(l); s1 += r; s2 += l; } else { s1 += l; s2 += r; } #if LOCAL_ENVIRONMENT Console.Error.WriteLine($"s1:{s1}, s2:{s2}, B:{B}"); Console.Error.WriteLine($"q1:{q1.ToString()}"); Console.Error.WriteLine($"q2:{q2.ToString()}"); #endif } else { long a = q1.Peek(); Console.WriteLine($"{a} {s2 - s1 + B}"); } } } // Main class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Empty() { return this.Count < 1; } public bool Any() { return size > 0; } public override string ToString() { return this.heap.ToArray().ToStringA(); } } public static int LowerBound<T>(T[] array, int start, int end, T value, IComparer<T> comparer) { int low = start, high = end, mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(array[mid], value) < 0) low = mid + 1; else high = mid; } #if LOCAL_ENVIRONMENT Console.Error.WriteLine($"LowerBound(array:{array.ToStringA()}"); Console.Error.WriteLine( $"LowerBound(start:{start}, end:{end}, value:{value.ToString()}) return:{low}"); #endif return low; } public static int LowerBound<T>(T[] array, T value) where T : IComparable { return LowerBound(array, 0, array.Length, value, Comparer<T>.Default); } public class BIT { int n; int[] data; public BIT(int size) { n = size + 1; data = new int[n]; } public void add(int i, int x) { while (i < n) { data[i] += x; i += i & -i; } } public int sum(int i) { int ret = 0; while (i > 0) { ret += data[i]; i -= i & -i; } return ret; } } public class Item : IEquatable<Item>, IComparable<Item> { public long value { get; set; } public long count { get; set; } public Item(long count, long value) { this.value = value; this.count = count; } public override string ToString() { return $"[value:{this.value}, count:{this.count}]"; } public bool Equals(Item other) { if (other == null) return false; return this.value == other.value && this.count == other.count; } public override bool Equals(Object obj) { if (obj == null) return false; Item item = obj as Item; if (item == null) return false; else return Equals(item); } public override int GetHashCode() { long hc = this.value * this.count; return hc.GetHashCode(); } public int CompareTo(Item other) { if (other == null) return -1; if (this.value == other.value) return this.count.CompareTo(other.count); else return -1 * this.value.CompareTo(other.value); } public int Compare(Item x, Item y) { if (x == null) return 1; else return x.CompareTo(y); } } public class SimpleScanner { private int cnt; private string[] items; public SimpleScanner(int cnt = 0) { this.cnt = 0; var sb = new StringBuilder(); var s = Console.ReadLine(); while (s != null) { sb.Append(s + " "); s = Console.ReadLine(); } this.items = sb.ToString().Split(' '); #if LOCAL_ENVIRONMENT if (cnt > 0) { int index = Array.IndexOf(this.items, __mark + cnt.ToString()); this.cnt = index + 1; } Console.Error.WriteLine("SimpleScanner.cnt: {0}", this.cnt); Console.Error.WriteLine("SimpleScanner.items: {0}", this.items.ToStringA()); #endif } public void SetCnt(int n) { this.cnt = n; } public int NextInt() { return int.Parse(this.items[this.cnt++]); } public long NextLong() { return long.Parse(this.items[this.cnt++]); } public string NextString() { return this.items[this.cnt++]; } public int[] NextIntArray(int n) { if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); var result = new int[n]; for (var i = 0; i < n; i++) result[i] = this.NextInt(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine("{0}", result.ToStringA()); #endif return result; } public long[] NextLongArray(int n) { if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); var result = new long[n]; for (var i = 0; i < n; i++) result[i] = this.NextLong(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine("{0}", result.ToStringA()); #endif return result; } public string[] NextStringArray(int n) { if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); var result = new string[n]; for (var i = 0; i < n; i++) result[i] = this.NextString(); #if LOCAL_ENVIRONMENT Console.Error.WriteLine("{0}", result.ToStringA()); #endif return result; } public int[][] NextInt2Col(int n) { const int M = 2; if (n < 1) throw new IndexOutOfRangeException("引数は1以上であること!"); int[][] result = new int [M][] { new int[n], new int[n], }; for (var i = 0; i < n; i++) { result[0][i] = this.NextInt(); result[1][i] = this.NextInt(); } #if LOCAL_ENVIRONMENT Console.Error.WriteLine("NextInt2Col: ["); for (var i = 0; i < M; i++) Console.Error.WriteLine(" {0},", result[i].ToStringA()); Console.Error.WriteLine("]"); #endif return result; } } } static class Extensions { public static string ToStringA<T>(this T[] array, string separator = ", ", string braces = "[]") { string bL = braces.Length > 0 ? braces[0].ToString() : ""; string bR = braces.Length > 1 ? braces[1].ToString() : ""; return bL + String.Join(separator, array) + bR; } }
[["-", 0, 283, 0, 284, 0, 16, 31, 16, 31, 22], ["-", 0, 283, 0, 284, 0, 16, 31, 16, 17, 72], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 17, 33], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 12, 22]]
8
2,289
4
using System; using System.Collections.Generic; namespace 私が灰コーダーです { class Inonoa { static void Main() { List<int> points = new List<int>(); // aが全部挿入されていくやつ long b = 0; // bがどんどん足されていくやつ int q = int.Parse(Console.ReadLine()); // Q long v = 0; // |x-a|の部分の最小値。更新クエリごとに少しずつずれる for (int i = 0; i < q; i++) { string[] qr = Console.ReadLine().Split(); if (qr[0] == "1") { // 更新クエリの場合 int a = int.Parse(qr[1]); //初めの一回は別 if (points.Count != 0) { // vを更新したいが、 //元のグラフの形状や、元のグラフの最小値を取るxと今のaの大小関係によって更新方法が変わると考えた if (points.Count % 2 == 0) { if (a < points[(points.Count - 1) / 2]) { v += Math.Abs(points[(points.Count - 1) / 2] - a); } else if (a > points[(points.Count - 1) / 2]) { v += Math.Abs(points[(points.Count + 1) / 2] - a); } } else { v += Math.Abs(points[(points.Count - 1) / 2] - a); } // aをpointsに挿入するのに挿入位置が分からないので二分探索と言うべきか分からない何かをやった int lft = 0; int rgt = points.Count; while (lft < rgt) { int c = points[(lft + rgt) / 2]; if (a < c) { rgt = (lft + rgt) / 2; } else if (a > c) { lft = (lft + rgt) / 2 + 1; } else { lft = (lft + rgt) / 2; break; } } points.Insert(lft, a); } else { //初めの一回、vは0のままですよね…? points.Add(a); } b += int.Parse(qr[2]); } else { //求値 Console.Write(points[(points.Count - 1) / 2]); Console.Write(" "); Console.Write(v + b); Console.Write("\n"); } } } } }
using System; using System.Collections.Generic; namespace 私が灰コーダーです { class Inonoa { static void Main() { List<int> points = new List<int>(); // aが全部挿入されていくやつ long b = 0; // bがどんどん足されていくやつ int q = int.Parse(Console.ReadLine()); // Q long v = 0; // |x-a|の部分の最小値。更新クエリごとに少しずつずれる for (int i = 0; i < q; i++) { string[] qr = Console.ReadLine().Split(); if (qr[0] == "1") { // 更新クエリの場合 int a = int.Parse(qr[1]); //初めの一回は別 if (points.Count != 0) { // vを更新したいが、 //元のグラフの形状や、元のグラフの最小値を取るxと今のaの大小関係によって更新方法が変わると考えた if (points.Count % 2 == 0) { if (a < points[(points.Count - 1) / 2]) { v += Math.Abs(points[(points.Count - 1) / 2] - a); } else if (a > points[(points.Count + 1) / 2]) { v += Math.Abs(points[(points.Count + 1) / 2] - a); } } else { v += Math.Abs(points[(points.Count - 1) / 2] - a); } // aをpointsに挿入するのに挿入位置が分からないので二分探索と言うべきか分からない何かをやった int lft = 0; int rgt = points.Count; while (lft < rgt) { int c = points[(lft + rgt) / 2]; if (a < c) { rgt = (lft + rgt) / 2; } else if (a > c) { lft = (lft + rgt) / 2 + 1; } else { lft = (lft + rgt) / 2; break; } } points.Insert(lft, a); } else { //初めの一回、vは0のままですよね…? points.Add(a); } b += int.Parse(qr[2]); } else { //求値 Console.Write(points[(points.Count - 1) / 2]); Console.Write(" "); Console.Write(v + b); Console.Write("\n"); } } } } }
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72]]
8
431
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { int N; int K; Multi(out N, out K); var S = GetStr().ToCharArray(); S[K - 1] = (char)S[K].ToString().ToLower()[0]; var ans = new string(S); Console.Write(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } 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]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { int N; int K; Multi(out N, out K); var S = GetStr().ToCharArray(); S[K - 1] = S[K - 1].ToString().ToLower()[0]; var ans = new string(S); Console.Write(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } 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]); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
662
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_126_A___Changing_a_Character { class Program { static void Main(string[] args) { int N, K; string S; var M = Console.ReadLine().Split(' '); N = int.Parse(M[0]); K = int.Parse(M[1]); Console.WriteLine(); S = Console.ReadLine(); char[] cs = S.ToCharArray(); if (cs[K - 1] == 'A') cs[K - 1] = 'a'; else if (cs[K - 1] == 'B') cs[K - 1] = 'b'; else cs[K - 1] = 'b'; Console.WriteLine(cs); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_126_A___Changing_a_Character { class Program { static void Main(string[] args) { int N, K; string S; var M = Console.ReadLine().Split(' '); N = int.Parse(M[0]); K = int.Parse(M[1]); Console.WriteLine(); S = Console.ReadLine(); char[] cs = S.ToCharArray(); if (cs[K - 1] == 'A') cs[K - 1] = 'a'; else if (cs[K - 1] == 'B') cs[K - 1] = 'b'; else cs[K - 1] = 'c'; Console.WriteLine(cs); Console.ReadLine(); } } }
[["-", 75, 57, 75, 1, 0, 11, 12, 252, 0, 253], ["+", 75, 57, 75, 1, 0, 11, 12, 252, 0, 253]]
8
193
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner cin = new Scaner(); write cout = new write(); Math2 mmath = new Math2(); //ここから var o = cin.IntM; var N = o[0]; var K = o[1]; var S = cin.Str.ToCharArray(); S[K + 1] = (char)(S[K + 1] + 'a' - 'A'); var T = new string(S); cout.wri(T); } } // b-aで降順 // priority queue class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } } namespace CompLib.Algorithms { #region BinarySearch public static partial class Algorithm { static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) { var l = 0; var r = a.Count - 1; while (l <= r) { var m = (l + r) / 2; var res = cmp.Compare(a[m], v); if (res < 0 || (res == 0 && !islb)) l = m + 1; else r = m - 1; } return l; } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) { return binarySearch(a, v, Comparer<T>.Create(f), true); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, true); } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) { return binarySearch(a, v, Comparer<T>.Create(cmp), false); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///より真に大きい要素が現れる最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, false); } } #endregion } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner cin = new Scaner(); write cout = new write(); Math2 mmath = new Math2(); //ここから var o = cin.IntM; var N = o[0]; var K = o[1]; var S = cin.Str.ToCharArray(); S[K - 1] = (char)(S[K - 1] + 'a' - 'A'); var T = new string(S); cout.wri(T); } } // b-aで降順 // priority queue class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } } namespace CompLib.Algorithms { #region BinarySearch public static partial class Algorithm { static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) { var l = 0; var r = a.Count - 1; while (l <= r) { var m = (l + r) / 2; var res = cmp.Compare(a[m], v); if (res < 0 || (res == 0 && !islb)) l = m + 1; else r = m - 1; } return l; } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) { return binarySearch(a, v, Comparer<T>.Create(f), true); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, true); } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) { return binarySearch(a, v, Comparer<T>.Create(cmp), false); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///より真に大きい要素が現れる最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, false); } } #endregion } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33]]
8
1,417
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nk = ReadLib.ReadAsIntArray(); var s = Console.ReadLine(); Console.WriteLine(new string( s.Select((c, i) => i == nk[1] ? c.ToString().ToLower().First() : c) .ToArray())); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation {} 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 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(); } } 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); } ///// <summary>nCr, 組み合わせ</summary> // public static long Combination(int n, int r) { // if (r == 0) { // return 1; // } // // 分子 // var moleculeArr = Enumerable // .Range(0, Math.Min(n - r, r)) // .Select(i => n - i) // .ToArray(); // var moleculeArrLength = moleculeArr.Length; // // 分母 // var denominatorArr = Enumerable // .Range(1, Math.Max(n - r, r)) // .ToArray(); // for (var m = 0; m < moleculeArrLength; m++) { // while (true) { // var mVal = moleculeArr[m]; // var gcds = denominatorArr.Select(b => Gcd(mVal, b)); // var maxGcd = gcds.Max(); // var maxI = gcds.ToList().IndexOf(maxGcd); // if (maxGcd == 1) { // break; // } // denominatorArr[maxI] /= (int)maxGcd; // moleculeArr[m] /= (int)maxGcd; // } // } // return FullPower(moleculeArr); //} #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); } } 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>あまりを計算するための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, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, 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; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nk = ReadLib.ReadAsIntArray(); var s = Console.ReadLine(); Console.WriteLine(new string( s.Select((c, i) => i == nk[1] - 1 ? c.ToString().ToLower().First() : c) .ToArray())); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation {} 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 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(); } } 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); } ///// <summary>nCr, 組み合わせ</summary> // public static long Combination(int n, int r) { // if (r == 0) { // return 1; // } // // 分子 // var moleculeArr = Enumerable // .Range(0, Math.Min(n - r, r)) // .Select(i => n - i) // .ToArray(); // var moleculeArrLength = moleculeArr.Length; // // 分母 // var denominatorArr = Enumerable // .Range(1, Math.Max(n - r, r)) // .ToArray(); // for (var m = 0; m < moleculeArrLength; m++) { // while (true) { // var mVal = moleculeArr[m]; // var gcds = denominatorArr.Select(b => Gcd(mVal, b)); // var maxGcd = gcds.Max(); // var maxI = gcds.ToList().IndexOf(maxGcd); // if (maxGcd == 1) { // break; // } // denominatorArr[maxI] /= (int)maxGcd; // moleculeArr[m] /= (int)maxGcd; // } // } // return FullPower(moleculeArr); //} #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); } } 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>あまりを計算するための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, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, 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; } }
[["+", 0, 218, 8, 41, 15, 16, 12, 16, 17, 33], ["+", 0, 218, 8, 41, 15, 16, 12, 16, 12, 203]]
8
1,545
2
using System; class plogram { static void Main() { string str = Console.ReadLine(); string[] array = str.Split(' '); int N = int.Parse(array[0]); int K = int.Parse(array[1]); string S = array[2]; string i = S.Substring(0, K - 1); string j = S.Substring(K - 1, 1); if (j == "A") { j = "a"; } else if (j == "B") { j = "b"; } else { j = "c"; } string k = S.Substring(K, S.Length - K); Console.WriteLine(i + j + k); } }
using System; class plogram { static void Main() { string str = Console.ReadLine(); string[] array = str.Split(' '); int N = int.Parse(array[0]); int K = int.Parse(array[1]); string S = Console.ReadLine(); string i = S.Substring(0, K - 1); string j = S.Substring(K - 1, 1); if (j == "A") { j = "a"; } else if (j == "B") { j = "b"; } else { j = "c"; } string k = S.Substring(K, S.Length - K); Console.WriteLine(i + j + k); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
168
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace app1 { class Program { static void Main(string[] args) { string[] NK = Console.ReadLine().Split(' '); int N = int.Parse(NK[0]); int K = int.Parse(NK[1]); char[] S = new char[N]; S = Console.ReadLine().ToCharArray(); K -= 1; if (K >= 0) { switch (S[K]) { case 'A': S[K] = 'a'; break; case 'B': S[K] = 'b'; break; case 'C': S[K] = 'C'; break; default: break; } } string str = new string(S); Console.WriteLine($"{str}"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace app1 { class Program { static void Main(string[] args) { string[] NK = Console.ReadLine().Split(' '); int N = int.Parse(NK[0]); int K = int.Parse(NK[1]); char[] S = new char[N]; S = Console.ReadLine().ToCharArray(); K -= 1; if (K >= 0) { switch (S[K]) { case 'A': S[K] = 'a'; break; case 'B': S[K] = 'b'; break; case 'C': S[K] = 'c'; break; default: break; } } string str = new string(S); Console.WriteLine($"{str}"); } } }
[["-", 0, 239, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 0, 239, 0, 1, 0, 11, 12, 252, 0, 253]]
8
206
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace ConsoleApp1 { using static Util; internal class Program { static void Main(string[] args) { var k = ReadIntArray()[1]; var s = Console.ReadLine(); var res = string.Join("", s.Select((x, idx) => idx == k + 1 ? x.ToString().ToLower() : x.ToString()) .ToArray()); Console.WriteLine($"{res}"); #if DEBUG Console.Read(); #endif } } public static class Util { public static long[] ReadLongArray() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); public static int[] ReadIntArray() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); public static long ReadLong() => long.Parse(Console.ReadLine()); public static long ReadInt() => int.Parse(Console.ReadLine()); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace ConsoleApp1 { using static Util; internal class Program { static void Main(string[] args) { var k = ReadIntArray()[1]; var s = Console.ReadLine(); var res = string.Join("", s.Select((x, idx) => idx == k - 1 ? x.ToString().ToLower() : x.ToString()) .ToArray()); Console.WriteLine($"{res}"); #if DEBUG Console.Read(); #endif } } public static class Util { public static long[] ReadLongArray() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); public static int[] ReadIntArray() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); public static long ReadLong() => long.Parse(Console.ReadLine()); public static long ReadInt() => int.Parse(Console.ReadLine()); } }
[["-", 0, 218, 8, 41, 15, 16, 12, 16, 17, 72], ["+", 0, 218, 8, 41, 15, 16, 12, 16, 17, 33]]
8
251
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public static void Main(string[] args) { string[] inputs = Console.ReadLine().Split(' '); int n = int.Parse(inputs[0]); int k = int.Parse(inputs[0]); string s = Console.ReadLine(); for (int i = 0; i < s.Length; i++) { if (i == (k - 1)) { Console.Write((char)(s[k - 1] - 'A' + 'a')); } else Console.Write(s[i]); } Console.WriteLine(); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public static void Main(string[] args) { string[] inputs = Console.ReadLine().Split(' '); int n = int.Parse(inputs[0]); int k = int.Parse(inputs[1]); string s = Console.ReadLine(); for (int i = 0; i < s.Length; i++) { if (i == (k - 1)) { Console.Write((char)(s[k - 1] - 'A' + 'a')); } else Console.Write(s[i]); } Console.WriteLine(); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
197
2
using System; class Program { static void Main() { int input = int.Parse(Console.ReadLine()); int first = input / 100; int latter = input - first * 100; string ans; if (first <= 12 && first > 0) { if (latter <= 12) { ans = "AMBIGUOUS"; } else { ans = "MMYY"; } } else { if (latter <= 12 && latter > 0) { ans = "YYMM"; } else { ans = "NA"; } } Console.Write(ans); } }
using System; class Program { static void Main() { int input = int.Parse(Console.ReadLine()); int first = input / 100; int latter = input - first * 100; string ans; if (first <= 12 && first > 0) { if (latter <= 12 && latter > 0) { ans = "AMBIGUOUS"; } else { ans = "MMYY"; } } else { if (latter <= 12 && latter > 0) { ans = "YYMM"; } else { ans = "NA"; } } Console.Write(ans); } }
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
119
4
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string result = "NA"; if (int.Parse(S.Substring(0, 2)) <= 12 && int.Parse(S.Substring(0, 2)) != 0) { if (int.Parse(S.Substring(2, 2)) <= 12 && int.Parse(S.Substring(0, 2)) != 0) { result = "AMBIGUOUS"; } else { result = "MMYY"; } } else if (int.Parse(S.Substring(2, 2)) <= 12 && int.Parse(S.Substring(2, 2)) != 0) { if (int.Parse(S.Substring(0, 2)) <= 12 && int.Parse(S.Substring(2, 2)) != 0) { result = "AMBIGUOUS"; } else { result = "YYMM"; } } Console.WriteLine(result); } } } // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray();
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string result = "NA"; if (int.Parse(S.Substring(0, 2)) <= 12 && int.Parse(S.Substring(0, 2)) != 0) { if (int.Parse(S.Substring(2, 2)) <= 12 && int.Parse(S.Substring(2, 2)) != 0) { result = "AMBIGUOUS"; } else { result = "MMYY"; } } else if (int.Parse(S.Substring(2, 2)) <= 12 && int.Parse(S.Substring(2, 2)) != 0) { if (int.Parse(S.Substring(0, 2)) <= 12 && int.Parse(S.Substring(0, 2)) != 0) { result = "AMBIGUOUS"; } else { result = "YYMM"; } } Console.WriteLine(result); } } } // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray();
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
260
4
using System; public class AtCoderA { static void Main() { string s = Console.ReadLine(); string front = s.Substring(0, 2); string end = s.Substring(2, 2); int f = int.Parse(front); int e = int.Parse(end); bool fValid = 0 <= f && f <= 12; bool eValid = 0 <= e && e <= 12; if (fValid && eValid) { Console.WriteLine("AMBIGUOUS"); } else if (fValid) { Console.WriteLine("MMYY"); } else if (eValid) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } }
using System; public class AtCoderA { static void Main() { string s = Console.ReadLine(); string front = s.Substring(0, 2); string end = s.Substring(2, 2); int f = int.Parse(front); int e = int.Parse(end); bool fValid = 0 < f && f <= 12; bool eValid = 0 < e && e <= 12; if (fValid && eValid) { Console.WriteLine("AMBIGUOUS"); } else if (fValid) { Console.WriteLine("MMYY"); } else if (eValid) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 19], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 18]]
8
151
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner cin = new Scaner(); write cout = new write(); Math2 mmath = new Math2(); //ここから var o = cin.IntM; var S = o[0]; var s2 = S % 100; var s1 = (S - s2) / 100; // cout.wri(s1); // cout.wri(s2); if (!month(s1) && !month(s2)) cout.wri("NA"); else if (month(s1) && month(s2)) cout.wri("AMBIGOUS"); else if (month(s1) && !month(s2)) cout.wri("MMYY"); else if (!month(s1) && month(s2)) cout.wri("YYMM"); } static bool month(int a) => 1 <= a && a <= 12; } // b-aで降順 // priority queue class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } } namespace CompLib.Algorithms { #region BinarySearch public static partial class Algorithm { static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) { var l = 0; var r = a.Count - 1; while (l <= r) { var m = (l + r) / 2; var res = cmp.Compare(a[m], v); if (res < 0 || (res == 0 && !islb)) l = m + 1; else r = m - 1; } return l; } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) { return binarySearch(a, v, Comparer<T>.Create(f), true); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, true); } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) { return binarySearch(a, v, Comparer<T>.Create(cmp), false); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///より真に大きい要素が現れる最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, false); } } #endregion } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner cin = new Scaner(); write cout = new write(); Math2 mmath = new Math2(); //ここから var o = cin.IntM; var S = o[0]; var s2 = S % 100; var s1 = (S - s2) / 100; // cout.wri(s1); // cout.wri(s2); if (!month(s1) && !month(s2)) cout.wri("NA"); else if (month(s1) && month(s2)) cout.wri("AMBIGUOUS"); else if (month(s1) && !month(s2)) cout.wri("MMYY"); else if (!month(s1) && month(s2)) cout.wri("YYMM"); } static bool month(int a) => 1 <= a && a <= 12; } // b-aで降順 // priority queue class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } } namespace CompLib.Algorithms { #region BinarySearch public static partial class Algorithm { static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) { var l = 0; var r = a.Count - 1; while (l <= r) { var m = (l + r) / 2; var res = cmp.Compare(a[m], v); if (res < 0 || (res == 0 && !islb)) l = m + 1; else r = m - 1; } return l; } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) { return binarySearch(a, v, Comparer<T>.Create(f), true); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, true); } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) { return binarySearch(a, v, Comparer<T>.Create(cmp), false); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///より真に大きい要素が現れる最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, false); } } #endregion } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,482
2
using System; using static System.Console; using static System.Math; using System.Collections.Generic; using System.Linq; using System.Text; namespace TemplateAlgorithm { class Program { public const long Inf = (long)1e18; public const double eps = 1e-6; public const string alfa = "abcdefghijklmnopqrstuvwxyz"; public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const int MOD = 1000000007; // c ot i static int ToInt(char c) => c - '0'; static void Main(string[] args) { int A = IO.ReadInt(); int L = A / 100; int R = A % 100; if (InRange(1,12,L)) { if (InRange(1, 12, R)) { WriteLine("AMBIGUOUS"); } else WriteLine("MMYY"); } else { if (InRange(1, 12, R)) WriteLine("YYMM"); else WriteLine("NA"); } } #region 範囲 public static bool InRange<T>(T begin, T end, T value) where T : IComparable<T> => value.CompareTo(begin) > 0 && value.CompareTo(end) < 0; #endregion #region MIN,MAX /// <summary> /// 最大値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MaxValue<T>(params T[] vals) => vals.Max(); /// <summary> /// 最小値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MinValue<T>(params T[] vals) => vals.Min(); #endregion } #region IO /// <summary> /// IO /// </summary> public class IO { public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine(); public static int ReadInt() => int.Parse(ReadStr()); public static long ReadLong() => long.Parse(ReadStr()); public static decimal ReadDecimal() => decimal.Parse(ReadStr()); public static double ReadDouble() => double.Parse(ReadStr()); public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator); public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse); public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse); public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse); public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse); } #endregion }
using System; using static System.Console; using static System.Math; using System.Collections.Generic; using System.Linq; using System.Text; namespace TemplateAlgorithm { class Program { public const long Inf = (long)1e18; public const double eps = 1e-6; public const string alfa = "abcdefghijklmnopqrstuvwxyz"; public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const int MOD = 1000000007; // c ot i static int ToInt(char c) => c - '0'; static void Main(string[] args) { int A = IO.ReadInt(); int L = A / 100; int R = A % 100; if (InRange(1,12,L)) { if (InRange(1, 12, R)) { WriteLine("AMBIGUOUS"); } else WriteLine("MMYY"); } else { if (InRange(1, 12, R)) WriteLine("YYMM"); else WriteLine("NA"); } } #region 範囲 public static bool InRange<T>(T begin, T end, T value) where T : IComparable<T> => value.CompareTo(begin) >= 0 && value.CompareTo(end) <= 0; #endregion #region MIN,MAX /// <summary> /// 最大値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MaxValue<T>(params T[] vals) => vals.Max(); /// <summary> /// 最小値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MinValue<T>(params T[] vals) => vals.Min(); #endregion } #region IO /// <summary> /// IO /// </summary> public class IO { public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine(); public static int ReadInt() => int.Parse(ReadStr()); public static long ReadLong() => long.Parse(ReadStr()); public static decimal ReadDecimal() => decimal.Parse(ReadStr()); public static double ReadDouble() => double.Parse(ReadStr()); public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator); public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse); public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse); public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse); public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse); } #endregion }
[["-", 0, 195, 8, 306, 0, 16, 31, 16, 17, 47], ["+", 0, 195, 8, 306, 0, 16, 31, 16, 17, 20], ["-", 0, 195, 8, 306, 0, 16, 12, 16, 17, 18], ["+", 0, 195, 8, 306, 0, 16, 12, 16, 17, 19]]
8
524
4
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int retval; if (!int.TryParse(input, out retval)) { Console.WriteLine("NA"); return; } string firstHalf = input.Substring(0, 2); bool isFirstMonth = IsMonthString(firstHalf); string latterHalf = input.Substring(2, 2); bool isLatterMonth = IsMonthString(latterHalf); if (isFirstMonth) { if (isLatterMonth) { Console.WriteLine("AMBIGUOUS"); return; } else { Console.WriteLine("MMYY'"); return; } } else { if (isLatterMonth) { Console.WriteLine("YYMM"); return; } else { Console.WriteLine("NA"); return; } } } static bool IsMonthString(string input) { int retval; if (!int.TryParse(input, out retval)) { return false; } return 1 <= retval && retval <= 12; } } }
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int retval; if (!int.TryParse(input, out retval)) { Console.WriteLine("NA"); return; } string firstHalf = input.Substring(0, 2); bool isFirstMonth = IsMonthString(firstHalf); string latterHalf = input.Substring(2, 2); bool isLatterMonth = IsMonthString(latterHalf); if (isFirstMonth) { if (isLatterMonth) { Console.WriteLine("AMBIGUOUS"); return; } else { Console.WriteLine("MMYY"); return; } } else { if (isLatterMonth) { Console.WriteLine("YYMM"); return; } else { Console.WriteLine("NA"); return; } } } static bool IsMonthString(string input) { int retval; if (!int.TryParse(input, out retval)) { return false; } return 1 <= retval && retval <= 12; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
210
2
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; namespace ABC126B { static class Program { static void Main(string[] args) { var s = Regex.Split(ReadLine(), @"(?<=\G.{2})(?!$)") .Select(x => int.Parse(x)) .ToList(); var a = ""; if (s[0] <= 0 && s[1] <= 0) { a = "NA"; } else { if ((s[0] <= 12 && s[1] != 0 && s[0] > 0) || (s[1] <= 12 && s[0] != 0 && s[1] > 0)) { a = "AMBIGUOUS"; } else if (s[0] <= 12 && s[0] > 0) { a = "MMYY"; } else if (s[1] <= 12 && s[1] > 0) { a = "YYMM"; } else { a = "NA"; } } WriteLine(a); } public static T TryParse<T>(this String input) { try { var converter = TypeDescriptor.GetConverter(typeof(T)); if (converter != null) { return (T)converter.ConvertFromString(input); } else { throw new InvalidCastException(""); } } catch { throw new InvalidCastException(typeof(T) + " is not supported."); } } public static List<T> SplitTryParseToList<T>(this String input) { return input.Split().Select(n => n.TryParse<T>()).ToList(); } public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2) { var t = list[index1]; list[index1] = list[index2]; list[index2] = t; return list; } public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list) { return list.GroupBy(i => i) .Where(g => g.Any()) .Select(g => Tuple.Create(g.Key, g.Count())) .ToList(); } public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list) { return list.OrderByDescending((x) => x.Item2).ToList(); } public static List<T> ReadLineOne<T>(int n) { var list = new List<T>(); foreach (var i in Enumerable.Range(1, n)) { list.Add(Console.ReadLine().TryParse<T>()); } return list; } public static void PrintAll<T>(this IEnumerable<T> list) { foreach (var i in list) { Console.Write($"{i} "); } Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; namespace ABC126B { static class Program { static void Main(string[] args) { var s = Regex.Split(ReadLine(), @"(?<=\G.{2})(?!$)") .Select(x => int.Parse(x)) .ToList(); var a = ""; if (s[0] <= 0 && s[1] <= 0) { a = "NA"; } else { if ((s[0] <= 12 && s[1] != 0 && s[0] > 0) && (s[1] <= 12 && s[0] != 0 && s[1] > 0)) { a = "AMBIGUOUS"; } else if (s[0] <= 12 && s[0] > 0) { a = "MMYY"; } else if (s[1] <= 12 && s[1] > 0) { a = "YYMM"; } else { a = "NA"; } } WriteLine(a); } public static T TryParse<T>(this String input) { try { var converter = TypeDescriptor.GetConverter(typeof(T)); if (converter != null) { return (T)converter.ConvertFromString(input); } else { throw new InvalidCastException(""); } } catch { throw new InvalidCastException(typeof(T) + " is not supported."); } } public static List<T> SplitTryParseToList<T>(this String input) { return input.Split().Select(n => n.TryParse<T>()).ToList(); } public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2) { var t = list[index1]; list[index1] = list[index2]; list[index2] = t; return list; } public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list) { return list.GroupBy(i => i) .Where(g => g.Any()) .Select(g => Tuple.Create(g.Key, g.Count())) .ToList(); } public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list) { return list.OrderByDescending((x) => x.Item2).ToList(); } public static List<T> ReadLineOne<T>(int n) { var list = new List<T>(); foreach (var i in Enumerable.Range(1, n)) { list.Add(Console.ReadLine().TryParse<T>()); } return list; } public static void PrintAll<T>(this IEnumerable<T> list) { foreach (var i in list) { Console.Write($"{i} "); } Console.WriteLine(); } } }
[["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98]]
8
647
2
using System; namespace ConsoleApplication4.Properties { public class Class1 { public static void Main() { var n = int.Parse(Console.ReadLine()); int a = n / 100; int b = n % 100; if (a != 0 && a <= 12) { if (b <= 12) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("MMYY"); } } else { if (b == 0) { Console.WriteLine("NA"); } else if (b <= 12) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } } } }
using System; namespace ConsoleApplication4.Properties { public class Class1 { public static void Main() { var n = int.Parse(Console.ReadLine()); int a = n / 100; int b = n % 100; if (a != 0 && a <= 12) { if (b != 0 && b <= 12) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("MMYY"); } } else { if (b == 0) { Console.WriteLine("NA"); } else if (b <= 12) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } } } }
[["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
141
4
using System; using System.Linq; namespace B___YYMM_or_MMYY { class Program { static void Main(string[] args) { var S = Console.ReadLine(); int AA = int.Parse(new string(S.Where((e, i) => i < 2).ToArray())); int BB = int.Parse(new string(S.Where((e, i) => 2 < i).ToArray())); if (MM(AA) && YY(BB)) Console.WriteLine(YY(AA) && MM(BB) ? "AMBIGUOUS" : "MMYY"); else if (YY(AA) && MM(BB)) Console.WriteLine("YYMM"); else Console.WriteLine("NA"); } static bool MM(int XX) => 1 <= XX && XX <= 12; static bool YY(int XX) => 0 <= XX && XX <= 99; } }
using System; using System.Linq; namespace B___YYMM_or_MMYY { class Program { static void Main(string[] args) { var S = Console.ReadLine(); int AA = int.Parse(new string(S.Where((e, i) => i < 2).ToArray())); int BB = int.Parse(new string(S.Where((e, i) => 2 <= i).ToArray())); if (MM(AA) && YY(BB)) Console.WriteLine(YY(AA) && MM(BB) ? "AMBIGUOUS" : "MMYY"); else if (YY(AA) && MM(BB)) Console.WriteLine("YYMM"); else Console.WriteLine("NA"); } static bool MM(int XX) => 1 <= XX && XX <= 12; static bool YY(int XX) => 0 <= XX && XX <= 99; } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 19]]
8
197
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var first = int.Parse(S.Substring(0, 2)); var second = int.Parse(S.Substring(2, 2)); bool isYymm = false; if (1 <= first && 1 <= second && second <= 12) { isYymm = true; } bool isMmyy = false; if (1 <= second && 1 <= first && first <= 12) { isMmyy = true; } string ans; if (isYymm && isMmyy) { ans = "AMBIGUOUS"; } else if (isYymm) { ans = "YYMM"; } else if (isMmyy) { ans = "MMYY"; } else { ans = "NA"; } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var first = int.Parse(S.Substring(0, 2)); var second = int.Parse(S.Substring(2, 2)); bool isYymm = false; if (0 <= first && 1 <= second && second <= 12) { isYymm = true; } bool isMmyy = false; if (0 <= second && 1 <= first && first <= 12) { isMmyy = true; } string ans; if (isYymm && isMmyy) { ans = "AMBIGUOUS"; } else if (isYymm) { ans = "YYMM"; } else if (isMmyy) { ans = "MMYY"; } else { ans = "NA"; } Console.WriteLine(ans); } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 203]]
8
182
4
using System; using System.Linq; class abc126b { static void Main() { var S = Console.ReadLine(); var AA = "" + S[0] + S[1]; var BB = "" + S[2] + S[3]; var aa = int.Parse(AA); var bb = int.Parse(BB); var result = ""; if (aa > 0 && aa < 13) { if (bb > 0 && aa < 13) { result = "AMBIGUOUS"; } else { result = "MMYY"; } } else { if (bb > 0 && aa < 13) { result = "YYMM"; } else { result = "NA"; } } Console.WriteLine(result); return; } }
using System; using System.Linq; class abc126b { static void Main() { var S = Console.ReadLine(); var AA = "" + S[0] + S[1]; var BB = "" + S[2] + S[3]; var aa = int.Parse(AA); var bb = int.Parse(BB); var result = ""; if (aa > 0 && aa < 13) { if (bb > 0 && bb < 13) { result = "AMBIGUOUS"; } else { result = "MMYY"; } } else { if (bb > 0 && bb < 13) { result = "YYMM"; } else { result = "NA"; } } Console.WriteLine(result); return; } }
[["-", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
164
4
using System; using System.Linq; using System.Threading.Tasks; static class Program { static void Main() { string inputVal = Console.ReadLine(); int val1 = int.Parse(inputVal.Substring(0, 2)); int val2 = int.Parse(inputVal.Substring(2, 2)); bool mayMonthVal1 = val1 >= 1 && val1 <= 12; bool mayMonthVal2 = val2 >= 1 && val2 <= 12; string ret = ""; // NA if (val1 < 0) ret = "NA"; else if (val1 == 0 && val2 == 0) ret = "NA"; else if (val1 == 0 || mayMonthVal2) ret = "YYMM"; else if (val2 == 0 || mayMonthVal1) ret = "MMYY"; else if (mayMonthVal1 && mayMonthVal2) ret = "AMBIGUOUS"; else if (mayMonthVal1) ret = "MMYY"; else if (mayMonthVal2) ret = "YYMM"; else ret = "NA"; Console.WriteLine(ret); } }
using System; using System.Linq; using System.Threading.Tasks; static class Program { static void Main() { string inputVal = Console.ReadLine(); int val1 = int.Parse(inputVal.Substring(0, 2)); int val2 = int.Parse(inputVal.Substring(2, 2)); bool mayMonthVal1 = val1 >= 1 && val1 <= 12; bool mayMonthVal2 = val2 >= 1 && val2 <= 12; string ret = ""; // NA if (val1 < 0) ret = "NA"; else if (val1 == 0 && val2 == 0) ret = "NA"; else if (val1 == 0 && mayMonthVal2) ret = "YYMM"; else if (val2 == 0 && mayMonthVal1) ret = "MMYY"; else if (mayMonthVal1 && mayMonthVal2) ret = "AMBIGUOUS"; else if (mayMonthVal1) ret = "MMYY"; else if (mayMonthVal2) ret = "YYMM"; else ret = "NA"; Console.WriteLine(ret); } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 106], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 17, 106], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 98]]
8
207
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Program { static void Main(string[] args) { //入力 string S = Console.ReadLine(); //前半二文字 string before = S.Substring(0, 2); //後半二文字 string after = S.Substring(2, 2); //月の可能性をまとめたリスト string[] month = { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }; //回答となる文字列 string ans; //実行 if (month.Contains(before) && month.Contains(after)) { ans = "AMBIGUOUS"; } else if (month.Contains(before)) { ans = "MMYY"; } else if (month.Contains(after)) { ans = "YYMM"; } else { ans = "NA"; } //出力 Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Program { static void Main(string[] args) { //入力 string S = Console.ReadLine(); //前半二文字 string before = S.Substring(0, 2); //後半二文字 string after = S.Substring(2, 2); //月の可能性をまとめたリスト string[] month = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }; //回答となる文字列 string ans; //実行 if (month.Contains(before) && month.Contains(after)) { ans = "AMBIGUOUS"; } else if (month.Contains(before)) { ans = "MMYY"; } else if (month.Contains(after)) { ans = "YYMM"; } else { ans = "NA"; } //出力 Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 229, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 229, 0, 5, 0, 62], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21]]
8
224
4
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { string S = Console.ReadLine(); var result = new DateTime(); IFormatProvider formatProvider = null; var isYymm = DateTime.TryParseExact( S, "yyMM", formatProvider, System.Globalization.DateTimeStyles.None, out result); var isMmyy = DateTime.TryParseExact( S, "yyMM", formatProvider, System.Globalization.DateTimeStyles.None, out result); if (isYymm && isMmyy) { WriteAMBIGUOUS(); return; } if (isYymm && !isMmyy) { WriteYYMM(); return; } if (!isYymm && isMmyy) { WriteMMYY(); return; } WriteNA(); return; } private static void WriteAMBIGUOUS() { Console.WriteLine("AMBIGUOUS"); } private static void WriteYYMM() { Console.WriteLine("YYMM"); } private static void WriteMMYY() { Console.WriteLine("MMYY"); } private static void WriteNA() { Console.WriteLine("NA"); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { string S = Console.ReadLine(); var result = new DateTime(); IFormatProvider formatProvider = null; var isYymm = DateTime.TryParseExact( S, "yyMM", formatProvider, System.Globalization.DateTimeStyles.None, out result); var isMmyy = DateTime.TryParseExact( S, "MMyy", formatProvider, System.Globalization.DateTimeStyles.None, out result); if (isYymm && isMmyy) { WriteAMBIGUOUS(); return; } if (isYymm && !isMmyy) { WriteYYMM(); return; } if (!isYymm && isMmyy) { WriteMMYY(); return; } WriteNA(); return; } private static void WriteAMBIGUOUS() { Console.WriteLine("AMBIGUOUS"); } private static void WriteYYMM() { Console.WriteLine("YYMM"); } private static void WriteMMYY() { Console.WriteLine("MMYY"); } private static void WriteNA() { Console.WriteLine("NA"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
221
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var S = int.Parse(Console.ReadLine()); var YY = S / 100; var MM = S % 100; if (YY > 12) { if (MM == 0) { Console.WriteLine("NA"); } else if (MM > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else if (1 <= YY && YY <= 12) { if (MM == 0) { Console.WriteLine("NA"); } else if (MM > 12) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBIGUOUS"); } } else { if (MM == 0) { Console.WriteLine("NA"); } else if (MM > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var S = int.Parse(Console.ReadLine()); var YY = S / 100; var MM = S % 100; if (YY > 12) { if (MM == 0) { Console.WriteLine("NA"); } else if (MM > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else if (1 <= YY && YY <= 12) { if (MM == 0) { Console.WriteLine("MMYY"); } else if (MM > 12) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBIGUOUS"); } } else { if (MM == 0) { Console.WriteLine("NA"); } else if (MM > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
223
2
using System; namespace ABC126 { class Program { static void Main(String[] args) { // 入力 String S = Console.ReadLine(); // 計算 // 文字列分割 int top = int.Parse(S.Substring(0, 2)); int buttom = int.Parse(S.Substring(2, 2)); // top,buttomがそれぞれ月になれるかを調べる Boolean topMonth = (top >= 1 && top <= 12); Boolean buttomMonth = (buttom >= 1 && buttom <= 12); // 出力 if (topMonth && buttomMonth) { Console.WriteLine("AMBIGUOUS"); } else if (!topMonth && buttomMonth) { Console.WriteLine("YYMM"); } else if (topMonth && buttomMonth) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } } }
using System; namespace ABC126 { class Program { static void Main(String[] args) { // 入力 String S = Console.ReadLine(); // 計算 // 文字列分割 int top = int.Parse(S.Substring(0, 2)); int buttom = int.Parse(S.Substring(2, 2)); // top,buttomがそれぞれ月になれるかを調べる Boolean topMonth = (top >= 1 && top <= 12); Boolean buttomMonth = (buttom >= 1 && buttom <= 12); // 出力 if (topMonth && buttomMonth) { Console.WriteLine("AMBIGUOUS"); } else if (!topMonth && buttomMonth) { Console.WriteLine("YYMM"); } else if (topMonth && !buttomMonth) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } } }
[["+", 75, 57, 75, 57, 15, 16, 12, 241, 0, 111]]
8
162
1
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ABC126 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); int first = int.Parse(S.Substring(0, 2)); int second = int.Parse(S.Substring(2, 2)); if (first == 0 && second > 12) { Console.WriteLine("NA"); } else if (first > 12 && second == 0) { Console.WriteLine("NA"); } else if (first == 0 && second == 0) { Console.WriteLine("NA"); } else if (first <= 12 && second == 0) { Console.WriteLine("MMYY"); } else if (first == 0 && second <= 12) { Console.WriteLine("MMYY"); } else if (first > 12 && second <= 12) { Console.WriteLine("YYMM"); } else if (first <= 12 && second > 12) { Console.WriteLine("MMYY"); } else if (first <= 12 && second <= 12) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("NA"); } } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ABC126 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); int first = int.Parse(S.Substring(0, 2)); int second = int.Parse(S.Substring(2, 2)); if (first == 0 && second > 12) { Console.WriteLine("NA"); } else if (first > 12 && second == 0) { Console.WriteLine("NA"); } else if (first == 0 && second == 0) { Console.WriteLine("NA"); } else if (first <= 12 && second == 0) { Console.WriteLine("MMYY"); } else if (first == 0 && second <= 12) { Console.WriteLine("YYMM"); } else if (first > 12 && second <= 12) { Console.WriteLine("YYMM"); } else if (first <= 12 && second > 12) { Console.WriteLine("MMYY"); } else if (first <= 12 && second <= 12) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("NA"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
269
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { char[] S = Console.ReadLine().ToCharArray(); int forward = (S[0] - '0') * 10 + S[1] - '0'; int backward = (S[2] - '0') * 10 + S[3] - '0'; if (1 <= forward && forward <= 12) { if (1 <= backward && backward <= 12) { Console.WriteLine("ANBIGUOUS"); } else { Console.WriteLine("MMYY"); } } else { if (1 <= backward && backward <= 12) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { char[] S = Console.ReadLine().ToCharArray(); int forward = (S[0] - '0') * 10 + S[1] - '0'; int backward = (S[2] - '0') * 10 + S[3] - '0'; if (1 <= forward && forward <= 12) { if (1 <= backward && backward <= 12) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("MMYY"); } } else { if (1 <= backward && backward <= 12) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
176
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc119d { class Program { static void Main(string[] args) { var S = ReadInt(); bool YYMM = false; bool MMYY = false; int u = S / 100; int d = S % 100; // YYMM if (u >= 1 && u <= 99) if (d >= 1 && d <= 12) YYMM = true; // MMYY if (u >= 1 && u <= 12) if (d >= 1 && d <= 99) MMYY = true; if (YYMM && MMYY) Console.WriteLine("AMBIGUOUS"); else if (YYMM) Console.WriteLine("YYMM"); else if (MMYY) Console.WriteLine("MMYY"); else Console.WriteLine("NA"); #if DEBUG Console.ReadKey(); #endif } private static bool IsRange(int a, int from, int to) => (from <= a && a <= to); private static int ReadInt() => int.Parse(Console.ReadLine()); private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList(); private static double ReadDouble() => double.Parse(Console.ReadLine()); private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList(); private static long ReadLong() => long.Parse(Console.ReadLine()); private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList(); private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList(); private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す where Type : IComparable { var lower = 0; var upper = s.Count - 1; while (upper - lower > 1) { var mid = lower + (upper - lower) / 2; if (s[mid].CompareTo(target) <= 0) { lower = mid; } else { upper = mid; } } return lower; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc119d { class Program { static void Main(string[] args) { var S = ReadInt(); bool YYMM = false; bool MMYY = false; int u = S / 100; int d = S % 100; // YYMM if (u >= 0 && u <= 99) if (d >= 1 && d <= 12) YYMM = true; // MMYY if (u >= 1 && u <= 12) if (d >= 0 && d <= 99) MMYY = true; if (YYMM && MMYY) Console.WriteLine("AMBIGUOUS"); else if (YYMM) Console.WriteLine("YYMM"); else if (MMYY) Console.WriteLine("MMYY"); else Console.WriteLine("NA"); #if DEBUG Console.ReadKey(); #endif } private static bool IsRange(int a, int from, int to) => (from <= a && a <= to); private static int ReadInt() => int.Parse(Console.ReadLine()); private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList(); private static double ReadDouble() => double.Parse(Console.ReadLine()); private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList(); private static long ReadLong() => long.Parse(Console.ReadLine()); private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList(); private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList(); private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す where Type : IComparable { var lower = 0; var upper = s.Count - 1; while (upper - lower > 1) { var mid = lower + (upper - lower) / 2; if (s[mid].CompareTo(target) <= 0) { lower = mid; } else { upper = mid; } } return lower; } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 57, 15, 16, 31, 16, 12, 203]]
8
496
4
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 s = Read(); var yy = s[0] + "" + s[1]; var mm = s[2] + "" + s[3]; var y = int.Parse(yy); var m = int.Parse(mm); if (y >= 1 && y <= 12 && m >= 1 && m <= 12) { WriteLine("AMBIGUOUS"); } else if (y >= 1 && y <= 99 && m >= 1 && m <= 12) { WriteLine("YYMM"); } else if (y >= 1 && y <= 12 && m >= 1 && m <= 99) { WriteLine("MMYY"); } else { WriteLine("NA"); } } 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); } //最大公約数 public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var reminder = a % b; a = b; b = reminder; } return a; } //最小公倍数 public static int Lcm(int a, int b) { return a * b / Gcd(a, b); } } }
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 s = Read(); var yy = s[0] + "" + s[1]; var mm = s[2] + "" + s[3]; var y = int.Parse(yy); var m = int.Parse(mm); if (y >= 1 && y <= 12 && m >= 1 && m <= 12) { WriteLine("AMBIGUOUS"); } else if (y >= 0 && y <= 99 && m >= 1 && m <= 12) { WriteLine("YYMM"); } else if (y >= 1 && y <= 12 && m >= 0 && m <= 99) { WriteLine("MMYY"); } else { WriteLine("NA"); } } 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); } //最大公約数 public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var reminder = a % b; a = b; b = reminder; } return a; } //最小公倍数 public static int Lcm(int a, int b) { return a * b / Gcd(a, b); } } }
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 12, 203]]
8
457
4
using System; using System.Linq; class abc126_B { static void Main(string[] args) { var QS = Console.ReadLine(); try { var first = int.Parse(QS.Substring(0, 2)); var second = int.Parse(QS.Substring(2, 2)); var firstCanMonth = 1 <= first && first <= 13; var secondCanMonth = 1 <= second && second <= 13; if (firstCanMonth && secondCanMonth) { Console.WriteLine("AMBIGUOUS"); } else if (firstCanMonth) { Console.WriteLine("MMYY"); } else if (secondCanMonth) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } catch (Exception) { Console.WriteLine("NA"); } } static long[][] readLongsN(int N) { return Enumerable.Range(0, N).Select(x => readLongs()).ToArray(); } static long readLong() { return long.Parse(Console.ReadLine()); } static long[] readLongs() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); } }
using System; using System.Linq; class abc126_B { static void Main(string[] args) { var QS = Console.ReadLine(); try { var first = int.Parse(QS.Substring(0, 2)); var second = int.Parse(QS.Substring(2, 2)); var firstCanMonth = 1 <= first && first <= 12; var secondCanMonth = 1 <= second && second <= 12; if (firstCanMonth && secondCanMonth) { Console.WriteLine("AMBIGUOUS"); } else if (firstCanMonth) { Console.WriteLine("MMYY"); } else if (secondCanMonth) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } catch (Exception) { Console.WriteLine("NA"); } } static long[][] readLongsN(int N) { return Enumerable.Range(0, N).Select(x => readLongs()).ToArray(); } static long readLong() { return long.Parse(Console.ReadLine()); } static long[] readLongs() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); } }
[["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203]]
8
261
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtC { class Program { static void Main(string[] args) { var S = ReadString(); var a = int.Parse(S.Substring(0, 2)); var b = int.Parse(S.Substring(2, 2)); switch ((0 < a && a <= 12 ? 1 : 0) << 1 | (0 < b && b <= 12 ? 1 : 0)) { case 0: Out("NA"); break; case 1: Out("YYMM"); break; case 2: Out("YYMM"); break; case 3: Out("AMBIGUOUS"); break; } } //最小公倍数 static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static string ReadString() { return Console.ReadLine(); } static void Out(object o) { Console.WriteLine(o); } } static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } class PriorityQueue<T> {} }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtC { class Program { static void Main(string[] args) { var S = ReadString(); var a = int.Parse(S.Substring(0, 2)); var b = int.Parse(S.Substring(2, 2)); switch ((0 < a && a <= 12 ? 1 : 0) << 1 | (0 < b && b <= 12 ? 1 : 0)) { case 0: Out("NA"); break; case 1: Out("YYMM"); break; case 2: Out("MMYY"); break; case 3: Out("AMBIGUOUS"); break; } } //最小公倍数 static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static string ReadString() { return Console.ReadLine(); } static void Out(object o) { Console.WriteLine(o); } } static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } class PriorityQueue<T> {} }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
552
2
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nm = ReadLib.ReadAsIntArray(); var mArr = ReadLib.ReadNTimesAsIntArray(nm[0]); var pArr = ReadLib.ReadAsIntArray(); var score = Calculation.Calculate(nm[0], nm[1], mArr, pArr); Console.WriteLine(score); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { static int[][] MArr; static int[] PArr; static int M; public static object Calculate(int n, int m, int[][] mArr, int[] pArr) { MArr = mArr; PArr = pArr; M = m; return Count(n, new List<bool>()); } private static int Count(int n, IEnumerable<bool> switchStatement) { if (n > 0) { return Count(n - 1, switchStatement.Concat(new bool[] { true })) + Count(n - 1, switchStatement.Concat(new bool[] { false })); } var statements = switchStatement.ToList(); for (int m = 0; m < M; m++) { var sArr = MArr[m].Skip(1).ToArray(); var nOn = sArr.Select(i => statements[i - 1]).Count(t => t); if (nOn % 2 != PArr[m]) { return 0; } } return 1; } } 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 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(); } } 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); } ///// <summary>nCr, 組み合わせ</summary> // public static long Combination(int n, int r) { // if (r == 0) { // return 1; // } // // 分子 // var moleculeArr = Enumerable // .Range(0, Math.Min(n - r, r)) // .Select(i => n - i) // .ToArray(); // var moleculeArrLength = moleculeArr.Length; // // 分母 // var denominatorArr = Enumerable // .Range(1, Math.Max(n - r, r)) // .ToArray(); // for (var m = 0; m < moleculeArrLength; m++) { // while (true) { // var mVal = moleculeArr[m]; // var gcds = denominatorArr.Select(b => Gcd(mVal, b)); // var maxGcd = gcds.Max(); // var maxI = gcds.ToList().IndexOf(maxGcd); // if (maxGcd == 1) { // break; // } // denominatorArr[maxI] /= (int)maxGcd; // moleculeArr[m] /= (int)maxGcd; // } // } // return FullPower(moleculeArr); //} #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); } } 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>あまりを計算するための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, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, 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; } }
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nm = ReadLib.ReadAsIntArray(); var mArr = ReadLib.ReadNTimesAsIntArray(nm[1]); var pArr = ReadLib.ReadAsIntArray(); var score = Calculation.Calculate(nm[0], nm[1], mArr, pArr); Console.WriteLine(score); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { static int[][] MArr; static int[] PArr; static int M; public static object Calculate(int n, int m, int[][] mArr, int[] pArr) { MArr = mArr; PArr = pArr; M = m; return Count(n, new List<bool>()); } private static int Count(int n, IEnumerable<bool> switchStatement) { if (n > 0) { return Count(n - 1, switchStatement.Concat(new bool[] { true })) + Count(n - 1, switchStatement.Concat(new bool[] { false })); } var statements = switchStatement.ToList(); for (int m = 0; m < M; m++) { var sArr = MArr[m].Skip(1).ToArray(); var nOn = sArr.Select(i => statements[i - 1]).Count(t => t); if (nOn % 2 != PArr[m]) { return 0; } } return 1; } } 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 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(); } } 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); } ///// <summary>nCr, 組み合わせ</summary> // public static long Combination(int n, int r) { // if (r == 0) { // return 1; // } // // 分子 // var moleculeArr = Enumerable // .Range(0, Math.Min(n - r, r)) // .Select(i => n - i) // .ToArray(); // var moleculeArrLength = moleculeArr.Length; // // 分母 // var denominatorArr = Enumerable // .Range(1, Math.Max(n - r, r)) // .ToArray(); // for (var m = 0; m < moleculeArrLength; m++) { // while (true) { // var mVal = moleculeArr[m]; // var gcds = denominatorArr.Select(b => Gcd(mVal, b)); // var maxGcd = gcds.Max(); // var maxI = gcds.ToList().IndexOf(maxGcd); // if (maxGcd == 1) { // break; // } // denominatorArr[maxI] /= (int)maxGcd; // moleculeArr[m] /= (int)maxGcd; // } // } // return FullPower(moleculeArr); //} #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); } } 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>あまりを計算するための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, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, 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; } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
1,754
2
using System; using System.Linq; namespace CSwitches { class Program { static void Main(string[] args) { // 入力 N/M の取得 var inputNM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputNM[0]; var m = inputNM[1]; // 各電球の繋がってるスイッチ取得 var lamps = new int [m][]; for (var i = 0; i < m; i++) { var switches = Console.ReadLine().Split().Skip(1).Select(int.Parse).ToArray(); lamps[i] = switches; } // 各電球の点灯条件を取得 var conds = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 全部OFF ~ 全部ON の全てのパターンをビット演算でチェックして数える var count = 0; var patterns = Math.Pow(2, n); for (var pattern = 0; pattern <= patterns; pattern++) { var isSatisfied = true; for (var i = 0; i < m; i++) { var switches = lamps[i]; var switchCount = switches.Count(s => (1 << (s - 1) & pattern) > 0); isSatisfied &= switchCount % 2 == conds[i]; if (!isSatisfied) break; } if (isSatisfied) count++; } // 解答の出力 Console.WriteLine(count); } } }
using System; using System.Linq; namespace CSwitches { class Program { static void Main(string[] args) { // 入力 N/M の取得 var inputNM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputNM[0]; var m = inputNM[1]; // 各電球の繋がってるスイッチ取得 var lamps = new int [m][]; for (var i = 0; i < m; i++) { var switches = Console.ReadLine().Split().Skip(1).Select(int.Parse).ToArray(); lamps[i] = switches; } // 各電球の点灯条件を取得 var conds = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 全部OFF ~ 全部ON の全てのパターンをビット演算でチェックして数える var count = 0; var patterns = Math.Pow(2, n); for (var pattern = 0; pattern < patterns; pattern++) { var isSatisfied = true; for (var i = 0; i < m; i++) { var switches = lamps[i]; var switchCount = switches.Count(s => (1 << (s - 1) & pattern) > 0); isSatisfied &= switchCount % 2 == conds[i]; if (!isSatisfied) break; } if (isSatisfied) count++; } // 解答の出力 Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
277
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static System.Console; namespace C_ABC128 { class MainClass { static int[] s; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); var kslist = new List<int[]>(); for (int i = 0; i < s[1]; i++) { int[] ks = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); kslist.Add(ks); } int[] p = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); int n = s[0]; int m = s[1]; var blst = new List<int>(); for (int bit1 = 0; bit1 < (1 << n); ++bit1) { blst.Add(bit1); } for (int i = 0; i < m; i++) { for (int bit = 0; bit < (1 << n); ++bit) { int ans = 0; for (int j = 1; j <= kslist[i][0]; j++) { if ((bit & (1 << kslist[i][j])) >= 1) { ans++; } } if (ans % 2 != p[i]) { int idx = blst.IndexOf(bit); if (idx >= 0) { blst.RemoveAt(idx); } } } } WriteLine(blst.Count); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static System.Console; namespace C_ABC128 { class MainClass { static int[] s; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); var kslist = new List<int[]>(); for (int i = 0; i < s[1]; i++) { int[] ks = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); kslist.Add(ks); } int[] p = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); int n = s[0]; int m = s[1]; var blst = new List<int>(); for (int bit1 = 0; bit1 < (1 << n); ++bit1) { blst.Add(bit1); } for (int i = 0; i < m; i++) { for (int bit = 0; bit < (1 << n); ++bit) { int ans = 0; for (int j = 1; j <= kslist[i][0]; j++) { if ((bit & (1 << kslist[i][j] - 1)) >= 1) { ans++; } } if (ans % 2 != p[i]) { int idx = blst.IndexOf(bit); if (idx >= 0) { blst.RemoveAt(idx); } } } } WriteLine(blst.Count); } } }
[["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 33], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 12, 203]]
8
354
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace CSharp { static class Program { static void Main(string[] args) { int n, k; ReadInt(out n, out k); var V = ReadLongArray(); long ans = 0; for (int a = 0; a < Min(n, k); a++) { for (int b = 0; a + b < Min(n, k); b++) { var array = V.Take(a).Concat(V.Reverse().Take(b)).OrderBy(x => x); ans = Max( ans, array.Sum() - array.Take(Max(k - (a + b), 0)).TakeWhile(x => x < 0).Sum()); } } Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count) .Select(_ => long.Parse(Console.ReadLine())) .ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static string YesNo(bool condition) => condition ? "Yes" : "No"; static string YESNO(bool condition) => condition ? "YES" : "NO"; #endregion } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace CSharp { static class Program { static void Main(string[] args) { int n, k; ReadInt(out n, out k); var V = ReadLongArray(); long ans = 0; for (int a = 0; a <= Min(n, k); a++) { for (int b = 0; a + b <= Min(n, k); b++) { var array = V.Take(a).Concat(V.Reverse().Take(b)).OrderBy(x => x).ToArray(); ans = Max( ans, array.Sum() - array.Take(Max(k - (a + b), 0)).TakeWhile(x => x < 0).Sum()); } } Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count) .Select(_ => long.Parse(Console.ReadLine())) .ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static string YesNo(bool condition) => condition ? "Yes" : "No"; static string YESNO(bool condition) => condition ? "YES" : "NO"; #endregion } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24]]
8
750
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Sandbox { class Program { static void Main(string[] args) { var scanner = new Scanner(); var n = scanner.GetNextAsInt(); var k = scanner.GetNextAsInt(); var v = scanner.ToIntArrayFromNextLine(); var pointMax = 0; for (var l = 0; l <= k; l++) { for (var r = 0; l + r < n && l + r < k; r++) { var dropNum = k - r - l; var vr = v.Take(l); var vl = v.Reverse().Take(r); var sort = new List<int>(); sort.AddRange(vr); sort.AddRange(vl); sort.Sort(); while (dropNum > 0 && sort.Count > 0 && sort[0] < 0) { sort.RemoveAt(0); dropNum--; } pointMax = Math.Max(pointMax, sort.Sum()); } } Console.WriteLine(pointMax); } } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Sandbox { class Program { static void Main(string[] args) { var scanner = new Scanner(); var n = scanner.GetNextAsInt(); var k = scanner.GetNextAsInt(); var v = scanner.ToIntArrayFromNextLine(); var pointMax = 0; for (var l = 0; l <= k; l++) { for (var r = 0; l + r <= n && l + r <= k; r++) { var dropNum = k - r - l; var vr = v.Take(l); var vl = v.Reverse().Take(r); var sort = new List<int>(); sort.AddRange(vr); sort.AddRange(vl); sort.Sort(); while (dropNum > 0 && sort.Count > 0 && sort[0] < 0) { sort.RemoveAt(0); dropNum--; } pointMax = Math.Max(pointMax, sort.Sum()); } } Console.WriteLine(pointMax); } } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion }
[["-", 8, 196, 0, 7, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 19]]
8
711
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.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); } static long Solve(int N, int K, long[] V) { long max = 0; for (int i = 0; i <= Math.Min(K, N); ++i) { for (int j = 0; i + j <= Math.Min(K, N); ++j) { var values = Enumerable.Union(V.Take(i), V.Skip(N - j)) .OrderBy(value => value) .ToArray(); long sum = values.Sum(); for (int k = 0; i + j + k < K && k < values.Length; ++k) { if (values[k] < 0) { sum -= values[k]; } } max = Math.Max(sum, max); } } return max; } static void Main(string[] args) { int[] values = ReadInts(); var V = ReadLongs(); Console.WriteLine(Solve(values[0], values[1], V)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.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); } static long Solve(int N, int K, long[] V) { long max = 0; for (int i = 0; i <= Math.Min(K, N); ++i) { for (int j = 0; i + j <= Math.Min(K, N); ++j) { var values = Enumerable.Concat(V.Take(i), V.Skip(N - j)) .OrderBy(value => value) .ToArray(); long sum = values.Sum(); for (int k = 0; i + j + k < K && k < values.Length; ++k) { if (values[k] < 0) { sum -= values[k]; } } max = Math.Max(sum, max); } } return max; } static void Main(string[] args) { int[] values = ReadInts(); var V = ReadLongs(); Console.WriteLine(Solve(values[0], values[1], V)); } } }
[["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
405
2
using System; using System.Linq; using static System.Math; public static class P { public static void Main() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); long res = 0; for (int i = 1; i < n / 2; i++) { var max = (n - 1) % i == 0 ? n / 2 : n; var cur = 0L; for (int j = 0; j < max; j += i) res = Max(res, cur += a[j] + a[n - 1 - j]); } Console.WriteLine(res); } }
using System; using System.Linq; using static System.Math; public static class P { public static void Main() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); long res = 0; for (int i = 1; i < n / 2; i++) { var max = (n - 1) % i == 0 ? n / 2 : n - i; var cur = 0L; for (int j = 0; j < max; j += i) res = Max(res, cur += a[j] + a[n - 1 - j]); } Console.WriteLine(res); } }
[["+", 0, 200, 0, 212, 0, 41, 75, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 12, 22]]
8
158
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using static System.Math; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); int n = sc.I; int[] a = sc.Ia; long ans = 0, p = 0; for (int i = n >> 1; i > 0; i--) { p = 0; for (int j = i, k = n - 1 - i; j < n && j != k && j != k + i; j += i, k -= i) { p += a[j] + a[k]; ans = Max(ans, p); } } Console.WriteLine("{0}", ans); } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return a[n]; } } public string Sz { get { return Console.ReadLine(); } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2(int b) { return Array.ConvertAll((((b & 1) != 0 ? "0 " : "") + Console.ReadLine() + ((b & 2) != 0 ? " 0" : "")) .Split(), int.Parse); } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public string[] Sa2 { get { return (Console.ReadLine() + " 0").Split(); } } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using static System.Math; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); int n = sc.I; int[] a = sc.Ia; long ans = 0, p = 0; for (int i = n >> 1; i > 0; i--) { p = 0; for (int j = i, k = n - 1 - i; j < n - i && j != k && j != k + i; j += i, k -= i) { p += a[j] + a[k]; ans = Max(ans, p); } } Console.WriteLine("{0}", ans); } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return a[n]; } } public string Sz { get { return Console.ReadLine(); } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2(int b) { return Array.ConvertAll((((b & 1) != 0 ? "0 " : "") + Console.ReadLine() + ((b & 2) != 0 ? " 0" : "")) .Split(), int.Parse); } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public string[] Sa2 { get { return (Console.ReadLine() + " 0").Split(); } } }
[["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22]]
8
742
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_128 { class F { static void Main(string[] args) { Method(args); } static void Method(string[] args) { int n = ReadInt(); long[] ss = ReadLongs(); long res = 0; for (int i = 1; i < n / 2; i++) { long sum = 0; var useSet = new HashSet<long>(); for (int j = 1; i * j < n - 1; j++) { long other = n - i * j - 1; useSet.Add(i * j); if (useSet.Contains(other)) break; sum += ss[i * j] + ss[other]; res = Max(res, sum); } } WriteLine(res); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_128 { class F { static void Main(string[] args) { Method(args); } static void Method(string[] args) { int n = ReadInt(); long[] ss = ReadLongs(); long res = 0; for (int i = 1; i < n / 2; i++) { long sum = 0; var useSet = new HashSet<long>(); for (int j = 1; i * (j + 1) < n - 1; j++) { long other = n - i * j - 1; useSet.Add(i * j); if (useSet.Contains(other)) break; sum += ss[i * j] + ss[other]; res = Max(res, sum); } } WriteLine(res); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["+", 0, 7, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 7, 15, 16, 31, 16, 12, 23, 0, 25]]
8
385
4
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var a = Enumerate(n, x => ri); var ans = 0L; for (int d = 1; d < n; d++) { var v = 0L; for (int k = 1; k < n; k++) { var p = k * d; var q = (n - 1) - k * d; if (q % d == 0 && q / d <= k) break; if (p >= n) break; if (q < 0) break; v += a[p]; v += a[q]; ans = Max(ans, v); } } Console.WriteLine(ans); } const long INF = 1L << 60; 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 IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++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(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } 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; 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 != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var a = Enumerate(n, x => ri); var ans = 0L; for (int d = 1; d < n; d++) { var v = 0L; for (int k = 1; k < n; k++) { var p = k * d; var q = (n - 1) - k * d; if (q % d == 0 && q / d <= k) break; if (p >= n) break; if (q < d) break; v += a[p]; v += a[q]; ans = Max(ans, v); } } Console.WriteLine(ans); } const long INF = 1L << 60; 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 IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++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(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } 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; 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 != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
944
2
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; partial class Solver { public void Run() { var N = ni(); var s = ni(N); long ans = 0; var visited = new BooleanArray(N); for (int d = 1; d <= N - 1; d++) { visited.Clear(); var begin1 = 0; var begin2 = (N - 1); long sub = 0; while (0 <= begin2 && begin1 < N) { if (begin1 == begin2) break; if (visited[begin1]) break; visited[begin1] = true; if (visited[begin2]) break; visited[begin2] = true; sub += s[begin1]; sub += s[begin2]; ans = Math.Max(ans, sub); begin1 += d; begin2 -= d; } } cout.WriteLine(ans); } } public class BooleanArray { private int[] array; private int trueValue = 1; public BooleanArray(int size) { array = new int[size]; } public void Clear() { trueValue++; } public bool this[int index] { get { return array[index] == trueValue; } set { array[index] = value ? trueValue : trueValue - 1; } } public int Length { get { return array.Length; } } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { new Solver(Console.In, Console.Out).Run(); } TextReader cin; TextWriter cout; public Solver(TextReader reader, TextWriter writer) : base(reader) { this.cin = reader; this.cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} public int ni() { return NextInt(); } public int[] ni(int n) { return NextIntArray(n); } public long nl() { return NextLong(); } public long[] nl(int n) { return NextLongArray(n); } public double nd() { return NextDouble(); } public string ns() { return Next(); } } public class Scanner { private TextReader Reader; private Queue<String> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { this.Reader = reader; } public int NextInt() { return Int32.Parse(Next(), ci); } public long NextLong() { return Int64.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); 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 bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; partial class Solver { public void Run() { var N = ni(); var s = ni(N); long ans = 0; var visited = new BooleanArray(N); for (int d = 1; d <= N - 1; d++) { visited.Clear(); var begin1 = 0; var begin2 = (N - 1); long sub = 0; while (d <= begin2 && begin1 < N - d) { if (begin1 == begin2) break; if (visited[begin1]) break; visited[begin1] = true; if (visited[begin2]) break; visited[begin2] = true; sub += s[begin1]; sub += s[begin2]; ans = Math.Max(ans, sub); begin1 += d; begin2 -= d; } } cout.WriteLine(ans); } } public class BooleanArray { private int[] array; private int trueValue = 1; public BooleanArray(int size) { array = new int[size]; } public void Clear() { trueValue++; } public bool this[int index] { get { return array[index] == trueValue; } set { array[index] = value ? trueValue : trueValue - 1; } } public int Length { get { return array.Length; } } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { new Solver(Console.In, Console.Out).Run(); } TextReader cin; TextWriter cout; public Solver(TextReader reader, TextWriter writer) : base(reader) { this.cin = reader; this.cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} public int ni() { return NextInt(); } public int[] ni(int n) { return NextIntArray(n); } public long nl() { return NextLong(); } public long[] nl(int n) { return NextLongArray(n); } public double nd() { return NextDouble(); } public string ns() { return Next(); } } public class Scanner { private TextReader Reader; private Queue<String> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { this.Reader = reader; } public int NextInt() { return Int32.Parse(Next(), ci); } public long NextLong() { return Int64.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); 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 bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
[["-", 8, 196, 0, 52, 15, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 0, 52, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 52, 15, 16, 12, 16, 12, 16, 12, 22]]
8
864
4
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; using static System.Console; using static System.Math; using static Func; class Z { static void Main() => new K(); } class K { int F => int.Parse(Str); long FL => long.Parse(Str); int[] G => Strs.Select(int.Parse).ToArray(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var N = F; var s = GL; var max = 0L; for (var d = 1; d < N; d++) { int l = 0, r = N - 1; var used = new HashSet<int> { l, r }; var sum = 0L; while (true) { l += d; r -= d; if (used.Contains(l) || used.Contains(r) || l >= r || l >= N || r < 0 || r <= d) break; used.Add(l); used.Add(r); sum += s[l] + s[r]; max = Max(max, sum); } } WriteLine(max); } } static class Func { public const long InfL = 4011686018427387913L; public static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } public static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } public static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } public static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } }
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; using static System.Console; using static System.Math; using static Func; class Z { static void Main() => new K(); } class K { int F => int.Parse(Str); long FL => long.Parse(Str); int[] G => Strs.Select(int.Parse).ToArray(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var N = F; var s = GL; var max = 0L; for (var d = 1; d < N; d++) { int l = 0, r = N - 1; var used = new HashSet<int> { l, r }; var sum = 0L; while (true) { l += d; r -= d; if (used.Contains(l) || used.Contains(r) || l == r || l >= N || r < 0 || r <= d) break; used.Add(l); used.Add(r); sum += s[l] + s[r]; max = Max(max, sum); } } WriteLine(max); } } static class Func { public const long InfL = 4011686018427387913L; public static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } public static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } public static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } public static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } }
[["-", 31, 16, 31, 16, 31, 16, 12, 16, 17, 20], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 17, 60]]
8
736
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc127_a { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]); int B = int.Parse(s[1]); int total = 0; if (A > 12) { total = B; } else if (A > 6) { total = B / 2; } Console.WriteLine(total); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc127_a { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]); int B = int.Parse(s[1]); int total = 0; if (A > 12) { total = B; } else if (A > 5) { total = B / 2; } Console.WriteLine(total); Console.Read(); } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
8
135
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc127_a { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int age = int.Parse(input[0]); int price = int.Parse(input[1]); if (age < 13) { if (age <= 5) { price = 0; } price = price / 2; } Console.WriteLine(age + " " + price); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc127_a { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int age = int.Parse(input[0]); int price = int.Parse(input[1]); if (age < 13) { if (age <= 5) { price = 0; } price = price / 2; } Console.WriteLine(price); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
129
6
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC127.A(); } class ABC127 { public static void A() { var A = Read.Int(); var B = Read.Int(); Console.WriteLine(A < 5 ? 0 : (A < 13 ? B / 2 : B)); } public static void B() { var R = Read.Int(); var D = Read.Int(); var X = Read.Long(); for (int i = 0; i < 10; ++i) { X = R * X - D; Console.WriteLine(X); } } public static void C() { var N = Read.Int(); var M = Read.Int(); var LR = Read.TupleInt(M); var maxL = LR.Select(x => x.Item1).Max(); var minR = LR.Select(x => x.Item2).Min(); Console.WriteLine(maxL > minR ? 0 : (minR - maxL + 1)); } public static void D() { var N = Read.Int(); var M = Read.Int(); var A = Read.LongN(); var BC = Read.TupleLong(M); List<long> cards = new List<long>(); foreach (var bc in BC) { for (int i = 0; i < bc.Item1; ++i) { cards.Add(bc.Item2); } if (cards.Count >= N) { break; } } foreach (var a in A) { cards.Add(a); } Console.WriteLine(cards.OrderBy(x => -x).Take(N).Sum()); } public static void E() { var N = Read.Int(); var M = Read.Int(); var K = Read.Long(); var comb = Util.Combin(N * M + 1, Util.P); Console.WriteLine((MOD)comb(N * M, (int)K) * K * (K - 1) / 2 / comb(N * M, 2) * (((MOD)N + 1) * N * (N - 1) / 6 * M * M + ((MOD)M + 1) * M * (M - 1) / 6 * N * N)); } public static void F() {} } class Util { public static readonly long P = 1000000007; public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } public MOD Inverse() { return Util.Inverse(V, P); } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC127.A(); } class ABC127 { public static void A() { var A = Read.Int(); var B = Read.Int(); Console.WriteLine(A < 6 ? 0 : (A < 13 ? B / 2 : B)); } public static void B() { var R = Read.Int(); var D = Read.Int(); var X = Read.Long(); for (int i = 0; i < 10; ++i) { X = R * X - D; Console.WriteLine(X); } } public static void C() { var N = Read.Int(); var M = Read.Int(); var LR = Read.TupleInt(M); var maxL = LR.Select(x => x.Item1).Max(); var minR = LR.Select(x => x.Item2).Min(); Console.WriteLine(maxL > minR ? 0 : (minR - maxL + 1)); } public static void D() { var N = Read.Int(); var M = Read.Int(); var A = Read.LongN(); var BC = Read.TupleLong(M); List<long> cards = new List<long>(); foreach (var bc in BC) { for (int i = 0; i < bc.Item1; ++i) { cards.Add(bc.Item2); } if (cards.Count >= N) { break; } } foreach (var a in A) { cards.Add(a); } Console.WriteLine(cards.OrderBy(x => -x).Take(N).Sum()); } public static void E() { var N = Read.Int(); var M = Read.Int(); var K = Read.Long(); var comb = Util.Combin(N * M + 1, Util.P); Console.WriteLine((MOD)comb(N * M, (int)K) * K * (K - 1) / 2 / comb(N * M, 2) * (((MOD)N + 1) * N * (N - 1) / 6 * M * M + ((MOD)M + 1) * M * (M - 1) / 6 * N * N)); } public static void F() {} } class Util { public static readonly long P = 1000000007; public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } public MOD Inverse() { return Util.Inverse(V, P); } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203]]
8
2,063
2
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() { int[] read = inta(); if (read[0] > 12) { WriteLine(read[0]); } else if (read[0] > 5) { WriteLine(read[0] / 2); } else { WriteLine(0); } } //各種読取 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() { int[] read = inta(); if (read[0] > 12) { WriteLine(read[1]); } else if (read[0] > 5) { WriteLine(read[1] / 2); } else { WriteLine(0); } } //各種読取 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, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
8
626
4
using System; using System.IO; using System.Linq; public class A { public static void Main() { string[] input = Console.ReadLine().Split(); int a = int.Parse(input[0]); int b = int.Parse(input[1]); if (b <= 5) { Console.Write(0); } else if (b <= 12) { Console.Write(b / 2); } else { Console.Write(b); } } }
using System; using System.IO; using System.Linq; public class A { public static void Main() { string[] input = Console.ReadLine().Split(); int a = int.Parse(input[0]); int b = int.Parse(input[1]); if (a <= 5) { Console.Write(0); } else if (a <= 12) { Console.Write(b / 2); } else { Console.Write(b); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22]]
8
110
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); if (a < 13 && a >= 6) Console.WriteLine(b / 2); else if (a <= 13) Console.WriteLine("0"); else Console.WriteLine(b); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); if (a < 13 && a >= 6) Console.WriteLine(b / 2); else if (a <= 6) Console.WriteLine("0"); else Console.WriteLine(b); Console.ReadKey(); } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
8
144
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int a, b; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); if (a >= 13) Console.WriteLine(b); if (a >= 6 || a <= 12) Console.WriteLine(b / 2); if (a <= 5) Console.WriteLine(0); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int a, b; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); if (a >= 13) Console.WriteLine(b); if (a >= 6 && a <= 12) Console.WriteLine(b / 2); if (a <= 5) Console.WriteLine(0); Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
142
2
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var line = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray(); var A = line[0]; var B = line[1]; if (A >= 13) { Console.WriteLine(B); } else if (A >= 6 && A <= 12) { Console.WriteLine(B / 2); } else if (A >= 5) { Console.WriteLine(0); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var line = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray(); var A = line[0]; var B = line[1]; if (A >= 13) { Console.WriteLine(B); } else if (A >= 6 && A <= 12) { Console.WriteLine(B / 2); } else if (A <= 5) { Console.WriteLine(0); } } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 20], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 19]]
8
128
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public 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.ReadAsIntArray(); Console.WriteLine(ab[0] >= 13 ? ab[1] : (ab[1] >= 6 ? ab[1] / 2 : 0)); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation {} static class RootedTreeNodesFactory { public class RootedTreeNode { public int Id { get; } public int Parent { get; } public int Depth { get; set; } int[] Childs { get; } public RootedTreeNode(int id, int parent, int[] childs) { this.Id = id; this.Parent = parent; this.Childs = childs; } } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(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; } } 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 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(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } 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(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } 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>計数ソート</summary> public static int[] CountingSort(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; } } /// <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>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; 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; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <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; } } /// <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>拡張メソッドs</summary> static class Extention { /// <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; } /// <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; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public 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.ReadAsIntArray(); Console.WriteLine(ab[0] >= 13 ? ab[1] : (ab[0] >= 6 ? ab[1] / 2 : 0)); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation {} static class RootedTreeNodesFactory { public class RootedTreeNode { public int Id { get; } public int Parent { get; } public int Depth { get; set; } int[] Childs { get; } public RootedTreeNode(int id, int parent, int[] childs) { this.Id = id; this.Parent = parent; this.Childs = childs; } } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(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; } } 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 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(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } 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(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } 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>計数ソート</summary> public static int[] CountingSort(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; } } /// <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>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; 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; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <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; } } /// <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>拡張メソッドs</summary> static class Extention { /// <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; } /// <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; } }
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
8
3,169
2
using System; namespace _20190629_ABC { class Program { static void Main(string[] args) { var AB = Console.ReadLine().Split(' '); var A = int.Parse(AB[0]); var B = int.Parse(AB[1]); // 13 <= A の場合、B // 6 <= A <= 12 の場合、B / 2 // A <= 5 の場合、B = 0 if (A <= 5) { B = 0; } else if (6 <= A || A <= 12) { B = B / 2; } Console.WriteLine(B); } } }
using System; namespace _20190629_ABC { class Program { static void Main(string[] args) { var AB = Console.ReadLine().Split(' '); var A = int.Parse(AB[0]); var B = int.Parse(AB[1]); // 13 <= A の場合、B // 6 <= A <= 12 の場合、B / 2 // A <= 5 の場合、B = 0 if (A <= 5) { B = 0; } else if (6 <= A && A <= 12) { B = B / 2; } Console.WriteLine(B); } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98]]
8
105
2
using System; using System.Linq; namespace A___Ferris_Wheel { class Program { static void Main(string[] args) { var AB = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = AB[0], B = AB[1]; Console.WriteLine(A < 5 ? 0 : A <= 12 ? B / 2 : B); } } }
using System; using System.Linq; namespace A___Ferris_Wheel { class Program { static void Main(string[] args) { var AB = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = AB[0], B = AB[1]; Console.WriteLine(A <= 5 ? 0 : A <= 12 ? B / 2 : B); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19]]
8
87
2
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); int ans; if (a >= 13) ans = b / 2; else if (a <= 5) ans = 0; else ans = b; Console.WriteLine(ans); } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); int ans; if (a >= 13) ans = b; else if (a <= 5) ans = 0; else ans = b / 2; Console.WriteLine(ans); } }
[["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 75, 57, 75, 1, 0, 11, 12, 16, 17, 85], ["+", 75, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
8
102
4
using System; using System.Linq; using System.Collections.Generic; namespace Program { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int A = input[0]; int B = input[1]; if (A < 6) Console.WriteLine(0); else if (A < 13) Console.WriteLine(A / 2); else Console.WriteLine(A); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Program { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int A = input[0]; int B = input[1]; if (A < 6) Console.WriteLine(0); else if (A < 13) Console.WriteLine(B / 2); else Console.WriteLine(B); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
121
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace atcoder { namespace atcoder { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int ans = B / 2; if (A <= 5) { Console.WriteLine(A); } else if (6 <= A && A <= 12) { Console.WriteLine(ans); } else { Console.WriteLine(B); } } } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace atcoder { namespace atcoder { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int ans = B / 2; if (A <= 5) { Console.WriteLine(0); } else if (6 <= A && A <= 12) { Console.WriteLine(ans); } else { Console.WriteLine(B); } } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
139
2
using System; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] list = Console.ReadLine().Split(' '); int a = int.Parse(list[0]); int b = int.Parse(list[1]); if (a >= 13) { Console.WriteLine(b); } else if (a >= 6 && b <= 12) { Console.WriteLine(b / 2); } else { Console.WriteLine(0); } } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] list = Console.ReadLine().Split(' '); int a = int.Parse(list[0]); int b = int.Parse(list[1]); if (a >= 13) { Console.WriteLine(b); } else if (a >= 6 && a <= 12) { Console.WriteLine(b / 2); } else { Console.WriteLine(0); } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22]]
8
118
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { var inputs = new List<string>(); // 入力が終わるまで全行読み込む for (int i = 0; i < 1; i++) { string input = Console.ReadLine(); if (input == null) break; else inputs.Add(input); }; String[] temp = inputs[0].Split(' '); int A = int.Parse(temp[0]); int B = int.Parse(temp[1]); if (A >= 13) { Console.WriteLine(B); } else if (A < 5) { Console.WriteLine(0); } else { Console.WriteLine(B / 2); } return; } } }
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 = new List<string>(); // 入力が終わるまで全行読み込む for (int i = 0; i < 1; i++) { string input = Console.ReadLine(); if (input == null) break; else inputs.Add(input); }; String[] temp = inputs[0].Split(' '); int A = int.Parse(temp[0]); int B = int.Parse(temp[1]); if (A >= 13) { Console.WriteLine(B); } else if (A <= 5) { Console.WriteLine(0); } else { Console.WriteLine(B / 2); } return; } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19]]
8
188
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 string s = Console.ReadLine(); int A = int.Parse(s.Split(' ')[0]); int B = int.Parse(s.Split(' ')[1]); if (A >= 13) { Console.WriteLine(B); } else if (6 <= B && B <= 12) { Console.WriteLine(B / 2); } else { Console.WriteLine("0"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 string s = Console.ReadLine(); int A = int.Parse(s.Split(' ')[0]); int B = int.Parse(s.Split(' ')[1]); if (A >= 13) { Console.WriteLine(B); } else if (6 <= A && A <= 12) { Console.WriteLine(B / 2); } else { Console.WriteLine("0"); } } }
[["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22]]
8
141
4
using System; using System.IO; namespace abc127 { class Program { static void Main(string[] args) { var scanner = new Scanner(); var a = scanner.GetNextAsInt(); var b = scanner.GetNextAsInt(); var r = a; if (a >= 13) { } else if (a >= 6) { r = b / 2; } else { r = 0; } Console.WriteLine(r); } } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion }
using System; using System.IO; namespace abc127 { class Program { static void Main(string[] args) { var scanner = new Scanner(); var a = scanner.GetNextAsInt(); var b = scanner.GetNextAsInt(); var r = b; if (a >= 13) { } else if (a >= 6) { r = b / 2; } else { r = 0; } Console.WriteLine(r); } } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
570
2