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
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; namespace DPMatome { public class Program { public static void Main(string[] args) { START: // A(); 20m // B(); 7m // C(); 42m // D(); 70m // E(); 70m -> 13m -> 5m // F(); 127m -> 27m -> 3m // G(); 160m -> 11m -> 6m // H(); 20m -> 4m // I(); 70m -> 4m J(); #if DEBUG goto START; #endif } public static void J() { long N = rl; long[] A = rla; double[,,] dp = new double[301, 301, 301]; for (int i = 0; i <= 301; i++) { for (int j = 0; j <= 301; j++) { for (int k = 0; k <= 301; k++) { dp[i, j, k] = -1; } } } Func<int, int, int, double> rec = null; rec = (int i, int j, int k) => { if (dp[i, j, k] != -1) return dp[i, j, k]; if (i == 0 && j == 0 && k == 0) return 0; double ret = 0.0; if (i > 0) ret += rec(i - 1, j, k) * i; if (j > 0) ret += rec(i + 1, j - 1, k) * j; if (k > 0) ret += rec(i, j + 1, k - 1) * k; ret += N; ret *= 1.0 / (i + j + k); dp[i, j, k] = ret; return ret; }; int one = 0; int two = 0; int three = 0; for (int i = 0; i < N; i++) { if (A[i] == 1) one++; else if (A[i] == 2) two++; else three++; } double ans = rec(one, two, three); Console.WriteLine(ans); } public static void I() { long N = rl; double[] ps = rda; double[,] dp = new double[N + 1, N + 1]; dp[0, 0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dp[i + 1, j] += dp[i, j] * (1 - ps[i]); dp[i + 1, j + 1] = dp[i, j] * ps[i]; } } long iMax = N / 2; double ans = 1.0; for (int i = 0; i <= iMax; i++) { ans -= dp[N, i]; } WriteLine(ans); } public static void H() { long H = rl; long W = rl; string[] table = new string[H]; for (int i = 0; i < H; i++) { table[i] = ReadString(); } long[,] dp = new long[H, W]; dp[0, 0] = 1; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (i == 0 && j == 0) continue; if (table[i][j] == '#') continue; if (i == 0) dp[i, j] = dp[i, j - 1]; else if (j == 0) dp[i, j] = dp[i - 1, j]; else dp[i, j] = (dp[i - 1, j] + dp[i, j - 1]) % MOD; } } WriteLine(dp[H - 1, W - 1]); } public static void G() { long N = ReadLong(); long M = ReadLong(); List<List<long>> G = new List<List<long>>(); for (int i = 0; i < N; i++) { G.Add(new List<long>()); } for (int i = 0; i < M; i++) { long from = ReadLong() - 1; long to = ReadLong() - 1; G[(int)from].Add(to); } long[] dp = new long[N]; FillArray(dp, -1); Func<long, long> rec = null; rec = (long v) => { if (dp[v] != -1) return dp[v]; if (!G[(int)v].Any()) return dp[v] = 0; long res = 0; foreach (var nv in G[(int)v]) { ChMax(ref res, rec(nv) + 1); } return dp[v] = res; }; long ans = 0; for (int i = 0; i < N; i++) { ChMax(ref ans, rec(i)); } WriteLine(ans); } public static void F() { string s = ReadString(); string t = ReadString(); int n = s.Length; int m = t.Length; long[,] dp = new long[n + 1, m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i - 1] == t[j - 1]) { dp[i, j] = dp[i - 1, j - 1] + 1; } else { dp[i, j] = Max(dp[i, j - 1], dp[i - 1, j]); } } } StringBuilder sb = new StringBuilder(); int x = n; int y = m; while (0 < x && 0 < y) { if (dp[x, y] == dp[x - 1, y]) x--; else if (dp[x, y] == dp[x, y - 1]) y--; else { x--; y--; sb.Append(s[x]); } } string ans = string.Concat(sb.ToString().Reverse()); WriteLine(ans); } public static void E() { long N = ReadLong(); long W = ReadLong(); long[] ws, vs; ReadArrays(out ws, out vs, N); long maxValue = 100000; long[,] dp = new long[N + 1, maxValue + 1]; FillArray(dp, INF); dp[0, 0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= maxValue; j++) { if (j - vs[i] >= 0) { dp[i + 1, j] = Min(dp[i, j], dp[i, j - vs[i]] + ws[i]); } else { dp[i + 1, j] = dp[i, j]; } } } long ans = 0; for (int i = 0; i <= maxValue; i++) { if (dp[N, i] <= W) ans = i; } WriteLine(ans); } class Jewel { public long w { get; set; } public long v { get; set; } } private static void D() { long N = ReadLong(); long W = ReadLong(); Jewel[] jewels = new Jewel[N]; for (int i = 0; i < N; i++) { var j = new Jewel(); j.w = ReadLong(); j.v = ReadLong(); jewels[i] = j; } long[,] dp = new long[N + 1, W + 1]; for (int i = 0; i < N; i++) { for (int w = 0; w <= W; w++) { if (w < jewels[i].w) { dp[i + 1, w] = dp[i, w]; } else { dp[i + 1, w] = Max(dp[i, w], dp[i, w - jewels[i].w] + jewels[i].v); } } } WriteLine(dp[N, W]); } private static void C() { long N = ReadLong(); long[] A = new long[N]; long[] B = new long[N]; long[] C = new long[N]; for (int i = 0; i < N; i++) { A[i] = ReadLong(); B[i] = ReadLong(); C[i] = ReadLong(); } long[,] dp = new long[N, 3]; dp[0, 0] = A[0]; dp[0, 1] = B[0]; dp[0, 2] = C[0]; for (int i = 0; i < N - 1; i++) { int ni = i + 1; // Aからの遷移 dp[ni, 1] = Max(dp[ni, 1], dp[i, 0] + B[ni]); dp[ni, 2] = Max(dp[ni, 2], dp[i, 0] + C[ni]); // Bからの遷移 dp[ni, 0] = Max(dp[ni, 0], dp[i, 1] + A[ni]); dp[ni, 2] = Max(dp[ni, 2], dp[i, 1] + C[ni]); // Cからの遷移 dp[ni, 0] = Max(dp[ni, 0], dp[i, 2] + A[ni]); dp[ni, 1] = Max(dp[ni, 1], dp[i, 2] + B[ni]); } long ans = Max(Max(dp[N - 1, 0], dp[N - 1, 1]), dp[N - 1, 2]); WriteLine(ans); } private static void B() { long N = ReadLong(); long K = ReadLong(); long[] H = ReadLongArray(); long[] dp = new long[N]; for (int i = 0; i < N; i++) dp[i] = long.MaxValue; dp[0] = 0; for (int i = 0; i < N; i++) { if (dp[i] == long.MaxValue) continue; for (int j = 1; j <= K; j++) { if (i + j < N) dp[i + j] = Min(dp[i + j], dp[i] + Abs(H[i] - H[i + j])); } } WriteLine(dp[N - 1]); } private static void A() { long N = ReadLong(); long[] H = ReadLongArray(); long[] dp = new long[N]; for (int i = 0; i < N; i++) dp[i] = long.MaxValue; dp[0] = 0; for (int i = 0; i < N; i++) { if (dp[i] == long.MaxValue) continue; if (i + 1 < N) dp[i + 1] = Min(dp[i + 1], dp[i] + Abs(H[i] - H[i + 1])); if (i + 2 < N) dp[i + 2] = Min(dp[i + 2], dp[i] + Abs(H[i] - H[i + 2])); } WriteLine(dp[N - 1]); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static void ModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; namespace DPMatome { public class Program { public static void Main(string[] args) { START: // A(); 20m // B(); 7m // C(); 42m // D(); 70m // E(); 70m -> 13m -> 5m // F(); 127m -> 27m -> 3m // G(); 160m -> 11m -> 6m // H(); 20m -> 4m // I(); 70m -> 4m J(); #if DEBUG goto START; #endif } public static void J() { long N = rl; long[] A = rla; double[,,] dp = new double[301, 301, 301]; for (int i = 0; i < 301; i++) { for (int j = 0; j < 301; j++) { for (int k = 0; k < 301; k++) { dp[i, j, k] = -1; } } } Func<int, int, int, double> rec = null; rec = (int i, int j, int k) => { if (dp[i, j, k] != -1) return dp[i, j, k]; if (i == 0 && j == 0 && k == 0) return 0; double ret = 0.0; if (i > 0) ret += rec(i - 1, j, k) * i; if (j > 0) ret += rec(i + 1, j - 1, k) * j; if (k > 0) ret += rec(i, j + 1, k - 1) * k; ret += N; ret *= 1.0 / (i + j + k); dp[i, j, k] = ret; return ret; }; int one = 0; int two = 0; int three = 0; for (int i = 0; i < N; i++) { if (A[i] == 1) one++; else if (A[i] == 2) two++; else three++; } double ans = rec(one, two, three); Console.WriteLine(ans); } public static void I() { long N = rl; double[] ps = rda; double[,] dp = new double[N + 1, N + 1]; dp[0, 0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dp[i + 1, j] += dp[i, j] * (1 - ps[i]); dp[i + 1, j + 1] = dp[i, j] * ps[i]; } } long iMax = N / 2; double ans = 1.0; for (int i = 0; i <= iMax; i++) { ans -= dp[N, i]; } WriteLine(ans); } public static void H() { long H = rl; long W = rl; string[] table = new string[H]; for (int i = 0; i < H; i++) { table[i] = ReadString(); } long[,] dp = new long[H, W]; dp[0, 0] = 1; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (i == 0 && j == 0) continue; if (table[i][j] == '#') continue; if (i == 0) dp[i, j] = dp[i, j - 1]; else if (j == 0) dp[i, j] = dp[i - 1, j]; else dp[i, j] = (dp[i - 1, j] + dp[i, j - 1]) % MOD; } } WriteLine(dp[H - 1, W - 1]); } public static void G() { long N = ReadLong(); long M = ReadLong(); List<List<long>> G = new List<List<long>>(); for (int i = 0; i < N; i++) { G.Add(new List<long>()); } for (int i = 0; i < M; i++) { long from = ReadLong() - 1; long to = ReadLong() - 1; G[(int)from].Add(to); } long[] dp = new long[N]; FillArray(dp, -1); Func<long, long> rec = null; rec = (long v) => { if (dp[v] != -1) return dp[v]; if (!G[(int)v].Any()) return dp[v] = 0; long res = 0; foreach (var nv in G[(int)v]) { ChMax(ref res, rec(nv) + 1); } return dp[v] = res; }; long ans = 0; for (int i = 0; i < N; i++) { ChMax(ref ans, rec(i)); } WriteLine(ans); } public static void F() { string s = ReadString(); string t = ReadString(); int n = s.Length; int m = t.Length; long[,] dp = new long[n + 1, m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i - 1] == t[j - 1]) { dp[i, j] = dp[i - 1, j - 1] + 1; } else { dp[i, j] = Max(dp[i, j - 1], dp[i - 1, j]); } } } StringBuilder sb = new StringBuilder(); int x = n; int y = m; while (0 < x && 0 < y) { if (dp[x, y] == dp[x - 1, y]) x--; else if (dp[x, y] == dp[x, y - 1]) y--; else { x--; y--; sb.Append(s[x]); } } string ans = string.Concat(sb.ToString().Reverse()); WriteLine(ans); } public static void E() { long N = ReadLong(); long W = ReadLong(); long[] ws, vs; ReadArrays(out ws, out vs, N); long maxValue = 100000; long[,] dp = new long[N + 1, maxValue + 1]; FillArray(dp, INF); dp[0, 0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= maxValue; j++) { if (j - vs[i] >= 0) { dp[i + 1, j] = Min(dp[i, j], dp[i, j - vs[i]] + ws[i]); } else { dp[i + 1, j] = dp[i, j]; } } } long ans = 0; for (int i = 0; i <= maxValue; i++) { if (dp[N, i] <= W) ans = i; } WriteLine(ans); } class Jewel { public long w { get; set; } public long v { get; set; } } private static void D() { long N = ReadLong(); long W = ReadLong(); Jewel[] jewels = new Jewel[N]; for (int i = 0; i < N; i++) { var j = new Jewel(); j.w = ReadLong(); j.v = ReadLong(); jewels[i] = j; } long[,] dp = new long[N + 1, W + 1]; for (int i = 0; i < N; i++) { for (int w = 0; w <= W; w++) { if (w < jewels[i].w) { dp[i + 1, w] = dp[i, w]; } else { dp[i + 1, w] = Max(dp[i, w], dp[i, w - jewels[i].w] + jewels[i].v); } } } WriteLine(dp[N, W]); } private static void C() { long N = ReadLong(); long[] A = new long[N]; long[] B = new long[N]; long[] C = new long[N]; for (int i = 0; i < N; i++) { A[i] = ReadLong(); B[i] = ReadLong(); C[i] = ReadLong(); } long[,] dp = new long[N, 3]; dp[0, 0] = A[0]; dp[0, 1] = B[0]; dp[0, 2] = C[0]; for (int i = 0; i < N - 1; i++) { int ni = i + 1; // Aからの遷移 dp[ni, 1] = Max(dp[ni, 1], dp[i, 0] + B[ni]); dp[ni, 2] = Max(dp[ni, 2], dp[i, 0] + C[ni]); // Bからの遷移 dp[ni, 0] = Max(dp[ni, 0], dp[i, 1] + A[ni]); dp[ni, 2] = Max(dp[ni, 2], dp[i, 1] + C[ni]); // Cからの遷移 dp[ni, 0] = Max(dp[ni, 0], dp[i, 2] + A[ni]); dp[ni, 1] = Max(dp[ni, 1], dp[i, 2] + B[ni]); } long ans = Max(Max(dp[N - 1, 0], dp[N - 1, 1]), dp[N - 1, 2]); WriteLine(ans); } private static void B() { long N = ReadLong(); long K = ReadLong(); long[] H = ReadLongArray(); long[] dp = new long[N]; for (int i = 0; i < N; i++) dp[i] = long.MaxValue; dp[0] = 0; for (int i = 0; i < N; i++) { if (dp[i] == long.MaxValue) continue; for (int j = 1; j <= K; j++) { if (i + j < N) dp[i + j] = Min(dp[i + j], dp[i] + Abs(H[i] - H[i + j])); } } WriteLine(dp[N - 1]); } private static void A() { long N = ReadLong(); long[] H = ReadLongArray(); long[] dp = new long[N]; for (int i = 0; i < N; i++) dp[i] = long.MaxValue; dp[0] = 0; for (int i = 0; i < N; i++) { if (dp[i] == long.MaxValue) continue; if (i + 1 < N) dp[i + 1] = Min(dp[i + 1], dp[i] + Abs(H[i] - H[i + 1])); if (i + 2 < N) dp[i + 2] = Min(dp[i + 2], dp[i] + Abs(H[i] - H[i + 2])); } WriteLine(dp[N - 1]); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static void ModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18]]
8
5,574
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int[] cnt = new int[4]; for (int i = 0; i < N; i++) { cnt[A[i]]++; } memo = new Dictionary<int, double>(); memo.Add(0, 0); Console.WriteLine(dfs(cnt[1], cnt[2], cnt[3])); } Dictionary<int, double> memo; double dfs(int one, int two, int three) { int h = one * 400 * 400 + two * 400 + three; if (memo.ContainsKey(h)) return memo[h]; int zero = N - one - two - three; double p0 = zero / (double)N; double p1 = one / (double)N; double p2 = two / (double)N; double p3 = three / (double)N; double v = 1; if (one > 0) v += p1 * dfs(one - 1, two, three); if (two > 0) v += p2 * dfs(one, two - 1, three); if (three > 0) v += p3 * dfs(one, two, three - 1); memo.Add(h, v / (1 - p0)); return v / (1 - p0); } int N; int[] A; public Sol() { N = ri(); A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int[] cnt = new int[4]; for (int i = 0; i < N; i++) { cnt[A[i]]++; } memo = new Dictionary<int, double>(); memo.Add(0, 0); Console.WriteLine(dfs(cnt[1], cnt[2], cnt[3])); } Dictionary<int, double> memo; double dfs(int one, int two, int three) { int h = one * 400 * 400 + two * 400 + three; if (memo.ContainsKey(h)) return memo[h]; int zero = N - one - two - three; double p0 = zero / (double)N; double p1 = one / (double)N; double p2 = two / (double)N; double p3 = three / (double)N; double v = 1; if (one > 0) v += p1 * dfs(one - 1, two, three); if (two > 0) v += p2 * dfs(one + 1, two - 1, three); if (three > 0) v += p3 * dfs(one, two + 1, three - 1); memo.Add(h, v / (1 - p0)); return v / (1 - p0); } int N; int[] A; public Sol() { N = ri(); A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
583
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.DP { class EDPC_K { public static void Main() { var nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int n = nk[0]; int k = nk[2]; var dp = new bool[k + 1]; dp[0] = false; for (int i = 0; i <= k; i++) for (int j = 0; j < n; j++) if (i >= a[j]) dp[i] |= !dp[i - a[j]]; Console.WriteLine(dp[k] ? "First" : "Second"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.DP { class EDPC_K { public static void Main() { var nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int n = nk[0]; int k = nk[1]; var dp = new bool[k + 1]; dp[0] = false; for (int i = 0; i <= k; i++) for (int j = 0; j < n; j++) if (i >= a[j]) dp[i] |= !dp[i - a[j]]; Console.WriteLine(dp[k] ? "First" : "Second"); } } }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
8
202
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); var input = cin.SplitRead(); int N = input[0]; int K = input[1]; var a = cin.SplitRead(); if (K == 0) { Console.WriteLine(1); return; } var dp = new long[N, K + 2]; for (var i = 0; i < N; i++) { dp[i, 0] = 0; } for (var i = 1; i <= K + 1; i++) { dp[0, i] = dp[0, i - 1] + (i - 1 > a[0] ? 0 : 1); } for (var i = 1; i < N; i++) { for (var k = 0; k <= K + 1; k++) { if (k == 0) { dp[i, k] = 0; continue; } dp[i, k] = dp[i, k - 1] % MOD + (dp[i - 1, k] - dp[i - 1, Max(0, k - a[i] - 1)] + MOD) % MOD; dp[i, k] %= MOD; } } Console.WriteLine(dp[N - 1, K + 1] - dp[N - 1, K]); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class UnionFind { public int[] parent; public int[] rank; public int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } private int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T search) { return Q.Contains(search); } } public class Scanner { public int[] SplitRead() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReadL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(T[] a, int i, int j) { T k = a[i]; a[i] = a[j]; a[j] = k; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); var input = cin.SplitRead(); int N = input[0]; int K = input[1]; var a = cin.SplitRead(); if (K == 0) { Console.WriteLine(1); return; } var dp = new long[N, K + 2]; for (var i = 0; i < N; i++) { dp[i, 0] = 0; } for (var i = 1; i <= K + 1; i++) { dp[0, i] = dp[0, i - 1] + (i - 1 > a[0] ? 0 : 1); } for (var i = 1; i < N; i++) { for (var k = 0; k <= K + 1; k++) { if (k == 0) { dp[i, k] = 0; continue; } dp[i, k] = dp[i, k - 1] % MOD + (dp[i - 1, k] - dp[i - 1, Max(0, k - a[i] - 1)] + MOD) % MOD; dp[i, k] %= MOD; } } Console.WriteLine((dp[N - 1, K + 1] - dp[N - 1, K] + MOD) % MOD); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class UnionFind { public int[] parent; public int[] rank; public int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } private int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T search) { return Q.Contains(search); } } public class Scanner { public int[] SplitRead() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReadL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(T[] a, int i, int j) { T k = a[i]; a[i] = a[j]; a[j] = k; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
1,620
using System; using System.Collections.Generic; class Program { const int mod = 1000000007; static long[] dat; static int m = 1; static void Main() { int n = int.Parse(Console.ReadLine()); int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); while (m <= n + 1) { m *= 2; } dat = new long[m + n]; long ans = 0; fdu(h[0], a[0]); for (int i = 1; i < n; i++) { long p = fdg(0, h[i] - 1, 0, 0, m - 1) + a[i]; fdu(h[i], p); ans = Math.Max(ans, p); } Console.WriteLine(ans); } static void fdu(int q, long b) { q += m - 1; dat[q] = b; while (q > 0) { dat[(q - 1) / 2] = Math.Max(dat[(q - 1) / 2], b); q = (q - 1) / 2; } } static long fdg(int a, int b, int k, int l, int r) { if (r < a || b < l) { return -1; } if (a <= l && r <= b) { return dat[k]; } else { return Math.Max(fdg(a, b, k * 2 + 1, l, (l + r) / 2), fdg(a, b, k * 2 + 2, (l + r + 1) / 2, r)); } } }
using System; using System.Collections.Generic; class Program { const int mod = 1000000007; static long[] dat; static int m = 1; static void Main() { int n = int.Parse(Console.ReadLine()); int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); while (m <= n + 1) { m *= 2; } dat = new long[m + n]; long ans = a[0]; fdu(h[0], a[0]); for (int i = 1; i < n; i++) { long p = fdg(0, h[i] - 1, 0, 0, m - 1) + a[i]; fdu(h[i], p); ans = Math.Max(ans, p); } Console.WriteLine(ans); } static void fdu(int q, long b) { q += m - 1; dat[q] = b; while (q > 0) { dat[(q - 1) / 2] = Math.Max(dat[(q - 1) / 2], b); q = (q - 1) / 2; } } static long fdg(int a, int b, int k, int l, int r) { if (r < a || b < l) { return -1; } if (a <= l && r <= b) { return dat[k]; } else { return Math.Max(fdg(a, b, k * 2 + 1, l, (l + r) / 2), fdg(a, b, k * 2 + 2, (l + r + 1) / 2, r)); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
8
399
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<long, long>; 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() { int N = cin.nextint; var K = cin.nextlong; var A = new ModInt[N][]; for (int i = 0; i < N; i++) { A[i] = new ModInt[N]; for (int j = 0; j < N; j++) { A[i][j] = cin.nextint; } } var mat = new Matrix<ModInt>((x, y) => x + y, (x, y) => x * y, 1); var B = mat.matpow(A, K); ModInt sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum += B[i][j]; } } WriteLine(sum); } } /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> /// <OriginalAuthor>camypaper</OriginalAuthor> struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e6 + 3; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } class BinomialCoefficient { public ModInt[] fact, ifact; /// <summary> /// <paramref name="n"/>は <paramref name="Mod"/>未満でお願いします。 /// </summary> /// <param name="n"></param> public BinomialCoefficient(ModInt _n) { int n = (int)_n.num; fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } class Matrix<T> { readonly Func<T, T, T> Add; readonly Func<T, T, T> Mul; readonly T exnum; /// <summary> /// 行列累乗ライブラリ /// </summary> /// <param name="Add">加算</param> /// <param name="Mul">積</param> /// <param name="exnum">積の単位元</param> public Matrix(Func<T, T, T> Add, Func<T, T, T> Mul, T exnum) { this.Add = Add; this.Mul = Mul; this.exnum = exnum; } public T[][] matpow(T[][] m, long a) { if (a == 0) { int N = m.Length; T[][] ret = new T[N][]; for (int i = 0; i < N; i++) { ret[i] = new T[N]; ret[i][i] = exnum; } return ret; } if (a % 2 == 0) { T[][] ret = matpow(m, a / 2); return matmul(ret, ret); } else { return matmul(m, matpow(m, a - 1)); } } public T[][] matmul(T[][] ma, T[][] mb) { int p = ma.Length; int q = mb[0].Length; int r = ma[0].Length; T[][] ret = new T[p][]; for (int i = 0; i < p; i++) { ret[i] = new T[q]; for (int j = 0; j < q; j++) { for (int k = 0; k < r; k++) { ret[i][j] = Add(ret[i][j], Mul(ma[i][k], mb[k][j])); } } } return ret; } } 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.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<long, long>; 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() { int N = cin.nextint; var K = cin.nextlong; var A = new ModInt[N][]; for (int i = 0; i < N; i++) { A[i] = new ModInt[N]; for (int j = 0; j < N; j++) { A[i][j] = cin.nextint; } } var mat = new Matrix<ModInt>((x, y) => x + y, (x, y) => x * y, 1); var B = mat.matpow(A, K); ModInt sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum += B[i][j]; } } WriteLine(sum); } } /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> /// <OriginalAuthor>camypaper</OriginalAuthor> struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } class BinomialCoefficient { public ModInt[] fact, ifact; /// <summary> /// <paramref name="n"/>は <paramref name="Mod"/>未満でお願いします。 /// </summary> /// <param name="n"></param> public BinomialCoefficient(ModInt _n) { int n = (int)_n.num; fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } class Matrix<T> { readonly Func<T, T, T> Add; readonly Func<T, T, T> Mul; readonly T exnum; /// <summary> /// 行列累乗ライブラリ /// </summary> /// <param name="Add">加算</param> /// <param name="Mul">積</param> /// <param name="exnum">積の単位元</param> public Matrix(Func<T, T, T> Add, Func<T, T, T> Mul, T exnum) { this.Add = Add; this.Mul = Mul; this.exnum = exnum; } public T[][] matpow(T[][] m, long a) { if (a == 0) { int N = m.Length; T[][] ret = new T[N][]; for (int i = 0; i < N; i++) { ret[i] = new T[N]; ret[i][i] = exnum; } return ret; } if (a % 2 == 0) { T[][] ret = matpow(m, a / 2); return matmul(ret, ret); } else { return matmul(m, matpow(m, a - 1)); } } public T[][] matmul(T[][] ma, T[][] mb) { int p = ma.Length; int q = mb[0].Length; int r = ma[0].Length; T[][] ret = new T[p][]; for (int i = 0; i < p; i++) { ret[i] = new T[q]; for (int j = 0; j < q; j++) { for (int k = 0; k < r; k++) { ret[i][j] = Add(ret[i][j], Mul(ma[i][k], mb[k][j])); } } } return ret; } } 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); }
[["-", 0, 200, 0, 212, 0, 16, 31, 74, 51, 250], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 51, 250], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
1,975
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<long, long>; 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() { int N = cin.nextint; int K = cin.nextint; var A = new long [N][]; for (int i = 0; i < N; i++) { A[i] = cin.scanlong; } var B = matpow(A, K, mod); var sum = 0L; for (int i = 0; i < N; i++) { sum += B[i].Sum(); sum %= mod; } WriteLine(sum); } long[][] matpow(long[][] m, long a, long Mod) { if (a == 0) { int N = m.Length; long[][] ret = new long [N][]; for (int i = 0; i < N; i++) { ret[i] = new long[N]; ret[i][i] = 1; } return ret; } if (a % 2 == 0) { long[][] ret = matpow(m, a / 2, Mod); return matmul(ret, ret, Mod); } else { return matmul(m, matpow(m, a - 1, Mod), Mod); } } long[][] matmul(long[][] ma, long[][] mb, long Mod) { int p = ma.Length; int q = mb[0].Length; int r = ma[0].Length; long[][] ret = new long [p][]; for (int i = 0; i < p; i++) { ret[i] = new long[q]; for (int j = 0; j < q; j++) { for (int k = 0; k < r; k++) { ret[i][j] += ma[i][k] * mb[k][j] % Mod; } ret[i][j] %= Mod; } } return ret; } } 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.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<long, long>; 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() { int N = cin.nextint; var K = cin.nextlong; var A = new long [N][]; for (int i = 0; i < N; i++) { A[i] = cin.scanlong; } var B = matpow(A, K, mod); var sum = 0L; for (int i = 0; i < N; i++) { sum += B[i].Sum(); sum %= mod; } WriteLine(sum); } long[][] matpow(long[][] m, long a, long Mod) { if (a == 0) { int N = m.Length; long[][] ret = new long [N][]; for (int i = 0; i < N; i++) { ret[i] = new long[N]; ret[i][i] = 1; } return ret; } if (a % 2 == 0) { long[][] ret = matpow(m, a / 2, Mod); return matmul(ret, ret, Mod); } else { return matmul(m, matpow(m, a - 1, Mod), Mod); } } long[][] matmul(long[][] ma, long[][] mb, long Mod) { int p = ma.Length; int q = mb[0].Length; int r = ma[0].Length; long[][] ret = new long [p][]; for (int i = 0; i < p; i++) { ret[i] = new long[q]; for (int j = 0; j < q; j++) { for (int k = 0; k < r; k++) { ret[i][j] += ma[i][k] * mb[k][j] % Mod; } ret[i][j] %= Mod; } } return ret; } } 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); }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
1,253
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { var e = new mMat(N); for (int i = 0; i < N; i++) e.m[i][i] = 1; var x = new mMat(A); var xk = e; long k = K; while (k > 0) { if (k % 2 == 1) xk *= x; x *= x; k >>= 1; } mlong tot = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { tot += xk.m[i][j]; } } Console.WriteLine(tot); } int N; long K; int[][] A; public Sol() { var d = ria(); N = d[0]; K = d[1]; A = new int [N][]; for (int i = 0; i < N; i++) { A[i] = ria(); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } } class mMat { public int N; public mlong[][] m; public mMat(int[][] a) { N = a.Length; m = new mlong[N][]; for (int i = 0; i < N; i++) { m[i] = new mlong[N]; for (int j = 0; j < N; j++) { m[i][j] = a[i][j]; } } } public mMat(int n) { N = n; m = new mlong[N][]; for (int i = 0; i < N; i++) { m[i] = new mlong[N]; } } public static mMat operator *(mMat a, mMat b) { var c = new mMat(a.N); for (int i = 0; i < c.N; i++) { for (int j = 0; j < c.N; j++) { for (int k = 0; k < c.N; k++) { c.m[i][j] += a.m[i][k] * b.m[k][j]; } } } return c; } } struct mlong { const long mod = (long)1e9 + 7; long V; public mlong(long _v = 0) { V = _v; } public static mlong operator +(mlong a, mlong b) { var v0 = a.V + b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator -(mlong a, mlong b) { var v0 = mod + a.V - b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator *(mlong a, mlong b) { var v0 = a.V * b.V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong operator /(mlong a, mlong b) { var v0 = a.V * inv(b.V).V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong inv(long x) { long a = 0, b = 0, c = 0; ExtGCD(x, mod, ref a, ref b, ref c); return (mlong)((a + mod) % mod); } public static void ExtGCD(long x, long y, ref long a, ref long b, ref long c) { long r0 = x; long r1 = y; long a0 = 1; long a1 = 0; long b0 = 0; long b1 = 1; long q1, r2, a2, b2; while (r1 > 0) { q1 = r0 / r1; r2 = r0 % r1; a2 = a0 - q1 * a1; b2 = b0 - q1 * b1; r0 = r1; r1 = r2; a0 = a1; a1 = a2; b0 = b1; b1 = b2; } c = r0; a = a0; b = b0; } public static mlong ModPow(mlong a, long k) { if (k == 0) return (mlong)1; if (a == 0) return (mlong)0; mlong x = a; mlong ret = 1; while (k > 0) { if (k % 2 == 1) ret *= x; x *= x; k >>= 1; } return ret; } public static bool operator ==(mlong a, mlong b) { return a.Equals(b); } public static bool operator !=(mlong a, mlong b) { return !(a == b); } public override bool Equals(System.Object obj) { if (obj == null) return false; mlong p = (mlong)obj; if ((System.Object)p == null) return false; return p.V == V; } public override int GetHashCode() { return V.GetHashCode(); } public static implicit operator mlong(long n) { return new mlong(n); } public static implicit operator mlong(int n) { return new mlong(n); } public static explicit operator long(mlong n) { return n.V; } public override String ToString() { return V.ToString(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { var e = new mMat(N); for (int i = 0; i < N; i++) e.m[i][i] = 1; var x = new mMat(A); var xk = e; long k = K; while (k > 0) { if (k % 2 == 1) xk *= x; x *= x; k >>= 1; } mlong tot = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { tot += xk.m[i][j]; } } Console.WriteLine(tot); } int N; long K; int[][] A; public Sol() { var d = rla(); N = (int)d[0]; K = d[1]; A = new int [N][]; for (int i = 0; i < N; i++) { A[i] = ria(); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } } class mMat { public int N; public mlong[][] m; public mMat(int[][] a) { N = a.Length; m = new mlong[N][]; for (int i = 0; i < N; i++) { m[i] = new mlong[N]; for (int j = 0; j < N; j++) { m[i][j] = a[i][j]; } } } public mMat(int n) { N = n; m = new mlong[N][]; for (int i = 0; i < N; i++) { m[i] = new mlong[N]; } } public static mMat operator *(mMat a, mMat b) { var c = new mMat(a.N); for (int i = 0; i < c.N; i++) { for (int j = 0; j < c.N; j++) { for (int k = 0; k < c.N; k++) { c.m[i][j] += a.m[i][k] * b.m[k][j]; } } } return c; } } struct mlong { const long mod = (long)1e9 + 7; long V; public mlong(long _v = 0) { V = _v; } public static mlong operator +(mlong a, mlong b) { var v0 = a.V + b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator -(mlong a, mlong b) { var v0 = mod + a.V - b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator *(mlong a, mlong b) { var v0 = a.V * b.V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong operator /(mlong a, mlong b) { var v0 = a.V * inv(b.V).V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong inv(long x) { long a = 0, b = 0, c = 0; ExtGCD(x, mod, ref a, ref b, ref c); return (mlong)((a + mod) % mod); } public static void ExtGCD(long x, long y, ref long a, ref long b, ref long c) { long r0 = x; long r1 = y; long a0 = 1; long a1 = 0; long b0 = 0; long b1 = 1; long q1, r2, a2, b2; while (r1 > 0) { q1 = r0 / r1; r2 = r0 % r1; a2 = a0 - q1 * a1; b2 = b0 - q1 * b1; r0 = r1; r1 = r2; a0 = a1; a1 = a2; b0 = b1; b1 = b2; } c = r0; a = a0; b = b0; } public static mlong ModPow(mlong a, long k) { if (k == 0) return (mlong)1; if (a == 0) return (mlong)0; mlong x = a; mlong ret = 1; while (k > 0) { if (k % 2 == 1) ret *= x; x *= x; k >>= 1; } return ret; } public static bool operator ==(mlong a, mlong b) { return a.Equals(b); } public static bool operator !=(mlong a, mlong b) { return !(a == b); } public override bool Equals(System.Object obj) { if (obj == null) return false; mlong p = (mlong)obj; if ((System.Object)p == null) return false; return p.V == V; } public override int GetHashCode() { return V.GetHashCode(); } public static implicit operator mlong(long n) { return new mlong(n); } public static implicit operator mlong(int n) { return new mlong(n); } public static explicit operator long(mlong n) { return n.V; } public override String ToString() { return V.ToString(); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 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]]
8
1,409
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; 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 = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n, m; sc.Multi(out n, out m); var sg = new LazySegtree<long, long>( n, Math.Max, (x, y, len) => x + y * len, (x, y) => x + y, -LM, 0); var q = new List<P>[n]; for (int i = 0; i < n; i++) q[i] = new List<P>(); for (int i = 0; i < m; i++) { int l, r, a; sc.Multi(out l, out r, out a); q[r - 1].Add(new P(l - 1, a)); } for (int i = 0; i < n; i++) { sg.update(i, i + 1, Math.Max(sg.run(0, i), 0)); foreach (var item in q[i]) sg.update(item.v1, i + 1, item.v2); } Prt(Math.Max(sg.run(0, n), 0)); 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(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static 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; 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 { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.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 { get { int a, b; Multi(out a, out b); return new P(a, b); } } 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]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = 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]); f = cv<Y>(ar[5]); } } class LazySegtree<T, U> { int n; T[] data; U[] lazy; bool[] is_lazy; Func<T, T, T> calc; Func<T, U, int, T> apply; Func<U, U, U> merge; T ex_data; public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data) { this.calc = calc; this.apply = apply; this.merge = merge; this.ex_data = ex_data; n = 1; while (n < m) n <<= 1; data = new T[n * 2 - 1]; lazy = new U[n * 2 - 1]; is_lazy = new bool[n * 2 - 1]; for (int i = 0; i < data.Length; i++) data[i] = ex_data; } public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data, T ini) : this(m, calc, apply, merge, ex_data) { for (int i = 0; i < m; i++) data[i + n - 1] = ini; for (int i = n - 2; i >= 0; i--) data[i] = calc(data[i * 2 + 1], data[i * 2 + 2]); } public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data, IList<T> ini) : this(m, calc, apply, merge, ex_data) { for (int i = 0; i < m; i++) data[i + n - 1] = ini[i]; for (int i = n - 2; i >= 0; i--) data[i] = calc(data[i * 2 + 1], data[i * 2 + 2]); } void assign_lazy(int k, U x) { if (k >= lazy.Length) return; if (is_lazy[k]) lazy[k] = merge(lazy[k], x); else { is_lazy[k] = true; lazy[k] = x; } } void eval(int k, int len) { if (!is_lazy[k]) return; assign_lazy(k * 2 + 1, lazy[k]); assign_lazy(k * 2 + 2, lazy[k]); data[k] = apply(data[k], lazy[k], len); is_lazy[k] = false; } T update(int s, int t, U x, int k, int l, int r) { eval(k, r - l); if (r <= s || t <= l) return data[k]; if (s <= l && r <= t) { assign_lazy(k, x); return apply(data[k], lazy[k], r - l); } return data[k] = calc(update(s, t, x, k * 2 + 1, l, (l + r) / 2), update(s, t, x, k * 2 + 2, (l + r) / 2, r)); } T run(int s, int t, int k, int l, int r) { eval(k, r - l); if (r <= s || t <= l) return ex_data; if (s <= l && r <= t) return data[k]; return calc(run(s, t, k * 2 + 1, l, (l + r) / 2), run(s, t, k * 2 + 2, (l + r) / 2, r)); } // [s, t) public void update(int s, int t, U x) => update(s, t, x, 0, 0, n); // [s, t) public T run(int s, int t) => run(s, t, 0, 0, n); }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; 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 = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n, m; sc.Multi(out n, out m); var sg = new LazySegtree<long, long>(n, Math.Max, (x, y, len) => x + y, (x, y) => x + y, 0); var q = new List<P>[n]; for (int i = 0; i < n; i++) q[i] = new List<P>(); for (int i = 0; i < m; i++) { int l, r, a; sc.Multi(out l, out r, out a); q[r - 1].Add(new P(l - 1, a)); } for (int i = 0; i < n; i++) { sg.update(i, i + 1, Math.Max(sg.run(0, i), 0)); foreach (var item in q[i]) sg.update(item.v1, i + 1, item.v2); } Prt(Math.Max(sg.run(0, n), 0)); 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(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static 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; 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 { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.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 { get { int a, b; Multi(out a, out b); return new P(a, b); } } 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]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = 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]); f = cv<Y>(ar[5]); } } class LazySegtree<T, U> { int n; T[] data; U[] lazy; bool[] is_lazy; Func<T, T, T> calc; Func<T, U, int, T> apply; Func<U, U, U> merge; T ex_data; public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data) { this.calc = calc; this.apply = apply; this.merge = merge; this.ex_data = ex_data; n = 1; while (n < m) n <<= 1; data = new T[n * 2 - 1]; lazy = new U[n * 2 - 1]; is_lazy = new bool[n * 2 - 1]; for (int i = 0; i < data.Length; i++) data[i] = ex_data; } public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data, T ini) : this(m, calc, apply, merge, ex_data) { for (int i = 0; i < m; i++) data[i + n - 1] = ini; for (int i = n - 2; i >= 0; i--) data[i] = calc(data[i * 2 + 1], data[i * 2 + 2]); } public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data, IList<T> ini) : this(m, calc, apply, merge, ex_data) { for (int i = 0; i < m; i++) data[i + n - 1] = ini[i]; for (int i = n - 2; i >= 0; i--) data[i] = calc(data[i * 2 + 1], data[i * 2 + 2]); } void assign_lazy(int k, U x) { if (k >= lazy.Length) return; if (is_lazy[k]) lazy[k] = merge(lazy[k], x); else { is_lazy[k] = true; lazy[k] = x; } } void eval(int k, int len) { if (!is_lazy[k]) return; assign_lazy(k * 2 + 1, lazy[k]); assign_lazy(k * 2 + 2, lazy[k]); data[k] = apply(data[k], lazy[k], len); is_lazy[k] = false; } T update(int s, int t, U x, int k, int l, int r) { eval(k, r - l); if (r <= s || t <= l) return data[k]; if (s <= l && r <= t) { assign_lazy(k, x); return apply(data[k], lazy[k], r - l); } return data[k] = calc(update(s, t, x, k * 2 + 1, l, (l + r) / 2), update(s, t, x, k * 2 + 2, (l + r) / 2, r)); } T run(int s, int t, int k, int l, int r) { eval(k, r - l); if (r <= s || t <= l) return ex_data; if (s <= l && r <= t) return data[k]; return calc(run(s, t, k * 2 + 1, l, (l + r) / 2), run(s, t, k * 2 + 2, (l + r) / 2, r)); } // [s, t) public void update(int s, int t, U x) => update(s, t, x, 0, 0, n); // [s, t) public T run(int s, int t) => run(s, t, 0, 0, n); }
[["-", 0, 28, 0, 218, 8, 16, 12, 16, 17, 48], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 21], ["-", 0, 230, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 230, 3, 4, 0, 28, 0, 241, 0, 22]]
8
3,099
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int answer = 0; if (a + b - 1 >= c) { answer = b + c; } else { answer = b + c - (c - (a + b - 1)); } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int answer = 0; if (a + b + 1 >= c) { answer = b + c; } else { answer = b + c - (c - (a + b + 1)); } 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(); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 72]]
8
412
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; void calc() { cin = new Scanner(); long[] ABC = cin.ArrayLong(2, 0); long ans = 0; if (ABC[0] + ABC[1] >= ABC[2] - 1) ans = ABC[2] + ABC[1] + 1; else ans = ABC[1] + Math.Min(ABC[0] + ABC[1] + 1, ABC[2]); 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; } 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; void calc() { cin = new Scanner(); long[] ABC = cin.ArrayLong(3, 0); long ans = 0; if (ABC[0] + ABC[1] >= ABC[2] - 1) ans = ABC[2] + ABC[1]; else ans = ABC[1] + Math.Min(ABC[0] + ABC[1] + 1, ABC[2]); 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; } public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
8
560
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; 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 readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main(string[] args) { int a, b, c; sc.Multi(out a, out b, out c); Prt(Math.Min(a + b * 2 + 1, b + c)); 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; 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 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 readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main(string[] args) { long a, b, c; sc.Multi(out a, out b, out c); Prt(Math.Min(a + b * 2 + 1, b + c)); 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; 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]); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
2,032
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A_PoisonousCookies { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); int result = 0; if (A + 2 > C) { result = B + C; } else { result = A + B + 1 + B; } Console.Write(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A_PoisonousCookies { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); int result = 0; if (A + B + 2 > C) { result = B + C; } else { result = A + B + 1 + B; } Console.Write(result); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72]]
8
144
using System; class Program { static int Main(string[] args) { string N = Console.ReadLine(); int count = 0; foreach (char item in N) { if (item == '2') { count += 1; } } return count; } }
using System; class Program { static void Main(string[] args) { string N = Console.ReadLine(); int count = 0; foreach (char item in N) { if (item == '2') { count += 1; } } Console.WriteLine(count); } }
[["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
58
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 998244353; public static void Main() { // 方針 // int[] n = inta(); int c = 0; for (int i = 0; i < n[0]; i++) { int[] t = inta(); if (n[1] >= t[0] && n[2] >= t[1]) { c++; } } WriteLine(c); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { var temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 998244353; public static void Main() { // 方針 // int[] n = inta(); int c = 0; for (int i = 0; i < n[0]; i++) { int[] t = inta(); if (n[1] <= t[0] && n[2] <= t[1]) { c++; } } WriteLine(c); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { var temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (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() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stack.Peek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // Array.Sort(list1,list2); // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush();
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
1,372
using System; using System.Collections.Generic; using System.IO; class Program { static long answer = 1; static void Main() { string[] Input = Console.ReadLine().Split(' '); long N = long.Parse(Input[0]); long P = long.Parse(Input[1]); long i = 2; long tmp = P; long count = 0; // Console.WriteLine(answer); while (i * i <= P) //※i <= √P { if (tmp % i == 0) { // Console.WriteLine(answer); tmp /= i; count++; if (count == N) answer *= i; } else { i++; count = 0; } } if (tmp != 1) { count++; if (count == N) answer *= tmp; } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; using System.IO; class Program { static long answer = 1; static void Main() { string[] Input = Console.ReadLine().Split(' '); long N = long.Parse(Input[0]); long P = long.Parse(Input[1]); long i = 2; long tmp = P; long count = 0; // Console.WriteLine(answer); while (i * i <= P) //※i <= √P { if (tmp % i == 0) { // Console.WriteLine(answer); tmp /= i; count++; if (count % N == 0) answer *= i; } else { i++; count = 0; } } if (tmp != 1) { count++; if (count % N == 0) answer *= tmp; } Console.WriteLine(answer); } }
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203]]
8
169
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main() { long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = input[0]; long p = input[1]; if (n == 1) { Console.WriteLine(p); return; } long pow = 0, pro = 1; for (long prime = 2; pow < p; prime++) { pow = Pow(prime, n); if (pow == -1) break; if (p % pow > 0) continue; p /= pow; pro *= pow; } Console.WriteLine(pro); } static long Pow(long a, long n) { if (n == 0) return 1; if (n == 1) return a; long b = Pow(a, n / 2); if (b == -1 || b > 1000000) return -1; return b * b * Pow(a, n % 2); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main() { long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = input[0]; long p = input[1]; if (n == 1) { Console.WriteLine(p); return; } long pow = 0, pro = 1; for (long prime = 2; pow < p; prime++) { pow = Pow(prime, n); if (pow == -1) break; while (p % pow == 0) { p /= pow; pro *= prime; } } Console.WriteLine(pro); } static long Pow(long a, long n) { if (n == 0) return 1; if (n == 1) return a; long b = Pow(a, n / 2); if (b == -1 || b > 1000000) return -1; return b * b * Pow(a, n % 2); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 52, 8, 196, 0, 46]]
8
231
using System; class c { static void Main() { var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0; if (inp[0] == 1) ans = inp[1]; else for (long i = 1; i <= Math.Pow(inp[1], 1.0 / inp[0]); i++) { if (inp[1] % (Math.Pow(i, inp[0])) == 0) ans = i; } Console.WriteLine(ans); } }
using System; class c { static void Main() { var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0; if (inp[0] == 1) ans = inp[1]; else for (int i = 1; i <= Math.Pow(inp[1], 1.0 / inp[0]) + 1; i++) { if (inp[1] % Math.Pow(i, inp[0]) == 0) ans = i; } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 57, 75, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 57, 75, 7, 10, 198, 39, 199], ["+", 0, 57, 75, 7, 15, 16, 12, 16, 17, 72], ["+", 0, 57, 75, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["-", 31, 16, 12, 23, 0, 213, 3, 4, 0, 25]]
8
123
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] s = Console.ReadLine().Split(); long n = long.Parse(s[0]); long p = long.Parse(s[1]); long m = (long)Math.Pow(p, 1.0 / n); for (; m >= 1; m--) { long m2 = (long)Math.Pow(m, n); if (p % m2 == 0) { Console.WriteLine(m); return; } } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] s = Console.ReadLine().Split(); long n = long.Parse(s[0]); long p = long.Parse(s[1]); long m = (long)Math.Pow(p, 1.0 / n) + 1; for (; m >= 1; m--) { long m2 = (long)Math.Pow(m, n); if (p % m2 == 0) { Console.WriteLine(m); return; } } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
130
using System; using System.Collections.Generic; using System.Text; namespace AtTest.Caddi2018 { class C { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { long[] np = ReadLongs(); if (np[0] == 1) { Console.WriteLine(np[1]); return; } double n = np[0]; long p = np[1]; long max = (long)Math.Pow(p, 1 / n); long res = 1; for (long i = 1; i <= max; i++) { long pow = (long)Math.Pow(i, n); if (pow < p && p % pow == 0) res = i; } Console.WriteLine(res); } 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.Text; namespace AtTest.Caddi2018 { class C { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { long[] np = ReadLongs(); if (np[0] == 1) { Console.WriteLine(np[1]); return; } double n = np[0]; long p = np[1]; long max = (long)Math.Pow(p, 1 / n) + 1; long res = 1; for (long i = 1; i <= max; i++) { long pow = (long)Math.Pow(i, n); if (pow <= p && p % pow == 0) res = i; } Console.WriteLine(res); } 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, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19]]
8
335
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); static long mod = 1000000007; static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var ans = "second"; for (int i = 0; i < N; i++) { var inp = long.Parse(Console.ReadLine()); if (inp % 2 == 0) { ans = "first"; } } Console.WriteLine(ans); } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); static long mod = 1000000007; static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var ans = "second"; for (int i = 0; i < N; i++) { var inp = long.Parse(Console.ReadLine()); if (inp % 2 == 1) { ans = "first"; break; } } Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
143
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemB { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var aList = NNList(N); if (aList.Sum() % 2 == 1) Console.WriteLine("first"); else Console.WriteLine("second"); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemB { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var aList = NNList(N); if (aList.Any(e => e % 2 == 1)) Console.WriteLine("first"); else Console.WriteLine("second"); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
[["-", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25]]
8
1,447
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(); long[] A = new long[N]; for (var i = 0; i < N; i++) { A[i] = long.Parse(str[i]); } long[,] D = new long[N, 16]; for (var i = 0; i < 16; i++) { D[N - 1, i] = i; } for (var i = N - 2; i >= 0; i--) { long x1 = A[i]; long x2 = A[i + 1]; if (x1 < x2) { long ct = 0; while (x1 < x2) { x1 *= 4; ct++; } for (var j = 0; j <= ct - 1; j++) { D[i, j] = D[i + 1, 0] + j; } if (x1 > x2) { for (var j = ct; j < 16; j++) { D[i, j] = D[i + 1, j - ct + 1] + j; } } else { D[i, ct] = D[i + 1, 0] + ct; for (var j = ct + 1; j < 16; j++) { D[i, j] = D[i + 1, j - ct + 1] + j; } } } else { long ct = 0; while (x1 > x2) { x2 *= 4; ct++; } for (var j = 0; j < 16; j++) { if (j + ct < 16) { D[i, j] = D[i + 1, j + ct] + j; } else { D[i, j] = D[i + 1, 15] + j + (j + ct - 15) * (N - i - 1); } } } } Array.Reverse(A); long[,] E = new long[N, 16]; for (var ia = 0; ia < 16; ia++) { E[N - 1, ia] = ia; } for (var ia = N - 2; ia >= 0; ia--) { long x1 = A[ia]; long x2 = A[ia + 1]; if (x1 < x2) { long ct = 0; while (x1 < x2) { x1 *= 4; ct++; } for (var j = 0; j <= ct - 1; j++) { E[ia, j] = E[ia + 1, j] + j; } if (x1 > x2) { for (var j = ct; j < 16; j++) { E[ia, j] = E[ia + 1, j - ct + 1] + j; } } else { E[ia, ct] = E[ia + 1, 0] + ct; for (var j = ct + 1; j < 16; j++) { E[ia, j] = E[ia + 1, j - ct + 1] + j; } } } else { long ct = 0; while (x1 > x2) { x2 *= 4; ct++; } for (var j = 0; j < 16; j++) { if (j + ct < 16) { E[ia, j] = E[ia + 1, j + ct] + j; } else { E[ia, j] = E[ia + 1, 15] + j + (j + ct - 15) * (N - ia - 1); } } } } long min = D[0, 0] * 2; for (var ib = 1; ib < N - 1; ib++) { long ans = D[ib, 0] * 2 + E[N - ib - 1, 0] * 2 + ib; min = Math.Min(ans, min); } min = Math.Min(min, E[0, 0] * 2 + N - 1); Console.WriteLine(min); for (var i = 0; i < N; i++) { for (var j = 0; j < 16; j++) { // Console.Write(D[i,j]+" "); } // Console.WriteLine(); } for (var i = 0; i < N; i++) { for (var j = 0; j < 16; j++) { // Console.Write(E[i,j]+" "); } // Console.WriteLine(); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(); long[] A = new long[N]; for (var i = 0; i < N; i++) { A[i] = long.Parse(str[i]); } long[,] D = new long[N, 16]; for (var i = 0; i < 16; i++) { D[N - 1, i] = i; } for (var i = N - 2; i >= 0; i--) { long x1 = A[i]; long x2 = A[i + 1]; if (x1 < x2) { long ct = 0; while (x1 < x2) { x1 *= 4; ct++; } for (var j = 0; j <= ct - 1; j++) { D[i, j] = D[i + 1, 0] + j; } if (x1 > x2) { for (var j = ct; j < 16; j++) { D[i, j] = D[i + 1, j - ct + 1] + j; } } else { D[i, ct] = D[i + 1, 0] + ct; for (var j = ct + 1; j < 16; j++) { D[i, j] = D[i + 1, j - ct + 1] + j; } } } else { long ct = 0; while (x1 > x2) { x2 *= 4; ct++; } for (var j = 0; j < 16; j++) { if (j + ct < 16) { D[i, j] = D[i + 1, j + ct] + j; } else { D[i, j] = D[i + 1, 15] + j + (j + ct - 15) * (N - i - 1); } } } } Array.Reverse(A); long[,] E = new long[N, 16]; for (var ia = 0; ia < 16; ia++) { E[N - 1, ia] = ia; } for (var ia = N - 2; ia >= 0; ia--) { long x1 = A[ia]; long x2 = A[ia + 1]; if (x1 < x2) { long ct = 0; while (x1 < x2) { x1 *= 4; ct++; } for (var j = 0; j <= ct - 1; j++) { E[ia, j] = E[ia + 1, 0] + j; } if (x1 > x2) { for (var j = ct; j < 16; j++) { E[ia, j] = E[ia + 1, j - ct + 1] + j; } } else { E[ia, ct] = E[ia + 1, 0] + ct; for (var j = ct + 1; j < 16; j++) { E[ia, j] = E[ia + 1, j - ct + 1] + j; } } } else { long ct = 0; while (x1 > x2) { x2 *= 4; ct++; } for (var j = 0; j < 16; j++) { if (j + ct < 16) { E[ia, j] = E[ia + 1, j + ct] + j; } else { E[ia, j] = E[ia + 1, 15] + j + (j + ct - 15) * (N - ia - 1); } } } } long min = D[0, 0] * 2; for (var ib = 1; ib < N - 1; ib++) { long ans = D[ib, 0] * 2 + E[N - ib - 1, 0] * 2 + ib; min = Math.Min(ans, min); } min = Math.Min(min, E[0, 0] * 2 + N - 1); Console.WriteLine(min); for (var i = 0; i < N; i++) { for (var j = 0; j < 16; j++) { // Console.Write(D[i,j]+" "); } // Console.WriteLine(); } for (var i = 0; i < N; i++) { for (var j = 0; j < 16; j++) { // Console.Write(E[i,j]+" "); } // Console.WriteLine(); } } }
[["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
8
976
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var A = cin.ReadIntArray(N); var C = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { if (C.ContainsKey(A[i])) C[A[i]]++; else C.Add(A[i], 1); } A.MergeSort(true); var res = 0; foreach (var a in A) { if (C[a] <= 0) continue; C[a]--; var target = 1; while (target <= a) target <<= 1; var partner = target - a; if (!C.ContainsKey(partner) || C[partner] <= 0) continue; C[a]--; C[partner]--; res++; } Console.WriteLine(res); } } static class ExtendClass { public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); public static void MergeSort<T>(this T[] A, bool desending) where T : IComparable<T> { if (desending) MergeSort(A, Comparer<T>.Create((x, y) => y.CompareTo(x))); else MergeSort(A, Comparer<T>.Create((x, y) => x.CompareTo(y))); } public static void MergeSort<T>(T[] A, IComparer<T> comparer) where T : IComparable<T> { MergeSort1(0, A.Length, A, comparer); } private static void Merge<T>(int left, int mid, int right, T[] A, IComparer<T> comparer) where T : IComparable<T> { var nl = mid - left; var nr = right - mid; var L = new T[nl]; var R = new T[nr]; for (int i = 0; i < nl; i++) L[i] = A[i + left]; for (int i = 0; i < nr; i++) R[i] = A[i + mid]; int il = 0, ir = 0; for (int k = left; k < right; k++) { if (comparer.Compare(L[il], R[ir]) <= 0) { A[k] = L[il++]; if (il == nl) { k++; for (; ir < nr;) A[k++] = R[ir++]; break; } } else { A[k] = R[ir++]; if (ir == nr) { k++; for (; il < nl;) A[k++] = L[il++]; break; } } } } private static void MergeSort1<T>(int left, int right, T[] A, IComparer<T> comparer) where T : IComparable<T> { if (left + 1 < right) { var mid = (left + right) / 2; MergeSort1(left, mid, A, comparer); MergeSort1(mid, right, A, comparer); Merge(left, mid, right, A, comparer); } } } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var A = cin.ReadIntArray(N); var C = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { if (C.ContainsKey(A[i])) C[A[i]]++; else C.Add(A[i], 1); } A.MergeSort(true); var res = 0; foreach (var a in A) { if (C[a] <= 0) continue; C[a]--; var target = 1; while (target <= a) target <<= 1; var partner = target - a; if (!C.ContainsKey(partner) || C[partner] <= 0) continue; C[partner]--; res++; } Console.WriteLine(res); } } static class ExtendClass { public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); public static void MergeSort<T>(this T[] A, bool desending) where T : IComparable<T> { if (desending) MergeSort(A, Comparer<T>.Create((x, y) => y.CompareTo(x))); else MergeSort(A, Comparer<T>.Create((x, y) => x.CompareTo(y))); } public static void MergeSort<T>(T[] A, IComparer<T> comparer) where T : IComparable<T> { MergeSort1(0, A.Length, A, comparer); } private static void Merge<T>(int left, int mid, int right, T[] A, IComparer<T> comparer) where T : IComparable<T> { var nl = mid - left; var nr = right - mid; var L = new T[nl]; var R = new T[nr]; for (int i = 0; i < nl; i++) L[i] = A[i + left]; for (int i = 0; i < nr; i++) R[i] = A[i + mid]; int il = 0, ir = 0; for (int k = left; k < right; k++) { if (comparer.Compare(L[il], R[ir]) <= 0) { A[k] = L[il++]; if (il == nl) { k++; for (; ir < nr;) A[k++] = R[ir++]; break; } } else { A[k] = R[ir++]; if (ir == nr) { k++; for (; il < nl;) A[k++] = L[il++]; break; } } } } private static void MergeSort1<T>(int left, int right, T[] A, IComparer<T> comparer) where T : IComparable<T> { if (left + 1 < right) { var mid = (left + right) / 2; MergeSort1(left, mid, A, comparer); MergeSort1(mid, right, A, comparer); Merge(left, mid, right, A, comparer); } } } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
[["-", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["-", 0, 210, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70]]
8
1,216
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_B.Lib_IO; using static Contest_B.Lib_Minifunc; public static class Contest_B { public static void Main() { checked{ long n; Lib_IO.rm(out n); ll[] a; ra(out a); long ans = 0; Set<ll> st = new Set<ll>(); st.IsMultiSet = true; foreach (var e in a) { st.Add(e); } for (int i = (int)n-1; 0 <= i; i--) { ll v = st[i]; ll b = 1; while(b<v) b<<=1; ll u = b-v; int j = st.LowerBound(u); if(j<i&&st[j]==u){ ans++; st.RemoveAt(i); st.RemoveAt(j); i--; } } Lib_IO.wm(ans); } } 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); } } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_B.Lib_IO; using static Contest_B.Lib_Minifunc; public static class Contest_B { public static void Main() { checked{ long n; Lib_IO.rm(out n); ll[] a; ra(out a); long ans = 0; Set<ll> st = new Set<ll>(); st.IsMultiSet = true; foreach (var e in a) { st.Add(e); } for (int i = (int)n-1; 0 <= i; i--) { ll v = st[i]; ll b = 1; while(b<=v) b<<=1; ll u = b-v; int j = st.LowerBound(u); if(j<i&&st[j]==u){ ans++; st.RemoveAt(i); st.RemoveAt(j); i--; } } Lib_IO.wm(ans); } } 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); } } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19]]
8
4,344
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Z { static void Main() => new K(); } class K { int[] G => ReadLine().Split().Select(int.Parse).ToArray(); public K() { var N = G[0]; var A = G; WriteLine(FirstBinary(1, N, p => Check(A, p))); } int FirstBinary(int min, int max, Predicate<int> pred) { while (min < max) { var mid = (min + max) / 2; if (pred(mid)) max = mid; else min = mid + 1; } return min; } bool Check(int[] A, int P) { var S = new Integer(A[0], P); foreach (var a in A.Skip(1)) if (a > S.Length) S.Add(a - S.Length); else { S.Cut(a); if (!S.Increment()) return false; } return true; } } struct Block { public readonly int Num, Count; public Block(int n, int c) { Num = n; Count = c; } } class Integer { readonly List<Block> blocks; readonly List<int> sum; // sum[n] = Sum(i in [0,n), blocks[i].Count) int C; public int Length => sum[C]; public readonly int P; public Integer(int n, int p) { blocks = new List<Block> { new Block(0, n) }; sum = new List<int> { 0, n }; C = 1; P = p; } public void Add(int c) { Add(new Block(0, c)); } Block Pop() { var x = blocks[C - 1]; blocks.RemoveAt(C - 1); sum.RemoveAt(C); C--; return x; } void Add(Block b) { Block p = b; if (blocks[C - 1].Num == b.Num) p = new Block(b.Num, b.Count + Pop().Count); blocks.Add(p); sum.Add(sum[C] + p.Count); C++; } public void Cut(int c) { Block b = new Block(); while (Length > c) b = Pop(); if (Length < c) Add(new Block(b.Num, c - Length)); } public bool Increment() { var x = blocks[C - 1].Count; if (blocks[C - 1].Num == P - 1 && C == 1) return false; // n*p p*x => n*(p-1) (n+1)*1 0*x if (blocks[C - 1].Num == P - 1) { var n = blocks[C - 2].Num; var p = blocks[C - 2].Count; Pop(); Pop(); if (p > 1) Add(new Block(n, p - 1)); Add(new Block(n + 1, 1)); Add(new Block(0, x)); } // n*x => n*(x-1) (n+1)*1 else { var n = blocks[C - 1].Num; Pop(); if (x > 1) Add(new Block(n, x - 1)); Add(new Block(n + 1, 1)); } return true; } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Z { static void Main() => new K(); } class K { int[] G => ReadLine().Split().Select(int.Parse).ToArray(); public K() { var N = G[0]; var A = G; WriteLine(FirstBinary(1, N, p => Check(A, p))); } int FirstBinary(int min, int max, Predicate<int> pred) { while (min < max) { var mid = (min + max) / 2; if (pred(mid)) max = mid; else min = mid + 1; } return min; } bool Check(int[] A, int P) { var S = new Integer(A[0], P); foreach (var a in A.Skip(1)) if (a > S.Length) S.Add(a - S.Length); else { S.Cut(a); if (!S.Increment()) return false; } return true; } } struct Block { public readonly int Num, Count; public Block(int n, int c) { Num = n; Count = c; } } class Integer { readonly List<Block> blocks; readonly List<int> sum; // sum[n] = Sum(i in [0,n), blocks[i].Count) int C; public int Length => sum[C]; public readonly int P; public Integer(int n, int p) { blocks = new List<Block> { new Block(0, n) }; sum = new List<int> { 0, n }; C = 1; P = p; } public void Add(int c) { Add(new Block(0, c)); } Block Pop() { var x = blocks[C - 1]; blocks.RemoveAt(C - 1); sum.RemoveAt(C); C--; return x; } void Add(Block b) { Block p = b; if (C > 0 && blocks[C - 1].Num == b.Num) p = new Block(b.Num, b.Count + Pop().Count); blocks.Add(p); sum.Add(sum[C] + p.Count); C++; } public void Cut(int c) { Block b = new Block(); while (Length > c) b = Pop(); if (Length < c) Add(new Block(b.Num, c - Length)); } public bool Increment() { var x = blocks[C - 1].Count; if (blocks[C - 1].Num == P - 1 && C == 1) return false; // n*p p*x => n*(p-1) (n+1)*1 0*x if (blocks[C - 1].Num == P - 1) { var n = blocks[C - 2].Num; var p = blocks[C - 2].Count; Pop(); Pop(); if (p > 1) Add(new Block(n, p - 1)); Add(new Block(n + 1, 1)); Add(new Block(0, x)); } // n*x => n*(x-1) (n+1)*1 else { var n = blocks[C - 1].Num; Pop(); if (x > 1) Add(new Block(n, x - 1)); Add(new Block(n + 1, 1)); } return true; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
726
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; 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(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var I = G; int X = I[0], Y = I[1], N = I[2]; var ls = new int[Y]; for (var x = 0; x < X; x++) ls[x] = Y; for (var i = 0; i < N; i++) { I = G; int x = I[0] - 1, y = I[1] - 1; ls[x] = Min(ls[x], y); } var R = 0; for (var x = 0; x < X - 1; x++) { // (x,0)~(x,R) で下に行けるか if (ls[x + 1] <= R) { WriteLine(x + 1); return; } if (ls[x + 1] > R + 1) R++; } WriteLine(X); } }
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; 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(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var I = G; int X = I[0], Y = I[1], N = I[2]; var ls = new int[X]; for (var x = 0; x < X; x++) ls[x] = Y; for (var i = 0; i < N; i++) { I = G; int x = I[0] - 1, y = I[1] - 1; ls[x] = Min(ls[x], y); } var R = 0; for (var x = 0; x < X - 1; x++) { // (x,0)~(x,R) で下に行けるか if (ls[x + 1] <= R) { WriteLine(x + 1); return; } if (ls[x + 1] > R + 1) R++; } WriteLine(X); } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22]]
8
386
// デバッグ実行:Ctrl+F5 using System; using System.Collections.Generic; class Program { static void Main(string[] args) { String line; line = Console.ReadLine(); String[] words = line.Split(' '); int H = int.Parse(words[0]); int W = int.Parse(words[1]); int N = int.Parse(words[2]); int MAX = W; int X, Y; var dict = new Dictionary<int, List<int>>(); for (int i = 0; i < N; i++) { line = Console.ReadLine(); words = line.Split(' '); X = int.Parse(words[0]); Y = int.Parse(words[1]); if (dict.ContainsKey(Y)) { dict[Y].Add(X); } else { dict[Y] = new List<int>(); dict[Y].Add(X); } } // 各リストはいったんソートされるべき foreach (KeyValuePair<int, List<int>> kvp in dict) { kvp.Value.Sort(); } int beforeX = 1; // 各行の最大Xをチェック for (int i = 1; i <= H; i++) // i:Y座標 { if (dict.ContainsKey(i)) { foreach (int value in dict[i]) { if (value > beforeX) { // 最小値の場合のみ更新する if (MAX > value - 1) MAX = value - 1; break; } } } // 次の行に移る前に"仕込み"(上に移動するときに邪魔になる障害物がないかチェック) if (i == H) break; //最終行は次をチェックしない beforeX++; if (dict.ContainsKey(i + 1)) { foreach (int value in dict[i + 1]) { // 1マス横に移動した後、上の場所にある場合、beforeXを1マスずらす(移動できないため) if (beforeX == value) { beforeX++; } } } } Console.WriteLine(MAX); } }
// デバッグ実行:Ctrl+F5 using System; using System.Collections.Generic; class Program { static void Main(string[] args) { String line; line = Console.ReadLine(); String[] words = line.Split(' '); int H = int.Parse(words[0]); // Xの最大値 int W = int.Parse(words[1]); // Yの最大値 int N = int.Parse(words[2]); int MAX = H; int X, Y; var dict = new Dictionary<int, List<int>>(); for (int i = 0; i < N; i++) { line = Console.ReadLine(); words = line.Split(' '); X = int.Parse(words[0]); Y = int.Parse(words[1]); if (dict.ContainsKey(Y)) { dict[Y].Add(X); } else { dict[Y] = new List<int>(); dict[Y].Add(X); } } // 各リストはいったんソートされるべき foreach (KeyValuePair<int, List<int>> kvp in dict) { kvp.Value.Sort(); } int beforeX = 1; // 各行の最大Xをチェック for (int i = 1; i <= W; i++) // i:Y座標 { if (dict.ContainsKey(i)) { foreach (int value in dict[i]) { // 現在地より後ろにある障害物だけ見る if (value > beforeX) { // 最小値の場合のみ更新する if (MAX > value - 1) MAX = value - 1; break; } } } // 次の行に移る前に"仕込み"(上に移動するときに邪魔になる障害物がないかチェック) if (i == W) break; //最終行は次をチェックしない beforeX++; if (dict.ContainsKey(i + 1)) { foreach (int value in dict[i + 1]) { // 1マス横に移動した後、上の場所にある場合、beforeXを1マスずらす(移動できないため) if (beforeX == value) { beforeX++; } } } } Console.WriteLine(MAX); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
378
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC029E { class Program { const int maxN = 200003; static int[] ans = new int[maxN]; static List<int>[] vec = new List<int>[maxN]; static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); { for (int i = 0; i < maxN; i++) { vec[i] = new List<int>(); dp[i] = new Dictionary<int, int>(); } for (int i = 0; i < N - 1; i++) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); vec[input[0]].Add(input[1]); vec[input[1]].Add(input[0]); } } foreach (int i in vec[1]) { dfs(i, 1, 1, 0); } for (int i = 2; i <= N; i++) Console.Write("{0} ", ans[i]); Console.ReadKey(); } static void dfs(int x, int ba, int pr, int cc) { cc += dfs2(x, ba, Math.Max(ba, cc)); if (pr > x) cc -= dfs2(x, ba, pr); ans[x] = cc; foreach (int y in vec[x]) { if (y == ba) continue; //自分自身はスルー dfs(y, x, Math.Max(pr, ba), cc); } } static Dictionary<int, int>[] dp = new Dictionary<int, int>[maxN]; static int dfs2(int x, int ba, int v) { if (dp[x].ContainsKey(v)) return dp[x][v]; int sm = 1; foreach (int y in vec[x]) { if (y == ba) continue; if (y < v) sm += dfs2(y, x, v); } return dp[x][v] = sm; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC029E { class Program { const int maxN = 200003; static int[] ans = new int[maxN]; static List<int>[] vec = new List<int>[maxN]; static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); { for (int i = 0; i < maxN; i++) { vec[i] = new List<int>(); dp[i] = new Dictionary<int, int>(); } for (int i = 0; i < N - 1; i++) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); vec[input[0]].Add(input[1]); vec[input[1]].Add(input[0]); } } foreach (int i in vec[1]) { dfs(i, 1, 1, 0); } for (int i = 2; i <= N; i++) Console.Write("{0} ", ans[i]); Console.ReadKey(); } static void dfs(int x, int ba, int pr, int cc) { cc += dfs2(x, ba, Math.Max(ba, pr)); if (pr > x) cc -= dfs2(x, ba, pr); ans[x] = cc; foreach (int y in vec[x]) { if (y == ba) continue; //自分自身はスルー dfs(y, x, Math.Max(pr, ba), cc); } } static Dictionary<int, int>[] dp = new Dictionary<int, int>[maxN]; static int dfs2(int x, int ba, int v) { if (dp[x].ContainsKey(v)) return dp[x][v]; int sm = 1; foreach (int y in vec[x]) { if (y == ba) continue; if (y < v) sm += dfs2(y, x, v); } return dp[x][v] = sm; } } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
8
483
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.A { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); var ans = "Christmas"; Console.WriteLine(ans + Enumerable.Repeat("Eve", 25 - n).Join(" ")); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.A { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); var ans = "Christmas"; Console.WriteLine(ans + Enumerable.Repeat(" Eve", 25 - n).Join()); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 205, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 12, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
2,661
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } void Omame() { cin = new Scanner(); long X = cin.nextLong(); switch (X) { case 25: Console.WriteLine("Christmas Eve"); break; case 24: Console.WriteLine("Christmas Eve"); break; case 23: Console.WriteLine("Christmas Eve Eve"); break; case 22: Console.WriteLine("Christmas Eve Eve Eve"); break; } } } }
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } void Omame() { cin = new Scanner(); long X = cin.nextLong(); switch (X) { case 25: Console.WriteLine("Christmas"); break; case 24: Console.WriteLine("Christmas Eve"); break; case 23: Console.WriteLine("Christmas Eve Eve"); break; case 22: Console.WriteLine("Christmas Eve Eve Eve"); break; } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
579
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int d; string s = "Christmas "; d = int.Parse(Console.ReadLine()); if (d == 25) Console.WriteLine(s); if (d == 24) Console.WriteLine(s + ("Eve")); if (d == 23) Console.WriteLine(s + ("EveEve")); if (d == 22) Console.WriteLine(s + ("EveEveEve")); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int d; string s = "Christmas "; d = int.Parse(Console.ReadLine()); if (d == 25) Console.WriteLine(s); if (d == 24) Console.WriteLine(s + ("Eve")); if (d == 23) Console.WriteLine(s + ("Eve Eve")); if (d == 22) Console.WriteLine(s + ("Eve Eve Eve")); Console.ReadKey(); } } }
[["-", 0, 28, 0, 16, 12, 23, 0, 5, 0, 222], ["+", 0, 28, 0, 16, 12, 23, 0, 5, 0, 222]]
8
145
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); string s = "Crisutmas"; for (int i = 0; i < 25 - D; i++) { s += " Eve"; } Console.WriteLine(s); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); string s = "Christmas"; for (int i = 0; i < 25 - D; i++) { s += " Eve"; } Console.WriteLine(s); Console.ReadKey(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
106
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int D; string s = "Christmas"; D = int.Parse(Console.ReadLine()); for (int I = 0; I < 25 - D; I++) ; { s += "Eve"; } Console.WriteLine(s); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int D; string s = "Christmas "; D = int.Parse(Console.ReadLine()); for (int I = 0; I < 25 - D; I++) { s += "Eve "; } Console.WriteLine(s); Console.ReadKey(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 0, 195, 8, 196, 0, 7, 8, 260, 0, 35], ["-", 0, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
107
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int D; var word = Console.ReadLine().Split(' '); D = int.Parse(word[0]); if (D == 22) { Console.WriteLine("christmas Eve Eve Eve"); } else if (D == 23) { Console.WriteLine("christmas Eve Eve"); } else if (D == 24) { Console.WriteLine("christmas Eve"); } else if (D == 25) { Console.WriteLine("christmas"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int D; var word = Console.ReadLine().Split(' '); D = int.Parse(word[0]); if (D == 22) { Console.WriteLine("Christmas Eve Eve Eve"); } else if (D == 23) { Console.WriteLine("Christmas Eve Eve"); } else if (D == 24) { Console.WriteLine("Christmas Eve"); } else if (D == 25) { Console.WriteLine("Christmas"); } Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
154
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_115A { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); if (D == 25) { Console.WriteLine("christmas"); } else if (D == 24) { Console.WriteLine("christmas Eve"); } else if (D == 23) { Console.WriteLine("christmas Eve Eve"); } else if (D == 22) { Console.WriteLine("christmas Eve Eve Eve"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_115A { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); if (D == 25) { Console.WriteLine("Christmas"); } else if (D == 24) { Console.WriteLine("Christmas Eve"); } else if (D == 23) { Console.WriteLine("Christmas Eve Eve"); } else if (D == 22) { Console.WriteLine("Christmas Eve Eve Eve"); } Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
139
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115A { class Program { static void Main(string[] args) { int D = int.Parse(Console.ReadLine()); if (D == 25) Console.WriteLine("christmas"); else if (D == 24) Console.WriteLine("christmas Eve"); else if (D == 23) Console.WriteLine("christmas Eve Eve"); else if (D == 22) Console.WriteLine("christmas Eve Eve Eve"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115A { class Program { static void Main(string[] args) { int D = int.Parse(Console.ReadLine()); if (D == 25) Console.WriteLine("Christmas"); else if (D == 24) Console.WriteLine("Christmas Eve"); else if (D == 23) Console.WriteLine("Christmas Eve Eve"); else if (D == 22) Console.WriteLine("Christmas Eve Eve Eve"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
129
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115A2 { class Program { static void Main(string[] args) { String D; D = Console.ReadLine(); if (D == "22") Console.WriteLine("Christmas Eve Eve Eve"); else if (D == "23") Console.WriteLine("Cristmas Eve Eve"); else if (D == "24") Console.WriteLine("Cristmas Eve"); else if (D == "25") Console.WriteLine("Cristmas"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115A2 { class Program { static void Main(string[] args) { String D; D = Console.ReadLine(); if (D == "22") Console.WriteLine("Christmas Eve Eve Eve"); else if (D == "23") Console.WriteLine("Christmas Eve Eve"); else if (D == "24") Console.WriteLine("Christmas Eve"); else if (D == "25") Console.WriteLine("Christmas"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
134
using System; class Plogram { static void Main() { var day = int.Parse(Console.ReadLine()); string D = "Chrismas"; if (day == 24) { D = "Chrismas Eve"; } else if (day == 23) { D = "Chrismas Eve Eve"; } else if (day == 22) { D = "Chrismas Eve Eve Eve"; } Console.WriteLine(D); } }
using System; class Plogram { static void Main() { var day = int.Parse(Console.ReadLine()); string D = "Christmas"; if (day == 24) { D = "Christmas Eve"; } else if (day == 23) { D = "Christmas Eve Eve"; } else if (day == 22) { D = "Christmas Eve Eve Eve"; } Console.WriteLine(D); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
86
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input = int.Parse(Console.ReadLine()); string ab = "Christmas"; for (int a = 0; a < 25 - input + 1; a++) { ab += " Eve"; } Console.WriteLine(ab); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input = int.Parse(Console.ReadLine()); string ab = "Christmas"; for (int a = 0; a < 25 - input; a++) { ab += " Eve"; } Console.WriteLine(ab); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
101
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace template { class Program { static void Main(string[] args) { int D = Convert.ToInt32(Console.ReadLine()); int eve = 25 - D; Console.Write("Christmas"); for (; 0 < eve; eve--) { Console.Write(" eve"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace template { class Program { static void Main(string[] args) { int D = Convert.ToInt32(Console.ReadLine()); int eve = 25 - D; Console.Write("Christmas"); for (; 0 < eve; eve--) { Console.Write(" Eve"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
97
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sample201 { class Program { static void Main(string[] args) { long a; a = long.Parse(Console.ReadLine()) + 20; switch (a) { case 25: Console.WriteLine("Christmas"); break; case 24: Console.WriteLine("Christmas Eve"); break; case 23: Console.WriteLine("Christmas Eve Eve"); break; case 22: Console.WriteLine("Christmas Eve Eve Eve"); break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { class Program { static void Main(string[] args) { long a; a = long.Parse(Console.ReadLine()); switch (a) { case 25: Console.WriteLine("Christmas"); break; case 24: Console.WriteLine("Christmas Eve"); break; case 23: Console.WriteLine("Christmas Eve Eve"); break; case 22: Console.WriteLine("Christmas Eve Eve Eve"); break; } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
126
using System; namespace Practice { class Program { static void Main(string[] args) { int D = int.Parse(Console.ReadLine()); if (D == 25) { Console.Write("Christmas"); } if (D == 24) { Console.Write("Christmas Eve"); } if (D == 23) { Console.Write("Christmas Eve Eve"); } if (D == 23) { Console.Write("Christmas Eve Eve Eve"); } } } }
using System; namespace Practice { class Program { static void Main(string[] args) { int D = int.Parse(Console.ReadLine()); if (D == 25) { Console.Write("Christmas"); } if (D == 24) { Console.Write("Christmas Eve"); } if (D == 23) { Console.Write("Christmas Eve Eve"); } if (D == 22) { Console.Write("Christmas Eve Eve Eve"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
104
using System; namespace a { class b { static void Main(string[] args) { string write = Console.ReadLine(); if (write == "23") { Console.WriteLine("Christmas Eve Eve Eve"); } else if (write == "23") { Console.WriteLine("Christmas Eve Eve"); } else if (write == "24") { Console.WriteLine("Christmas Eve"); } else if (write == "25") { Console.WriteLine("Christmas"); } } } }
using System; namespace a { class b { static void Main(string[] args) { string write = Console.ReadLine(); if (write == "22") { Console.WriteLine("Christmas Eve Eve Eve"); } else if (write == "23") { Console.WriteLine("Christmas Eve Eve"); } else if (write == "24") { Console.WriteLine("Christmas Eve"); } else if (write == "25") { Console.WriteLine("Christmas"); } } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222]]
8
110
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var k = new int[n]; for (int i = 0; i < n; i++) { k[i] = Console.ReadLine().ToInt(); } Array.Sort(k); long wa = 0; for (int i = 0; i < n; i++) { if (i == n - 1) wa += k[i] / 2; wa += k[i]; } Console.WriteLine(wa); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var k = new int[n]; for (int i = 0; i < n; i++) { k[i] = Console.ReadLine().ToInt(); } Array.Sort(k); long wa = 0; for (int i = 0; i < n; i++) { if (i == n - 1) wa += k[i] / 2; else wa += k[i]; } Console.WriteLine(wa); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
357
using System; using System.IO; using System.Linq; using static ABC115B.Input; namespace ABC115B { 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 int N; private long[] P; public void Solve() { Cin(out N); Cin(out P); Console.WriteLine(P.Sum() - P.Max() / 2); } } }
using System; using System.IO; using System.Linq; using static ABC115B.Input; namespace ABC115B { 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 int N; private long[] P; public void Solve() { Cin(out N); Cin(N, out P); Console.WriteLine(P.Sum() - P.Max() / 2); } } }
[["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21]]
8
1,411
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { public Program() {} Scanner cin; void myon() { cin = new Scanner(); int N = cin.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = cin.nextInt(); } int maxPrice = 0; int sumPrice = 0; for (int i = 0; i < N; i++) { maxPrice = Math.Max(maxPrice, A[i]); sumPrice += A[i]; } int Payment = sumPrice + maxPrice / 2; Console.WriteLine(Payment); } static void Main(string[] args) { new Program().myon(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { public Program() {} Scanner cin; void myon() { cin = new Scanner(); int N = cin.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = cin.nextInt(); } int maxPrice = 0; int sumPrice = 0; for (int i = 0; i < N; i++) { maxPrice = Math.Max(maxPrice, A[i]); sumPrice += A[i]; } int Payment = sumPrice - maxPrice / 2; Console.WriteLine(Payment); } static void Main(string[] args) { new Program().myon(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33]]
8
347
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_Christmas_Eve_Eve { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] P = new int[N]; for (int i = 0; i < N; i++) { P[i] = int.Parse(Console.ReadLine()); } int max = P[0]; int total = P[0]; for (int i = 1; i < N; i++) { if (P[i - 1] < P[i]) { max = P[i]; } total += P[i]; } total -= max / 2; Console.Write(total); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_Christmas_Eve_Eve { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] P = new int[N]; for (int i = 0; i < N; i++) { P[i] = int.Parse(Console.ReadLine()); } int max = P[0]; int total = P[0]; for (int i = 1; i < N; i++) { if (max < P[i]) { max = P[i]; } total += P[i]; } total -= max / 2; Console.Write(total); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22]]
8
178
using System; using System.Collections; namespace a { class b { static void Main(string[] args) { ArrayList al = new ArrayList(); int cntrow = int.Parse(Console.ReadLine()); for (int cnt = 1; cnt <= cntrow; cnt++) { al.Add(Console.ReadLine()); } al.Sort(); int sum = 0; for (int i = 0; i < (al.Count - 1); i++) { sum += int.Parse(al[i].ToString()); } sum += int.Parse(al[al.Count - 1].ToString()) / 2; Console.WriteLine(sum); } } }
using System; using System.Collections; namespace a { class c { static void Main(string[] args) { ArrayList al = new ArrayList(); int cntrow = int.Parse(Console.ReadLine()); for (int cnt = 1; cnt <= cntrow; cnt++) { al.Add(int.Parse(Console.ReadLine())); } al.Sort(); int sum = 0; for (int i = 0; i < (al.Count - 1); i++) { sum += int.Parse(al[i].ToString()); } sum += int.Parse(al[al.Count - 1].ToString()) / 2; Console.WriteLine(sum); } } }
[["-", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
154
using System; using System.Collections.Generic; class test { static void Main() { int n = Int32.Parse(Console.ReadLine()); List<int> inputs = new List<int>(); for (int i = 0; i < n; i++) inputs.Add(Int32.Parse(Console.ReadLine())); int max_index = 0; for (int i = 1; i < n; i++) if (inputs[i] > inputs[max_index]) max_index = i; int result = 0; for (int i = 0; i < n; i++) if (i == max_index) result += inputs[i]; else result += (int)(inputs[i] / 2); Console.WriteLine(result.ToString()); } }
using System; using System.Collections.Generic; class test { static void Main() { int n = Int32.Parse(Console.ReadLine()); List<int> inputs = new List<int>(); for (int i = 0; i < n; i++) inputs.Add(Int32.Parse(Console.ReadLine())); int max_index = 0; for (int i = 1; i < n; i++) if (inputs[i] > inputs[max_index]) max_index = i; int result = 0; for (int i = 0; i < n; i++) if (i != max_index) result += inputs[i]; else result += (int)(inputs[i] / 2); Console.WriteLine(result.ToString()); } }
[["-", 8, 196, 0, 7, 8, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 7, 8, 57, 15, 16, 17, 79]]
8
172
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static readonly long Mod = 1000000000 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NK = Sarray(); var N = NK[0]; var K = NK[1]; var hi = new long[N]; for (var i = 0; i < N; ++i) hi[i] = Sarray()[0]; Array.Sort(hi); var ans = 100000 + 1L; for (var i = 0; i + K - 1 < N; ++i) ans = Min(ans, hi[i + K - 1] - hi[i]); WriteLine(ans); // Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static readonly long Mod = 1000000000 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NK = Sarray(); var N = NK[0]; var K = NK[1]; var hi = new long[N]; for (var i = 0; i < N; ++i) hi[i] = Sarray()[0]; Array.Sort(hi); var ans = Mod; for (var i = 0; i + K - 1 < N; ++i) ans = Min(ans, hi[i + K - 1] - hi[i]); WriteLine(ans); // Out.Flush(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
244
using System; class C { static void Main() { int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = Ar[0], K = Ar[1]; long[] Tree = new long[N]; for (int i = 0; i < N; i++) { // 木を取得 Tree[i] = int.Parse(Console.ReadLine()); } Array.Sort(Tree); long ans = 999999999; for (int i = 0; i < N - K; i++) { ans = Math.Min(ans, Tree[i + K - 1] - Tree[i]); } Console.WriteLine(ans); } }
using System; class C { static void Main() { int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = Ar[0], K = Ar[1]; long[] Tree = new long[N]; for (int i = 0; i < N; i++) { // 木を取得 Tree[i] = int.Parse(Console.ReadLine()); } Array.Sort(Tree); long ans = 999999999; for (int i = 0; i <= N - K; i++) { // Console.WriteLine(Tree[i + K - 1] + " - " + Tree[i]); ans = Math.Min(ans, Tree[i + K - 1] - Tree[i]); } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
160
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (n, k) = cin.ReadValue<int, int>(); var h = cin.ReadIntArray(n); int ans = int.MaxValue; Array.Sort(h); for (int i = 0; i < n - k; i++) { Chmin(ref ans, h[i + k - 1] - h[i]); } Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (n, k) = cin.ReadValue<int, int>(); var h = cin.ReadIntArray(n); int ans = int.MaxValue; Array.Sort(h); for (int i = 0; i <= n - k; i++) { Chmin(ref ans, h[i + k - 1] - h[i]); } Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
2,705
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } void Omame() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); List<long> h = new List<long>(); for (int i = 0; i < N; i++) { h.Add(cin.nextLong()); } h.Sort(); long ans = long.MaxValue; for (int i = 0; i < N - K + 1; i++) { ans = Math.Min(ans, h[N - K + 1] - h[i]); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } void Omame() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); List<long> h = new List<long>(); for (int i = 0; i < N; i++) { h.Add(cin.nextLong()); } h.Sort(); long ans = long.MaxValue; for (int i = 0; i < N - K + 1; i++) { ans = Math.Min(ans, h[i + K - 1] - h[i]); } Console.WriteLine(ans); } } }
[["-", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33]]
8
630
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int k = sc.NextInt(); int[] h = new int[n]; for (int i = 0; i < n; i++) { h[i] = sc.NextInt(); } h = h.OrderBy(i => i).ToArray(); int answer = int.MaxValue; for (int i = 0; i < n - k; i++) { answer = Math.Min(answer, h[i + k - 1] - h[i]); } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int k = sc.NextInt(); int[] h = new int[n]; for (int i = 0; i < n; i++) { h[i] = sc.NextInt(); } h = h.OrderBy(i => i).ToArray(); int answer = int.MaxValue; for (int i = 0; i < n - k + 1; i++) { answer = Math.Min(answer, h[i + k - 1] - h[i]); } 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(); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
460
using System; using System.IO; using System.Linq; using static ABC115C.Input; namespace ABC115C { 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 K; private long[] h; public void Solve() { Cin(out N, out K); Cin(N, out h); Array.Sort(h); long ans = h[N - 1]; for (int i = 0; i < N - K; i++) { ans = Math.Min(ans, h[K + i - 1] - h[i]); } Console.WriteLine(ans); } } }
using System; using System.IO; using System.Linq; using static ABC115C.Input; namespace ABC115C { 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 K; private long[] h; public void Solve() { Cin(out N, out K); Cin(N, out h); Array.Sort(h); long ans = h[N - 1] - h[0]; for (int i = 0; i <= N - K; i++) { ans = Math.Min(ans, h[K + i - 1] - h[i]); } Console.WriteLine(ans); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
1,466
using System; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 long[] nk = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nk[0]; var k = nk[1]; long[] h = new long[n]; for (int i = 0; i < n; i++) { h[i] = long.Parse(Console.ReadLine()); } Array.Sort(h); long ans = long.MaxValue; for (int i = 0; i < n - k - 1; i++) { ans = Math.Min(ans, h[i + k - 1] - h[i]); } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 long[] nk = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nk[0]; var k = nk[1]; long[] h = new long[n]; for (int i = 0; i < n; i++) { h[i] = long.Parse(Console.ReadLine()); } Array.Sort(h); long ans = long.MaxValue; for (int i = 0; i < n - (k - 1); i++) { ans = Math.Min(ans, h[i + (k - 1)] - h[i]); } Console.WriteLine(ans); } }
[["+", 0, 7, 15, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 7, 15, 16, 12, 16, 12, 23, 0, 25], ["+", 206, 207, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 206, 207, 0, 28, 0, 16, 12, 23, 0, 25]]
8
178
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var K = cin.ReadInt; var h = cin.ReadIntArray(N); Array.Sort(h); int ans = 100000000; for (int i = 0; i < N - K + 1; i++) { int tmp = h[i + K - 1] - h[i]; if (tmp < ans) { ans = tmp; } } Console.WriteLine(ans); } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var K = cin.ReadInt; var h = cin.ReadIntArray(N); Array.Sort(h); int ans = 1000000000; for (int i = 0; i < N - K + 1; i++) { int tmp = h[i + K - 1] - h[i]; if (tmp < ans) { ans = tmp; } } Console.WriteLine(ans); } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
560
using System; using System.Linq; using static System.Console; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var t = ReadIntArray(); int n = t[0], k = t[1]; var h = new int[n]; for (int i = 0; i < n; i++) { h[i] = int.Parse(ReadLine()); } Array.Sort(h); int ans = 1000000; for (int i = 0; i + k - 1 < n; i++) { int hMax = h[i + k - 1]; int hMin = h[i]; ans = Math.Min(ans, hMax - hMin); } WriteLine(ans); } }
using System; using System.Linq; using static System.Console; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var t = ReadIntArray(); int n = t[0], k = t[1]; var h = new int[n]; for (int i = 0; i < n; i++) { h[i] = int.Parse(ReadLine()); } Array.Sort(h); int ans = 2000000000; for (int i = 0; i + k - 1 < n; i++) { int hMax = h[i + k - 1]; int hMin = h[i]; ans = Math.Min(ans, hMax - hMin); } WriteLine(ans); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
200
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 firstLine = Console.ReadLine().Split(' '); var N = int.Parse(firstLine[0]); var K = int.Parse(firstLine[1]); List<int> trees = new List<int>(); for (int i = 0; i < N; i++) { trees.Add(int.Parse(Console.ReadLine())); } trees = trees.OrderBy(x => x).ToList(); var len = trees.Count; int result = int.MaxValue; for (int i = 0; i < len - K; i++) { int tmp = 0; tmp = trees[i + K - 1] - trees[i]; if (tmp <= result) { result = tmp; } } Console.WriteLine(result.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var firstLine = Console.ReadLine().Split(' '); var N = int.Parse(firstLine[0]); var K = int.Parse(firstLine[1]); List<int> trees = new List<int>(); for (int i = 0; i < N; i++) { trees.Add(int.Parse(Console.ReadLine())); } trees = trees.OrderBy(x => x).ToList(); var len = trees.Count; int result = int.MaxValue; for (int i = 0; i < len - K + 1; i++) { int tmp = 0; tmp = trees[i + K - 1] - trees[i]; if (tmp <= result) { result = tmp; } } Console.WriteLine(result.ToString()); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
225
using System; using System.Linq; namespace CSharp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input[0]; var K = input[1]; var H = new int[N]; for (var i = 0; i < N; i++) { H[i] = Console.ReadLine().Split().Select(int.Parse).ToArray()[0]; } Array.Sort(H); var min = H[K - 1] - H[0]; for (var i = 0; i + K - 1 < N; i++) { Math.Min(min, H[i + K - 1] - H[i]); } Console.WriteLine(min); } } }
using System; using System.Linq; namespace CSharp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input[0]; var K = input[1]; var H = new int[N]; for (var i = 0; i < N; i++) { H[i] = Console.ReadLine().Split().Select(int.Parse).ToArray()[0]; } Array.Sort(H); var min = H[K - 1] - H[0]; for (var i = 0; i + K - 1 < N; i++) { min = Math.Min(min, H[i + K - 1] - H[i]); } Console.WriteLine(min); } } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
8
191
using System; using System.Collections.Generic; using System.Linq; namespace Christmas_Eve { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split().Select(int.Parse); int n = nk.ElementAt(0); int k = nk.ElementAt(1); var list = new List<int>(); for (int i = 0; i < n; i++) { list.Add(int.Parse(Console.ReadLine())); } list.Sort(); int result = int.MaxValue; for (int i = 0; i < n - k; i++) { var temp = list[k + i - 1] - list[i]; result = result < temp ? result : temp; } Console.WriteLine(result); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Christmas_Eve { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split().Select(int.Parse); int n = nk.ElementAt(0); int k = nk.ElementAt(1); var list = new List<int>(); for (int i = 0; i < n; i++) { list.Add(int.Parse(Console.ReadLine())); } list.Sort(); int result = int.MaxValue; for (int i = 0; i < n - k + 1; i++) { var temp = list[k + i - 1] - list[i]; result = result < temp ? result : temp; } Console.WriteLine(result); Console.ReadLine(); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
188
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = s[0]; int k = s[1]; List<int> h = new List<int>(); for (int i = 0; i < n; i++) h.Add(int.Parse(Console.ReadLine())); int ans = h[k - 1] - h[0]; for (int i = 1; i < n - k + 1; i++) { int tmp = h[i + k - 1] - h[i]; if (tmp < ans) ans = tmp; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = s[0]; int k = s[1]; List<int> h = new List<int>(); for (int i = 0; i < n; i++) h.Add(int.Parse(Console.ReadLine())); h.Sort(); int ans = h[k - 1] - h[0]; for (int i = 1; i < n - k + 1; i++) { int tmp = h[i + k - 1] - h[i]; if (tmp < ans) ans = tmp; } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
186
using System; using System.Linq; namespace C_Christmas_Eve { public class Program { public static void Main(string[] args) { var raw_input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = raw_input[0]; int K = raw_input[1]; var h = Enumerable.Range(0, N) .Select(x => Console.ReadLine()) .Select(int.Parse) .ToArray(); h = h.OrderBy(x => x).ToArray(); var min = Enumerable.Range(0, N - K - 1).Select(x => h[x + K - 1] - h[x]).Min(); Console.WriteLine(min); } } }
using System; using System.Linq; namespace C_Christmas_Eve { public class Program { public static void Main(string[] args) { var raw_input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = raw_input[0]; int K = raw_input[1]; var h = Enumerable.Range(0, N) .Select(x => Console.ReadLine()) .Select(int.Parse) .ToArray(); h = h.OrderBy(x => x).ToArray(); var min = Enumerable.Range(0, N - K + 1).Select(x => h[x + K - 1] - h[x]).Min(); Console.WriteLine(min); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
164
using System; class Sample { public static void Main() { String[] temp = System.Console.ReadLine().Split(' '); int treeNum = int.Parse(temp[0]); int choiceTreeNum = int.Parse(temp[1]); int[] treeHigh = new int[treeNum]; for (int i = 0; i < treeNum; i++) { treeHigh[i] = int.Parse(System.Console.ReadLine()); } Array.Sort(treeHigh); int dif = int.MaxValue; for (int i = 0; i < treeNum - choiceTreeNum; i++) { dif = Math.Min(dif, treeHigh[i + choiceTreeNum - 1] - treeHigh[i]); } System.Console.WriteLine(dif); } }
using System; class Sample { public static void Main() { String[] temp = System.Console.ReadLine().Split(' '); int treeNum = int.Parse(temp[0]); int choiceTreeNum = int.Parse(temp[1]); int[] treeHigh = new int[treeNum]; for (int i = 0; i < treeNum; i++) { treeHigh[i] = int.Parse(System.Console.ReadLine()); } Array.Sort(treeHigh); int dif = int.MaxValue; for (int i = 0; i <= treeNum - choiceTreeNum; i++) { dif = Math.Min(dif, treeHigh[i + choiceTreeNum - 1] - treeHigh[i]); } System.Console.WriteLine(dif); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
170
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Extension; class AC { /*------------------------------------------------------------------*/ int N, K; int[] h; void Solve() { io.i(out N, out K); io.ini(out h, N); Array.Sort(h); var ans = int.MaxValue; (h.Length - K + 1).Rep(i => { var min = h[i]; var max = h[i + K - 1]; ans = MIN(max - min); }); ans.Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class LinqExtension { public struct IndexedValue<T> { public int Index; public T Value; public IndexedValue(int index, T value) { this.Index = index; this.Value = value; } public override string ToString() { return string.Format("Index: {0}, Value: {1}", Index, Value); } } public struct Pair<T> { public T Fst; public T Snd; public Pair(T fst, T snd) { Fst = fst; Snd = snd; } public override string ToString() { return string.Format("({0}, {1})", Fst, Snd); } } public static IEnumerable<IndexedValue<T>> Indexed<T>(this IEnumerable<T> source) { return source.Select((value, index) => new IndexedValue<T>(index, value)); } public static void Iter<T>(this IEnumerable<T> source, Action<T> action) { foreach (var s in source) action(s); } public static IEnumerable<Pair<T>> PairWise<T>(this IEnumerable<T> source) { return source.Zip(source.Skip(1), (fst, snd) => new Pair<T>(fst, snd)); } public static T Then<T>(this T source, Action<T> action) { if (source == null) return source; action(source); return source; } } static class Extension { public static void FOR(int a, int b, int n, Action<int> f) { for (var i = a; i < b; i += n) f(i); } public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, 1, f); public static void REP(int a, int n, Action<int> f) => FOR(0, a, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, 1, f); public static void REPEQ(int a, int n, Action<int> f) => FOR(0, a + 1, n, f); public static void Rep(this int a, Action<int> f) => FOR(0, a, 1, f); public static void Rep(this int a, int n, Action<int> f) => FOR(0, a, n, f); public static void RepEQ(this int a, Action<int> f) => FOR(0, a + 1, 1, f); public static void RepEQ(this int a, int n, Action<int> f) => FOR(0, a + 1, n, f); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt_<T>(this IEnumerable<T> xs) { xs.Iter(x => WriteLine($"{x} ")); WriteLine(); } public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Extension; class AC { /*------------------------------------------------------------------*/ int N, K; int[] h; void Solve() { io.i(out N, out K); io.ini(out h, N); Array.Sort(h); var ans = int.MaxValue; (h.Length - K + 1).Rep(i => { var min = h[i]; var max = h[i + K - 1]; ans = MIN(ans, max - min); }); ans.Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class LinqExtension { public struct IndexedValue<T> { public int Index; public T Value; public IndexedValue(int index, T value) { this.Index = index; this.Value = value; } public override string ToString() { return string.Format("Index: {0}, Value: {1}", Index, Value); } } public struct Pair<T> { public T Fst; public T Snd; public Pair(T fst, T snd) { Fst = fst; Snd = snd; } public override string ToString() { return string.Format("({0}, {1})", Fst, Snd); } } public static IEnumerable<IndexedValue<T>> Indexed<T>(this IEnumerable<T> source) { return source.Select((value, index) => new IndexedValue<T>(index, value)); } public static void Iter<T>(this IEnumerable<T> source, Action<T> action) { foreach (var s in source) action(s); } public static IEnumerable<Pair<T>> PairWise<T>(this IEnumerable<T> source) { return source.Zip(source.Skip(1), (fst, snd) => new Pair<T>(fst, snd)); } public static T Then<T>(this T source, Action<T> action) { if (source == null) return source; action(source); return source; } } static class Extension { public static void FOR(int a, int b, int n, Action<int> f) { for (var i = a; i < b; i += n) f(i); } public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, 1, f); public static void REP(int a, int n, Action<int> f) => FOR(0, a, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, 1, f); public static void REPEQ(int a, int n, Action<int> f) => FOR(0, a + 1, n, f); public static void Rep(this int a, Action<int> f) => FOR(0, a, 1, f); public static void Rep(this int a, int n, Action<int> f) => FOR(0, a, n, f); public static void RepEQ(this int a, Action<int> f) => FOR(0, a + 1, 1, f); public static void RepEQ(this int a, int n, Action<int> f) => FOR(0, a + 1, n, f); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt_<T>(this IEnumerable<T> xs) { xs.Iter(x => WriteLine($"{x} ")); WriteLine(); } public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); }
[["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21]]
8
2,117
using System; using System.Collections.Generic; class test { static void Main() { string[] inputs = Console.ReadLine().Split(' '); int N = Int32.Parse(inputs[0]); int K = Int32.Parse(inputs[1]); List<int> h = new List<int>(); for (int count = 0; count < N; count++) h.Add(Int32.Parse(Console.ReadLine())); h.Sort(); int result = 1000000001; for (int count = 0; count < N - K - 1; count++) if (result > (h[count + K - 1] - h[count])) result = h[count + K - 1] - h[count]; Console.WriteLine(result.ToString()); } }
using System; using System.Collections.Generic; class test { static void Main() { string[] inputs = Console.ReadLine().Split(' '); int N = Int32.Parse(inputs[0]); int K = Int32.Parse(inputs[1]); List<int> h = new List<int>(); for (int count = 0; count < N; count++) h.Add(Int32.Parse(Console.ReadLine())); h.Sort(); int result = 1000000001; for (int count = 0; count < N - K + 1; count++) if (result > (h[count + K - 1] - h[count])) result = h[count + K - 1] - h[count]; Console.WriteLine(result.ToString()); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72]]
8
185
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Remoting; using System.Runtime.Remoting.Contexts; using System.Text; using System.Threading; using System.Xml.Schema; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public ulong NextUlong() { return ulong.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class Program { private int N, K; private int[] H; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); K = sc.NextInt(); H = new int[N]; for (int i = 0; i < N; i++) { H[i] = sc.NextInt(); } } public void Solve() { Scan(); Array.Sort(H); int ans = int.MaxValue; for (int i = 0; i < N - K; i++) { ans = Math.Min(ans, H[i + K] - H[i]); } Console.WriteLine(ans); } static void Main() => new Program().Solve(); } }
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Remoting; using System.Runtime.Remoting.Contexts; using System.Text; using System.Threading; using System.Xml.Schema; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public ulong NextUlong() { return ulong.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class Program { private int N, K; private int[] H; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); K = sc.NextInt(); H = new int[N]; for (int i = 0; i < N; i++) { H[i] = sc.NextInt(); } } public void Solve() { Scan(); Array.Sort(H); int ans = int.MaxValue; for (int i = 0; i <= N - K; i++) { ans = Math.Min(ans, H[i + K - 1] - H[i]); } Console.WriteLine(ans); } static void Main() => new Program().Solve(); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
516
using System; using System.Collections.Generic; using System.Linq; class P { static void Main() { string[] s = Console.ReadLine().Split(); int n = int.Parse(s[0]); int k = int.Parse(s[1]); int[] h = new int[n]; for (int i = 0; i < n; i++) h[i] = int.Parse(Console.ReadLine()); Array.Sort(h); List<int> l = new List<int>(); for (int i = 0; i < n - k; i++) l.Add(h[i + k - 1] - h[i]); Console.WriteLine(l.Min()); } }
using System; using System.Collections.Generic; using System.Linq; class P { static void Main() { string[] s = Console.ReadLine().Split(); int n = int.Parse(s[0]); int k = int.Parse(s[1]); int[] h = new int[n]; for (int i = 0; i < n; i++) h[i] = int.Parse(Console.ReadLine()); Array.Sort(h); List<int> l = new List<int>(); for (int i = 0; i <= n - k; i++) l.Add(h[i + k - 1] - h[i]); Console.WriteLine(l.Min()); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
175
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { //出力の都度更新をやめる var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Ans(); //更新する Console.Out.Flush(); } public static void Ans() { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var N = (int)inputArray[0]; var X = inputArray[1]; var p = new long[N + 1]; var all = new long[N + 1]; p[0] = 1; all[0] = 1; for (int i = 1; i <= N; i++) { p[i] = p[i - 1] * 2 + 1; all[i] = all[i - 1] * 2 + 3; } var shokuyoku = X; var current = N; long ans = 0; while (shokuyoku > 0) { // currentのバーガーを食べきれる場合 if (shokuyoku > all[current]) { shokuyoku -= all[current]; ans += p[current]; if (shokuyoku > 0) { //中間のパテを食べる ans += 1; shokuyoku -= 1; } continue; } //食べきれない場合 shokuyoku -= 1; //端っこのバンを食べる current--; } //答えの出力 Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { //出力の都度更新をやめる var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Ans(); //更新する Console.Out.Flush(); } public static void Ans() { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var N = (int)inputArray[0]; var X = inputArray[1]; var p = new long[N + 1]; var all = new long[N + 1]; p[0] = 1; all[0] = 1; for (int i = 1; i <= N; i++) { p[i] = p[i - 1] * 2 + 1; all[i] = all[i - 1] * 2 + 3; } var shokuyoku = X; var current = N; long ans = 0; while (shokuyoku > 0) { // currentのバーガーを食べきれる場合 if (shokuyoku >= all[current]) { shokuyoku -= all[current]; ans += p[current]; if (shokuyoku > 0) { //中間のパテを食べる ans += 1; shokuyoku -= 1; } continue; } //食べきれない場合 shokuyoku -= 1; //端っこのバンを食べる current--; } //答えの出力 Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20]]
8
511
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var NX = IO.RSLong; var N = (int)NX[0]; var X = NX[1]; WriteLine(Func(N, X)); } public static long Func(int N, long X) { // レベル0はそれより下の階層がないので if (N == 0 && X == 1) return 1; // 1レベル下の総枚数、パティの枚数 long sub_Len = (1L << (N + 1)) - 3; long sub_Patty = (1L << N) - 1; if (X == 1) return 0; else if (X <= sub_Len + 1) return Func(N - 1, X - 1); else if (X == sub_Len + 2) return sub_Patty + 1; else if (X <= 2 * sub_Len + 2) return sub_Patty + Func(N - 1, X - (sub_Len + 2)); else return 2 * sub_Patty + 1; } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var NX = IO.RSLong; var N = (int)NX[0]; var X = NX[1]; WriteLine(Func(N, X)); } public static long Func(int N, long X) { // レベル0はそれより下の階層がないので if (N == 0 && X == 1) return 1; // 1レベル下の総枚数、パティの枚数 long sub_Len = (1L << (N + 1)) - 3; long sub_Patty = (1L << N) - 1; if (X == 1) return 0; else if (X <= sub_Len + 1) return Func(N - 1, X - 1); else if (X == sub_Len + 2) return sub_Patty + 1; else if (X <= 2 * sub_Len + 2) return sub_Patty + 1 + Func(N - 1, X - (sub_Len + 2)); else return 2 * sub_Patty + 1; } } 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 } }
[["+", 75, 57, 64, 37, 0, 16, 31, 16, 12, 203], ["+", 75, 57, 75, 57, 64, 37, 0, 16, 17, 72]]
8
635
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace Atcoder { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Program { static bool[] visited; static List<int>[] togo; static void Main(string[] args) { long mod = 1000000007; StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); int n = scan.Integer(); long x = scan.Long(); Console.WriteLine(getpatti(n, x)); } static long getpatti(int level, long n) { if (level == 0) { return 1; } if (n == 0) { return 0; } else if (n <= (1L << (level - 1)) * 4 - 3) { return getpatti(level - 1, n - 1); } else if (n == (1L << (level - 1)) * 4 - 2) { return (1L << (level - 1)) * 2; } else if (n <= (1L << (level - 1)) * 8 - 5) { return (1L << (level - 1)) * 2 + getpatti(level - 1, n - (1L << (level - 1)) * 4 + 1); } else { return (1L << level) * 2 - 1; } } static bool DFS(int now, int last) { visited[now] = true; for (int i = 0; i < togo[now].Count; i++) { if (togo[now][i] == last) { continue; } if (visited[togo[now][i]]) { return false; } if (!DFS(togo[now][i], now)) { return false; } } return true; } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public List<int> Topological_Sort(List<List<Edge>> G) { var ret = new List<int>(); var Nodes = new Queue<int>(); int N = G.Count(); var Link = new int[N]; for (var i = 0; i < N; i++) { Link[i] = 0; } for (var i = 0; i < N; i++) { foreach (var nx in G[i]) { Link[nx.to]++; } } for (var i = 0; i < N; i++) { if (Link[i] == 0) { Nodes.Enqueue(i); } } while (Nodes.Any()) { var nd = Nodes.Dequeue(); ret.Add(nd); foreach (var nx in G[nd]) { Link[nx.to]--; if (Link[nx.to] == 0) { Nodes.Enqueue(nx.to); } } } return ret; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(int n) { char[] kore = new char[n]; for (int i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(int n, int m) { char[,] kore = new char[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { public static long mod = 1000000007; public long num; public Mlong(long num) { this.num = num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } 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; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace Atcoder { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Program { static bool[] visited; static List<int>[] togo; static void Main(string[] args) { long mod = 1000000007; StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); int n = scan.Integer(); long x = scan.Long(); Console.WriteLine(getpatti(n, x - 1)); } static long getpatti(int level, long n) { if (level == 0) { return 1; } if (n == 0) { return 0; } else if (n <= (1L << (level - 1)) * 4 - 3) { return getpatti(level - 1, n - 1); } else if (n == (1L << (level - 1)) * 4 - 2) { return (1L << (level - 1)) * 2; } else if (n <= (1L << (level - 1)) * 8 - 5) { return (1L << (level - 1)) * 2 + getpatti(level - 1, n - (1L << (level - 1)) * 4 + 1); } else { return (1L << level) * 2 - 1; } } static bool DFS(int now, int last) { visited[now] = true; for (int i = 0; i < togo[now].Count; i++) { if (togo[now][i] == last) { continue; } if (visited[togo[now][i]]) { return false; } if (!DFS(togo[now][i], now)) { return false; } } return true; } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public List<int> Topological_Sort(List<List<Edge>> G) { var ret = new List<int>(); var Nodes = new Queue<int>(); int N = G.Count(); var Link = new int[N]; for (var i = 0; i < N; i++) { Link[i] = 0; } for (var i = 0; i < N; i++) { foreach (var nx in G[i]) { Link[nx.to]++; } } for (var i = 0; i < N; i++) { if (Link[i] == 0) { Nodes.Enqueue(i); } } while (Nodes.Any()) { var nd = Nodes.Dequeue(); ret.Add(nd); foreach (var nx in G[nd]) { Link[nx.to]--; if (Link[nx.to] == 0) { Nodes.Enqueue(nx.to); } } } return ret; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(int n) { char[] kore = new char[n]; for (int i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(int n, int m) { char[,] kore = new char[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { public static long mod = 1000000007; public long num; public Mlong(long num) { this.num = num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } 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; } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
12,001
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var s = stra(); int a = int.Parse(s[0]); var b = long.Parse(s[1]); var num = new long[51]; var pnum = new long[51]; num[0] = 1; pnum[0] = 1; for (int i = 1; i < 51; i++) { num[i] = num[i - 1] * 2 + 3; pnum[i] = pnum[i - 1] * 2 + 1; } WriteLine(function(a, b, num, pnum)); } static long function(int n, long x, long[] num, long[] pnum) { if (x == 1) { if (n == 0) { return 1; } else { return 0; } } else if (1 < x && x <= num[n - 1] + 1) { // WriteLine(1); return function(n - 1, x - 1, num, pnum); } else if (x == num[n - 1] + 2) { // WriteLine(2); return pnum[n - 1] + 1; } else if (num[n - 1] + 2 < x && x < 2 * num[n - 1] + 2) { // WriteLine(3); return function(n - 1, x - 2 - num[n - 1], num, pnum) + pnum[n - 1]; } else { // WriteLine(4); return pnum[n - 1] * 2 + 1; } } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 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 char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var s = stra(); int a = int.Parse(s[0]); var b = long.Parse(s[1]); var num = new long[51]; var pnum = new long[51]; num[0] = 1; pnum[0] = 1; for (int i = 1; i < 51; i++) { num[i] = num[i - 1] * 2 + 3; pnum[i] = pnum[i - 1] * 2 + 1; } WriteLine(function(a, b, num, pnum)); } static long function(int n, long x, long[] num, long[] pnum) { if (x == 1) { if (n == 0) { return 1; } else { return 0; } } else if (1 < x && x <= num[n - 1] + 1) { // WriteLine(1); return function(n - 1, x - 1, num, pnum); } else if (x == num[n - 1] + 2) { // WriteLine(2); return pnum[n - 1] + 1; } else if (num[n - 1] + 2 < x && x <= 2 * num[n - 1] + 2) { // WriteLine(3); return function(n - 1, x - 2 - num[n - 1], num, pnum) + pnum[n - 1] + 1; } else { // WriteLine(4); return pnum[n - 1] * 2 + 1; } } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 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 char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
[["-", 75, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["+", 75, 57, 64, 196, 0, 37, 0, 16, 17, 72], ["+", 75, 57, 64, 196, 0, 37, 0, 16, 12, 203]]
8
1,401
using System; class D { static void Main() { var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long n = h[0], x = h[1]; var p = new long[n + 1]; p[0] = 1; var c = new long[n + 1]; c[0] = 1; for (int i = 0; i < n; i++) { p[i + 1] = 2 * p[i] + 1; c[i + 1] = 2 * c[i] + 3; } Console.WriteLine(Find(n, x, p, c)); } static long Find(long n, long x, long[] p, long[] c) { return x <= 1 ? 0 : x <= c[n - 1] + 1 ? Find(n - 1, x - 1, p, c) : x <= c[n - 1] + 2 ? p[n - 1] + 1 : x <= c[n] - 1 ? p[n - 1] + 1 + Find(n - 1, x - c[n - 1] - 2, p, c) : p[n]; } }
using System; class D { static void Main() { var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long n = h[0], x = h[1]; var p = new long[n + 1]; p[0] = 1; var c = new long[n + 1]; c[0] = 1; for (int i = 0; i < n; i++) { p[i + 1] = 2 * p[i] + 1; c[i + 1] = 2 * c[i] + 3; } Console.WriteLine(Find(n, x, p, c)); } static long Find(long n, long x, long[] p, long[] c) { return n == 0 ? 1 : x <= 1 ? 0 : x <= c[n - 1] + 1 ? Find(n - 1, x - 1, p, c) : x <= c[n - 1] + 2 ? p[n - 1] + 1 : x <= c[n] - 1 ? p[n - 1] + 1 + Find(n - 1, x - c[n - 1] - 2, p, c) : p[n]; } }
[["+", 8, 196, 0, 37, 0, 41, 15, 16, 31, 22], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 17, 60], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 101], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 64, 203], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 102]]
8
271
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static long[] num; static long[] p; static void Solve() { var nx = Input.arL; num = new long[nx[0] + 1]; num[0] = 1; p = new long[nx[0] + 1]; p[0] = 1; for (var i = 1; i <= nx[0]; i++) { num[i] = 2 * num[i - 1] + 3; p[i] = 2 * p[i - 1] + 1; } WriteLine(rec(nx[0], nx[1])); } static long rec(long lev, long x) { if (lev == 0) return ToInt32(x == 1); var q = (num[lev] + 1) / 2; if (x == q) return rec(lev - 1, q - 2) + 1; else if (x < q) return rec(lev - 1, x - 1); else return rec(lev - 1, x - q) + 1 + p[lev - 1]; } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static long[] num; static long[] p; static void Solve() { var nx = Input.arL; num = new long[nx[0] + 1]; num[0] = 1; p = new long[nx[0] + 1]; p[0] = 1; for (var i = 1; i <= nx[0]; i++) { num[i] = 2 * num[i - 1] + 3; p[i] = 2 * p[i - 1] + 1; } WriteLine(rec(nx[0], nx[1])); } static long rec(long lev, long x) { if (lev == 0) return ToInt32(x >= 1); var q = (num[lev] + 1) / 2; if (x == q) return rec(lev - 1, q - 2) + 1; else if (x < q) return rec(lev - 1, x - 1); else return rec(lev - 1, x - q) + 1 + p[lev - 1]; } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 60], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 20]]
8
933
using System; namespace question4 { class Program2 { static void Main(string[] args) { var p = new Program2(); p.Run(); } private long[] ai; private long[] pi; void Run() { var line = Console.ReadLine(); var n = int.Parse(line.Split(' ')[0]); var x = long.Parse(line.Split(' ')[1]); ai = new long[n + 1]; pi = new long[n + 1]; ai[0] = 1; pi[0] = 1; for (int i = 1; i <= n; i++) { ai[i] = ai[i - 1] * 2 + 3; pi[i] = pi[i - 1] * 2 + 1; } var ans = this.Func(n, x); Console.WriteLine(ans); } long Func(int n, long x) { if (x == 0) { return n == 0 ? 1 : 0; } if (x <= ai[n - 1] + 1) { return this.Func(n - 1, x - 1); } else if (x == ai[n - 1] + 2) { return pi[n - 1] + 1; } else if (x <= ai[n - 1] * 2 + 2) { return pi[n - 1] + 1 + this.Func(n - 1, x - (ai[n - 1] + 2)); } else { return pi[n]; } } } }
using System; namespace question4 { class Program2 { static void Main(string[] args) { var p = new Program2(); p.Run(); } private long[] ai; private long[] pi; void Run() { var line = Console.ReadLine(); var n = int.Parse(line.Split(' ')[0]); var x = long.Parse(line.Split(' ')[1]); ai = new long[n + 1]; pi = new long[n + 1]; ai[0] = 1; pi[0] = 1; for (int i = 1; i <= n; i++) { ai[i] = ai[i - 1] * 2 + 3; pi[i] = pi[i - 1] * 2 + 1; } var ans = this.Func(n, x); Console.WriteLine(ans); } long Func(int n, long x) { if (n == 0) { return x == 1 ? 1 : 0; } if (x <= ai[n - 1] + 1) { return this.Func(n - 1, x - 1); } else if (x == ai[n - 1] + 2) { return pi[n - 1] + 1; } else if (x <= ai[n - 1] * 2 + 2) { return pi[n - 1] + 1 + this.Func(n - 1, x - (ai[n - 1] + 2)); } else { return pi[n]; } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 64, 196, 0, 37, 0, 41, 15, 16, 31, 22], ["+", 64, 196, 0, 37, 0, 41, 15, 16, 31, 22], ["-", 64, 196, 0, 37, 0, 41, 15, 16, 12, 203], ["+", 64, 196, 0, 37, 0, 41, 15, 16, 12, 203]]
8
346
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const int MOD = 1000000007; private static List<long> ps = null; static void Solve() { var nk = ReadAndParseLongArr(); long n = nk[0]; long x = nk[1]; long length = powNoMod(2, n + 2) - 3; ps = new List<long>(); for (int i = 0; i <= n; ++i) { ps.Add(pow(2, i + 1) - 1); } long ans = CalcP(x - 1, 0, length - 1, (int)n); Console.WriteLine(ans); } private static long CalcP(long x, long a, long b, int n) { if (a == b) { return 1; } long halfP = (b - a) / 2 + a; if (x == a) { return 0; } else if (x < halfP) { return CalcP(x, a + 1, halfP - 1, n - 1); } else if (x == halfP) { return ps[n - 1] + 1; } else // (x <= b) { return ps[n - 1] + 1 + CalcP(x, halfP + 1, b - 1, n - 1); } } private static long powNoMod(long x, long n) { if (n == 0) { return 1; } long res = powNoMod(x * x, n / 2); if (n % 2 == 1) { res = res * x; } return res; } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const int MOD = 1000000007; private static List<long> ps = null; static void Solve() { var nk = ReadAndParseLongArr(); long n = nk[0]; long x = nk[1]; long length = powNoMod(2, n + 2) - 3; ps = new List<long>(); for (int i = 0; i <= n; ++i) { ps.Add(powNoMod(2, i + 1) - 1); } long ans = CalcP(x - 1, 0, length - 1, (int)n); Console.WriteLine(ans); } private static long CalcP(long x, long a, long b, int n) { if (a == b) { return 1; } long halfP = (b - a) / 2 + a; if (x == a) { return 0; } else if (x < halfP) { return CalcP(x, a + 1, halfP - 1, n - 1); } else if (x == halfP) { return ps[n - 1] + 1; } else // (x <= b) { return ps[n - 1] + 1 + CalcP(x, halfP + 1, b - 1, n - 1); } } private static long powNoMod(long x, long n) { if (n == 0) { return 1; } long res = powNoMod(x * x, n / 2); if (n % 2 == 1) { res = res * x; } return res; } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
[["-", 3, 4, 0, 28, 0, 16, 31, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 213, 63, 22]]
8
663
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { using VI = VectorInt2; static class Program { static long[] size = new long[51]; static long[] pate = new long[51]; static void Main() { var n = ReadInt(); var x = ReadLong(); pate[0] = 1; size[0] = 1; checked { for (int i = 1; i <= 50; i++) { pate[i] = pate[i - 1] * 2 + 1; size[i] = size[i - 1] * 2 + 3; } } calc_pate(n, x - 1).WriteLine(); } static long calc_pate(int m, long index) { checked { var mid = size[m] / 2; if (m == 0) return 1; if (index == 0) return 0; if (index < mid) return calc_pate(m - 1, index - 1); if (index == mid) return pate[m - 1] + 1; if (index < size[m] - 1) return pate[m - 1] + 1 + calc_pate(m - 1, index - mid - 1); /* if (index ==size[m] - 1) */ return 2 * pate[m - 1]; } } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Multiply); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Multiply); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Multiply(long i, long j) => i * j; public static Func<long, long> Multiply(long j) => i => i * j; public static long Divide(long i, long j) => j / j; public static Func<long, long> Divide(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static long Max(params long[] ns) => ns.Max(); public static long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<long> Factors(this long n) { for (long i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static void Write<T>(this T t) => Console.Write(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Multiply); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine(); } public struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } class MultiSet<T> : IEnumerable<KeyValuePair<T, int>> { Dictionary<T, int> dictionary = new Dictionary<T, int>(); public MultiSet(IEnumerable<T> data) { foreach (var datum in data) { if (dictionary.ContainsKey(datum)) { dictionary[datum]++; } else { dictionary[datum] = 1; } } } public bool Contains(T t) => dictionary.ContainsKey(t); public void RemoveIfAny(T t) { if (dictionary.ContainsKey(t)) { dictionary[t]--; if (dictionary[t] == 0) { dictionary.Remove(t); } } } public int this[T key] { get { return dictionary.ContainsKey(key) ? dictionary[key] : 0; } } public MultiSet() {} public static MultiSet<S> ToMultiSet<S>(IEnumerable<S> source) => new MultiSet<S>(source); public Dictionary<T, int> AsDict() => dictionary; public IEnumerator<KeyValuePair<T, int>> GetEnumerator() => dictionary.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { using VI = VectorInt2; static class Program { static long[] size = new long[51]; static long[] pate = new long[51]; static void Main() { var n = ReadInt(); var x = ReadLong(); pate[0] = 1; size[0] = 1; checked { for (int i = 1; i <= 50; i++) { pate[i] = pate[i - 1] * 2 + 1; size[i] = size[i - 1] * 2 + 3; } } calc_pate(n, x - 1).WriteLine(); } static long calc_pate(int m, long index) { checked { var mid = size[m] / 2; if (m == 0) return 1; if (index == 0) return 0; if (index < mid) return calc_pate(m - 1, index - 1); if (index == mid) return pate[m - 1] + 1; if (index < size[m] - 1) return pate[m - 1] + 1 + calc_pate(m - 1, index - mid - 1); /* if (index ==size[m] - 1) */ return 2 * pate[m - 1] + 1; } } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Multiply); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Multiply); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Multiply(long i, long j) => i * j; public static Func<long, long> Multiply(long j) => i => i * j; public static long Divide(long i, long j) => j / j; public static Func<long, long> Divide(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static long Max(params long[] ns) => ns.Max(); public static long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<long> Factors(this long n) { for (long i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static void Write<T>(this T t) => Console.Write(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Multiply); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine(); } public struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } class MultiSet<T> : IEnumerable<KeyValuePair<T, int>> { Dictionary<T, int> dictionary = new Dictionary<T, int>(); public MultiSet(IEnumerable<T> data) { foreach (var datum in data) { if (dictionary.ContainsKey(datum)) { dictionary[datum]++; } else { dictionary[datum] = 1; } } } public bool Contains(T t) => dictionary.ContainsKey(t); public void RemoveIfAny(T t) { if (dictionary.ContainsKey(t)) { dictionary[t]--; if (dictionary[t] == 0) { dictionary.Remove(t); } } } public int this[T key] { get { return dictionary.ContainsKey(key) ? dictionary[key] : 0; } } public MultiSet() {} public static MultiSet<S> ToMultiSet<S>(IEnumerable<S> source) => new MultiSet<S>(source); public Dictionary<T, int> AsDict() => dictionary; public IEnumerator<KeyValuePair<T, int>> GetEnumerator() => dictionary.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } }
[["+", 0, 287, 0, 196, 0, 37, 0, 16, 17, 72], ["+", 0, 287, 0, 196, 0, 37, 0, 16, 12, 203]]
8
4,634
using System; using static System.Console; namespace Main { class Program { static void Main(string[] args) { int X = int.Parse(ReadLine()); WriteLine(X == 7 || X == 5 || X == 3 ? "Yes" : "No"); } } }
using System; using static System.Console; namespace Main { class Program { static void Main(string[] args) { int X = int.Parse(ReadLine()); WriteLine(X == 7 || X == 5 || X == 3 ? "YES" : "NO"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
63
using System; using System.IO; using System.Linq; using static ABC114A.Input; namespace ABC114A { 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 int X; public void Solve() { Cin(out X); if (X == 3 || X == 5 || X == 7) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.IO; using System.Linq; using static ABC114A.Input; namespace ABC114A { 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 = Convert<string[]>(String()); 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 int X; public void Solve() { Cin(out X); if (X == 3 || X == 5 || X == 7) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,417
using System; class ac { static void Main() { int s = int.Parse(Console.ReadLine()); if (s == 3 || s == 5 || s == 7) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; class ac { static void Main() { int s = int.Parse(Console.ReadLine()); if (s == 3 || s == 5 || s == 7) Console.WriteLine("YES"); else Console.WriteLine("NO"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
61
using System; public class HelloWorld { static public void Main() { var num = int.Parse(Console.ReadLine()); if (num == 7 || num == 5 || num == 3) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } }
using System; public class HelloWorld { static public void Main() { var num = int.Parse(Console.ReadLine()); if (num == 7 || num == 5 || num == 3) { 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
67
using System; namespace test { class Program { static void Main(string[] args) { string b = Console.ReadLine(); int A = int.Parse(b); string an; if (A == 3 || A == 5 || A == 7) { an = "Yes"; } else { an = "No"; } Console.Write(an); } } }
using System; namespace test { class Program { static void Main(string[] args) { string b = Console.ReadLine(); int A = int.Parse(b); string an; if (A == 3 || A == 5 || A == 7) { an = "YES"; } else { an = "NO"; } Console.Write(an); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
82
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int a; a = int.Parse(Console.ReadLine()); if (a == 3 || a == 5 || a == 7) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int a; a = int.Parse(Console.ReadLine()); if (a == 3 || a == 5 || a == 7) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
101
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); if (x == 7 || x == 5 || x == 3) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int x; x = int.Parse(Console.ReadLine()); if (x == 7 || x == 3 || x == 5) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
99
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int X; string b; var word = Console.ReadLine().Split(' '); X = int.Parse(word[0]); if (X == 3 || X == 5 || X == 7) { b = "Yes"; } else { b = "No"; } Console.WriteLine(b); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int X; string b; var word = Console.ReadLine().Split(' '); X = int.Parse(word[0]); if (X == 3 || X == 5 || X == 7) { b = "YES"; } else { b = "NO"; } Console.WriteLine(b); Console.ReadKey(); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
124
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); if ((x == 3) || (x == 5) || (x == 7)) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); if ((x == 3) || (x == 5) || (x == 7)) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
105
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int a; var word = Console.ReadLine(); a = int.Parse(word); if (((a > 2 && a < 3) || (a > 4 && a < 6) || (a > 6 && a < 8))) Console.WriteLine("OK"); else { Console.WriteLine("NO"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC114A { class Program { static void Main(string[] args) { int a; var word = Console.ReadLine(); a = int.Parse(word); if (((a > 2 && a < 4) || (a > 4 && a < 6) || (a > 6 && a < 8))) Console.WriteLine("YES"); else { Console.WriteLine("NO"); } Console.ReadKey(); } } }
[["-", 31, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
128
using System; namespace ABC114_a { class Program { static void Main(string[] args) { string[] array = Console.ReadLine().Split(' '); int a = int.Parse(array[0]); if ((a == 3) || (a == 5) || (a == 7)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace ABC114_a { class Program { static void Main(string[] args) { string[] array = Console.ReadLine().Split(' '); int a = int.Parse(array[0]); if ((a == 3) || (a == 5) || (a == 7)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
96
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static ABC114.Util; using static System.Console; #if DEBUG using System.Diagnostics; #endif namespace ABC114 { class Program { static void Main(string[] args) { START: Shitigosan(); #if DEBUG goto START; #endif } private static void Shitigosan() { int X = ReadInt(); if (X == 7 || X == 5 || X == 3) { WriteLine("Yes"); } else { WriteLine("No"); } } } #region ToolBox /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadIntArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static string ReadString() { return Console.ReadLine(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray(); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { return Console.ReadLine().Select(c => c == '1').ToArray(); } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 逆順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] ReverseSort<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } #if DEBUG static void SampleGenerator() { int A = 1000; int B = 1000; int Q = 1000; Random r = new Random(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("{0} {1} {2}", A, B, Q)); A.Times(a => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); B.Times(b => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Q.Times(q => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Debug.WriteLine(sb.ToString()); } #endif } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static ABC114.Util; using static System.Console; #if DEBUG using System.Diagnostics; #endif namespace ABC114 { class Program { static void Main(string[] args) { START: Shitigosan(); #if DEBUG goto START; #endif } private static void Shitigosan() { int X = ReadInt(); if (X == 7 || X == 5 || X == 3) { WriteLine("YES"); } else { WriteLine("NO"); } } } #region ToolBox /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadIntArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static string ReadString() { return Console.ReadLine(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray(); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { return Console.ReadLine().Select(c => c == '1').ToArray(); } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 逆順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] ReverseSort<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } #if DEBUG static void SampleGenerator() { int A = 1000; int B = 1000; int Q = 1000; Random r = new Random(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("{0} {1} {2}", A, B, Q)); A.Times(a => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); B.Times(b => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Q.Times(q => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Debug.WriteLine(sb.ToString()); } #endif } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } #endregion }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
2,346
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder08 { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); if (a == 3 || a == 5 || a == 7) { Console.WriteLine("yes"); } else Console.WriteLine("no"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder08 { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); if (a == 3 || a == 5 || a == 7) { Console.WriteLine("YES"); } else Console.WriteLine("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
95
using System; using System.Collections; using System.Collections.Generic; using System.Text; public class A { public static void Main() { int X = Int32.Parse(Console.ReadLine()); string ans = null; switch (X) { case 7: case 5: case 3: ans = "YES"; break; default: ans = "No"; break; } Console.WriteLine(ans); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; public class A { public static void Main() { int X = Int32.Parse(Console.ReadLine()); string ans = null; switch (X) { case 7: case 5: case 3: ans = "YES"; break; default: ans = "NO"; break; } Console.WriteLine(ans); } }
[["-", 0, 239, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 239, 0, 1, 0, 11, 12, 5, 0, 222]]
8
92
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { class Program { static void Main() { //ここから int x = ReadLineToInt(); string ans = x == 3 || x == 5 || x == 7 ? "Yes" : "No"; Console.WriteLine(ans); Console.ReadKey(); } static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(int a, int b) { return (long)a * b / GCD(a, b); } static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public string[] ReadLineToStringArray() { return Console.ReadLine().Split(' ').ToArray(); } static public int[] ReadLineToIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { class Program { static void Main() { //ここから int x = ReadLineToInt(); string ans = x == 3 || x == 5 || x == 7 ? "YES" : "NO"; Console.WriteLine(ans); Console.ReadKey(); } static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(int a, int b) { return (long)a * b / GCD(a, b); } static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public string[] ReadLineToStringArray() { return Console.ReadLine().Split(' ').ToArray(); } static public int[] ReadLineToIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
433
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var X = cin.ReadInt; string result = "No"; if (X == 3 || X == 5 || X == 7) { result = "Yes"; } Console.Write(result); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var X = cin.ReadInt; string result = "NO"; if (X == 3 || X == 5 || X == 7) { result = "YES"; } Console.Write(result); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
467
using System; using System.IO; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); if (x == 7 || x == 5 || x == 3) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); if (x == 7 || x == 5 || x == 3) { 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
90
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace template { class Program { static void Main(string[] args) { int imp = Convert.ToInt32(Console.ReadLine()); switch (imp) { case 7: case 5: case 3: Console.WriteLine("Yes"); break; default: Console.WriteLine("No"); break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace template { class Program { static void Main(string[] args) { int imp = Convert.ToInt32(Console.ReadLine()); switch (imp) { case 7: case 5: case 3: Console.WriteLine("YES"); break; default: Console.WriteLine("NO"); break; } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
99
using System; class Program { static void Main() { int x; x = int.Parse(Console.ReadLine()); //標準入力 // string[] str = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 b = int.Parse(str[0]); // //数値で受け取りたい場合は変換する c = int.Parse(str[1]); if (x == 3 | x == 5 | x == 7) { Console.Write("Yes"); //改行なし出力 } else { Console.Write("No"); //改行なし出力 } // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, // c);//改行付き出力 } }
using System; class Program { static void Main() { int x; x = int.Parse(Console.ReadLine()); //標準入力 // string[] str = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 b = int.Parse(str[0]); // //数値で受け取りたい場合は変換する c = int.Parse(str[1]); if (x == 3 || x == 5 || x == 7) { Console.Write("YES"); //改行なし出力 } else { Console.Write("NO"); //改行なし出力 } // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, // c);//改行付き出力 } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 139], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 139], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
75
using System; class Program { static void Main(string[] args) { var str = Console.ReadLine(); if (str == "3" && str == "5" && str == "7") { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; class Program { static void Main(string[] args) { var str = Console.ReadLine(); if (str == "3" || str == "5" || str == "7") { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
8
70
using System; class Program { static void Main(String[] args) { int b = int.Parse(Console.ReadLine()); if (b == 7 || b == 5 || b == 3) { Console.WriteLine("YES"); } else { Console.WriteLine("No"); } } }
using System; class Program { static void Main(String[] args) { int b = int.Parse(Console.ReadLine()); if (b == 7 || b == 5 || b == 3) { 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
69
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_ABC089_A { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); bool answer = a == 7 || a == 5 || a == 3; Console.WriteLine(answer ? "true" : "false"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_ABC089_A { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); bool answer = a == 7 || a == 5 || a == 3; Console.WriteLine(answer ? "YES" : "NO"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
90