{"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Linq;\n\nnamespace Codeforces.TaskE\n{\n public class Task\n {\n void Solve()\n {\n long n, x, y, dx, dy, t;\n Input.Next(out n, out x, out y, out dx, out dy, out t);\n\n while (dx < 0) dx += n;\n while (dy < 0) dy += n;\n var v = new long[] {x-1, y-1, dx, dy, 0, 1};\n\n // k = x + y + t + 2\n // dx' = dx + k = dx + x + y + t + 2\n // dy' = dy + k = dy + x + y + t + 2\n // x'= x + dx' = 2x + y + dx + t + 2\n // y'= y + dy' = x + 2y + dy + t + 2\n // t' = t + 1\n\n // x=0 y=1 dx=0 dy=1 t=0 k=3 dx'=3 dy'=4\n // x=3 y=0 dx=3 dy=4 t=1 k=6 dx'=4 dy'=0\n // x=2 y=0 dx=1 dy=2 t=2\n\n\n\n var m1 = Matrix.Create(new[,] { { 2, 1, 1, 1, 0, 0 }, \n { 1, 2, 1, 1, 0, 0 },\n { 1, 0, 1, 0, 0, 0 },\n { 0, 1, 0, 1, 0, 0 },\n { 1, 1, 1, 1, 1, 0 },\n { 2, 2, 2, 2, 1, 1 }\n });\n m1.Modulo = n;\n var u = v*m1.BinPower(t);\n/*\n var u1 = v*m1;\n var u2 = u1*m1;\n var u3 = u2 * m1;\n var u4 = u3 * m1;\n var u5 = u4 * m1;\n */ \n Console.WriteLine(++u[0] + \" \" + ++u[1]);\n }\n\n public static void Main()\n {\n var task = new Task();\n #if DEBUG\n task.Solve();\n #else\n try\n {\n task.Solve();\n }\n catch (Exception ex)\n {\n Console.ForegroundColor = ConsoleColor.Red;\n Console.WriteLine(ex);\n }\n #endif\n }\n }\n}\n\nnamespace Codeforces\n{\n public class Input\n {\n private static string _line;\n\n public static bool Next()\n {\n _line = Console.ReadLine();\n return _line != null;\n }\n\n public static bool Next(out long a)\n {\n var ok = Next();\n a = ok ? long.Parse(_line) : 0;\n return ok;\n }\n\n public static bool Next(out long a, out long b)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n }\n else\n {\n a = b = 0;\n }\n\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n }\n else\n {\n a = b = c = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n }\n else\n {\n a = b = c = d = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d, out long e)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n }\n else\n {\n a = b = c = d = e = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d, out long e, out long f)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n f = array[5];\n }\n else\n {\n a = b = c = d = e = f = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a)\n {\n var ok = Next();\n a = ok ? int.Parse(_line) : 0;\n return ok;\n }\n\n public static bool Next(out int a, out int b)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n }\n else\n {\n a = b = 0;\n }\n\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n }\n else\n {\n a = b = c = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c, out int d)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n }\n else\n {\n a = b = c = d = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c, out int d, out int e)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n }\n else\n {\n a = b = c = d = e = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c, out int d, out int e, out int f)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n f = array[5];\n }\n else\n {\n a = b = c = d = e = f = 0;\n }\n return ok;\n }\n\n public static IEnumerable ArrayLong()\n {\n return !Next() ? new List() : _line.Split().Select(long.Parse);\n }\n\n public static IEnumerable ArrayInt()\n {\n return !Next() ? new List() : _line.Split().Select(int.Parse);\n }\n\n public static bool Next(out string value)\n {\n value = string.Empty;\n if (!Next()) return false;\n value = _line;\n return true;\n }\n }\n\n public class DisjointSet\n {\n private readonly int[] _parent;\n private readonly int[] _rank;\n public int Count { get; private set; }\n\n public DisjointSet(int count, int initialize = 0)\n {\n Count = count;\n _parent = new int[Count];\n _rank = new int[Count];\n for (var i = 0; i < initialize; i++) _parent[i] = i;\n }\n\n private DisjointSet(int count, int[] parent, int[] rank)\n {\n Count = count;\n _parent = parent;\n _rank = rank;\n }\n\n public void Add(int v)\n {\n _parent[v] = v;\n _rank[v] = 0;\n }\n\n public int Find_Recursive(int v)\n {\n if (_parent[v] == v) return v;\n return _parent[v] = Find(_parent[v]);\n }\n\n public int Find(int v)\n {\n if (_parent[v] == v) return v;\n var last = v;\n while (_parent[last] != last) last = _parent[last];\n while (_parent[v] != v)\n {\n var t = _parent[v];\n _parent[v] = last;\n v = t;\n }\n return last;\n }\n\n public int this[int v]\n {\n get { return Find(v); }\n set { Union(v, value); }\n }\n\n public void Union(int a, int b)\n {\n a = Find(a);\n b = Find(b);\n if (a == b) return;\n if (_rank[a] < _rank[b])\n {\n var t = _rank[a];\n _rank[a] = _rank[b];\n _rank[b] = t;\n }\n _parent[b] = a;\n if (_rank[a] == _rank[b]) _rank[a]++;\n }\n\n public int GetSetCount()\n {\n var result = 0;\n for (var i = 0; i < Count; i++)\n {\n if (_parent[i] == i) result++;\n }\n return result;\n }\n\n public DisjointSet Clone()\n {\n var rank = new int[Count];\n _rank.CopyTo(rank, 0);\n var parent = new int[Count];\n _parent.CopyTo(parent, 0);\n return new DisjointSet(Count, parent, rank);\n }\n\n public override string ToString()\n {\n return string.Join(\",\", _parent.Take(50));\n }\n }\n\n public class Matrix\n {\n public static Matrix Create(int[,] array)\n {\n var I = array.GetUpperBound(0) + 1;\n var J = array.GetUpperBound(1) + 1;\n var m = new Matrix(I, J);\n for(var i=0;i : IEnumerable>\n {\n private readonly List _items;\n private Node _root;\n private readonly IComparer _comparer;\n\n public RedBlackTree(int capacity = 10)\n {\n _items = new List(capacity);\n _comparer = Comparer.Default;\n }\n\n private Node _search(TKey key)\n {\n var node = _root;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return node;\n node = i > 0 ? node.Right : node.Left;\n }\n return null;\n }\n\n /// \n /// Returns lower or equal key\n /// \n public TKey Lower(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i > 0)\n {\n good = node;\n node = node.Right;\n }\n else\n node = node.Left;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns higher or equal key\n /// \n public TKey Higher(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i < 0)\n {\n good = node;\n node = node.Left;\n }\n else\n node = node.Right;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns minimum region, which encloses given key\n /// \n public Tuple Bounds(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node lower = null;\n Node higher = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return new Tuple(key, key);\n if (i < 0)\n {\n higher = node;\n node = node.Left;\n }\n else\n {\n lower = node;\n node = node.Right;\n }\n }\n return new Tuple(lower == null ? notFound : lower.Key, higher == null ? notFound : higher.Key);\n }\n\n public void Add(TKey key, TValue value)\n {\n var node = new Node { Key = key, Value = value, Red = true };\n _items.Add(node);\n if (_root == null)\n {\n _root = node;\n _root.Red = false;\n return;\n }\n var x = _root;\n Node y = null;\n while (x != null)\n {\n y = x;\n x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;\n }\n node.Parent = y;\n if (y == null) _root = node;\n else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;\n else y.Left = node;\n InsertFixup(node);\n }\n\n private void InsertFixup(Node node)\n {\n while (true)\n {\n var parent = node.Parent;\n if (parent == null || !parent.Red || parent.Parent == null) break;\n var grand = parent.Parent;\n\n if (parent == grand.Left)\n {\n var uncle = grand.Right;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Right) /* we rotate around the parent */\n {\n node = parent;\n RotateLeft(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateRight(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n else\n {\n if (_root.Parent != null) Debugger.Break();\n\n var uncle = grand.Left;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Left) /* we rotate around the parent */\n {\n node = parent;\n RotateRight(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateLeft(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n }\n _root.Red = false;\n }\n\n private void RotateLeft(Node node)\n {\n if (node.Right == null)\n throw new NotSupportedException(\"Cannot rotate left: right node is missing\");\n var parent = node.Parent;\n var right = node.Right;\n right.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = right;\n else parent.Right = right;\n }\n node.Right = right.Left;\n if (node.Right != null)\n node.Right.Parent = node;\n right.Left = node;\n node.Parent = right;\n }\n\n private void RotateRight(Node node)\n {\n if (node.Left == null)\n throw new NotSupportedException(\"Cannot rotate right: left node is missing\");\n var parent = node.Parent;\n var left = node.Left;\n left.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = left;\n else parent.Right = left;\n }\n node.Left = left.Right;\n if (node.Left != null)\n node.Left.Parent = node;\n left.Right = node;\n node.Parent = left;\n }\n\n public void Remove(TKey key)\n {\n var node = _search(key);\n if (node == null) return;\n\n var deleted = node.Left == null || node.Right == null ? node : Next(node);\n var child = deleted.Left ?? deleted.Right;\n if (child != null)\n child.Parent = deleted.Parent;\n if (deleted.Parent == null) /* root */\n _root = child;\n else if (deleted == deleted.Parent.Left)\n deleted.Parent.Left = child;\n else\n deleted.Parent.Right = child;\n if (node != deleted)\n {\n node.Key = deleted.Key;\n node.Value = deleted.Value;\n }\n\n if (!deleted.Red)\n {\n DeleteFixup(child, deleted.Parent);\n }\n }\n\n private void DeleteFixup(Node node, Node parent)\n {\n while (parent != null && (node == null || !node.Red))\n {\n if (node == parent.Left)\n {\n var brother = parent.Right;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateLeft(parent);\n brother = parent.Right;\n }\n if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Right == null || !brother.Right.Red)\n {\n if (brother.Left != null)\n brother.Left.Red = false;\n brother.Red = true;\n RotateRight(brother);\n brother = parent.Right;\n }\n if (!brother.Right.Red) Debugger.Break();\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Right != null)\n brother.Right.Red = false;\n RotateLeft(parent);\n node = _root;\n }\n }\n else\n {\n var brother = parent.Left;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateRight(parent);\n brother = parent.Left;\n }\n if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Left == null || !brother.Left.Red)\n {\n if (brother.Right != null)\n brother.Right.Red = false;\n brother.Red = true;\n RotateLeft(brother);\n brother = parent.Left;\n }\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Left != null)\n brother.Left.Red = false;\n RotateRight(parent);\n node = _root;\n }\n }\n parent = node.Parent;\n }\n\n node.Red = false;\n }\n\n public TValue this[TKey key]\n {\n get\n {\n var node = _search(key);\n return node == null ? default(TValue) : node.Value;\n }\n set\n {\n var node = _search(key);\n if (node == null) Add(key, value);\n else node.Value = value;\n }\n }\n\n public bool Check()\n {\n int count;\n return _root == null || _root.Check(out count);\n }\n\n private Node Minimum(Node node)\n {\n var result = node;\n while (result.Left != null) result = result.Left;\n return result;\n }\n\n private Node Maximum(Node node)\n {\n var result = node;\n while (result.Right != null) result = result.Right;\n return result;\n }\n\n private Node Next(Node node)\n {\n Node result;\n if (node.Right != null)\n {\n result = Minimum(node.Right);\n }\n else\n {\n while (node.Parent != null && node.Parent.Right == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n private Node Previous(Node node)\n {\n Node result;\n if (node.Left != null)\n {\n result = Maximum(node.Left);\n }\n else\n {\n while (node.Parent != null && node.Parent.Left == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n public void Print()\n {\n var node = Minimum(_root);\n while (node != null)\n {\n Console.Write(node.Red ? '*' : ' ');\n Console.Write(node.Key);\n Console.Write('\\t');\n node = Next(node);\n }\n }\n\n #region Nested classes\n\n [DebuggerDisplay(\"{ToString()}\")]\n private sealed class Node\n {\n public TKey Key;\n public TValue Value;\n public bool Red;\n\n public Node Parent;\n public Node Left;\n public Node Right;\n\n public bool Check(out int count)\n {\n count = 0;\n if (Red)\n {\n if (Left != null && Left.Red) return false;\n if (Right != null && Right.Red) return false;\n }\n var left = 0;\n var right = 0;\n if (Left != null && !Left.Check(out left)) return false;\n if (Right != null && !Right.Check(out right)) return false;\n count = left + (Red ? 0 : 1);\n if (left != right)\n {\n ;\n }\n return left == right;\n }\n\n public override string ToString()\n {\n return ToShortString(2);\n }\n\n private string ToShortString(int depth = 0)\n {\n return depth == 0\n ? string.Format(\"{0}{1}\", Red ? \"*\" : \"\", Key)\n : string.Format(\"({1}<{0}>{2})\", ToShortString(), Left == null ? \"null\" : Left.ToShortString(depth - 1), Right == null ? \"null\" : Right.ToShortString(depth - 1));\n }\n }\n\n #endregion\n\n #region IEnumerable\n\n public IEnumerator> GetEnumerator()\n {\n throw new NotImplementedException();\n }\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return GetEnumerator();\n }\n\n #endregion\n }\n\n public class RedBlackTreeSimple\n {\n private readonly List _items;\n private Node _root;\n private readonly IComparer _comparer;\n\n public RedBlackTreeSimple(int capacity = 10)\n {\n _items = new List(capacity);\n _comparer = Comparer.Default;\n }\n\n private Node _search(TKey key)\n {\n var node = _root;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return node;\n node = i > 0 ? node.Right : node.Left;\n }\n return null;\n }\n\n /// \n /// Returns lower or equal key\n /// \n public TKey Lower(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i > 0)\n {\n good = node;\n node = node.Right;\n }\n else\n node = node.Left;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns higher or equal key\n /// \n public TKey Higher(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i < 0)\n {\n good = node;\n node = node.Left;\n }\n else\n node = node.Right;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns minimum region, which encloses given key\n /// \n public Tuple Bounds(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node lower = null;\n Node higher = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return new Tuple(key, key);\n if (i < 0)\n {\n higher = node;\n node = node.Left;\n }\n else\n {\n lower = node;\n node = node.Right;\n }\n }\n return new Tuple(lower == null ? notFound : lower.Key, higher == null ? notFound : higher.Key);\n }\n\n public void Add(TKey key)\n {\n var node = new Node(key);\n _items.Add(node);\n if (_root == null)\n {\n _root = node;\n _root.Red = false;\n return;\n }\n var x = _root;\n Node y = null;\n while (x != null)\n {\n y = x;\n x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;\n }\n node.Parent = y;\n if (y == null) _root = node;\n else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;\n else y.Left = node;\n InsertFixup(node);\n }\n\n private void InsertFixup(Node node)\n {\n while (true)\n {\n var parent = node.Parent;\n if (parent == null || !parent.Red || parent.Parent == null) break;\n var grand = parent.Parent;\n\n if (parent == grand.Left)\n {\n var uncle = grand.Right;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Right) /* we rotate around the parent */\n {\n node = parent;\n RotateLeft(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateRight(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n else\n {\n if (_root.Parent != null) Debugger.Break();\n\n var uncle = grand.Left;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Left) /* we rotate around the parent */\n {\n node = parent;\n RotateRight(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateLeft(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n }\n _root.Red = false;\n }\n\n private void RotateLeft(Node node)\n {\n if (node.Right == null)\n throw new NotSupportedException(\"Cannot rotate left: right node is missing\");\n var parent = node.Parent;\n var right = node.Right;\n right.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = right;\n else parent.Right = right;\n }\n node.Right = right.Left;\n if (node.Right != null)\n node.Right.Parent = node;\n right.Left = node;\n node.Parent = right;\n }\n\n private void RotateRight(Node node)\n {\n if (node.Left == null)\n throw new NotSupportedException(\"Cannot rotate right: left node is missing\");\n var parent = node.Parent;\n var left = node.Left;\n left.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = left;\n else parent.Right = left;\n }\n node.Left = left.Right;\n if (node.Left != null)\n node.Left.Parent = node;\n left.Right = node;\n node.Parent = left;\n }\n\n public void Remove(TKey key)\n {\n var node = _search(key);\n if (node == null) return;\n\n var deleted = node.Left == null || node.Right == null ? node : Next(node);\n var child = deleted.Left ?? deleted.Right;\n if (child != null)\n child.Parent = deleted.Parent;\n if (deleted.Parent == null) /* root */\n _root = child;\n else if (deleted == deleted.Parent.Left)\n deleted.Parent.Left = child;\n else\n deleted.Parent.Right = child;\n if (node != deleted)\n {\n node.Key = deleted.Key;\n }\n\n if (!deleted.Red)\n {\n DeleteFixup(child, deleted.Parent);\n }\n }\n\n private void DeleteFixup(Node node, Node parent)\n {\n while (parent != null && (node == null || !node.Red))\n {\n if (node == parent.Left)\n {\n var brother = parent.Right;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateLeft(parent);\n brother = parent.Right;\n }\n if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Right == null || !brother.Right.Red)\n {\n if (brother.Left != null)\n brother.Left.Red = false;\n brother.Red = true;\n RotateRight(brother);\n brother = parent.Right;\n }\n if (!brother.Right.Red) Debugger.Break();\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Right != null)\n brother.Right.Red = false;\n RotateLeft(parent);\n node = _root;\n }\n }\n else\n {\n var brother = parent.Left;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateRight(parent);\n brother = parent.Left;\n }\n if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Left == null || !brother.Left.Red)\n {\n if (brother.Right != null)\n brother.Right.Red = false;\n brother.Red = true;\n RotateLeft(brother);\n brother = parent.Left;\n }\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Left != null)\n brother.Left.Red = false;\n RotateRight(parent);\n node = _root;\n }\n }\n parent = node.Parent;\n }\n\n node.Red = false;\n }\n\n private Node Minimum(Node node)\n {\n var result = node;\n while (result.Left != null) result = result.Left;\n return result;\n }\n\n private Node Maximum(Node node)\n {\n var result = node;\n while (result.Right != null) result = result.Right;\n return result;\n }\n\n private Node Next(Node node)\n {\n Node result;\n if (node.Right != null)\n {\n result = Minimum(node.Right);\n }\n else\n {\n while (node.Parent != null && node.Parent.Right == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n private Node Previous(Node node)\n {\n Node result;\n if (node.Left != null)\n {\n result = Maximum(node.Left);\n }\n else\n {\n while (node.Parent != null && node.Parent.Left == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n public void Print()\n {\n var node = Minimum(_root);\n while (node != null)\n {\n Console.Write(node.Red ? '*' : ' ');\n Console.Write(node.Key);\n Console.Write('\\t');\n node = Next(node);\n }\n }\n\n #region Nested classes\n\n private sealed class Node\n {\n public Node(TKey key)\n {\n Key = key;\n }\n\n public TKey Key;\n public bool Red = true;\n\n public Node Parent;\n public Node Left;\n public Node Right;\n }\n\n #endregion\n }\n\n /// \n /// Fenwick tree for summary on the array\n /// \n public class FenwickSum\n {\n public readonly int Size;\n private readonly int[] _items;\n public FenwickSum(int size)\n {\n Size = size;\n _items = new int[Size];\n }\n\n public FenwickSum(IList items)\n : this(items.Count)\n {\n for (var i = 0; i < Size; i++)\n Increase(i, items[i]);\n }\n\n private int Sum(int r)\n {\n if (r < 0) return 0;\n if (r >= Size) r = Size - 1;\n var result = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1)\n result += _items[r];\n return result;\n }\n\n private int Sum(int l, int r)\n {\n return Sum(r) - Sum(l - 1);\n }\n\n public int this[int r]\n {\n get { return Sum(r); }\n }\n\n public int this[int l, int r]\n {\n get { return Sum(l, r); }\n }\n\n public void Increase(int i, int delta)\n {\n for (; i < Size; i = i | (i + 1))\n _items[i] += delta;\n }\n }\n\n /// \n /// Prime numbers\n /// \n public class Primes\n {\n /// \n /// Returns prime numbers in O(n)\n /// Returns lowet divisors as well\n /// Memory O(n)\n /// \n public static void ImprovedSieveOfEratosthenes(int n, out int[] lp, out List pr)\n {\n lp = new int[n];\n pr = new List();\n for (var i = 2; i < n; i++)\n {\n if (lp[i] == 0)\n {\n lp[i] = i;\n pr.Add(i);\n }\n foreach (var prJ in pr)\n {\n var prIj = i * prJ;\n if (prJ <= lp[i] && prIj <= n - 1)\n {\n lp[prIj] = prJ;\n }\n else\n {\n break;\n }\n }\n }\n }\n\n /// \n /// Returns prime numbers in O(n*n)\n /// \n public static void SieveOfEratosthenes(int n, out List pr)\n {\n var m = 2 * n / 5;\n pr = new List { 2 };\n var f = new bool[n + 1];\n for (var i = 3; i <= m; i += 2)\n if (!f[i])\n for (long j = (long)i * i; j <= n; j += i)\n f[j] = true;\n for (var i = 3; i <= n; i += 2)\n if (!f[i])\n pr.Add(i);\n }\n\n /// \n /// Returns array of inverted prime numbers map in O(n*n)\n /// \n public static void SieveOfEratosthenes(int n, out bool[] isPrime)\n {\n var m = 2 * n / 5;\n var f = new bool[n + 1];\n for (var i = 3; i <= m; i += 2)\n if (!f[i])\n for (long j = (long)i * i; j <= n; j += i)\n f[j] = true;\n isPrime = f;\n }\n\n /// \n /// Greatest common divisor \n /// \n public static int Gcd(int x, int y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Greatest common divisor\n /// \n public static long Gcd(long x, long y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Greatest common divisor\n /// \n public static BigInteger Gcd(BigInteger x, BigInteger y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Returns all divisors of n in O(√n)\n /// \n public static IEnumerable GetDivisors(long n)\n {\n long r;\n while (true)\n {\n var x = Math.DivRem(n, 2, out r);\n if (r != 0) break;\n n = x;\n yield return 2;\n }\n var i = 3;\n while (i <= Math.Sqrt(n))\n {\n var x = Math.DivRem(n, i, out r);\n if (r == 0)\n {\n n = x;\n yield return i;\n }\n else i += 2;\n }\n if (n != 1) yield return n;\n }\n }\n\n /// \n /// Graph matching algorithms\n /// \n public class GraphMatching\n {\n #region Kuhn algorithm\n\n /// \n /// Kuhn algorithm for finding maximal matching\n /// in bipartite graph\n /// Vertexes are numerated from zero: 0, 1, 2, ... n-1\n /// Return array of matchings\n /// \n public static int[] Kuhn(List[] g, int leftSize, int rightSize)\n {\n Debug.Assert(g.Count() == leftSize);\n\n var matching = new int[leftSize];\n for (var i = 0; i < rightSize; i++)\n matching[i] = -1;\n var used = new bool[leftSize];\n\n for (var v = 0; v < leftSize; v++)\n {\n Array.Clear(used, 0, leftSize);\n _kuhn_dfs(v, g, matching, used);\n }\n\n return matching;\n }\n\n private static bool _kuhn_dfs(int v, List[] g, int[] matching, bool[] used)\n {\n if (used[v]) return false;\n used[v] = true;\n for (var i = 0; i < g[v].Count; i++)\n {\n var to = g[v][i];\n if (matching[to] == -1 || _kuhn_dfs(matching[to], g, matching, used))\n {\n matching[to] = v;\n return true;\n }\n }\n return false;\n }\n\n #endregion\n }\n}", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace problemB\n{\n class Program\n {\n static int getMask(int a)\n {\n int result = 0;\n int coef = 1;\n while (a > 0)\n {\n int m = a % 10;\n if (m == 4 || m == 7)\n {\n result += (m*coef);\n coef *= 10;\n }\n a /= 10;\n }\n return result;\n }\n\n static void Main(string[] args)\n {\n int[] data = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n int a = data[0], b = data[1];\n int first = a+1;\n int mask=0;\n while (true)\n {\n if ((mask=getMask(first)) == b)\n {\n Console.WriteLine(first);\n break;\n }\n first++;\n }\n }\n }\n}\n", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"} {"source_code": "//#undef DEBUG\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Diagnostics;\n\nnamespace codeforces\n{\n class C\n {\n // test\n static CodeforcesUtils CF = new CodeforcesUtils(\n@\"\nrock\nrock\nrock\n\");\n\n class Solver\n {\n public void Solve()\n {\n int[] a = new int[3];\n for (int i = 0; i < 3; i++)\n {\n string s = CF.ReadLine();\n if (s == \"rock\")\n a[i] = 0;\n else if (s == \"paper\")\n a[i] = 1;\n else if (s == \"scissors\")\n a[i] = 2;\n }\n\n int[] win = new int[3];\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n {\n if (a[i] == ((a[j] + 1) % 3))\n win[i]++;\n }\n }\n \n if (win[0] > 0 && win[1] == 0 && win[2] == 0)\n CF.WriteLine(\"F\");\n else if (win[1] > 0 && win[0] == 0 && win[2] == 0)\n CF.WriteLine(\"M\");\n else if (win[2] > 0 && win[0] == 0 && win[1] == 0)\n CF.WriteLine(\"S\");\n else\n CF.WriteLine(\"?\");\n }\n\n }\n \n \n #region test\n\n static void Main(string[] args)\n {\n System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(\"ru-RU\");\n\n new Solver().Solve();\n CF.Close();\n }\n\n static void TLE()\n {\n for (; ; ) ;\n }\n\n class CodeforcesUtils\n {\n public string ReadLine()\n {\n#if DEBUG\n if (_lines == null)\n {\n _lines = new List();\n string[] ss = _test_input.Replace(\"\\n\", \"\").Split('\\r');\n for (int i = 0; i < ss.Length; i++)\n {\n if (\n (i == 0 || i == ss.Length - 1) &&\n ss[i].Length == 0\n )\n continue;\n\n _lines.Add(ss[i]);\n }\n }\n\n string s = null;\n if (_lines.Count > 0)\n {\n s = _lines[0];\n _lines.RemoveAt(0);\n }\n return s;\n\n#else\n //return _sr.ReadLine();\n return Console.In.ReadLine();\n#endif\n }\n\n public void WriteLine(object o)\n {\n#if DEBUG\n System.Diagnostics.Trace.WriteLine(o);\n#else\n //_sw.WriteLine(o);\n Console.WriteLine(o);\n#endif\n }\n\n public void Write(object o)\n {\n#if DEBUG\n System.Diagnostics.Trace.Write(o);\n#else\n //_sw.Write(o);\n Console.Write(o);\n#endif\n }\n\n\n string _test_input;\n\n List _lines;\n\n#if DEBUG\n public CodeforcesUtils(string test_input)\n {\n _test_input = test_input;\n }\n#else\n\n public CodeforcesUtils(string dummy)\n {\n //_sr = new System.IO.StreamReader(\"input.txt\");\n //_sw = new System.IO.StreamWriter(\"output.txt\");\n }\n#endif\n\n public void Close()\n {\n if( _sr!= null)\n _sr.Close();\n if( _sw != null)\n _sw.Close();\n }\n\n System.IO.StreamReader _sr=null;\n System.IO.StreamWriter _sw=null;\n \n }\n\n #endregion\n }\n}\n", "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"source_code": "using System;\nusing System.IO;\nusing System.Reflection;\nusing System.Collections;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n int nextInt()\n {\n int c = ' ';\n while ((c == (int)' ' || c == (int)'\\n' || \n c == (int)'\\t' || c == (int)'\\r') \n && c != -1)\n {\n c = Console.Read();\n }\n bool flag = false;\n if (c == '-') flag = true;\n else\n if ((c < '0' || c > '9') && c != '+') return 0;\n int res = 0;\n if (!char.IsDigit((char)c)) c = Console.Read();\n while (char.IsDigit((char)c))\n {\n res = res * 10 + (int)c - (int)'0';\n c = Console.Read();\n }\n if (flag) res = -res;\n return res;\n }\n\n long f(long n, long s)\n {\n if (n % s == 0) return n;\n return (n / s + 1) * (n % s);\n }\n\n void Solve()\n {\n long n = nextInt(), m = nextInt(), s = nextInt();\n Console.Write(f(n, s) * f(m, s));\n }\n\n static void Main(string[] args)\n {\n#if MY_SUPER_PUPER_ONLINE_JUDGE\n string strAppDir =\n Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);\n Console.SetIn(new StreamReader(strAppDir + \"\\\\input.txt\"));\n Console.SetOut(new StreamWriter(strAppDir + \"\\\\output.txt\"));\n#endif\n new Program().Solve();\n#if MY_SUPER_PUPER_ONLINE_JUDGE\n Console.In.Close();\n Console.Out.Close();\n#endif\n }\n }\n}\n", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\n\nclass Program\n{\n const int WWW = 20;\n int[] a = new int[WWW];\n\n void Next()\n {\n for (int i = 0; i < WWW; i++)\n {\n if (a[i] > 0)\n {\n if (a[i + 1] < 9)\n {\n a[i + 1]++;\n var p = a[i];\n a[i] = 0;\n a[0] = p - 1;\n }\n else\n {\n a[i + 2] = 1;\n a[i + 1] = 0;\n a[i] = 0;\n a[0] = 9;\n }\n break;\n }\n }\n }\n\n //////////////////////////////////////////////////\n void Solution()\n {\n var k = ri;\n a[0] = 9;\n a[1] = 1;\n for (int i = 1; i < k; i++)\n {\n Next();\n }\n\n for (int i = WWW-1; i >= 0; i--)\n {\n if (a[i] > 0)\n {\n for (int j = i; j >= 0; j--)\n wrt(a[j]);\n return;\n }\n }\n }\n //////////////////////////////////////////////////\n\n static void swap(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }\n\n static void wln() { Console.WriteLine(); }\n static void wln(T o) { Console.WriteLine(o); }\n static void wsp(T o) { Console.Write(o + \" \"); }\n static void wrt(T o) { Console.Write(o); }\n\n static void wln(double o) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, \"{0:F12}\", o)); }\n static void wsp(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, \"{0:F12} \", o)); }\n static void wrt(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, \"{0:F12}\", o)); }\n\n static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }\n static long lcm(long a, long b) { return a / gcd(a, b) * b; }\n\n int ri\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind;\n int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n int p = 0;\n while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;\n }\n }\n long rl\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind;\n int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n long p = 0;\n while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;\n }\n }\n double rd\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';\n if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;\n }\n }\n string rs\n {\n get\n {\n _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;\n var tmp = _str.IndexOf(' ', _ind);\n if (tmp == -1) { var res = _str.Substring(_ind); _count = 0; _ind = 0; return res; }\n var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;\n }\n }\n\n int[] ria(int n)\n {\n var res = new int[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n long[] rla(int n)\n {\n var res = new long[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n double[] rda(int n)\n {\n var res = new double[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';\n if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }\n res[k++] = (double)p / q * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }\n string _str = null; int _count = 0; int _ind = 0;\n void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }\n static void Main()\n {\n //Console.SetIn(new StreamReader(\"input.txt\"));\n //Console.SetOut(new StreamWriter(\"output.txt\"));\n new Program().Solution();\n //Console.In.Close();\n //Console.Out.Close();\n }\n}", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"source_code": "using System;\n\nnamespace Codeforces {\n class Program {\n static void Main(string[] args) {\n Console.ReadLine();\n string[] day1 = Console.ReadLine().Split(' ');\n string[] day2 = Console.ReadLine().Split(' ');\n long sum1 = 0, sum2 = 0;\n foreach (string n in day1) {\n sum1 += long.Parse(n);\n }\n foreach (string n in day2) {\n sum2 += long.Parse(n);\n }\n if (sum1 >= sum2) Console.WriteLine(\"Yes\");\n else Console.WriteLine(\"No\");\n }\n }\n}\n", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace prA {\n internal class Program {\n static void Main(string[] args) {\n#if ONLINE_JUDGE\n#else\n\n StreamWriter sw = new StreamWriter(\"output\");\n Console.SetOut(sw);\n Console.SetIn(new StreamReader(\"input\"));\n#endif\n int n = int.Parse(Console.ReadLine());\n int[] a = new int[n];\n string[] ss = Console.ReadLine().Split(' ');\n for(int i = 0; i < n; i++) {\n a[i] = int.Parse(ss[i]);\n }\n Array.Sort(a);\n int[] x = new int[n];\n x[0] = a[n - 1];\n x[n - 1] = a[0];\n for(int i = 1; i < n - 1; i++) {\n x[i] = a[i];\n }\n for(int i = 0; i < n; i++) {\n Console.Write(x[i]);\n Console.Write(' ');\n }\n\n#if ONLINE_JUDGE\n#else\n sw.Close();\n#endif\n }\n }\n}", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace B\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n\n string[] colors = { \"r\", \"o\", \"y\", \"g\", \"b\", \"i\", \"v\" };\n String s =\"\";\n\n for (int i = 0; i < n-3; i++)\n {\n s += colors[i % 4];\n }\n s += colors[6];\n s += colors[5];\n s += colors[4];\n s = s.ToUpper();\n Console.WriteLine(s);\n Console.ReadLine();\n\n }\n }\n}\n", "src_uid": "dc3817c71b1fa5606f316e5e94732296"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Solver.Ex;\nusing Enum = System.Linq.Enumerable;\nusing Watch = System.Diagnostics.Stopwatch;\nusing StringBuilder = System.Text.StringBuilder;\nusing BitVector = System.Collections.Specialized.BitVector32;\nnamespace Solver\n{\n\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Long();\n var count = 0;\n for (long i = 1; i < n; i++)\n {\n var t = 3 * i * (i + 1) / 2;\n var num = n + i;\n if (t > num)\n break;\n if (num % 3 != 0)\n continue;\n count++;\n }\n IO.Printer.Out.PrintLine(count);\n }\n internal IO.StreamScanner sc;\n }\n\n #region Main and Settings\n static class Program\n {\n static void Main(string[] arg)\n {\n#if DEBUG\n var errStream = new System.IO.FileStream(@\"..\\..\\dbg.out\", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);\n System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, \"debugStream\"));\n System.Diagnostics.Debug.AutoFlush = false;\n var sw = new Watch();\n sw.Start();\n try\n {\n#endif\n var solver = new Solver();\n solver.sc = new IO.StreamScanner(Console.OpenStandardInput());\n IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n solver.Solve();\n IO.Printer.Out.Flush();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.Error.WriteLine(ex.Message);\n Console.Error.WriteLine(ex.StackTrace);\n }\n finally\n {\n sw.Stop();\n Console.ForegroundColor = ConsoleColor.Green;\n Console.Error.WriteLine(\"Time:{0}ms\", sw.ElapsedMilliseconds);\n System.Diagnostics.Debug.Close();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n }\n#endif\n }\n\n\n }\n #endregion\n}\n#region IO Helper\nnamespace Solver.IO\n{\n public class Printer\n {\n static Printer()\n {\n Out = new Printer(Console.Out);\n }\n public static Printer Out { get; set; }\n private readonly System.IO.TextWriter writer;\n private readonly System.Globalization.CultureInfo info;\n public string Separator { get; set; }\n public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? \"\\n\"; } }\n public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)\n {\n writer = tw ?? System.IO.TextWriter.Null;\n info = ci ?? System.Globalization.CultureInfo.InvariantCulture;\n NewLine = newLine;\n Separator = separator ?? \" \";\n }\n public void Print(int num) { writer.Write(num.ToString(info)); }\n public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(long num) { writer.Write(num.ToString(info)); }\n public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(double num) { writer.Write(num.ToString(\"F12\", info)); }\n public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(string str) { writer.Write(str); }\n public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }\n public void Print(string format, IEnumerable sources) { writer.Write(format, sources.OfType().ToArray()); }\n public void Print(IEnumerable sources) { writer.Write(sources.AsString()); }\n public void Print(IEnumerable sources)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.Write(res.ToString(0, res.Length - Separator.Length));\n }\n public void PrintLine() { writer.WriteLine(); }\n public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }\n public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }\n public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(double num) { writer.WriteLine(num.ToString(\"F12\", info)); }\n public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(string str) { writer.WriteLine(str); }\n public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }\n public void PrintLine(string format, IEnumerable sources) { writer.WriteLine(format, sources.OfType().ToArray()); }\n public void PrintLine(IEnumerable sources)\n {\n var res = new StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (!string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.WriteLine(res.ToString(0, res.Length - Separator.Length));\n }\n public void Flush() { writer.Flush(); }\n }\n public class StreamScanner\n {\n public StreamScanner(System.IO.Stream stream)\n {\n iStream = stream;\n }\n private readonly System.IO.Stream iStream;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n private bool eof = false;\n public bool EndOfStream { get { return eof; } }\n private byte readByte()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n if (ptr >= len)\n {\n ptr = 0;\n len = iStream.Read(buf, 0, 1024);\n if (len <= 0)\n {\n eof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n private bool inSpan(byte c)\n {\n const byte lb = 33, ub = 126;\n return !(c >= lb && c <= ub);\n }\n private byte skip()\n {\n byte b = 0;\n do b = readByte();\n while (!eof && inSpan(b));\n return b;\n }\n public char Char()\n {\n return (char)skip();\n }\n public char[] Char(int n)\n {\n var a = new char[n];\n for (int i = 0; i < n; i++)\n a[i] = (char)skip();\n return a;\n }\n public char[][] Char(int n, int m)\n {\n var a = new char[n][];\n for (int i = 0; i < n; i++)\n a[i] = Char(m);\n return a;\n }\n public string Scan()\n {\n\n const byte lb = 33, ub = 126;\n if (eof) throw new System.IO.EndOfStreamException();\n\n do\n {\n while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))\n {\n ptr++;\n }\n if (ptr < len)\n break;\n ptr = 0;\n len = iStream.Read(buf, 0, 1024);\n if (len <= 0)\n {\n eof = true;\n return null;\n }\n continue;\n } while (true);\n\n StringBuilder sb = null;\n do\n {\n var i = ptr;\n while (i < len)\n {\n if (buf[i] < lb || ub < buf[i])\n {\n string s;\n if (sb != null)\n {\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n s = sb.ToString();\n }\n else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n ptr = i + 1;\n return s;\n }\n i++;\n }\n i = len - ptr;\n if (sb == null) sb = new StringBuilder(i + 32);\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));\n ptr = 0;\n } while ((len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true;\n return sb.ToString();\n }\n public string[] Scan(int n)\n {\n var a = new string[n];\n for (int i = 0; i < n; i++)\n a[i] = Scan();\n return a;\n }\n public string ScanLine()\n {\n const byte el = 10, cr = 13;\n if (eof) throw new System.IO.EndOfStreamException();\n StringBuilder sb = null;\n do\n {\n var i = ptr;\n while (i < len)\n {\n if (buf[i] == cr || buf[i] == el)\n {\n string s;\n if (sb != null)\n {\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n s = sb.ToString();\n }\n else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n if (buf[i] == cr) i++;\n if (buf[i] == el) i++;\n ptr = i;\n return s;\n }\n i++;\n }\n i = len - ptr;\n if (sb == null) sb = new StringBuilder(i + 32);\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));\n ptr = 0;\n } while ((len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true;\n return sb.ToString();\n }\n public double Double()\n {\n return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);\n }\n public double[] Double(int n)\n {\n var a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = Double();\n return a;\n }\n public int Integer()\n {\n var ret = 0;\n byte b = 0;\n bool isMynus = false;\n const byte zero = 48, nine = 57, mynus = 45;\n do b = readByte();\n while (!eof && !((b >= zero && b <= nine) || b == mynus));\n\n if (b == mynus)\n {\n isMynus = true;\n b = readByte();\n }\n while (true)\n {\n if (b >= zero && b <= nine)\n {\n ret = ret * 10 + b - zero;\n }\n else return isMynus ? -ret : ret;\n b = readByte();\n }\n\n }\n public int[] Integer(int n)\n {\n var a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = Integer();\n return a;\n }\n public long Long()\n {\n long ret = 0;\n byte b = 0;\n bool isMynus = false;\n const byte zero = 48, nine = 57, mynus = 45;\n do b = readByte();\n while (!eof && !((b >= zero && b <= nine) || b == mynus));\n if (b == '-')\n {\n isMynus = true;\n b = readByte();\n }\n while (true)\n {\n if (b >= zero && b <= nine)\n ret = ret * 10 + (b - zero);\n else return isMynus ? -ret : ret;\n b = readByte();\n }\n\n }\n public long[] Long(int n)\n {\n var a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = Long();\n return a;\n }\n public void Flush()\n {\n iStream.Flush();\n }\n\n }\n\n}\n#endregion\n#region Extension\nnamespace Solver.Ex\n{\n static public partial class EnumerableEx\n {\n static public string AsString(this IEnumerable source)\n {\n return new string(source.ToArray());\n }\n static public string AsJoinedString(this IEnumerable source, string separator = \" \")\n {\n return string.Join(separator, source);\n }\n static public T[] Enumerate(this int n, Func selector)\n {\n var res = new T[n];\n for (int i = 0; i < n; i++)\n res[i] = selector(i);\n return res;\n }\n }\n}\n#endregion\n", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _218a\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\t//Console.SetIn(File.OpenText(\"in.txt\"));\n\t\t\tvar d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n\t\t\tvar n = d[0];\n\t\t\tvar k = d[1];\n\t\t\tvar a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n\n\t\t\tvar size = n / k;\n\t\t\tvar change = 0;\n\t\t\tfor (int i = 0; i < k; i++)\n\t\t\t{\n\t\t\t\tvar s = i;\n\t\t\t\tvar c1 = 0;\n\t\t\t\tvar c2 = 0;\n\t\t\t\twhile (s <= n - 1)\n\t\t\t\t{\n\t\t\t\t\tif (a[s] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tc1++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tc2++;\n\t\t\t\t\t}\n\n\t\t\t\t\ts += k;\n\t\t\t\t}\n\n\t\t\t\tchange += Math.Min(c1, c2);\n\t\t\t}\n\n\t\t\tConsole.WriteLine(change);\n\t\t}\n\t}\n}\n", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces\n{\n\n class Program\n {\n public static readonly int MOD = Convert.ToInt32(1e9 + 7);\n public static readonly int oo = Convert.ToInt32(1e9);\n public static readonly long OO = Convert.ToInt64(1e18);\n\n static void Main(string[] args)\n {\n int weights = int.Parse(Console.ReadLine());\n int[] masses = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();\n int[] cnt = new int[101];\n foreach (int mass in masses)\n {\n cnt[mass]++;\n }\n int nonZero = 0;\n for (int i = 1; i <= 100; i++)\n {\n if (cnt[i] > 0)\n {\n nonZero++;\n }\n }\n if (nonZero <= 2)\n {\n Console.WriteLine(weights);\n return;\n }\n\n int[,] C = new int[101, 101];\n C[0, 0] = 1;\n for (int i = 1; i <= 100; i++)\n {\n C[i, 0] = C[i, i] = 1;\n for (int j = 1; j < i; j++)\n {\n C[i, j] = (C[i - 1, j] + C[i - 1, j - 1]) % MOD;\n }\n }\n\n\n int sum = masses.Sum();\n int[,] ways = new int[weights + 1, sum + 1];\n ///\n /// dp(i, j, k) = dp(i - 1, j - 1, k - masses[j])\n ///\n\n ways[0, 0] = 1;\n for (int i = 0; i < weights; i++)\n {\n int[,] nways = new int[weights + 1, sum + 1];\n nways[0, 0] = 1;\n for (int j = 1; j <= i + 1; j++)\n {\n for (int k = sum; k > 0; k--)\n {\n nways[j, k] = ways[j, k];\n if (k >= masses[i])\n {\n nways[j, k] = (nways[j, k] + ways[j - 1, k - masses[i]]) % MOD;\n }\n }\n }\n \n ways = nways;\n }\n \n\n int ans = 1;\n for (int i = 1; i <= 100; i++)\n {\n if (cnt[i] > 0)\n {\n for (int j = i; j <= sum; j += i)\n {\n if (j / i <= weights && ways[j / i, j] > 0 && ways[j / i, j] == C[cnt[i], j / i])\n {\n ans = Math.Max(ans, j / i);\n }\n }\n }\n }\n\n Console.WriteLine(ans);\n\n\n }\n\n }\n\n}\n", "src_uid": "ccc4b27889598266e8efe73b8aa3666c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\n\nnamespace Codeforces\n{\n class A\n {\n private static ThreadStart s_threadStart = new A().Go;\n private static bool s_time = false;\n\n long mod = 1000000009;\n\n private void Go()\n {\n int n = GetInt();\n int m = GetInt();\n\n long ans = 1;\n long k = 1;\n for (int i = 0; i < m; i++)\n {\n k = (k * 2) % mod;\n }\n k--;\n for (int i = 0; i < n; i++)\n {\n ans = (ans * k) % mod;\n k--;\n }\n\n Wl(ans);\n }\n\n #region Template\n\n public static void Main(string[] args)\n {\n System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();\n Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);\n timer.Start();\n main.Start();\n main.Join();\n timer.Stop();\n if (s_time)\n Wl(timer.ElapsedMilliseconds);\n }\n\n private static IEnumerator ioEnum;\n private static string GetString()\n {\n while (ioEnum == null || !ioEnum.MoveNext())\n {\n ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();\n }\n\n return ioEnum.Current;\n }\n\n private static int GetInt()\n {\n return int.Parse(GetString());\n }\n\n private static long GetLong()\n {\n return long.Parse(GetString());\n }\n\n private static double GetDouble()\n {\n return double.Parse(GetString());\n }\n\n private static List GetIntArr(int n)\n {\n List ret = new List(n);\n for (int i = 0; i < n; i++)\n {\n ret.Add(GetInt());\n }\n return ret;\n }\n\n private static void Wl(T o)\n {\n if (o is double)\n {\n Wld((o as double?).Value, \"\");\n }\n else if (o is float)\n {\n Wld((o as float?).Value, \"\");\n }\n else\n Console.WriteLine(o.ToString());\n }\n\n private static void Wl(IEnumerable enumerable)\n {\n Wl(string.Join(\" \", enumerable.Select(e => e.ToString()).ToArray()));\n }\n\n private static void Wld(double d, string format)\n {\n Wl(d.ToString(format, CultureInfo.InvariantCulture));\n }\n\n public struct Tuple : IComparable>\n where T : IComparable\n where K : IComparable\n {\n public T Item1;\n public K Item2;\n\n public Tuple(T t, K k)\n {\n Item1 = t;\n Item2 = k;\n }\n\n public override bool Equals(object obj)\n {\n var o = (Tuple)obj;\n return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);\n }\n\n public override int GetHashCode()\n {\n return Item1.GetHashCode() ^ Item2.GetHashCode();\n }\n\n public override string ToString()\n {\n return \"(\" + Item1 + \" \" + Item2 + \")\";\n }\n\n #region IComparable> Members\n\n public int CompareTo(Tuple other)\n {\n int ret = Item1.CompareTo(other.Item1);\n if (ret != 0) return ret;\n return Item2.CompareTo(other.Item2);\n }\n\n #endregion\n }\n\n #endregion\n }\n}", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Plant\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static long mod = 1000000007;\n\n private static long Pow(long a, long k)\n {\n long r = 1;\n while (k > 0)\n {\n if ((k & 1) == 1)\n {\n r = (r*a)%mod;\n }\n a = (a*a)%mod;\n k >>= 1;\n }\n return r;\n }\n\n private static void Main(string[] args)\n {\n long n = Next();\n if (n==0)\n writer.WriteLine(\"1\");\n else\n writer.WriteLine(Pow(2, n - 1)*(1 + Pow(2, n))%mod);\n writer.Flush();\n }\n\n private static long Next()\n {\n int c;\n long res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace acm\n{\n class Program\n {\n static void Main(string[] args)\n {\n var s1 = Console.ReadLine().Split(' ');\n long sx = long.Parse(s1[0]);\n long sy = long.Parse(s1[1]);\n int n = int.Parse(Console.ReadLine());\n long[] x = new long[n];\n long[] y = new long[n];\n for (int i = 0; i < n; ++i)\n {\n var s2 = Console.ReadLine().Split(' ');\n x[i] = long.Parse(s2[0]);\n y[i] = long.Parse(s2[1]);\n }\n long[] d = new long[1 << n];\n int[] df = new int[1 << n];\n if( n % 2 == 0 ) d[0] = 1;\n else{\n for (int i = 0; i < n; ++i) d[1 << i] = 1 + dst(sx - x[i], sy - y[i]);\n }\n for (int i = 0; i < (1 << n); ++i) if (d[i] > 0)\n {\n int i1 = -1;\n for (int i2 = 0; i2 < n; ++i2)\n {\n if ((i & (1 << i2)) == 0)\n {\n if (i1 == -1)\n {\n i1 = i2;\n long nd = d[i] + dst(x[i1] - sx, y[i1] - sy);\n int ni = (i | (1 << i1));\n if (d[ni] == 0 || d[ni] > nd)\n {\n d[ni] = nd;\n df[ni] = i;\n }\n }\n else\n {\n long nd = d[i] + dst(x[i1] - x[i2], y[i1] - y[i2]);\n int ni = (i | (1 << i1) | (1 << i2));\n if (d[ni] == 0 || d[ni] > nd)\n {\n d[ni] = nd;\n df[ni] = i;\n }\n }\n }\n }\n }\n long ans = d[(1 << n) - 1] - 1;\n int cur = (1 << n) - 1;\n List a = new List();\n a.Add(0);\n while (cur != 0)\n {\n ans += dir(cur & ~df[cur], x, y, sx, sy);\n for (int i = 0; i < n; ++i) if ((cur & ~df[cur] & (1 << i)) != 0) a.Add(i + 1);\n a.Add(0);\n cur = df[cur];\n }\n Console.WriteLine(ans);\n Console.WriteLine(string.Join(\" \", (from v in a select v.ToString()).ToArray()));\n }\n static long dir(int mask, long[] x, long[] y, long sx, long sy)\n {\n long ret = 0;\n int cnt = 0;\n for (int i = 0; i < 30; ++i)\n {\n if (0 !=(mask & (1 << i)))\n {\n ++cnt;\n ret += dst(sx - x[i], sy - y[i]);\n }\n }\n return ret;\n }\n static long dst(long a, long b)\n {\n return a * a + b * b;\n }\n }\n}\n", "src_uid": "2ecbac20dc5f4060bc873553946281bc"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CF1248D1 {\n class Sequence {\n public LinkedList elems;\n public int brackets_left;\n\n public Sequence(LinkedList elems, int brackets_left) {\n this.elems = elems;\n this.brackets_left = brackets_left;\n }\n\n public void CyclicShift() {\n //Remove first and append to the end\n int first = elems.First.Value;\n elems.RemoveFirst();\n elems.AddLast(first);\n\n //Now if first == -1, we need to go back through to find the first occurence of a 1\n if (first == -1) {\n LinkedListNode node = elems.Last.Previous;\n int sum = 2;\n elems.RemoveLast();\n while(node.Value != 1) {\n sum += node.Value;\n node = node.Previous;\n elems.RemoveLast();\n }\n elems.RemoveLast();\n elems.AddLast(sum);\n brackets_left--;\n }\n }\n\n public int Beauty() {\n while(brackets_left > 0) {\n CyclicShift();\n }\n return elems.Count;\n }\n }\n\n class Program {\n static void Main(string[] args) {\n int n = int.Parse(Console.ReadLine());\n char[] input = Console.ReadLine().ToArray();\n if (n % 2 == 1 || input.Count(x => x == ')') != input.Count(x => x == '(')) {\n Console.WriteLine(0);\n Console.WriteLine(\"1 1\");\n return;\n }\n // Console.WriteLine(\"Starting...\");\n Sequence seq = PartialConvert(input);\n int b = seq.Beauty();\n int s = 0;\n int r = 0;\n int[,] DP_table = new int[n, n];\n for (int i = 0; i < n; i++) {\n for (int j = i+1; j < n; j++) {\n if (input[i] == input[j]) continue;\n char temp = input[i];\n input[i] = input[j];\n input[j] = temp;\n seq = PartialConvert(input);\n\n int p = seq.Beauty();\n //Console.WriteLine(\"Swapping {0} and {1} gives b={2}\", i + 1, j + 1, p);\n if (p > b) {\n b = p;\n s = i;\n r = j;\n }\n DP_table[i, j] = p;\n temp = input[i];\n input[i] = input[j];\n input[j] = temp;\n }\n }\n Console.WriteLine(b);\n Console.WriteLine((s+1) + \" \" + (r+1));\n#if DEBUG\n //PrintArray(DP_table);\n Console.ReadKey();\n#endif\n }\n\n //1 = (, -1 = ), any number = correct sequence of this length\n static int[] Convert(char[] seq) {\n int[] arr = new int[seq.Length];\n int i = 0;\n foreach (char c in seq) {\n arr[i++] = (c == '(' ? 1 : -1);\n }\n return arr;\n }\n\n static Sequence PartialConvert(char[] seq) {\n int[] arr = Convert(seq);\n Stack stack = new Stack();\n\n int open = 0;\n int sum;\n int left = 0; //how many brackets have not yet been fulfilled\n foreach (int elem in arr) {\n if (elem == 1) {\n open++;\n stack.Push(elem);\n } else {\n if (open > 0) {\n sum = 2;\n while (stack.Peek() > 1) {\n sum += stack.Pop();\n }\n stack.Pop();\n stack.Push(sum);\n open--;\n } else {\n left++;\n stack.Push(elem);\n }\n }\n }\n\n LinkedList ll = new LinkedList();\n while (stack.Count > 0) {\n ll.AddFirst(stack.Pop());\n }\n return new Sequence(ll, left);\n }\n\n //static void PrintArray(int[,] arr) {\n // int rowLength = arr.GetLength(0);\n // int colLength = arr.GetLength(1);\n\n // for (int i = 0; i < rowLength; i++) {\n // for (int j = 0; j < colLength; j++) {\n // Console.Write(string.Format(\"{0} \", arr[i, j]));\n // }\n // Console.Write(Environment.NewLine + Environment.NewLine);\n // }\n //}\n\n //static int Beauty(int[] seq) {\n\n // for (int i = 0; i < seq.Length; i++) {\n // if (Verify(seq, i)) {\n // return Contract(seq, i);\n // }\n // }\n // return 0;\n //}\n //static void PrintList(LinkedList seq) {\n // foreach (int i in seq) {\n // Console.Write(i);\n // }\n // Console.WriteLine();\n //}\n\n\n\n //static bool Verify(int[] seq, int start) {\n // int open = 0;\n // if (seq[(start + seq.Length - 1) % seq.Length] == 1) return false;\n // for (int i = 0; i < seq.Length; i++) {\n // if (open < 0) return false;\n // open += (seq[(start + i) % seq.Length]);\n // }\n // return open == 0;\n //}\n\n //static int Contract(int[] seq, int start) {\n // Stack stack = new Stack();\n // for (int j = 0; j < seq.Length; j++){\n // int i = (start + j) % seq.Length; \n // stack.Push(seq[i]);\n // if (stack.Peek() == -1) {\n // stack.Pop();\n // int sum = 2;\n // while (stack.Peek() > 1) {\n // sum += stack.Pop();\n // }\n // stack.Pop();\n // stack.Push(sum);\n // }\n // }\n // //Console.Write(\"Contracted: \" + stack.Count + \": \");\n // //PrintList(new LinkedList(stack.ToArray()));\n // return stack.Count;\n //}\n }\n}\n", "src_uid": "2d10668fcc2d8e90e102b043f5e0578d"} {"source_code": "using System;\n\nnamespace CF_664A\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tvar num = Console.ReadLine().Split();\n\n\t\t\tConsole.WriteLine(num[0].Equals(num[1])? num[1]: \"1\");\n\t\t}\n\t}\n}\n", "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication4\n{\n class Program\n {\n static void Main(string[] args)\n {\n int kol_chisel;\n int[] array;\n kol_chisel = int.Parse(Console.ReadLine());\n string chisla = Console.ReadLine();\n string[] array2 = chisla.Split(' ');\n kol_chisel = array2.Length;\n array = new int[kol_chisel];\n for (int i = 0; i < kol_chisel; i++)\n array[i] = int.Parse(array2[i]);\n int index_min = 0;\n int index_max = 0;\n for (int i = 0; i < kol_chisel; i++)\n {\n if (array[i] == 1) index_min = i;\n if (array[i] == kol_chisel) index_max = i;\n }\n if (index_max < index_min)\n {\n int z = index_min;\n index_min = index_max;\n index_max = z;\n }\n int razmer = Math.Abs(index_min - index_max);\n int output = razmer;\n if (razmer != kol_chisel)\n {\n int m = kol_chisel - 1 - index_max;\n if (m > index_min) output += m;\n else output += index_min;\n }\n Console.WriteLine(output);\n }\n }\n}\n", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace _11111\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] iData = Console.ReadLine().Split(' ');\n int iA = Convert.ToInt32(iData[0]);\n int iX = Convert.ToInt32(iData[1]);\n int iY = Convert.ToInt32(iData[2]);\n\n int iLevel = iY / iA;\n int iNumberSquare = -1;\n if (iY % iA != 0)\n {\n iNumberSquare = 0;\n int iIndexLevel = 0;\n while (iIndexLevel != iLevel)\n {\n iIndexLevel++;\n iNumberSquare++;\n if (iIndexLevel != 1 && iIndexLevel % 2 != 0)\n iNumberSquare++;\n }\n\n if(iLevel+1 == 1 || (iLevel+1) % 2 == 0)\n {\n if (iX > -((double)iA) / 2 && iX < ((double)iA) / 2)\n iNumberSquare++;\n else\n iNumberSquare = -1;\n }\n else\n {\n if (iX > -((double)iA) && iX < 0)\n iNumberSquare++;\n else\n if (iX > 0 && iX < ((double)iA))\n iNumberSquare += 2;\n else\n iNumberSquare = -1;\n }\n\n }\n Console.WriteLine(iNumberSquare);\n }\n \n }\n}", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"source_code": "using System;\n\nclass P { \n static void Main() {\n var str = Console.ReadLine();\n var protocol = str.StartsWith(\"ht\")?\"http\" : \"ftp\";\n str = str.Substring(protocol.Length);\n var i = str.IndexOf(\"ru\", 1);\n var domain = str.Remove(i);\n var context = str.Substring(i+2);\n if (context != \"\") context = \"/\" + context;\n Console.WriteLine(\"{0}://{1}.ru{2}\", protocol, domain, context); \n }\n}", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Collections;\nusing System.Collections.Specialized;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Reflection;\nusing static System.Math;\nusing System.Numerics;\nstatic class Program{\n\tconst int mod=(int)1e9+7;\n\tconst double eps=1e-11;\n\tstatic void Main(){\n\t\tSc sc=new Sc();\n\t\tvar n=sc.I;\n\t\tvar a=new int[n][];\n\t\tint ans=0;\n\t\tfor(int i = 0;i=0;j--) {\n\t\t\t\tif(a[i][0]==a[j][1]){ans++;}\n\t\t\t\tif(a[j][0]==a[i][1]){ans++;}\n\t\t\t}\n\t\t}\n\t\tConsole.WriteLine(\"{0}\",ans);\n\t}\n}\n\npublic class Sc{\n\tpublic int I{get{return int.Parse(Console.ReadLine());}}\n\tpublic long L{get{return long.Parse(Console.ReadLine());}}\n\tpublic double D{get{return double.Parse(Console.ReadLine());}}\n\tpublic string S{get{return Console.ReadLine();}}\n\tpublic int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}\n\tpublic long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}\n\tpublic double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}\n\tpublic string[] Sa{get{return Console.ReadLine().Split();}}\n\tpublic object[] Oa{get{return Console.ReadLine().Split();}}\n\tpublic int[] Ia2{get{return Array.ConvertAll((\"0 \"+Console.ReadLine()+\" 0\").Split(),int.Parse);}}\n\tpublic int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}\n\tpublic int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+\" \"+a.ToString()).Split(),int.Parse);}\n\tpublic long[] La2{get{return Array.ConvertAll((\"0 \"+Console.ReadLine()+\" 0\").Split(),long.Parse);}}\n\tpublic long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}\n\tpublic long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+\" \"+a.ToString()).Split(),long.Parse);}\n\tpublic double[] Da2{get{return Array.ConvertAll((\"0 \"+Console.ReadLine()+\" 0\").Split(),double.Parse);}}\n\tpublic double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}\n\tpublic T[] Arr(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i q = new Queue();\n for (int i = 1; i <= n; i++)\n {\n var p = new point(i - 1, i + 1, nn[i]);\n points[i] = p;\n if (p.value>=p.current)\n {\n q.Enqueue(p);\n p.used = true;\n }\n }\n\n while (q.Count>0)\n {\n point p = q.Dequeue();\n count += p.value;\n\n point p1 = points[p.left];\n point p2 = points[p.right];\n p1.right = p.right;\n p2.left = p.left;\n p1.Recalc();\n p2.Recalc();\n\n if (p1.value >= p1.current && !p1.used)\n {\n q.Enqueue(p1);\n p1.used = true;\n }\n if (p2.value >= p2.current && !p2.used)\n {\n q.Enqueue(p2);\n p2.used = true;\n }\n }\n \n\n var heap = new MaxBinaryHeapObject(new point(0, 0, 0));\n for (int i = 1; i <= n; i++)\n {\n if (!points[i].used)\n heap.Add(points[i]);\n }\n \n while (heap.HeapSize > 2)\n {\n point p = heap.GetMax();\n count += p.value;\n\n point p1 = points[p.left];\n point p2 = points[p.right];\n p1.right = p.right;\n p2.left = p.left;\n\n p1.Recalc();\n heap.Remove(p1);\n p2.Recalc();\n heap.Remove(p2);\n\n heap.Add(p1);\n heap.Add(p2);\n }\n\n writer.WriteLine(count);\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n\n #region Nested type: MaxBinaryHeapObject\n\n public class MaxBinaryHeapObject\n {\n private readonly IComparer _comparer;\n private readonly List _list;\n\n public MaxBinaryHeapObject(IComparer comparer)\n {\n _comparer = comparer ?? Comparer.Default;\n _list = new List();\n }\n\n public int HeapSize\n {\n get { return _list.Count; }\n }\n\n public void Add(point value)\n {\n _list.Add(value);\n value.where = _list.Count - 1;\n int i = HeapSize - 1;\n int parent = (i - 1)/2;\n\n while (i > 0 && _comparer.Compare(_list[parent], _list[i]) == -1)\n {\n point temp = _list[i];\n _list[i] = _list[parent];\n _list[parent] = temp;\n\n _list[i].where = i;\n _list[parent].where = parent;\n\n i = parent;\n parent = (i - 1)/2;\n }\n }\n\n public void Remove(point t)\n {\n _list[t.where] = _list[HeapSize - 1];\n _list[t.where].where = t.where;\n _list.RemoveAt(HeapSize - 1);\n Heapify(t.where);\n }\n\n\n public void Heapify(int i)\n {\n for (;;)\n {\n int leftChild = 2*i + 1;\n int rightChild = 2*i + 2;\n int largestChild = i;\n\n if (leftChild < HeapSize && _comparer.Compare(_list[leftChild], _list[largestChild]) == 1)\n {\n largestChild = leftChild;\n }\n\n if (rightChild < HeapSize && _comparer.Compare(_list[rightChild], _list[largestChild]) == 1)\n {\n largestChild = rightChild;\n }\n\n if (largestChild == i)\n {\n break;\n }\n\n point temp = _list[i];\n _list[i] = _list[largestChild];\n _list[largestChild] = temp;\n\n _list[i].where = i;\n _list[largestChild].where = largestChild;\n\n i = largestChild;\n }\n }\n\n\n public point Max()\n {\n return _list[0];\n }\n\n public point GetMax()\n {\n point result = _list[0];\n _list[0] = _list[HeapSize - 1];\n _list[0].where = 0;\n _list.RemoveAt(HeapSize - 1);\n Heapify(0);\n return result;\n }\n }\n\n #endregion\n\n #region Nested type: point\n\n public class point : IComparer\n {\n public readonly int current;\n public int left;\n public int right;\n public int value;\n public int where;\n public bool used;\n\n\n public point(int left, int right, int current)\n {\n this.left = left;\n this.right = right;\n this.current = current;\n value = Math.Min(nn[left], nn[right]);\n }\n\n #region IComparer Members\n\n public int Compare(point x, point y)\n {\n int c = (x.value).CompareTo(y.value);\n //if (c == 0)\n // c = y._current.CompareTo(x._current);\n return c;\n }\n\n #endregion\n\n public void Recalc()\n {\n value = Math.Min(nn[left], nn[right]);\n }\n }\n\n #endregion\n }\n}", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Squares\n{\n class Dictionary\n {\n static void Main(string[] args)\n {\n string line1 = Console.ReadLine().ToLower();\n string line2 = Console.ReadLine().ToLower();\n\n char[] array1 = new char[line1.Length];\n char[] array2 = new char[line2.Length];\n for (int i = 0; i < line1.Length; i++)\n {\n array1[i] = Convert.ToChar(line1.Substring(i, 1));\n array2[i] = Convert.ToChar(line2.Substring(i, 1));\n }\n for (int i = 0; i < array1.Length; i++)\n {\n if (array1[i] > array2[i])\n {\n Console.WriteLine(\"1\");\n break;\n\n }\n else if (array1[i] < array2[i])\n {\n Console.WriteLine(\"-1\");\n break;\n\n }\n else if (array1[i] == array2[i])\n {\n if (i == array1.Length - 1)\n {\n Console.WriteLine(\"0\");\n break;\n }\n\n }\n \n }\n\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "ffeae332696a901813677bd1033cf01e"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.Numerics;\nusing Debug = System.Diagnostics.Debug;\nusing SB = System.Text.StringBuilder;\nusing Number = System.Int64;\nusing KV = System.Collections.Generic.KeyValuePair;\nnamespace Program {\n public class Solver {\n public void Solve() {\n var k = ri;\n var pa = ri;\n var pb = ri;\n var p = pa * ModInt.Inverse(pa + pb);\n\n var q = pb * ModInt.Inverse(pa + pb);\n var invq = ModInt.Inverse(q);\n var dp = new ModInt[k + 5, k + 5];\n for (int i = 0; i < k + 5; i++)\n for (int j = 0; j < k + 5; j++)\n dp[i, j].num = -1;\n Func dfs = null;\n dfs = (a, cnt) => {\n if (cnt >= k) return cnt;\n if (a + cnt >= k) {\n return cnt + a + invq - 1;\n }\n if (dp[a, cnt].num != -1) return dp[a, cnt];\n ModInt ret = new ModInt(0);\n // a を出す\n ret += p * dfs(a + 1, cnt);\n // b を出す\n ret += q * dfs(a, cnt + a);\n\n return dp[a, cnt] = ret;\n };\n Console.WriteLine(dfs(1, 0));\n\n }\n const long INF = 1L << 60;\n int[] dx = { -1, 0, 1, 0 };\n int[] dy = { 0, 1, 0, -1 };\n\n int ri { get { return sc.Integer(); } }\n long rl { get { return sc.Long(); } }\n double rd { get { return sc.Double(); } }\n string rs { get { return sc.Scan(); } }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n\n static T[] Enumerate(int n, Func f) {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f(i);\n return a;\n }\n\n static public void Swap(ref T a, ref T b) {\n var tmp = a;\n a = b;\n b = tmp;\n }\n }\n}\n\n#region main\n\nstatic class Ex {\n static public string AsString(this IEnumerable ie) {\n return new string(ie.ToArray());\n }\n\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") {\n return string.Join(st, ie.Select(x => x.ToString()).ToArray());\n //return string.Join(st, ie);\n }\n\n static public void Main() {\n Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });\n var solver = new Program.Solver();\n solver.Solve();\n Console.Out.Flush();\n }\n}\n\n#endregion\n#region Ex\n\nnamespace Program.IO {\n using System.IO;\n using System.Text;\n using System.Globalization;\n\n public class Printer: StreamWriter {\n public override IFormatProvider FormatProvider {\n get { return CultureInfo.InvariantCulture; }\n }\n public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n }\n\n public class StreamScanner {\n public StreamScanner(Stream stream) {\n str = stream;\n }\n\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream {\n get { return isEof; }\n }\n\n private byte read() {\n if (isEof) return 0;\n if (ptr >= len) {\n ptr = 0;\n if ((len = str.Read(buf, 0, 1024)) <= 0) {\n isEof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n\n public char Char() {\n byte b = 0;\n do b = read(); while ((b < 33 || 126 < b) && !isEof);\n return (char)b;\n }\n\n public string Scan() {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);\n return sb.ToString();\n }\n\n public string ScanLine() {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n' && b != 0; b = (char)read()) if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n\n public long Long() {\n return isEof ? long.MinValue : long.Parse(Scan());\n }\n\n public int Integer() {\n return isEof ? int.MinValue : int.Parse(Scan());\n }\n\n public double Double() {\n return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture);\n }\n }\n}\n\n#endregion\n\n\n#region ModInt\npublic struct ModInt {\n public const long Mod = (long)1e9 + 7;\n public long num;\n public ModInt(long n) { num = n; }\n public override string ToString() { return num.ToString(); }\n public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }\n public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }\n public static ModInt operator *(ModInt l, ModInt r) { return new ModInt((int)(l.num * r.num % Mod)); }\n public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }\n public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }\n public static ModInt Pow(long v, long k) {\n long ret = 1;\n for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n if ((k & 1) == 1) ret = ret * v % Mod;\n return new ModInt(ret);\n }\n public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }\n}\n#endregion", "src_uid": "0dc9f5d75143a2bc744480de859188b4"} {"source_code": "using System.IO;\nusing System;\n\nclass Program\n{\n static void Main()\n {\n \n int n = 0;\n string S;\n int CheckPoint = 0;\n int[] a = null;\n int SUM = 0;\n \n n = Int32.Parse(Console.ReadLine());\n \n S = Console.ReadLine();\n \n a = new int[n];\n \n for(int i=0; i Array.IndexOf(n, k[1][0]) ? \"YES\" : \"NO\");\n } else if(k[0][1] == m[0]) {\n writer.Write(\"YES\");\n }\n else\n writer.Write(\"NO\");\n\n writer.Flush();\n#if !ONLINE_JUDGE\n writer.Close();\n#endif\n }\n private static int Next() {\n int c;\n int res = 0;\n do {\n c = reader.Read();\n if(c == -1)\n return res;\n } while(c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if(c == '-') {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while(true) {\n c = reader.Read();\n if(c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}\n", "src_uid": "da13bd5a335c7f81c5a963b030655c26"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\nnamespace Codeforces\n{\n class A\n {\n private static bool s_time = false;\n\n static long mod = 1000003;\n\n private static object Go()\n {\n string s = GetString();\n\n Dictionary map = new Dictionary();\n map['>'] = 8;\n map['<'] = 9;\n map['+'] = 10;\n map['-'] = 11;\n map['.'] = 12;\n map[','] = 13;\n map['['] = 14;\n map[']'] = 15;\n\n long ret = 0;\n for (int i = 0; i < s.Length; i++)\n {\n ret = (ret * 16 + map[s[i]]) % mod;\n }\n\n return ret;\n }\n\n #region Template\n\n public static void Main(string[] args)\n {\n DateTime start = DateTime.Now;\n object output = Go();\n TimeSpan duration = DateTime.Now.Subtract(start);\n if (output != null)\n Wl(output.ToString());\n if (s_time)\n Wl(duration);\n }\n\n private static IEnumerator ioEnum;\n private static string GetString()\n {\n while (ioEnum == null || !ioEnum.MoveNext())\n {\n ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();\n }\n\n return ioEnum.Current;\n }\n\n private static int GetInt()\n {\n return int.Parse(GetString());\n }\n\n private static long GetLong()\n {\n return long.Parse(GetString());\n }\n\n private static double GetDouble()\n {\n return double.Parse(GetString());\n }\n\n private static List GetIntArr(int n)\n {\n List ret = new List(n);\n for (int i = 0; i < n; i++)\n {\n ret.Add(GetInt());\n }\n return ret;\n }\n\n private static void Wl(T o)\n {\n Console.WriteLine(o.ToString());\n }\n\n private static void Wl(IEnumerable enumerable)\n {\n Wl(string.Join(\" \", enumerable.Select(e => e.ToString()).ToArray()));\n }\n\n public struct Tuple : IComparable>\n where T : IComparable\n where K : IComparable\n {\n public T Item1;\n public K Item2;\n\n public Tuple(T t, K k)\n {\n Item1 = t;\n Item2 = k;\n }\n\n public override bool Equals(object obj)\n {\n var o = (Tuple)obj;\n return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);\n }\n\n public override int GetHashCode()\n {\n return Item1.GetHashCode() ^ Item2.GetHashCode();\n }\n\n public override string ToString()\n {\n return \"(\" + Item1 + \" \" + Item2 + \")\";\n }\n\n #region IComparable> Members\n\n public int CompareTo(Tuple other)\n {\n int ret = Item1.CompareTo(other.Item1);\n if (ret != 0) return ret;\n return Item2.CompareTo(other.Item2);\n }\n\n #endregion\n }\n\n #endregion\n }\n}", "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"source_code": "using System;\n\nnamespace test\n{\n static class Program\n {\n static void Main()\n {\n var str = Console.ReadLine();\n var names = new string[] { \"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\" };\n var count = 0;\n var index = 0;\n for(var i = 0; i < 5; i++)\n {\n index = 0;\n for (int j = 0; j < 2 && index!=-1; j++)\n {\n index = str.IndexOf(names[i], index);\n if (index != -1) { count++; index++; }\n }\n }\n if (count == 1)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n }\n}", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n public object Solve()\n {\n int n = ReadInt();\n string s = ReadToken();\n if (s.Distinct().Count() < n)\n return \"NO\";\n\n Write(\"YES\");\n if (n == 1)\n {\n Write(s);\n return null;\n }\n\n var f = new bool[200];\n f[s[0]] = true;\n int c = 0, p = 0;\n for (int i = 1; i < s.Length; i++)\n if (!f[s[i]])\n {\n Write(s.Substring(p, i - p));\n c++;\n p = i;\n f[s[i]] = true;\n if (c == n - 1)\n {\n Write(s.Substring(p));\n break;\n }\n }\n\n return null;\n }\n \n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"hull.in\");\n //writer = new StreamWriter(\"hull.out\");\n#endif\n try\n {\n// var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n// thread.Start();\n// thread.Join();\n var ret = new Solver().Solve();\n if (ret != null)\n Write(ret);\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() {return reader.ReadLine().Split(new[] { ' ', '\\t', '-' }, StringSplitOptions.RemoveEmptyEntries);}\n public static string ReadToken(){while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine());return currentLineTokens.Dequeue();}\n public static int ReadInt(){return int.Parse(ReadToken());}\n public static long ReadLong(){return long.Parse(ReadToken());}\n public static double ReadDouble(){return double.Parse(ReadToken(), CultureInfo.InvariantCulture);}\n public static int[] ReadIntArray(){return ReadAndSplitLine().Select(int.Parse).ToArray();}\n public static long[] ReadLongArray(){return ReadAndSplitLine().Select(long.Parse).ToArray();}\n public static double[] ReadDoubleArray(){return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();}\n public static int[][] ReadIntMatrix(int numberOfRows){int[][] matrix = new int[numberOfRows][];for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray();return matrix;}\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows){int[][] matrix = ReadIntMatrix(numberOfRows);int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++){ret[i] = new int[numberOfRows];for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i];}return ret;}\n public static string[] ReadLines(int quantity){string[] lines = new string[quantity];for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim();return lines;}\n public static void WriteArray(IEnumerable array){writer.WriteLine(string.Join(\" \", array));}\n public static void Write(params object[] array){WriteArray(array);}\n public static void WriteLines(IEnumerable array){foreach (var a in array)writer.WriteLine(a);}\n private class SDictionary : Dictionary{public new TValue this[TKey key]{\n get { return ContainsKey(key) ? base[key] : default(TValue); }set { base[key] = value; }}}\n private static T[] Init(int size) where T : new(){var ret = new T[size];for (int i = 0; i < size; i++)ret[i] = new T();return ret;}\n #endregion\n}", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"} {"source_code": "#define Online\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace CF\n{\n delegate double F(double x);\n delegate decimal Fdec(decimal x);\n\n\n class Program\n {\n\n static void Main(string[] args)\n {\n\n#if FileIO\n StreamReader sr = new StreamReader(\"input.txt\");\n StreamWriter sw = new StreamWriter(\"output.txt\");\n Console.SetIn(sr);\n Console.SetOut(sw);\n#endif\n\n D();\n\n#if Online\n Console.ReadLine();\n#endif\n\n#if FileIO\n sr.Close();\n sw.Close();\n#endif\n }\n\n static void A()\n {\n int n = ReadInt();\n int[] a = new int[n];\n int[] b = new int[n];\n for (int i = 0; i < n; i++)\n {\n string[] tokens = ReadArray(' ');\n a[i] = int.Parse(tokens[0]);\n b[i] = int.Parse(tokens[1]);\n }\n int ans = 0;\n for (int i = 0; i < n; i++)\n {\n bool isHere = false;\n for (int j = 0; j < n; j++)\n {\n if (i == j) continue;\n if (b[j] == a[i])\n isHere = true;\n }\n if (!isHere)\n ans++;\n }\n Console.WriteLine(ans);\n }\n\n static void B()\n {\n int n, m;\n string[] tokens = ReadArray(' ');\n n = int.Parse(tokens[0]);\n m = int.Parse(tokens[1]);\n int[] a = new int[n];\n tokens = ReadArray(' ');\n for (int i = 0; i < n; i++)\n a[i] = int.Parse(tokens[i]);\n\n int[] sum = new int[m + 1];\n int[] last = new int[n];\n StringBuilder ans = new StringBuilder();\n for (int i = 1; i <= m; i++)\n {\n sum[i] = sum[i - 1];\n tokens = ReadArray(' ');\n int t = int.Parse(tokens[0]);\n if (t == 1)\n {\n int v = int.Parse(tokens[1]);\n int x = int.Parse(tokens[2]);\n a[v - 1] = x;\n last[v - 1] = i;\n }\n if (t == 2)\n {\n int y = int.Parse(tokens[1]);\n sum[i] += y;\n }\n if (t == 3)\n {\n int q = int.Parse(tokens[1]);\n int val = a[q - 1] + (sum[i] - sum[last[q - 1]]);\n ans.AppendLine(val.ToString());\n }\n }\n Console.Write(ans);\n }\n\n static void C()\n {\n long n, k;\n string[] tokens = ReadArray(' ');\n n = long.Parse(tokens[0]);\n k = long.Parse(tokens[1]);\n long[] a = new long[n + 1];\n tokens = ReadArray(' ');\n for (int i = 1; i <= n; i++)\n {\n a[i] = long.Parse(tokens[i - 1]);\n }\n StringBuilder ans = new StringBuilder();\n long cnt = 0;\n long cur = 0;\n long _d = 0;\n for (int i = 1; i <= n; i++)\n {\n _d = 0;\n _d -= (i - 1 - cnt) * ((n-cnt) - (i-cnt)) * a[i];\n _d += cur;\n if (_d < k)\n {\n ans.AppendLine(i.ToString());\n cnt++;\n }\n else\n {\n cur += (i - cnt - 1) * a[i];\n }\n }\n Console.Write(ans);\n }\n\n static int FirstIndex(string a, string c, int i,int z, int j)\n {\n for (int k = 0; k < a.Length; k++, z++)\n {\n if (a[(i + z) % a.Length].Equals(c[j])) return (z + 1);\n }\n return -1;\n }\n\n static void D()\n {\n int b, d;\n string[] tokens = ReadArray(' ');\n b = int.Parse(tokens[0]);\n d = int.Parse(tokens[1]);\n string a = ReadLine();\n string c = ReadLine();\n\n int[] _cnt = new int[a.Length];\n for (int i = 0; i < a.Length; i++)\n {\n int z = 0;\n for (int j = 0; j < c.Length; j++)\n {\n int m = FirstIndex(a, c, i, z, j);\n if (m == -1)\n {\n Console.WriteLine(0);\n return;\n }\n z = m;\n }\n _cnt[i] = z;\n }\n\n int[] r = new int[a.Length];\n int[] __cnt = new int[a.Length];\n for (int i = 0; i < a.Length; i++)\n {\n int j = 0;\n for (int k = 0; k < a.Length; k++)\n r[k] = -1;\n for (int k = 0; k < d; j += _cnt[(i + j) % a.Length], k++)\n {\n if (r[(i + j) % a.Length] > 0)\n {\n int dif = j - r[(i + j) % a.Length];\n j += (d - k) * dif;\n break;\n }\n r[(i + j) % a.Length] = j;\n }\n __cnt[i] = j;\n }\n r = new int[a.Length];\n int[] _r = new int[a.Length];\n int p = 0;\n for (int j = 0; j < a.Length * b; )\n {\n if (r[j % a.Length] > 0)\n {\n int dif = j - r[j % a.Length];\n int _dif = p - _r[j % a.Length];\n p += ((a.Length * b - j) / dif) * (_dif);\n j += ((a.Length * b - j) / dif) * dif;\n while (j + __cnt[j % a.Length] <= a.Length * b)\n {\n p++;\n j += __cnt[j % a.Length];\n }\n break;\n }\n r[j % a.Length] = j;\n _r[j % a.Length] = p;\n j += __cnt[j % a.Length];\n if (j <= a.Length * b) p++;\n }\n Console.WriteLine(p);\n\n }\n\n static void E()\n {\n\n }\n\n static void TestGen()\n {\n\n }\n\n static string[] ReadArray(char sep)\n {\n return Console.ReadLine().Split(sep);\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n\n public static class MyMath\n {\n public static long BinPow(long a, long n, long mod)\n {\n long res = 1;\n while (n > 0)\n {\n if ((n & 1) == 1)\n {\n res = (res * a) % mod;\n }\n a = (a * a) % mod;\n n >>= 1;\n }\n return res;\n }\n\n public static long GCD(long a, long b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static int GCD(int a, int b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static long LCM(long a, long b)\n {\n return (a * b) / GCD(a, b);\n }\n\n public static int LCM(int a, int b)\n {\n return (a * b) / GCD(a, b);\n }\n }\n\n class Edge\n {\n public int a;\n public int b;\n public int w;\n\n public Edge(int a, int b, int w)\n {\n this.a = a;\n this.b = b;\n this.w = w;\n }\n }\n\n class Graph\n {\n public List[] g;\n public int[] color; //0-white, 1-gray, 2-black\n public int[] o; //open\n public int[] c; //close\n public int[] p;\n public int[] d;\n public List e;\n public Stack ans = new Stack();\n public Graph(int n)\n {\n g = new List[n + 1];\n for (int i = 0; i <= n; i++)\n g[i] = new List();\n color = new int[n + 1];\n o = new int[n + 1];\n c = new int[n + 1];\n p = new int[n + 1];\n d = new int[n + 1];\n }\n\n const int white = 0;\n const int gray = 1;\n const int black = 2;\n\n public bool DFS(int u, ref int time)\n {\n color[u] = gray;\n time++;\n o[u] = time;\n for (int i = 0; i < g[u].Count; i++)\n {\n int v = g[u][i];\n if (color[v] == gray)\n {\n return true;\n }\n if (color[v] == white)\n {\n p[v] = u;\n if (DFS(v, ref time)) return true;\n }\n }\n color[u] = black;\n ans.Push(u);\n c[u] = time;\n time++;\n return false;\n }\n }\n\n static class GraphUtils\n {\n const int white = 0;\n const int gray = 1;\n const int black = 2;\n\n public static void BFS(int s, Graph g)\n {\n Queue q = new Queue();\n q.Enqueue(s);\n while (q.Count != 0)\n {\n int u = q.Dequeue();\n for (int i = 0; i < g.g[u].Count; i++)\n {\n int v = g.g[u][i];\n if (g.color[v] == white)\n {\n g.color[v] = gray;\n g.d[v] = g.d[u] + 1;\n g.p[v] = u;\n q.Enqueue(v);\n }\n }\n g.color[u] = black;\n }\n }\n\n public static bool DFS(int u, ref int time, Graph g, Stack st)\n {\n g.color[u] = gray;\n time++;\n g.o[u] = time;\n for (int i = 0; i < g.g[u].Count; i++)\n {\n int v = g.g[u][i];\n if (g.color[v] == gray)\n {\n return true;\n }\n if (g.color[v] == white)\n {\n g.p[v] = u;\n if (DFS(v, ref time, g, st)) return true;\n }\n }\n g.color[u] = black;\n st.Push(u);\n g.c[u] = time;\n time++;\n return false;\n }\n\n public static void FordBellman(int u, Graph g)\n {\n int n = g.g.Length;\n for (int i = 0; i <= n; i++)\n {\n g.d[i] = int.MaxValue;\n g.p[i] = 0;\n }\n\n g.d[u] = 0;\n\n for (int i = 0; i < n - 1; i++)\n {\n for (int j = 0; j < g.e.Count; j++)\n {\n if (g.d[g.e[j].a] != int.MaxValue)\n {\n if (g.d[g.e[j].a] + g.e[j].w < g.d[g.e[j].b])\n {\n g.d[g.e[j].b] = g.d[g.e[j].a] + g.e[j].w;\n g.p[g.e[j].b] = g.e[j].a;\n }\n }\n }\n }\n }\n }\n\n static class ArrayUtils\n {\n public static int BinarySearch(int[] a, int val)\n {\n int left = 0;\n int right = a.Length - 1;\n int mid;\n\n while (left < right)\n {\n mid = left + ((right - left) >> 1);\n if (val <= a[mid])\n {\n right = mid;\n }\n else\n {\n left = mid + 1;\n }\n }\n\n if (a[left] == val)\n return left;\n else\n return -1;\n }\n\n public static double Bisection(F f, double left, double right, double eps)\n {\n double mid;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2d);\n if (Math.Sign(f(mid)) != Math.Sign(f(left)))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2d;\n }\n\n\n public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)\n {\n decimal m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3m;\n m2 = r - (r - l) / 3m;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static double TernarySearch(F f, double eps, double l, double r, bool isMax)\n {\n double m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3d;\n m2 = r - (r - l) / 3d;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R, Comparison comp)\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (comp(L[i], R[j]) <= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R, Comparison comp)\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R, comp);\n Merge_Sort(A, q + 1, r, L, R, comp);\n Merge(A, p, q, r, L, R, comp);\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (L[i].CompareTo(R[j]) >= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R) where T : IComparable\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R);\n Merge_Sort(A, q + 1, r, L, R);\n Merge(A, p, q, r, L, R);\n }\n\n static void Shake(T[] a)\n {\n Random rnd = new Random(Environment.TickCount);\n T temp;\n int b, c;\n for (int i = 0; i < a.Length; i++)\n {\n b = rnd.Next(0, a.Length);\n c = rnd.Next(0, a.Length);\n temp = a[b];\n a[b] = a[c];\n a[c] = temp;\n }\n }\n }\n}", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa"} {"source_code": "using System;\n\nnamespace CF_357A\n{\n class Program\n {\n static void Main()\n {\n int n = Int32.Parse(Console.ReadLine());\n string[] str = Console.ReadLine().Split(' ');\n long sumAll = 0;\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n {\n int temp = Int32.Parse(str[i]);\n sumAll += temp;\n a[i] = temp;\n }\n str = Console.ReadLine().Split(' ');\n int x = Int32.Parse(str[0]);\n int y = Int32.Parse(str[1]);\n\n\n int mark = 1;\n long sumLooser = a[0];\n long sumWinner = sumAll - sumLooser;\n\n bool solve = false;\n\n for (int i = 1; i < n; i++)\n {\n if (sumLooser >= x && sumLooser <= y && sumWinner >= x && sumWinner <= y)\n {\n solve = true;\n break;\n }\n mark++;\n sumLooser += a[i];\n sumWinner -= a[i];\n if (sumLooser > y || sumWinner < x)\n {\n break;\n }\n }\n\n if (solve)\n {\n Console.Write(++mark);\n }\n else\n {\n Console.Write(0);\n }\n }\n }\n}\n", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"} {"source_code": "using System;\nclass Program\n {\n static void Main(string[] args)\n {\n string[] input = Console.ReadLine().Split(new char[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n long a = long.Parse(input[0]), b = long.Parse(input[1]), diff = b-a;\n if (diff == 1) Console.WriteLine(input[1][input[1].Length - 1]);\n else if (diff >= 5) Console.WriteLine(\"0\");\n else\n {\n a = 1L;\n while(diff-->0)\n a *= b-- % 10L;\n Console.WriteLine((a % 10L));\n }\n }\n }", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n\t\t\tstring textBox1 = Console.ReadLine();\n \t\t string textBox2=\"\";//= Console.ReadLine();\n /* char[] arr;\n arr = num.ToCharArray(0, num.Length);\n */\n /* char[] arr2;\n arr2 = num.ToCharArray(0, num.Length);\n*/\n int len = textBox1.Length;\n int beg ;\n beg =Convert.ToInt32( Math.Pow(2, len))-1;\n int end = beg*2;\n int ser =(end-beg+1)/2;\n char[] first = new char[len];\n int i = 0;\n\n while (i < len)\n {\n first[i] = textBox1[i];\n i++;\n }\n i = 0;\n while (i < len)\n {\n if(first[i]=='4')\n {\n end = end - ser;\n ser = ser / 2;\n }\n else\n {\n beg = beg + ser;\n ser = ser / 2;\n }\n\n \n i++;\n \n }\n // label1.Text = Convert.ToString(beg);\n\t\t\t\t\t\n\t\t\tConsole.WriteLine(Convert.ToString(beg));\n\t\t\t\n }\n }\n} \n \n ", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\n\nclass Program\n{\n private static long[,] GetCount(int n, int m, long k)\n {\n var rows = new List();\n for (int i = 1; i <= n; i++) rows.Add(i);\n for (int i = n - 1; i > 1; i--) rows.Add(i);\n\n long[,] map = new long[n + 1, m + 1];\n long countPerIteration = 0;\n\n for (int i = 0; i < rows.Count; i++)\n for (int j = 1; j <= m; j++)\n {\n countPerIteration++;\n //map[rows[i], j]++;\n }\n\n long iterations = k / countPerIteration;\n\n for (int i = 0; i < rows.Count; i++)\n for (int j = 1; j <= m; j++)\n {\n map[rows[i], j] += iterations;\n }\n\n k %= countPerIteration;\n\n for (int i = 0; i < rows.Count; i++)\n for (int j = 1; j <= m; j++)\n {\n if (k > 0)\n {\n map[rows[i], j]++;\n k--;\n }\n }\n\n return map;\n }\n\n static void Main(string[] args)\n {\n int n = RI();\n int m = RI();\n long k = RL();\n int x = RI();\n int y = RI();\n\n var map = GetCount(n, m, k);\n\n var ser = map[x, y];\n long min = long.MaxValue;\n long max = 0;\n for (int i = 1; i <= n; i++)\n for (int j = 1; j <= m; j++)\n {\n max = Math.Max(max, map[i, j]);\n min = Math.Min(min, map[i, j]);\n }\n\n Console.WriteLine(max + \" \" + min + \" \" + ser);\n }\n\n private const int Mod = 1000000000 + 7;\n\n #region Data Read\n private static char ReadSign()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans == '+' || ans == '-' || ans == '?')\n return (char)ans;\n }\n }\n\n private static long GCD(long a, long b)\n {\n if (a % b == 0) return b;\n return GCD(b, a % b);\n }\n\n private static List[] ReadGraph(int n, int m)\n {\n List[] g = new List[n];\n for (int i = 0; i < g.Length; i++) g[i] = new List();\n for (int i = 0; i < m; i++)\n {\n int a = RI() - 1;\n int b = RI() - 1;\n\n g[a].Add(b);\n g[b].Add(a);\n }\n\n return g;\n }\n\n private static int[,] ReadGraphAsMatrix(int n, int m)\n {\n int[,] matrix = new int[n + 1, n + 1];\n for (int i = 0; i < m; i++)\n {\n int a = RI();\n int b = RI();\n matrix[a, b] = matrix[b, a] = 1;\n }\n\n return matrix;\n }\n\n private static void Sort(ref int a, ref int b)\n {\n if (a > b) Swap(ref a, ref b);\n }\n\n private static void Swap(ref int a, ref int b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n private const int BufferSize = 1 << 16;\n private static StreamReader consoleReader;\n private static MemoryStream testData;\n\n private static int RI()\n {\n int ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static ulong RUL()\n {\n ulong ans = 0;\n int chr;\n do\n {\n chr = consoleReader.Read();\n if (chr == -1)\n return 0;\n } while (chr < '0' || chr > '9');\n\n ans = (uint)(chr - '0');\n while (true)\n {\n chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans;\n ans = ans * 10 + (uint)(chr - '0');\n }\n }\n\n private static long RL()\n {\n long ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static int[] RIA(int n)\n {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = RI();\n return ans;\n }\n\n private static long[] RLA(int n)\n {\n long[] ans = new long[n];\n for (int i = 0; i < n; i++)\n ans[i] = RL();\n return ans;\n }\n\n private static char[] ReadWord()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n List s = new List();\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s.ToArray();\n }\n\n private static char[] ReadString(int n)\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n char[] s = new char[n];\n int pos = 0;\n do\n {\n s[pos++] = (char)ans;\n if (pos == n) break;\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s;\n }\n\n private static char[] ReadStringLine()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (ans == 10 || ans == 13);\n\n List s = new List();\n\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while (ans != 10 && ans != 13 && ans != -1);\n\n return s.ToArray();\n }\n\n private static char ReadLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))\n return (char)ans;\n }\n }\n private static char ReadNonLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))\n return (char)ans;\n }\n }\n\n private static char ReadAnyOf(IEnumerable allowed)\n {\n while (true)\n {\n char ans = (char)consoleReader.Read();\n if (allowed.Contains(ans))\n return ans;\n }\n }\n\n private static char ReadDigit()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans >= '0' && ans <= '9')\n return (char)ans;\n }\n }\n\n private static int ReadDigitInt()\n {\n return ReadDigit() - (int)'0';\n }\n\n private static char ReadAnyChar()\n {\n return (char)consoleReader.Read();\n }\n\n private static string DoubleToString(double x)\n {\n return x.ToString(CultureInfo.InvariantCulture);\n }\n\n private static double DoubleFromString(string x)\n {\n return double.Parse(x, CultureInfo.InvariantCulture);\n }\n\n static Program()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n }\n\n private static void PushTestData(StringBuilder sb)\n {\n PushTestData(sb.ToString());\n }\n private static void PushTestData(string data)\n {\n #if TOLYAN_TEST\n if (testData == null)\n {\n testData = new MemoryStream();\n consoleReader = new StreamReader(testData);\n }\n\n var pos = testData.Position;\n var bytes = Encoding.UTF8.GetBytes(data);\n testData.Write(bytes, 0, bytes.Length);\n testData.Flush();\n testData.Position = pos;\n #endif\n }\n #endregion\n}", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.Round55\n{\n class C\n {\n public static void Main()\n {\n int k = int.Parse(Console.ReadLine());\n string s = Console.ReadLine();\n int n = s.Length;\n bool[] used = new bool[26];\n for (int i = 0; i < n; i++)\n if (s[i] != '?')\n used[s[i] - 'a'] = true;\n char[] res = s.ToCharArray();\n\n for (int i = 0; i < n; i++)\n if (res[i] != '?' && res[n - 1 - i] == '?')\n res[n - 1 - i] = res[i];\n\n for (int i = k - 1; i >= 0; i--)\n if (!used[i])\n for (int j = n / 2; j >= 0; j--)\n if (res[j] == '?' && res[n - j - 1] == '?')\n {\n res[j] = res[n - j - 1] = (char)(i + 'a');\n used[i] = true;\n break;\n }\n\n for (int i = 0; i < n; i++)\n if (res[i] == '?' && res[n - 1 - i] == '?')\n res[n - 1 - i] = res[i] = 'a';\n\n for(int i = 0; i < k; i++)\n if (!used[i])\n {\n Console.WriteLine(\"IMPOSSIBLE\");\n return;\n }\n\n for (int i = 0; i < n; i++)\n if (res[i] != res[n - 1 - i])\n {\n Console.WriteLine(\"IMPOSSIBLE\");\n return;\n }\n\n Console.WriteLine(new string(res));\n }\n }\n}\n", "src_uid": "9d1dd9d722e5fe46823224334b3b208a"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nnamespace CodeForces\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n \r\n var n = Int32.Parse(Console.ReadLine());\r\n\r\n Console.WriteLine(GetVal(n));\r\n }\r\n\r\n\r\n const int MOD_VAL = 1000000007;\r\n private static int GetVal(int n)\r\n {\r\n var primes = GetAllPrimes(n);\r\n var res = 0;\r\n var primeCache = GetPrimeCache(primes, n);\r\n var dfsSolver = new DFSSolver(primeCache);\r\n for(var i = 1;i<=n-2;i++)\r\n {\r\n var primeFactors = GetPrimeFactors(i, primes);\r\n var primeMap = new Dictionary();\r\n foreach(var (prime, primeCnt) in primeFactors)\r\n {\r\n primeMap[prime] = primeCnt;\r\n }\r\n dfsSolver.SetPrimeMap(primeMap);\r\n dfsSolver.SetPrimeFactors(GetPrimeFactors(n-i, primes));\r\n res = (int)((res + (long)dfsSolver.GetRes()*i ) % MOD_VAL);\r\n }\r\n return res;\r\n }\r\n\r\n private class DFSSolver\r\n {\r\n private int _res;\r\n private Dictionary _primeMap;\r\n private List<(int,int)> _primeFactors;\r\n\r\n private Dictionary _primeCache;\r\n public DFSSolver(Dictionary primeCache)\r\n {\r\n _primeCache = primeCache;\r\n }\r\n\r\n public void SetPrimeMap(Dictionary primeMap)\r\n {\r\n _primeMap = primeMap;\r\n }\r\n\r\n public void SetPrimeFactors(List<(int,int)> primeFactors)\r\n {\r\n _primeFactors = primeFactors; \r\n }\r\n\r\n public int GetRes()\r\n {\r\n _res = 0;\r\n DFS(0,1);\r\n var tmp = 1;\r\n foreach(var (prime, cnt) in _primeFactors)\r\n {\r\n if(_primeMap.ContainsKey(prime))\r\n {\r\n if(cnt > _primeMap[prime])\r\n {\r\n tmp*= _primeCache[prime][cnt-_primeMap[prime]];\r\n }\r\n }\r\n else\r\n {\r\n tmp*= _primeCache[prime][cnt];\r\n }\r\n }\r\n _res-=tmp;\r\n if (_res < MOD_VAL) _res+=MOD_VAL;\r\n return _res;\r\n }\r\n\r\n private void DFS(int index, int val)\r\n {\r\n if(index == _primeFactors.Count)\r\n {\r\n _res = (_res + val) % MOD_VAL;\r\n return;\r\n }\r\n var prime = _primeFactors[index].Item1;\r\n var cnt = _primeFactors[index].Item2;\r\n for(var i = 0;i<= cnt;i++)\r\n {\r\n var append = 1;\r\n if(_primeMap.ContainsKey(prime))\r\n {\r\n if(i > _primeMap[prime])\r\n {\r\n append = _primeCache[prime][i - _primeMap[prime]];\r\n }\r\n }\r\n else\r\n {\r\n append = _primeCache[prime][i];\r\n }\r\n\r\n if (i < cnt)\r\n {\r\n append = append * (prime - 1) * _primeCache[prime][cnt-i-1]; \r\n }\r\n DFS(index+1, (int)((long)val * append % MOD_VAL));\r\n }\r\n }\r\n }\r\n\r\n private static Dictionary GetPrimeCache(List primes, int n)\r\n {\r\n var primeCache = new Dictionary();\r\n foreach(var prime in primes)\r\n {\r\n var list = new List();\r\n list.Add(1);\r\n var tmp = prime;\r\n while(tmp <= n)\r\n {\r\n list.Add(tmp);\r\n tmp*=prime;\r\n }\r\n primeCache[prime] = list.ToArray();\r\n }\r\n return primeCache;\r\n }\r\n\r\n private static int GetLCM(int num0, int num1)\r\n {\r\n return (int)((long)num0 * num1 /GetGCD(num0, num1));\r\n }\r\n\r\n private static int GetGCD(int num0, int num1)\r\n {\r\n if (num0 < num1)\r\n {\r\n var tmp = num1;\r\n num1 = num0;\r\n num0 = tmp;\r\n }\r\n while (num1 > 0)\r\n {\r\n var tmp = num1;\r\n num1 = num0 % num1;\r\n num0 = tmp;\r\n }\r\n return num0;\r\n }\r\n\r\n static List GetAllPrimes(int n)\r\n {\r\n var isNotPrimes = new bool[n+1];\r\n var primes = new List();\r\n for(var i = 2;i<=n;i++)\r\n {\r\n if (!isNotPrimes[i])\r\n {\r\n primes.Add(i);\r\n var num = i * 2;\r\n while(num <= n)\r\n {\r\n isNotPrimes[num]= true;\r\n num+=i;\r\n }\r\n }\r\n }\r\n return primes;\r\n }\r\n\r\n static List<(int,int)> GetPrimeFactors(int num, List primes)\r\n {\r\n var primeFactors = new List<(int,int)>();\r\n foreach(var prime in primes)\r\n {\r\n if (num < prime * prime) break;\r\n var cnt = 0;\r\n while(num % prime == 0)\r\n {\r\n cnt++;\r\n num/=prime;\r\n }\r\n if (cnt > 0)\r\n {\r\n primeFactors.Add((prime, cnt));\r\n }\r\n }\r\n if (num!=1)\r\n {\r\n primeFactors.Add((num, 1));\r\n }\r\n return primeFactors;\r\n }\r\n\r\n static int[] GetFactors(int num, List primes)\r\n {\r\n return GetFactors(GetPrimeFactors(num, primes));\r\n }\r\n\r\n static int[] GetFactors(List<(int,int)> primeFactors)\r\n {\r\n var factorCnt = 1;\r\n foreach(var (_, cnt) in primeFactors)\r\n {\r\n factorCnt*=cnt+1;\r\n }\r\n var factors = new int[factorCnt];\r\n var preCnt = 1;\r\n var index = 1;\r\n factors[0] = 1;\r\n foreach(var (prime, cnt) in primeFactors)\r\n {\r\n var factor = prime;\r\n for(var i = 1;i<=cnt;i++)\r\n {\r\n for(var j = 0;j int.Parse(s.ToString())).ToArray();\n var n = int.Parse(Console.ReadLine());\n var d = Console.ReadLine().Select(s => int.Parse(s.ToString())).ToArray();\n var p1 = d.Take(n).OrderBy(o => o).ToArray();\n var p2 = d.Skip(n).OrderBy(o => o).ToArray();\n bool sign = p1[0]>p2[0];\n bool fail = false;\n for (int i = 0; i < n; i++)\n {\n if (sign)\n {\n if (p1[i] > p2[i]) continue;\n else { fail = true; break; }\n }\n else\n {\n if (p1[i] < p2[i]) continue;\n else { fail = true; break; }\n }\n }\n Console.WriteLine(fail?\"NO\":\"YES\");\n }\n\n\n\n }\n}\n", "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Diagnostics;\nusing Pair = System.IComparable;\nusing Point = System.Tuple;\n\npublic class Solution : Helper\n{\n public Solution()\n {\n // http://codeforces.com/contest/899/problem/D\n var n = readInt32();\n long ans = 0;\n //\n if (n < 5)\n {\n ans = n * (n - 1) / 2;\n }\n else\n {\n var bs = bestSum(n);\n var str = bs.ToString();\n var f = str[0] - '0';\n if (f == 9)\n {\n ans = cp(bs, n);\n }\n else\n {\n range(0, f).each(h =>\n {\n ans += cp(int.Parse(str.Replace(\n f.ToString(),\n h.ToString()\n )), n);\n });\n }\n }\n //\n Console.WriteLine(ans);\n }\n //\n int cp(int sum, int n)\n {\n var a = sum / 2 + 1;\n var b = sum - 1;\n return count(a, Math.Min(b, n));\n }\n int count(int left, int right)\n {\n if (left > right) return 0;\n return (int)(right - left + 1);\n }\n int bestSum(int n)\n {\n var a = n + n - 1;\n var b = a.ToString();\n var c = b[0] - '0';\n var l = b.Length;\n var nines = b.Reverse().TakeWhile(x => x == '9').Count();\n if (nines >= l - 1)\n return a;\n return int.Parse((c - 1) + new string('9', l - 1));\n }\n}\n\n#region Core helper library\n[DebuggerNonUserCode]\nstatic partial class Extension\n{\n internal static IEnumerable each(this IEnumerable stream, Action act) { foreach (var elem in stream) act(elem); return stream; }\n internal static IEnumerable> kvp(this IEnumerable stream) { return stream.Select((elem, idx) => new KeyValuePair(idx, elem)); }\n internal static IEnumerable each(this IEnumerable stream, Action act) { stream.kvp().each(kvp => act(kvp.Value, kvp.Key)); return stream; }\n internal static IEnumerable indexIndices(this IList list) { return Helper.range(0, list.Count - 1); }\n internal static TValue? getOrDefault(this IDictionary dict, TKey key) where TValue : struct\n { TValue ans; if (dict.TryGetValue(key, out ans)) return ans; return null; }\n internal static T? FirstOrNullable(this IEnumerable stream) where T : struct { foreach (var val in stream) return val; return null; }\n internal static List Collect(this IEnumerable stream, int capacity) { var ans = new List(capacity); ans.AddRange(stream); return ans; }\n internal static LinkedList Collect(this IEnumerable stream) { return new LinkedList(stream); }\n}\n[DebuggerNonUserCode]\npublic partial class Helper\n{\n internal const int DEFAULT_BUFFER_SIZE = 4194304;\n internal static void fail(string reason = \"ASSERTION FAILED\") { throw new ApplicationException(reason); }\n internal static void debug(string reason = \"ASSERTION FAILED\") { Debug.Fail(reason); }\n internal static IEnumerable range(int left, int right) { for (var i = left; i <= right; i++) yield return i; }\n internal static int? explainSearchIndex(int rawIndex) { if (rawIndex < 0) return null; return rawIndex; }\n internal static Pair pair(T1 value1, T2 value2) { return Tuple.Create(value1, value2); }\n}\n#endregion\n\n// additional plugable library\npublic partial class Helper\n{\n #region STDIO\n#if !DEBUG\n static void Main() { new Solution(); }\n#endif\n static void eof() { throw new System.IO.EndOfStreamException(); }\n internal static string readLine_TRIM()\n { while (true) { var ans = Console.ReadLine(); if (ans == null) eof(); ans = ans.Trim(); if (ans.Any()) return ans; } }\n static IEnumerable stream() { while (true) { var iread = Console.Read(); if (iread < 0) break; yield return (char)iread; } }\n static bool isWhitespace(char c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'; }\n internal static string readString_TRIM(int maxCapacity)\n {\n var sb = new System.Text.StringBuilder(maxCapacity, maxCapacity);\n var iter = stream().SkipWhile(isWhitespace).TakeWhile(c => !isWhitespace(c));\n foreach (var c in iter) sb.Append(c);\n if (sb.Length == 0) eof(); return sb.ToString();\n }\n internal static long readLong64() { return long.Parse(readString_TRIM(21)); }\n internal static int readInt32() { return Convert.ToInt32(readLong64()); }\n #endregion\n}\nstatic partial class Extension\n{\n\n}", "src_uid": "c20744c44269ae0779c5f549afd2e3f2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] nM = Console.ReadLine().Split(' ');\n string[] str = Console.ReadLine().Split(' ');\n int n = int.Parse(nM[0]);\n int m = int.Parse(nM[1]);\n\n int k = 1;\n int Ob = 0;\n\n for (int i = 0; i < n; i++)\n {\n if (Ob + int.Parse(str[i]) <= m)\n Ob += int.Parse(str[i]);\n else \n {\n k++;\n Ob = int.Parse(str[i]);\n }\n \n }\n Console.WriteLine(k);\n }\n }\n}\n", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication35\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n string s = Console.ReadLine();\n int u = 0, d = 0,l=0,r=0,co=0;\n for (int i = 0; i < s.Length; i++)\n {\n if (s[i]=='U')\n {\n u++;\n }\n else if (s[i] == 'D')\n {\n d++;\n }\n else if (s[i] == 'R')\n {\n r++;\n }\n else if (s[i] == 'L')\n {\n l++;\n }\n }\n co += 2 * Math.Min(r, l) + 2 * Math.Min(u, d);\n Console.WriteLine(co);\n }\n }\n}\n", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace TaskA\n{\n class Program\n {\n static void Main(string[] args)\n {\n String[] sa = Console.ReadLine().Split('/');\n sa = (from x in sa where x != \"\" select x).ToArray();\n if (sa.Length == 0) Console.WriteLine('/');\n else foreach (String s in sa) Console.Write(\"/\" + s);\n }\n }\n}\n", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace Contest\n{\n internal class Program\n {\n private static void Main()\n {\n Console.ReadLine();\n var h = Console.ReadLine().ToCharArray();\n int X = h.Count(f=> f == 'X');\n int x = h.Count(z => z == 'x');\n if (X > x)\n {\n int r = (X - x)/2;\n Console.WriteLine(r);\n for (int i = 0; i < h.Length; i++)\n {\n if (h[i] == 'X')\n {\n h[i] = 'x';\n r--;\n }\n if(r==0) break;\n }\n }\n else if (x > X)\n {\n int r = (x - X)/2;\n Console.WriteLine(r);\n for (int i = 0; i < h.Length; i++)\n {\n if (h[i] == 'x')\n {\n h[i] = 'X';\n r--;\n }\n if (r == 0) break;\n }\n }\n else\n {\n Console.WriteLine(0);\n }\n \n Console.WriteLine(String.Join(\"\",h));\n }\n }\n}", "src_uid": "fa6311c72d90d8363d97854b903f849d"} {"source_code": "using System;\nusing Math = System.Math;\nusing Dec = System.Decimal;\nusing System.Globalization;\nusing System.Linq;\n\nnamespace taskA\n{\n\tclass newDecimal {\n\tprivate \n\t\t\tInt64 Z, F, kol;\n\tpublic newDecimal(decimal t, Int64 Kol) {\n\t\t\tkol = Kol;\n\t\t\tZ = Dec.ToInt64 (t);\n\t\t\tInt64 p = 1;\n\t\t\tfor (int i = 0; i < kol; i ++)\n\t\t\t\tp *= 10L;\t\t\n\t\t\tF = Dec.ToInt64 ((t - Z) * p);\n\t\t}\n\t\tpublic void print () {\n\t\t\tConsole.Write (\"{0}.\", Z);\n\t\t\tint sz = F.ToString ().Length;\n\t\t\tfor (int i = 0; i < kol - sz; i ++) \n\t\t\t\tConsole.Write (0);\n\t\t\tConsole.Write (F);\n\t\t}\n\t}\n\n\tclass MainClass\n\t{\n\t\tpublic static long[,] C = new long[800, 10];\n\n\t\tpublic static void PreCalc() {\n\t\t\tC [1,1] = 1L;\n\t\t\tC [2,1] = 2L;\n\t\t\tC [2,2] = 1L;\n\t\t\tfor (int i = 3; i <= 777; i ++) C[i,1] = 1L*i;\n\t\t\tfor (int i = 3; i <= 777; i ++)\n\t\t\t\tfor (int j = 2; j <= 7; j ++) \n\t\t\t\t\tC [i,j] = C [i - 1,j] + C [i - 1,j - 1];\n\t\t}\n\n\t\tpublic static void Main(string[] args) {\n\t\t\tPreCalc ();\n\t\t\tint n = int.Parse (Console.ReadLine ());\n\t\t\tlong ans = 0l;\n\n\t\t\tans += 4l * 3l * 2l * (1l << ((n - 3) << 1));\n\t\t\tif (n >= 4)\n\t\t\t\tans += 3L * 3L * (n - 3L) * (1L << (2 * (n - 3)));\n\t\t\tConsole.WriteLine (ans);\n\t\t}\n\t}\n}\n", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing static Template;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing Pi = Pair;\n\nclass Solver\n{\n Scanner sc = new Scanner();\n //\n public void Solve()\n {\n int l, r, x, y;\n sc.Make(out l, out r, out x, out y);\n var fx = Factorize(x);\n var fy = Factorize(y);\n foreach (var p in fx)\n {\n if (!fy.ContainsKey(p.Key)||fy[p.Key]();\n foreach (var p in fy)\n {\n if (!fx.ContainsKey(p.Key)) fx[p.Key] = 0;\n n.Add(new P(p.Key, p.Value, fx[p.Key]));\n }\n var res = 0;\n var ok = new Dictionary>();\n for(var i = 0; i < (1 << n.Count); i++)\n {\n long u = 1, v = 1;\n for(var j=0;j> j) == 1)\n {\n for (var k = 0; k < n[j].x; k++)\n u *= n[j].v;\n for (var k = 0; k < n[j].y; k++)\n v *= n[j].v;\n }\n else\n {\n for (var k = 0; k < n[j].x; k++)\n v *= n[j].v;\n for (var k = 0; k < n[j].y; k++)\n u *= n[j].v;\n }\n if (r < u || u < l || r < v || v < l) continue;\n if (!ok.ContainsKey(u))\n ok[u] = new Dictionary();\n if (!ok[u].ContainsKey(v))\n {\n res++;\n ok[u][v] = true;\n }\n }\n WriteLine(res);\n }\n struct P\n {\n public long v, x, y;\n public P(long V,int X,int Y)\n {\n v = V;x = X;y = Y;\n }\n }\n\n public static Dictionary Factorize(long num)\n {\n var dic = new Dictionary();\n for (var i = 2L; i * i <= num; i++)\n {\n var ct = 0;\n while (num % i == 0)\n {\n ct++;\n num /= i;\n }\n if (ct != 0) dic[i] = ct;\n }\n if (num != 1) dic[num] = 1;\n return dic;\n }\n}\n\n#region Template\npublic class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver().Solve();\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable\n { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable\n { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b)\n { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static T[] Create(int n, Func f)\n {\n var rt = new T[n];\n for (var i = 0; i < rt.Length; ++i)\n rt[i] = f();\n return rt;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static T[] Create(int n, Func f)\n {\n var rt = new T[n];\n for (var i = 0; i < rt.Length; ++i)\n rt[i] = f(i);\n return rt;\n }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\n\npublic class Scanner\n{\n public string Str => ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n public Pair PairMake() => new Pair(Next(), Next());\n public Pair PairMake() => new Pair(Next(), Next(), Next());\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n}\n\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }\n}\n#endregion\n", "src_uid": "d37dde5841116352c9b37538631d0b15"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\nusing Point = System.Numerics.Complex;\nusing Number = System.Int64;\nnamespace Program\n{\n public class Solver\n {\n public void Solve()\n {\n var q = sc.Integer();\n var par = new int[500002];\n par[0] = -1;\n var dp = Enumerate(500002, x => new double[45]);\n for (int i = 1; i < 45; i++)\n dp[0][i] = 1.0;\n\n var ptr = 1;\n Action recalc = null;\n recalc = v =>\n {\n for (int h = 1; h < 40; h++)\n dp[v][h] = 1.0;\n var ps = new List();\n for (int h = 0; h <= 40; h++)\n {\n if (v == -1) break;\n ps.Add(v);\n v = par[v];\n }\n for (int i = ps.Count - 2; i > 0; i--)\n {\n var u = ps[i]; var h = i;\n var p = ps[i + 1];\n dp[p][h + 1] /= (dp[u][h] + 1) / 2;\n }\n for (int i = 0; i + 1 < ps.Count; i++)\n {\n var u = ps[i]; var h = i;\n var p = ps[i + 1];\n dp[p][h + 1] *= (dp[u][h] + 1) / 2;\n }\n };\n for (int i = 0; i < q; i++)\n {\n if (sc.Integer() == 1)\n {\n var p = sc.Integer() - 1;\n par[ptr] = p;\n recalc(ptr);\n ptr++;\n\n }\n else\n {\n var v = sc.Integer() - 1;\n var ans = 0.0;\n for (int h = 1; h < 40; h++)\n ans += 1 - dp[v][h];\n Debug.WriteLine(dp[v].AsJoinedString());\n IO.Printer.Out.WriteLine(ans);\n\n }\n }\n }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n\n#region main\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Text;\n using System.Globalization;\n public class Printer: StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, T[] source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, T[] source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }\n\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n'; b = (char)read())\n if (b == 0) break;\n else if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != 0 && b != '-' && (b < '0' || '9' < b));\n if (b == 0) return long.MinValue;\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { var s = Scan(); return s != \"\" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public char[] Char(int n) { return enumerate(n, Char); }\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n }\n}\n#endregion\n\n", "src_uid": "55affe752cb214d1e4031a9e3972597b"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace A_TrickyAlchemy\n{\n class Program\n {\n static void Main(string[] args)\n {\n var having = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();\n var want = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();\n var neededYellow = 2 * want[0] + want[1];\n var neededBlue = want[1] + 3 * want[2];\n var result = Math.Max(0, neededYellow - having[0]) + Math.Max(0, neededBlue - having[1]);\n\n Console.WriteLine(result);\n }\n }\n}\n", "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\n \nnamespace Solution\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.ReadLine();\n var a = Console.ReadLine();\n var SFtoS = Regex.Matches(a, \"FS\");\n var StoSF = Regex.Matches(a, \"SF\");\n Console.WriteLine(StoSF.Count > SFtoS.Count ? \"YES\" : \"NO\");\n }\n }\n}", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"source_code": "// Submitted by Silithus @ Macau\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace CF389_Round228d2\n{\n\tclass CF389A\n\t{\n\t\tpublic int GCD(int a, int b)\n\t\t{\n\t\t\tint t;\n\t\t\tif (a < b) { t = b; b = a; a = t; }\n\t\t\twhile ((t = a % b) != 0) { a = b; b = t; }\n\t\t\treturn b;\n\t\t}\n\n\t\tpublic void Solve()\n\t\t{\n\t\t\tint i, N,ans;\n\t\t\tint[] x = new int[100];\n\n\t\t\tN = XOI.r32();\n\t\t\tans = XOI.r32();\n\t\t\tfor(i=1; i= '0'; c = Console.Read())\n\t\t\t\tn = n * 10 + (c - '0');\n\t\t\treturn n;\n\t\t}\n\n\t\tpublic static void r32x2(out int a, out int b)\n\t\t{\n\t\t\ta = XOI.r32();\n\t\t\tb = XOI.r32();\n\t\t}\n\n\t\tpublic static void r32x3(out int a, out int b, out int c)\n\t\t{\n\t\t\tXOI.r32x2(out a, out b);\n\t\t\tc = XOI.r32();\n\t\t}\n\n\t\tpublic static long r64()\n\t\t{\n\t\t\tlong n, c;\n\t\t\tdo { c = Console.Read(); } while (c < '0');\n\t\t\tfor (n = 0; c >= '0'; c = Console.Read())\n\t\t\t\tn = n * 10 + (c - '0');\n\t\t\treturn n;\n\t\t}\n\t}\n}\n", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CSharp\n{\n public class _9A\n {\n public static void Main(string[] args)\n {\n switch (Console.ReadLine().Split().Select(token => int.Parse(token)).Max())\n {\n case 1:\n Console.WriteLine(\"1/1\");\n break;\n case 2:\n Console.WriteLine(\"5/6\");\n break;\n case 3:\n Console.WriteLine(\"2/3\");\n break;\n case 4:\n Console.WriteLine(\"1/2\");\n break;\n case 5:\n Console.WriteLine(\"1/3\");\n break;\n case 6:\n Console.WriteLine(\"1/6\");\n break;\n }\n }\n }\n}", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApp5\n{\n public class Program\n {\n //var t = int.Parse(Console.ReadLine());\n //var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n\n static void Main()\n {\n var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n var r = a[0];\n var c = a[1];\n var setR = new HashSet();\n var setC = new HashSet();\n for (int i = 0; i < r; i++)\n {\n var s = Console.ReadLine();\n for (int j = 0; j < c; j++)\n {\n if (s[j] == 'S')\n {\n setR.Add(i);\n setC.Add(j);\n }\n }\n }\n\n var rCount = r - setR.Count();\n var cCount = c - setC.Count();\n var res = rCount * c + cCount * r - rCount * cCount;\n Console.WriteLine(res);\n }\n }\n}", "src_uid": "ebaf7d89c623d006a6f1ffd025892102"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Test\n{\n class IOHelper : IDisposable\n {\n StreamReader reader;\n StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding)\n {\n StreamReader iReader;\n StreamWriter oWriter;\n if (inputFile == null)\n iReader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n iReader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n oWriter = new StreamWriter(outputFile, false, encoding);\n\n reader = iReader;\n writer = oWriter;\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public string ReadNextToken()\n {\n if (curTokenIdx >= curLine.Length)\n {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n if (curTokenIdx >= curLine.Length)\n return null;\n\n return curLine[curTokenIdx++];\n }\n\n public int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n public double ReadNextDouble()\n {\n var nextToken = ReadNextToken();\n var result = 0.0;\n nextToken = nextToken.Replace(\".\", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);\n result = double.Parse(nextToken);\n return result;\n }\n\n public void Write(string stringToWrite)\n {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(string stringToWrite)\n {\n writer.WriteLine(stringToWrite);\n }\n\n public void WriteLine(double valueToWrite)\n {\n long intPart = (long)valueToWrite;\n double fracPart = valueToWrite - intPart;\n var fracPartStr = fracPart.ToString(\"F8\");\n if (fracPartStr.Length > 1)\n fracPartStr = fracPartStr.Substring(2);\n var strToWrite = string.Format(\"{0}.{1}\", intPart, fracPartStr);\n writer.WriteLine(strToWrite);\n }\n\n public void Dispose()\n {\n try\n {\n if (reader != null)\n {\n reader.Dispose();\n }\n if (writer != null)\n {\n writer.Dispose();\n }\n }\n catch { };\n }\n\n\n public void Flush()\n {\n if (writer != null)\n {\n writer.Flush();\n }\n }\n }\n\n class Program\n {\n protected IOHelper ioHelper;\n\n int n;\n int k;\n\n int[] types;\n int E, S;\n\n int Compute(int r)\n {\n int j;\n int e = 0;\n int s = 0;\n for(j=r;j best)\n best = resHere;\n }\n\n\n ioHelper.WriteLine(best.ToString());\n ioHelper.Flush();\n\n //Console.ReadKey();\n }\n\n public Program(string inputFile, string outputFile)\n {\n ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);\n Solve();\n ioHelper.Dispose();\n }\n\n static void Main(string[] args)\n {\n Program myProgram = new Program(null, null);\n }\n }\n}", "src_uid": "6119258322e06fa6146e592c63313df3"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Candy_Boxes\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int n = Next();\n\n if (n == 0)\n {\n writer.Write(\"YES\\n1\\n1\\n3\\n3\");\n writer.Flush();\n return;\n }\n\n var nn = new int[n];\n for (int i = 0; i < n; i++)\n {\n nn[i] = Next();\n }\n\n Array.Sort(nn);\n\n if (n == 1)\n {\n writer.WriteLine(\"YES\");\n writer.WriteLine(nn[0]);\n writer.WriteLine(nn[0]*3);\n writer.WriteLine(nn[0]*3);\n }\n else if (n == 2)\n {\n if (nn[0]*3 == nn[1])\n {\n writer.WriteLine(\"YES\");\n writer.WriteLine(nn[0]);\n writer.WriteLine(nn[0]*3);\n }\n else if (nn[0]*3 > nn[1])\n {\n writer.WriteLine(\"YES\");\n writer.WriteLine(nn[0]*4 - nn[1]);\n writer.WriteLine(nn[0]*3);\n }\n else\n {\n writer.WriteLine(\"NO\");\n }\n }\n else if (n == 3)\n {\n if (nn[0]*3 == nn[2])\n {\n writer.WriteLine(\"YES\");\n writer.WriteLine(nn[0]*4 - nn[1]);\n }\n else if (nn[0]*3 > nn[2])\n {\n if (4*nn[0] == nn[1] + nn[2])\n {\n writer.WriteLine(\"YES\");\n writer.WriteLine(nn[0]*3);\n }\n else if (nn[2]%3 == 0 && 4*nn[2]/3 == nn[0] + nn[1])\n {\n writer.WriteLine(\"YES\");\n writer.WriteLine(nn[2]/3);\n }\n else\n {\n writer.WriteLine(\"NO\");\n }\n }\n else\n {\n writer.WriteLine(\"NO\");\n }\n }\n else\n {\n writer.WriteLine(nn[0]*3 == nn[3] && (nn[0] + nn[3] == nn[1] + nn[2]) ? \"YES\" : \"NO\");\n }\n\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "230e613abf0f6a768829cbc1f1a09219"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace c1cs\n{\n class Program\n {\n static void Main()\n {\n int ans = 0;\n string[] ss = Console.ReadLine().Split();\n int n = int.Parse(ss[0]);\n int m = int.Parse(ss[1]);\n if (n > m)\n {\n int a = n;\n n = m;\n m = a;\n }\n if (n == 1) ans = ((m - 1) / 3 + 1);\n if (n == 2) ans = m / 2 + 1;\n if (n == 3)\n {\n if (m < 5) ans = m;\n else\n {\n int mo = (m - 5) / 4 + 1;\n ans = m - mo;\n }\n }\n if (n == 4)\n {\n if (m % 2 == 0) ans = m;\n else ans = m + 1;\n if (m == 6) ans = 7;\n if (m == 7) ans = 7;\n }\n if (n == 5)\n {\n if (m == 5) ans = 7;\n if (m == 6) ans = 8;\n if (m == 7) ans = 9;\n if (m == 8) ans = 11;\n }\n if (n == 6) ans = (10);\n Console.WriteLine(n * m - ans);\n }\n }\n}\n", "src_uid": "097674b4dd696b30e102938f71dd39b9"} {"source_code": "using System;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Threading;\n\nnamespace CodeForces\n{\n\tclass A\n\t{\n\t\tScanner In = new Scanner();\n\t\tTextWriter Out = Console.Out;\n\n\t\tprivate void Solve()\n\t\t{\n\t\t\tvar n = In.NextInt();\n\t\t\tif ( n == 1 )\n\t\t\t{\n\t\t\t\tOut.WriteLine( 0 );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar lst = new List();\n\t\t\tvar res = int.MaxValue;\n\t\t\tfor ( var i = 1; i < n; ++i )\n\t\t\t{\n\t\t\t\tlst.Add( i );\n\t\t\t\tvar x = i;\n\t\t\t\tvar cur = 0;\n\t\t\t\tvar y = n;\n\t\t\t\twhile ( x > 0 && y > 0 )\n\t\t\t\t{\n\t\t\t\t\tif ( x > y )\n\t\t\t\t\t{\n\t\t\t\t\t\tcur += x / y;\n\t\t\t\t\t\tx %= y;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcur += y / x;\n\t\t\t\t\t\ty %= x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( x + y == 1 )\n\t\t\t\t\tres = Math.Min( res, cur );\n\t\t\t}\n\n\n\t\t\tOut.WriteLine( res - 1 );\n\t\t}\n\n\t\t#region Local wireup\n\n\t\tvoid Start()\n\t\t{\n#if !ONLINE_JUDGE\n\t\t\tStopwatch timer = new Stopwatch();\n\t\t\ttimer.Start();\n#endif\n\t\t\tThread t = new Thread( Solve, 20000000 );\n\t\t\tt.Start();\n\t\t\tt.Join();\n#if !ONLINE_JUDGE\n\t\t\ttimer.Stop();\n\t\t\tConsole.WriteLine( string.Format( \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0 ) );\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\n\t\tstatic void Main( string[] args )\n\t\t{\n\t\t\tnew A().Start();\n\t\t}\n\n\t\tclass Scanner : IDisposable\n\t\t{\n\t\t\t#region Fields\n\n\t\t\tTextReader _reader;\n\t\t\tint _bufferSize;\n\t\t\tbool _closeReader;\n\t\t\tchar[] _buffer;\n\t\t\tint _length, _pos;\n\n\t\t\t#endregion\n\n\t\t\t#region .ctors\n\n\t\t\tpublic Scanner( TextReader reader, int bufferSize, bool closeReader )\n\t\t\t{\n\t\t\t\t_reader = reader;\n\t\t\t\t_bufferSize = bufferSize;\n\t\t\t\t_closeReader = closeReader;\n\t\t\t\t_buffer = new char[_bufferSize];\n\t\t\t\tFillBuffer( false );\n\t\t\t}\n\n\t\t\tpublic Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }\n\n\t\t\tpublic Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }\n\n#if ONLINE_JUDGE\n\t\t\tpublic Scanner() : this( Console.In, false ) { }\n#else\n\t\t\tpublic Scanner() : this( \"input.txt\" ) { }\n#endif\n\n\t\t\t#endregion\n\n\t\t\t#region IDisposable Members\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\tif ( _closeReader )\n\t\t\t\t{\n\t\t\t\t\t_reader.Close();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Properties\n\n\t\t\tpublic bool Eof\n\t\t\t{\n\t\t\t\tget\n\t\t\t\t{\n\t\t\t\t\tif ( _pos < _length ) return false;\n\t\t\t\t\tFillBuffer( false );\n\t\t\t\t\treturn _pos >= _length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Methods\n\n\t\t\tprivate char NextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos++];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos++];\n\t\t\t}\n\n\t\t\tprivate char PeekNextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos];\n\t\t\t}\n\n\t\t\tprivate void FillBuffer( bool throwOnEof )\n\t\t\t{\n\t\t\t\t_length = _reader.Read( _buffer, 0, _bufferSize );\n\t\t\t\tif ( throwOnEof && Eof )\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException( \"Can't read beyond the end of file\" );\n\t\t\t\t}\n\t\t\t\t_pos = 0;\n\t\t\t}\n\n\t\t\tpublic int NextInt()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tint res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic long NextLong()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic string NextLine()\n\t\t\t{\n\t\t\t\tSkipUntilNextLine();\n\t\t\t\tif ( Eof ) return \"\";\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn builder.ToString();\n\t\t\t}\n\n\t\t\tpublic double NextDouble()\n\t\t\t{\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn double.Parse( builder.ToString(), CultureInfo.InvariantCulture );\n\t\t\t}\n\n\t\t\tprivate void SkipWhitespaces()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void SkipUntilNextLine()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static bool IsWhitespace( char c )\n\t\t\t{\n\t\t\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\tprivate static bool IsEndOfLine( char c )\n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\t#endregion\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "75739f77378b21c331b46b1427226fa1"} {"source_code": "using System;\n\nnamespace Test\n{\n class MainClass\n {\n public static void Main (string[] args)\n {\n string wall = Console.ReadLine ();\n int k = 0, i = 0;\n while (i < wall.Length) {\n char curr = wall[i];\n int j = i;\n while(j < wall.Length && wall[j] == curr && j - i < 5)\n j++;\n i = j;\n k++;\n }\n Console.Write (k);\n }\n }\n}\n", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n var x = int.Parse(Console.ReadLine());\n var n = 0;\n while (x > 0)\n {\n var log = (int) Math.Log(x, 2);\n var newX = (int) Math.Pow(2, log);\n x = x - newX;\n n++;\n }\n Console.WriteLine(n);\n //Console.ReadLine();\n }\n }\n}\n", "src_uid": "03e4482d53a059134676f431be4c16d2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Collections;\n\nnamespace Practice\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = new string[3];\n for (int i = 0; i < 3;i++)\n {\n s[i] = Console.ReadLine();\n }\n SolveProblem(s);\n Console.ReadLine();\n\n }\n\n static void SolveProblem(string [] s)\n {\n Dictionary coins = new Dictionary();\n coins.Add('A',0);\n coins.Add('B', 0);\n coins.Add('C', 0);\n\n for (int i = 0; i < s.Length;i++)\n {\n switch (s [i] [1])\n {\n case '>':\n coins[s[i][0]] += 1;\n break;\n case '<':\n coins[s[i][2]] += 1;\n break;\n \n }\n }\n \n if (coins ['A'] == coins ['B'] && coins['B'] == coins['C'])\n {\n Console.WriteLine(\"Impossible\");\n\n } else\n {\n var items = from pair in coins\n orderby pair.Value ascending\n select pair;\n foreach (KeyValuePair pair in items)\n {\n Console.Write(pair.Key);\n }\n }\n }\n\n }\n\n}\n", "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Util;\nusing System.Threading;\nusing CompLib.Mathematics;\nusing CompLib.String;\n\npublic class Program\n{\n int N;\n string S;\n public void Solve()\n {\n var sc = new Scanner();\n N = sc.NextInt();\n S = sc.Next();\n\n int cnt = 0;\n int min = 0;\n foreach (var c in S)\n {\n if (c == '(') cnt++;\n else cnt--;\n min = Math.Min(min, cnt);\n }\n /*\n * Sを部分文字列に含むカッコ列の個数\n */\n\n // iで間違えたときどこに飛ぶか?\n int[] next = new int[S.Length];\n for (int i = 0; i < S.Length; i++)\n {\n if (i == 0)\n {\n next[i] = 0;\n continue;\n }\n\n bool f2 = false;\n for (int len = i; len >= 1; len--)\n {\n bool f = true;\n for (int j = 0; f && j < len - 1; j++)\n {\n f &= S[j] == S[i - len + 1 + j];\n }\n if (!f) continue;\n if (S[len - 1] != S[i])\n {\n next[i] = len;\n f2 = true;\n break;\n }\n }\n\n }\n\n // i文字目まで作る、カウンタ、Sより前、Sより後, Sの何文字までできたか?\n var dp = new ModInt[2 * N + 1, N + 1, S.Length, 2];\n dp[0, 0, 0, 0] = 1;\n for (int i = 0; i < 2 * N; i++)\n {\n for (int j = 0; j <= N; j++)\n {\n for (int k = 0; k < S.Length; k++)\n {\n // (\n if (j + 1 <= N)\n {\n if (S[k] == '(')\n {\n if (k + 1 == S.Length)\n {\n dp[i + 1, j + 1, 0, 1] += dp[i, j, k, 0];\n }\n else\n {\n dp[i + 1, j + 1, k + 1, 0] += dp[i, j, k, 0];\n }\n }\n else\n {\n // どこに飛ぶ\n dp[i + 1, j + 1, next[k], 0] += dp[i, j, k, 0];\n }\n\n\n }\n\n if (j - 1 >= 0)\n {\n if (S[k] == ')')\n {\n if (k + 1 == S.Length)\n {\n dp[i + 1, j - 1, 0, 1] += dp[i, j, k, 0];\n }\n else\n {\n dp[i + 1, j - 1, k + 1, 0] += dp[i, j, k, 0];\n }\n }\n else\n {\n dp[i + 1, j - 1, next[k], 0] += dp[i, j, k, 0];\n }\n\n }\n }\n\n if (j + 1 <= N)\n {\n dp[i + 1, j + 1, 0, 1] += dp[i, j, 0, 1];\n }\n if (j - 1 >= 0)\n {\n dp[i + 1, j - 1, 0, 1] += dp[i, j, 0, 1];\n }\n }\n }\n\n Console.WriteLine(dp[2 * N, 0, 0, 1]);\n }\n\n public static void Main(string[] args) => new Program().Solve();\n // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();\n}\n\n\nnamespace CompLib.String\n{\n using System;\n using System.Collections.Generic;\n using System.Diagnostics;\n public static partial class StringACL\n {\n private const int ThresholdNative = 10;\n private const int ThresholdDoubling = 40;\n\n #region SuffixArray\n public static int[] SuffixArray(int[] s, int upper)\n {\n Debug.Assert(0 <= upper);\n\n // C++みたいに内部で何もしないループをスキップするのか?\n // してくれるなら #ifいらない\n#if DEBUG\n foreach (var d in s)\n {\n Debug.Assert(0 <= d && d <= upper);\n }\n#endif\n return SAIS(s, upper);\n }\n\n public static int[] SuffixArray(T[] s, Comparison cmp)\n {\n int n = s.Length;\n int[] idx = new int[n];\n for (int i = 0; i < n; i++)\n {\n idx[i] = i;\n }\n\n Array.Sort(idx, (l, r) => cmp(s[l], s[r]));\n\n int[] s2 = new int[n];\n int now = 0;\n for (int i = 0; i < n; i++)\n {\n if (0 < i && cmp(s[idx[i - 1]], s[idx[i]]) != 0) now++;\n s2[idx[i]] = now;\n }\n\n return SAIS(s2, now);\n }\n public static int[] SuffixArray(T[] s)\n {\n return SuffixArray(s, Comparer.Default.Compare);\n }\n\n /// \n /// 長さnの文字列のsuffixArrayを返す\n /// \n /// \n /// {0,1,2,...,n-1}の順列、s[sa[i],n) < s[sa[i+1],n)\n /// suffixArrayの辞書順\n /// \n /// \n /// \n public static int[] SuffixArray(string s)\n {\n int n = s.Length;\n int[] s2 = new int[n];\n for (int i = 0; i < n; i++)\n {\n s2[i] = s[i];\n }\n return SAIS(s2, 255);\n }\n\n // O(n^2)\n private static int[] SANative(int[] s)\n {\n int n = s.Length;\n int[] sa = new int[n];\n for (int i = 0; i < n; i++)\n {\n sa[i] = i;\n }\n Array.Sort(sa, (l, r) =>\n {\n // 同じなら0\n if (l == r) return 0;\n // 順番に見る\n while (l < n && r < n)\n {\n\n if (s[l] != s[r]) return s[l].CompareTo(s[r]);\n l++;\n r++;\n }\n\n // indexが大きい方が辞書順で小さい\n return r.CompareTo(l);\n });\n return sa;\n }\n private static int[] SADoubling(int[] s)\n {\n int n = s.Length;\n int[] sa = new int[n];\n int[] rnk = new int[n];\n int[] tmp = new int[n];\n Array.Copy(s, rnk, n);\n for (int i = 0; i < n; i++)\n {\n sa[i] = i;\n }\n\n for (int k = 1; k < n; k *= 2)\n {\n Comparison cmp = (int x, int y) =>\n {\n if (rnk[x] != rnk[y]) return rnk[x].CompareTo(rnk[y]);\n int rx = x + k < n ? rnk[x + k] : -1;\n int ry = y + k < n ? rnk[y + k] : -1;\n return rx.CompareTo(ry);\n };\n\n Array.Sort(sa, cmp);\n tmp[sa[0]] = 0;\n for (int i = 1; i < n; i++)\n {\n tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) < 0 ? 1 : 0);\n }\n\n var t = tmp;\n tmp = rnk;\n rnk = t;\n }\n\n return sa;\n }\n\n private static int[] SAIS(int[] s, int upper)\n {\n int n = s.Length;\n if (n == 0) return new int[0];\n if (n == 1) return new int[1];\n if (n == 2)\n {\n if (s[0] < s[1])\n {\n return new int[] { 0, 1 };\n }\n else\n {\n return new int[] { 1, 0 };\n }\n }\n\n if (n < ThresholdNative)\n {\n return SANative(s);\n }\n\n if (n < ThresholdDoubling)\n {\n return SADoubling(s);\n }\n\n int[] sa = new int[n];\n bool[] ls = new bool[n];\n\n for (int i = n - 2; i >= 0; i--)\n {\n ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);\n }\n\n int[] sumL = new int[upper + 1];\n int[] sumS = new int[upper + 1];\n\n for (int i = 0; i < n; i++)\n {\n if (!ls[i])\n {\n sumS[s[i]]++;\n }\n else\n {\n sumL[s[i] + 1]++;\n }\n }\n\n for (int i = 0; i <= upper; i++)\n {\n sumS[i] += sumL[i];\n if (i < upper) sumL[i + 1] += sumS[i];\n }\n\n Action> induce = (List lms) =>\n {\n for (int i = 0; i < n; i++)\n {\n sa[i] = -1;\n }\n\n int[] buf = new int[upper + 1];\n Array.Copy(sumS, buf, upper + 1);\n\n foreach (var d in lms)\n {\n if (d == n) continue;\n sa[buf[s[d]]++] = d;\n }\n\n Array.Copy(sumL, buf, upper + 1);\n sa[buf[s[n - 1]]++] = n - 1;\n for (int i = 0; i < n; i++)\n {\n int v = sa[i];\n if (v >= 1 && !ls[v - 1])\n {\n sa[buf[s[v - 1]]++] = v - 1;\n }\n }\n\n Array.Copy(sumL, buf, upper + 1);\n\n for (int i = n - 1; i >= 0; i--)\n {\n int v = sa[i];\n if (v >= 1 && ls[v - 1])\n {\n sa[--buf[s[v - 1] + 1]] = v - 1;\n }\n }\n };\n\n int[] lmsMap = new int[n + 1];\n for (int i = 0; i <= n; i++)\n {\n lmsMap[i] = -1;\n }\n\n int m = 0;\n for (int i = 1; i < n; i++)\n {\n if (!ls[i - 1] && ls[i])\n {\n lmsMap[i] = m++;\n }\n }\n\n List lmsL = new List(m);\n for (int i = 1; i < n; i++)\n {\n if (!ls[i - 1] && ls[i])\n {\n lmsL.Add(i);\n }\n }\n\n induce(lmsL);\n\n if (m != 0)\n {\n List sortedLms = new List(m);\n foreach (var v in sa)\n {\n if (lmsMap[v] != -1) sortedLms.Add(v);\n }\n\n int[] recS = new int[m];\n\n int recUpper = 0;\n recS[lmsMap[sortedLms[0]]] = 0;\n for (int i = 1; i < m; i++)\n {\n int l = sortedLms[i - 1], r = sortedLms[i];\n int endL = (lmsMap[l] + 1 < m) ? lmsL[lmsMap[l] + 1] : n;\n int endR = (lmsMap[r] + 1 < m) ? lmsL[lmsMap[r] + 1] : n;\n\n bool same = true;\n\n if (endL - l != endR - r)\n {\n same = false;\n }\n else\n {\n while (l < endL)\n {\n if (s[l] != s[r])\n {\n break;\n }\n l++;\n r++;\n }\n\n if (l == n || s[l] != s[r]) same = false;\n }\n\n if (!same) recUpper++;\n recS[lmsMap[sortedLms[i]]] = recUpper;\n }\n\n var recSa = SAIS(recS, recUpper);\n\n for (int i = 0; i < m; i++)\n {\n sortedLms[i] = lmsL[recSa[i]];\n }\n\n induce(sortedLms);\n }\n return sa;\n }\n #endregion // SuffixArray\n\n #region LCPArray\n /// \n /// sのLCPArrayとして長さ n-1の配列を返す\n /// \n /// \n /// res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common Prefixの長さ\n /// O(n)\n /// \n /// \n /// \n /// \n /// \n /// \n public static int[] LCPArray(T[] s, int[] sa, Comparison cmp)\n {\n int n = s.Length;\n Debug.Assert(n >= 1);\n int[] rnk = new int[n];\n for (int i = 0; i < n; i++)\n {\n rnk[sa[i]] = i;\n }\n\n int[] lcp = new int[n - 1];\n int h = 0;\n for (int i = 0; i < n; i++)\n {\n if (h > 0) h--;\n if (rnk[i] == 0) continue;\n int j = sa[rnk[i] - 1];\n for (; j + h < n && i + h < n; h++)\n {\n if (cmp(s[j + h], s[i + h]) != 0) break;\n }\n lcp[rnk[i] - 1] = h;\n }\n\n return lcp;\n }\n\n /// \n /// sのLCPArrayとして長さ n-1の配列を返す\n /// \n /// \n /// res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common Prefixの長さ\n /// O(n)\n /// \n /// \n /// \n /// \n /// \n public static int[] LCPArray(T[] s, int[] sa)\n {\n return LCPArray(s, sa, Comparer.Default.Compare);\n }\n /// \n /// sのLCPArrayとして長さ n-1の配列を返す\n /// \n /// \n /// res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common Prefixの長さ\n /// O(n)\n /// \n /// \n /// \n /// \n /// \n public static int[] LCPArray(string s, int[] sa)\n {\n //int n = s.Length;\n //int[] s2 = new int[n];\n //for (int i = 0; i < n; i++)\n //{\n // s2[i] = s[i];\n //}\n return LCPArray(s.ToCharArray(), sa);\n }\n\n #endregion // LCPArray\n\n #region ZAlgorithm\n\n /// \n /// 長さnの配列sについて sと s[i,n)のLCPの長さを返す\n /// \n /// \n /// \n /// \n /// \n public static int[] ZAlgorithm(T[] s, EqualityComparer eq)\n {\n int n = s.Length;\n if (n == 0) return new int[0];\n int[] z = new int[n];\n z[0] = 0;\n for (int i = 1, j = 0; i < n; i++)\n {\n ref int k = ref z[i];\n k = (j + z[j] <= i) ? 0 : Math.Min(j + z[j] - i, z[i - j]);\n while (i + k < n && eq.Equals(s[k], s[i + k])) k++;\n if (j + z[j] < i + z[i]) j = i;\n }\n z[0] = n;\n return z;\n }\n\n /// \n /// 長さnの配列sについて sと s[i,n)のLCPの長さを返す\n /// \n /// \n /// \n /// \n public static int[] ZAlgorithm(T[] s)\n {\n return ZAlgorithm(s, EqualityComparer.Default);\n }\n\n /// \n /// 長さnの文字列sについて sと s[i,n)のLCPの長さを返す\n /// \n /// \n /// \n /// \n public static int[] ZAlgorithm(string s)\n {\n return ZAlgorithm(s.ToCharArray());\n }\n\n #endregion\n }\n}\n\n\n// https://bitbucket.org/camypaper/complib\nnamespace CompLib.Mathematics\n{\n #region ModInt\n /// \n /// [0,) までの値を取るような数\n /// \n public struct ModInt\n {\n /// \n /// 剰余を取る値.\n /// \n public const long Mod = (int)1e9 + 7;\n // public const long Mod = 998244353;\n\n /// \n /// 実際の数値.\n /// \n public long num;\n /// \n /// 値が であるようなインスタンスを構築します.\n /// \n /// インスタンスが持つ値\n /// パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため, ∈ [0,) を満たすような を渡してください.このコンストラクタは O(1) で実行されます.\n public ModInt(long n) { num = n; }\n /// \n /// このインスタンスの数値を文字列に変換します.\n /// \n /// [0,) の範囲内の整数を 10 進表記したもの.\n public override string ToString() { return num.ToString(); }\n public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }\n public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }\n public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }\n public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(long v, long k)\n {\n long ret = 1;\n for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n if ((k & 1) == 1) ret = ret * v % Mod;\n return new ModInt(ret);\n }\n /// \n /// 与えられた数の逆元を計算します.\n /// \n /// 逆元を取る対象となる数\n /// 逆元となるような値\n /// 法が素数であることを仮定して,フェルマーの小定理に従って逆元を O(log N) で計算します.\n public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }\n }\n #endregion\n #region Binomial Coefficient\n public class BinomialCoefficient\n {\n public ModInt[] fact, ifact;\n public BinomialCoefficient(int n)\n {\n fact = new ModInt[n + 1];\n ifact = new ModInt[n + 1];\n fact[0] = 1;\n for (int i = 1; i <= n; i++)\n fact[i] = fact[i - 1] * i;\n ifact[n] = ModInt.Inverse(fact[n]);\n for (int i = n - 1; i >= 0; i--)\n ifact[i] = ifact[i + 1] * (i + 1);\n ifact[0] = ifact[1];\n }\n public ModInt this[int n, int r]\n {\n get\n {\n if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;\n return fact[n] * ifact[n - r] * ifact[r];\n }\n }\n public ModInt RepeatedCombination(int n, int k)\n {\n if (k == 0) return 1;\n return this[n + k - 1, k];\n }\n }\n #endregion\n}\n\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "590a49a7af0eb83376ed911ed488d7e5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\n//using System.Threading.Tasks;\n\nnamespace Contest\n{\n\n class Program\n {\n\n static void Main(string[] args)\n {\n var inp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();\n var x = inp[0];\n var y = inp[1];\n var sum = 100 * x + 10 * y;\n var fox = false;\n while (sum >= 220)\n {\n \n var xs = 0; var ys = 0;\n if (y < 2) break;\n if (!fox)\n {\n xs = x > 1 ? 2 : x;\n ys = (220 - 100 * xs) / 10;\n x -= xs;\n y -= ys;\n }\n else\n {\n ys = y >= 22 ? 22 : y >= 12 ? 12 : y >= 2 ? 2 : y;\n xs = (220 - 10 * ys)/100;\n x -= xs;\n y -= ys;\n }\n fox = !fox;\n sum = 100 * x + 10 * y;\n }\n Console.WriteLine(fox ? \"Ciel\" : \"Hanako\");\n\n }\n }\n}", "src_uid": "8ffee18bbc4bb281027f91193002b7f5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace ConsoleApplication1\n{\n class IndiaHacks2\n {\n static void Main(string[] args)\n {\n //Console.SetIn(new StreamReader(@\"D:\\Sergey\\Code\\2.txt\"));\n\n string[] strParams = Console.ReadLine().Split(new char[] { ' ' }); \n int n = int.Parse(strParams[0]);\n int q = int.Parse(strParams[1]);\n\n var a = new List();\n var d = new Dictionary(q);\n var g = new Dictionary>();\n\n //var ba = new List();\n\n int k = n;\n long r = 0;\n\n for (int i = 0; i < q; i++)\n {\n strParams = Console.ReadLine().Split(new char[] { ' ' });\n d[strParams[0]] = strParams[1][0];\n\n List f;\n if (!g.TryGetValue(strParams[1][0], out f))\n {\n f = new List();\n g[strParams[1][0]] = f;\n }\n f.Add(strParams[0]);\n }\n\n //HashSet h = new HashSet();\n\n var s = new LinkedList();\n var c = new char[n];\n c[n - 1] = 'a';\n s.AddLast(c);\n LinkedListNode sp = s.First;\n for (int i = n - 1; i >= 1; i--)\n {\n for (int j = 0, count = s.Count; j < count && sp != null; j++)\n {\n List f;\n if (g.TryGetValue(sp.Value[i], out f))\n {\n for (k = 1; k < f.Count; k++)\n {\n char[] cc = sp.Value.ToArray();\n cc[i] = f[k][1];\n cc[i - 1] = f[k][0];\n s.AddLast(cc);\n }\n sp.Value[i] = f[0][1];\n sp.Value[i - 1] = f[0][0];\n s.AddLast(sp.Value);\n }\n sp = sp.Next;\n s.RemoveFirst();\n }\n }\n\n\n Console.WriteLine(s.Count);\n }//main\n\n }\n}\n", "src_uid": "c42abec29bfd17de3f43385fa6bea534"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\n\nnamespace sm\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n int k = int.Parse(Console.ReadLine());\n Dictionary dic = new Dictionary();\n int m = k;\n int i = 1;\n dic.Add(k,k);\n while (true)\n {\n int a = getDigit(k);\n if (!dic.ContainsKey(a))\n {\n dic.Add(a, a);\n i++;\n //Console.WriteLine(a);\n }\n else break;\n k = a;\n\n m--;\n }\n Console.WriteLine(i);\n\n\n }\n static int getDigit(int k)\n {\n int digit = k + 1;\n while (digit % 10 == 0)\n digit /= 10;\n return digit;\n }\n\n\n\n\n }\n}", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"source_code": "\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\n\n\nclass GFG\n{\n\n\n public static void Main()\n {\n var n = int.Parse(Console.ReadLine());\n Console.Write(n + \" \");\n for (int i = n / 2; i >= 1; i--)\n {\n if (n % i == 0)\n {\n Console.Write(i + \" \");\n n = i;\n }\n }\n }\n\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.Collections;\n\t\t\t\t\t\npublic class Program\n{\n\tpublic static void Main()\n\t{\t\t\n\t var arr=Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n\t\tint k=arr[0];\n\t\tint n=arr[1];\n\t\tint w=arr[2];\n\t\tint sum=0;\n\t\t\n\t\tfor(int i=0; i=sum ? 0 : sum-n);\n\t}\n}", "src_uid": "e87d9798107734a885fd8263e1431347"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class Program\n {\n static bool can(int a, int b)\n {\n if(b==3)\n {\n return (a==1||a==2||a==4||a==5);\n }\n if (b % 2 == 0)\n {\n int mod = a % 4;\n if (mod > 0) return false;\n int div = a / 4;\n int can = (((b - 1) / 2) * ((b - 1) / 2) + 1) / 2;\n return div <= can;\n }\n else\n {\n if (a % 2 == 1)\n {\n a--;\n }\n int can4 = (((b - 1) / 2) * ((b - 1) / 2) + 1) / 2;\n int can2 = b / 2 / 2 * 2;\n if (a % 4 == 2)\n {\n if (can2 > 0)\n {\n can2--;\n a -= 2;\n }\n else return false;\n }\n can4 += can2 / 2;\n return a <= can4*4;\n }\n }\n static void Main(string[] args)\n {\n int x;\n x = int.Parse(Console.ReadLine());\n for (int i = 1; i <= 100; i++)\n {\n if (can(x, i))\n {\n Console.WriteLine(i.ToString());\n break;\n }\n }\n \n }\n }\n}\n", "src_uid": "01eccb722b09a0474903b7e5abc4c47a"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Array\n{\n internal class Program\n {\n private const int mod = 1000000007;\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static long[] fact;\n private static long[] fact1;\n\n private static void Main(string[] args)\n {\n int n = int.Parse(reader.ReadLine());\n\n long count = n;\n n--;\n\n InitFact(2*n + 2);\n long c = GetCFact(2*n + 1, n + 1);\n count = (count + 2 * (c - count + mod)) % mod;\n writer.WriteLine(count);\n writer.Flush();\n }\n\n private static void InitFact(int n)\n {\n fact = new long[n];\n fact1 = new long[n];\n\n fact[0] = 1;\n\n for (int i = 1; i < fact.Length; i++)\n {\n fact[i] = (fact[i - 1]*i)%mod;\n }\n fact1[n - 1] = Pow(fact[n - 1], mod - 2);\n for (int i = fact1.Length - 2; i >= 0; i--)\n {\n fact1[i] = (fact1[i + 1]*(i + 1))%mod;\n }\n }\n\n private static long GetCFact(int n, int k)\n {\n return (((fact[n]*fact1[k])%mod)*fact1[n - k])%mod;\n }\n\n private static long Pow(long a, int k)\n {\n long r = 1;\n while (k > 0)\n {\n if ((k & 1) == 1)\n {\n r = (r*a)%mod;\n }\n a = (a*a)%mod;\n k >>= 1;\n }\n return r;\n }\n }\n}", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace A\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n string[] t_A = Console.ReadLine().Split(' ');\n string[] t_B = Console.ReadLine().Split(' ');\n string[] HHH = Console.ReadLine().Split(':');\n int hour = 0;\n if (HHH[0][0] == '0') hour = int.Parse(HHH[0][1].ToString());\n else\n hour = int.Parse(HHH[0][0].ToString()) * 10 + int.Parse(HHH[0][1].ToString());\n int minute = 0;\n if (HHH[1][0] == '0') minute = int.Parse(HHH[1][1].ToString());\n else\n minute = int.Parse(HHH[1][0].ToString()) * 10 + int.Parse(HHH[1][1].ToString());\n int starttime = hour * 60 + minute;\n int endtime = starttime + int.Parse(t_A[1].ToString());\n int ans = 0;\n int start = 300;\n int chastota = int.Parse(t_B[0].ToString());\n int time = int.Parse(t_B[1].ToString());\n while (true)\n {\n if (start >= endtime || start > 1439) break;\n if (start + time > starttime)\n {\n ans++;\n }\n start += chastota;\n }\n\n\n Console.WriteLine(ans);\n\n }\n }\n}\n", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\nnamespace AlgoTest\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n\n int sum = 0;\n int max = int.MinValue;\n\n for (int i = 0; i < a.Length; i++)\n {\n sum += a[i];\n max = Math.Max(max, a[i]);\n }\n\n int k = max;\n int sum2 = 0;\n\n while(true)\n {\n sum2 = 0;\n\n for (int i = 0; i < a.Length; i++)\n {\n sum2 += k - a[i];\n }\n\n if (sum2 > sum) break;\n\n k++;\n \n }\n\n Console.WriteLine(k);\n // Console.ReadKey();\n }\n\n \n private static string [] customizeEmails(string [] emails)\n {\n for (int i = 0; i < emails.Length; i++)\n {\n emails[i] = customizeTheString(emails[i]);\n }\n\n return emails.Distinct().ToArray();\n }\n\n private static string customizeTheString(string email)\n {\n int indexOfAt = email.IndexOf('@');\n string name = email.Substring(0, indexOfAt);\n\n StringBuilder newMail = new StringBuilder();\n\n for (int i = 0; i < name.Length; i++)\n {\n if (name[i] == '+') break;\n if (name[i] == '.') continue;\n\n newMail.Append(name[i]);\n }\n\n return newMail.Append(email.Substring(indexOfAt)).ToString();\n }\n public static string ReverseVowels(string s)\n {\n StringBuilder sb = new StringBuilder();\n\n List vowels = new List();\n\n for (int i = 0; i < s.Length; i++)\n {\n if (isVowel(s[i]))\n {\n vowels.Add(i);\n }\n }\n\n int[] c = vowels.ToArray();\n\n char[] answer = new char[s.Length];\n\n int j = 0;\n\n for (int i = 0; i < s.Length; i++)\n {\n if (isVowel(s[i]))\n {\n answer[i] = s[c[c.Length - 1 - j]];\n answer[c[c.Length - 1 - j]] = s[i];\n j++;\n }\n else\n {\n answer[i] = s[i];\n }\n }\n\n return new string(answer);\n }\n\n public static bool isVowel(char c)\n {\n c = char.ToLowerInvariant(c);\n return c == 'a' || c == 'o' || c == 'e' || c == 'u' || c == 'i';\n }\n }\n}\n", "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n//неправильный ответ на тесте 15\nnamespace F\n{\n class Program\n {\n static Tree[] wt;\n class Tree\n {\n public long ves;\n public long ves_;\n public int nn;//индек первого элемента\n public int nk;//индек последнего элемента\n public Tree l;\n public Tree r;\n public Tree p;\n public Tree(int[] m, int[] a, int i1, int ik, Tree p1)\n {\n nn = i1;\n nk = ik;\n if (i1 == ik)\n {\n l = null;\n r = null;\n ves = m[i1];\n ves_ = ((long)(a[i1] - i1) * (long)m[i1]) % (long)(1000000007);\n //ves_ = ((long)(a[i1] - i1) * (long)m[i1]) ;\n wt[i1] = this;\n }\n else\n {\n int s = (ik + i1 + 1) / 2;\n l = new Tree(m, a, i1, s - 1, this);\n r = new Tree(m, a, s, ik, this);\n ves = l.ves + r.ves;\n ves_ = (l.ves_ + r.ves_) % (long)(1000000007);\n }\n p = p1;\n if (ves < 0) Console.WriteLine(\"ОЙ\");\n if (ves_ < 0) Console.WriteLine(\"ОЙ\");\n //if (ves >= 1000000007) Console.WriteLine(\"ОЙ\");\n if (ves_ >= 1000000007) Console.WriteLine(\"ОЙ\");\n }\n }\n\n static long FindVes(Tree t1, Tree tn, bool t)//t=true ves;t=false ves_;\n {\n long ves = 0;\n int x1 = t1.nn;\n int y1 = tn.nk;\n if (y1 < x1) return 0;\n Tree ti = wt[x1];\n while (ti.nk < y1) ti = ti.p;\n if (t) ves = (long)ti.ves;\n else ves = (long)ti.ves_;\n Tree tiv = ti;\n while (ti.nn < x1)\n {\n if (ti.r.nn <= x1)\n {\n if (t) ves = ves - (long)ti.l.ves;\n else ves = (ves - (long)ti.l.ves_ + (long)(1000000007)) % (long)(1000000007);\n ti = ti.r;\n }\n else\n {\n ti = ti.l;\n }\n }\n ti = tiv;\n while (ti.nk > y1)\n {\n if (ti.l.nk >= y1)\n {\n if (t) ves = ves - (long)ti.r.ves;\n else ves = (ves - (long)ti.r.ves_ + (long)(1000000007)) % (long)(1000000007);\n ti = ti.l;\n }\n else\n {\n ti = ti.r;\n }\n }\n return ves;\n }\n\n static void Main(string[] args)\n {\n TextReader sr = Console.In;\n //StreamReader sr = new StreamReader(\"in115.txt\");\n string[] s = sr.ReadLine().Split();\n int n = Convert.ToInt32(s[0]);\n int q = Convert.ToInt32(s[1]);\n s = sr.ReadLine().Split();\n string[] s1 = sr.ReadLine().Split();\n int[] a = new int[n];\n int[] w = new int[n];\n for (int i = 0; i < n; i++)\n {\n a[i] = Convert.ToInt32(s[i]);\n w[i] = Convert.ToInt32(s1[i]);\n }\n //решение\n wt = new Tree[n];\n Tree t1 = new Tree(w, a, 0, n - 1, null);\n\n int ll;\n int rr;\n int id, nw;\n bool zapros1;\n Tree ti;\n List res = new List();\n for (int i = 0; i < q; i++)\n {\n s = sr.ReadLine().Split();\n ll = Convert.ToInt32(s[0]);\n if (ll < 0) zapros1 = true; else zapros1 = false;\n id = -1 - ll;\n ll--;\n nw = Convert.ToInt32(s[1]);\n rr = nw - 1;\n if (zapros1)\n {\n ti = wt[id];\n long delta = (long)nw - ti.ves;\n long delta_ = (((long)(a[id] - id) * (long)nw)) % (long)(1000000007) - ti.ves_;\n w[id] = nw;\n while (ti != null)\n {\n ti.ves = ti.ves + delta;\n ti.ves_ = (ti.ves_ + delta_ + (long)(1000000007)) % (long)(1000000007);\n ti = ti.p;\n }\n }\n else\n {\n if (ll == rr)\n {\n res.Add(0);\n }\n else if ((rr - ll) == (a[rr] - a[ll]))\n {\n res.Add(0);\n }\n else if ((rr - ll) == 1)\n {\n if (w[ll] > w[rr])\n {\n res.Add((int)(((long)(a[rr] - a[ll] - 1) * (long)w[rr]) % (long)(1000000007)));\n }\n else\n {\n res.Add((int)(((long)(a[rr] - a[ll] - 1) * (long)w[ll]) % (long)(1000000007)));\n }\n }\n else\n {\n //найти вес отрезка\n //int x1 = x - 1;\n //int y1 = y - 1;\n long ves = FindVes(wt[ll], wt[rr], true);\n long vl, vr, vv;\n int iis, iiss;\n int iisll = ll, iislr = rr;\n iis = (ll + rr + 1) / 2;\n vl = FindVes(wt[ll], wt[iis - 1], true);\n vr = FindVes(wt[iis + 1], wt[rr], true);\n while (true)\n {\n if ((vl + w[iis] > vr) && (vr + w[iis] > vl)) break;\n if (vl + w[iis] == vr)\n {\n if (w[iis] >= w[iis + 1]) break;\n else\n {\n iis++;\n break;\n }\n }\n if (vr + w[iis] == vl)\n {\n if (w[iis] >= w[iis - 1]) break;\n else\n {\n iis--;\n break;\n }\n }\n if ((vl + w[iis]) > (vr + w[iis]))\n {\n iiss = (iisll + iis) / 2;\n vv = FindVes(wt[iiss + 1], wt[iis - 1], true);\n vl = vl - vv - w[iiss];\n vr = vr + vv + w[iis];\n iislr = iis;\n iis = iiss;\n }\n else\n {\n iiss = (iislr + iis + 1) / 2;\n vv = FindVes(wt[iis + 1], wt[iiss - 1], true);\n vl = vl + vv + w[iis];\n vr = vr - vv - w[iiss];\n iisll = iis;\n iis = iiss;\n }\n }\n //long r1 = 0;\n //for (int j = ll; j < iis; j++)\n //{\n // r1 = (r1 + ((long)w[j] * (long)(a[iis] - a[j] - (iis - j)))) % 1000000007;\n //}\n //for (int j = iis + 1; j <= rr; j++)\n //{\n // r1 = (r1 + ((long)w[j] * (long)(a[j] - a[iis] - (j - iis)))) % 1000000007;\n //}\n long r = 0;\n if (iis > ll)\n {\n r = (r - (FindVes(wt[ll], wt[iis - 1], false) % (long)(1000000007)) + (long)(1000000007)) % (long)(1000000007);\n r = (r + ((long)(a[iis] - iis)) * (FindVes(wt[ll], wt[iis - 1], true) % (long)(1000000007))) % (long)(1000000007);\n\n }\n if (iis < rr)\n {\n r = (r + (FindVes(wt[iis + 1], wt[rr], false)) % (long)(1000000007)) % (long)(1000000007);\n r = (r - ((long)(a[iis] - iis) * (FindVes(wt[iis + 1], wt[rr], true) % (long)(1000000007))) % (long)(1000000007) + (long)(1000000007)) % (long)(1000000007);\n }\n res.Add((int)r);\n }\n }\n }\n Console.WriteLine(string.Join(\"\\n\", res));\n }\n }\n}\n", "src_uid": "c0715f71efa327070eba7e491856d66a"} {"source_code": "using System;\n\nnamespace Problem51Nod\n{\n class Program\n {\n public static void Main(String[] args)\n {\n string[] input = Console.ReadLine().Split(' ');\n int n = Convert.ToInt32(input[0]);\n long sum = Convert.ToInt64(input[1]);\n input = Console.ReadLine().Split(' ');\n long[] nums = new long[n];\n for (int i = 0; i < n; i++)\n nums[i] = Convert.ToInt64(input[i]);\n\n Console.WriteLine(Cal(sum, nums));\n }\n \n static long Mod = 1000000007;\n static long[] Nums, InvFacts;\n\n static void Init(long[] nums)\n {\n long[] invs = new long[30];\n InvFacts = new long[30];\n invs[1] = InvFacts[1] = 1;\n\n for (int i = 2; i < invs.Length; i++)\n {\n invs[i] = (Mod - Mod / i * invs[Mod % i] % Mod) % Mod;\n InvFacts[i] = InvFacts[i - 1] * invs[i] % Mod;\n }\n\n Nums = new long[nums.Length];\n\n for (int i = 0; i < nums.Length; i++)\n Nums[i] = nums[i] + 1;\n\n Array.Sort(Nums, (a, b) => b.CompareTo(a));\n }\n\n static long Cal(long sum, long[] nums)\n {\n if (nums.Length == 1) return nums[0] < sum ? 0 : 1;\n Init(nums);\n return (Cal(Nums.Length - 1, sum) + Mod) % Mod;\n }\n\n static long Cal(int index, long sum)\n {\n int k = Nums.Length - 1;\n long result = Cmn(sum + k, k);\n\n for(int i = index; i >= 0 && Nums[i] <= sum; i--)\n result -= Cal(i - 1, sum - Nums[i]);\n\n return result % Mod;\n }\n\n static long Cmn(long m, long n)\n {\n long result = 1;\n\n for(long i = m - n + 1; i <= m; i++)\n result = i % Mod * result % Mod;\n\n result = result * InvFacts[n] % Mod;\n return result;\n }\n }\n}", "src_uid": "8b883011eba9d15d284e54c7a85fcf74"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n static int divisor(int n)\n {\n for (int i = 2; i <= Math.Sqrt(n); i++)\n {\n if ((n % i) == 0) return i;\n }\n return 1;\n }\n \n static void Main(string[] args)\n {\n int n;\n string s;\n s = Console.ReadLine();\n n = int.Parse(s);\n int sum = 0;\n while (n>1)\n {\n sum += n;\n int div = divisor(n);\n n = n / div;\n if (div == 1) n = 1;\n }\n sum += 1;\n Console.Write(sum);\n }\n }\n}\n", "src_uid": "821c0e3b5fad197a47878bba5e520b6e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace InnaAndPony\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] nmijab = Console.ReadLine().Split(' ');\n int n = Convert.ToInt32(nmijab[0]);\n int m = Convert.ToInt32(nmijab[1]);\n int i = Convert.ToInt32(nmijab[2]);\n int j = Convert.ToInt32(nmijab[3]);\n int a = Convert.ToInt32(nmijab[4]);\n int b = Convert.ToInt32(nmijab[5]);\n int k1 = 0;\n int k2 = 0;\n int k3 = 0;\n int k4 = 0;\n int k = 0;\n\n if (((i == 1) && (j == 1)) || ((i == n) && (j == 1)) || ((i == n) && (j == m)) || ((i == 1) && (j == m)))\n {\n Console.WriteLine(0);\n }\n else\n {\n if (((i - 1 >= a) || (n - i >= a)) && ((j - 1 >= b) || (m - j >= b)))\n {\n if ((Math.Abs(i - 1) % a == 0) && (Math.Abs(j - 1) % b == 0) && ((Math.Abs(i - 1) / a + Math.Abs(j - 1) / b) % 2 == 0))\n {\n k1 = Math.Max(Math.Abs(i - 1) / a, Math.Abs(j - 1) / b);\n // Console.WriteLine(k1);\n }\n else\n {\n k1 = 1000000000;\n // Console.WriteLine(k1);\n }\n\n if ((Math.Abs(i - n) % a == 0) && (Math.Abs(j - 1) % b == 0) && ((Math.Abs(i - n) / a + Math.Abs(j - 1) / b) % 2 == 0))\n {\n k2 = Math.Max(Math.Abs(i - n) / a, Math.Abs(j - 1) / b);\n // Console.WriteLine(k2);\n }\n else\n {\n k2 = 1000000000;\n // Console.WriteLine(k2);\n }\n\n if ((Math.Abs(i - n) % a == 0) && (Math.Abs(j - m) % b == 0) && ((Math.Abs(i - n) / a + Math.Abs(j - m) / b) % 2 == 0))\n {\n k3 = Math.Max(Math.Abs(i - n) / a, Math.Abs(j - m) / b);\n // Console.WriteLine(k3);\n }\n else\n {\n k3 = 1000000000;\n // Console.WriteLine(k3);\n }\n\n if ((Math.Abs(i - 1) % a == 0) && (Math.Abs(j - m) % b == 0) && ((Math.Abs(i - 1) / a + Math.Abs(j - m) / b) % 2 == 0))\n {\n k4 = Math.Max(Math.Abs(i - 1) / a, Math.Abs(j - m) / b);\n // Console.WriteLine(k4);\n }\n else\n {\n k4 = 1000000000;\n // Console.WriteLine(k4);\n }\n\n k = Math.Min(Math.Min(k1, k2), Math.Min(k3, k4));\n\n if (k < 1000000000)\n {\n Console.WriteLine(k);\n }\n else\n {\n Console.WriteLine(\"Poor Inna and pony!\");\n }\n }\n else\n {\n Console.WriteLine(\"Poor Inna and pony!\");\n }\n }\n\n // Console.ReadKey();\n }\n }\n}", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace A_Prank\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args));\n writer.Flush();\n }\n\n private static int Solve(string[] args)\n {\n int n = Next();\n\n var nn = new int[n + 2];\n for (int i = 1; i <= n; i++)\n {\n nn[i] = Next();\n }\n nn[0] = 0;\n nn[n + 1] = 1001;\n\n int ans = 0;\n int cnt = 1;\n\n for (int i = 1; i < nn.Length; i++)\n {\n if (nn[i] == nn[i - 1] + 1)\n {\n cnt++;\n }\n else\n {\n if (cnt >= 3)\n ans = Math.Max(ans, cnt - 2);\n cnt = 1;\n }\n }\n if (cnt >= 3)\n ans = Math.Max(ans, cnt - 2);\n return ans;\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication89\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n int n;\n string s;\n n =int.Parse(Console.ReadLine());\n s = Console.ReadLine();\n\n string v = \"aeiouy\";\n start:\n for (int i = 0; i < s.Length-1; ++i)\n {\n if(v.Contains(s[i]) && v.Contains(s[i+1]) )\n {\n s = s.Remove(i+1, 1);\n goto start;\n }\n }\n\n\n Console.WriteLine(s);\n\n }\n }\n}\n", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "using System;\nusing System.Collections.Generic;\nclass Program\n{\n\tstatic void Main(string[] args)\n\t{\n\t\tstring[] str = Console.ReadLine().Split();\n\t\tlong LA = long.Parse(str[0]);\n\t\tlong RA = long.Parse(str[1]);\n\t\tlong TA = long.Parse(str[2]);\n\t\tstring[] str2 = Console.ReadLine().Split();\n\t\tlong LB = long.Parse(str2[0]);\n\t\tlong RB = long.Parse(str2[1]);\n\t\tlong TB = long.Parse(str2[2]);\n\t\tif(LA>LB){\n\t\t\tlong tL = LB;\n\t\t\tlong tR = RB;\n\t\t\tlong tT = TB;\n\t\t\tLB = LA;\n\t\t\tRB = RA;\n\t\t\tTB = TA;\n\t\t\tLA = tL;\n\t\t\tRA = tR;\n\t\t\tTA = tT;\n\t\t}\t\t\n\t\tlong LA1 = LA + (LB - LA) / Gcd(TA,TB) * Gcd(TA,TB);\n\t\tlong ans1 = Math.Max(0,Math.Min(LA1+(RA-LA),RB)-LB+1);\n\t\tlong LA2 = LA1 + Gcd(TA,TB);\n\t\tlong ans2 = Math.Max(0,(Math.Min(RB,LA2-LA+RA)-LA2)+1);\n\t\tConsole.WriteLine(Math.Max(ans1,ans2));\n\t}\n\t\n\tpublic static long Gcd(long a, long b) {\n\t\tif (a < b)\n\t\t\treturn Gcd(b, a);\n\t\twhile (b != 0) {\n\t\t\tvar r = a % b;\n\t\t\ta = b;\n\t\t\tb = r;\n\t\t}\n\t\treturn a;\n\t}\n}", "src_uid": "faa75751c05c3ff919ddd148c6784910"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _1426E\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.ReadLine();\n int[] alice = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n int[] Bob = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n\n //most wins\n int mostWins = 0;\n mostWins += Math.Min(alice[0], Bob[1]);\n mostWins += Math.Min(alice[1], Bob[2]);\n mostWins += Math.Min(alice[2], Bob[0]);\n\n //least wins\n List aliceDistribution = new List()\n { new int[3] { 0, 0, 0 }, new int[3] { 0, 0, 0 }, new int[3] { 0, 0, 0 } };\n\n for (int a = 0; a < alice.Length; a++)\n {\n for (int b = 0; b < Bob.Length; b++)\n {\n if ((a + b) % alice.Length == (a + 1) % alice.Length)\n continue;\n int c = Math.Min(Bob[(a + b) % alice.Length], alice[a]);\n alice[a] -= c;\n Bob[(a + b) % alice.Length] -= c;\n aliceDistribution[a][(a + b) % alice.Length] += c;\n }\n\n if (alice[a] > 0)\n {\n for (int a2 = 0; a2 < alice.Length; a2++)\n {\n if (a2 == a)\n continue;\n for (int ad = 0; ad < aliceDistribution.Count; ad++)\n {\n if (ad == (a + 1) % alice.Length)\n continue;\n\n int c = Math.Min(alice[a], aliceDistribution[a2][ad]);\n alice[a] -= c;\n aliceDistribution[a2][ad] -= c;\n aliceDistribution[a2][(a + 1) % alice.Length] += c;\n }\n }\n }\n }\n\n int leastWins = 0;\n foreach (var item in alice)\n leastWins += item;\n\n Console.WriteLine(leastWins + \" \" + mostWins);\n }\n }\n}\n", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Numerics;\nusing System.Diagnostics;\n\nnamespace cfgr8\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n if (File.Exists(\"input.txt\"))\n {\n Console.SetIn(new StreamReader(\"input.txt\"));\n }\n Stopwatch sw = new Stopwatch();\n //sw.Start();\n solve_cfgr8B();\n //sw.Stop();\n //Console.WriteLine(sw.ElapsedMilliseconds / 1000);\n Console.Out.Flush();\n }\n\n public static void solve_cfgr8B()\n {\n long k = Convert.ToInt64(Console.ReadLine());\n long cnt = 1;\n long[] codeforces = new long[10];\n for (int i = 0; i < codeforces.Length; i++)\n {\n codeforces[i] = 1;\n }\n long idx = 0;\n while (cnt < k)\n {\n codeforces[idx % 10]++;\n cnt = 1;\n for (int i = 0; i < codeforces.Length; i++)\n {\n if (codeforces[i] > 1)\n {\n cnt *= codeforces[i];\n }\n }\n idx++;\n }\n StringBuilder res = new StringBuilder();\n string code = \"codeforces\";\n for (int i = 0; i < codeforces.Length; i++)\n {\n res.Append(new string(code[i], (int)codeforces[i]));\n }\n Console.WriteLine(res.ToString());\n }\n\n public static void solve_cfgr8A()\n {\n //int[] test = new int [7] {2, 3, 3, 3, 5, 6, 8};\n int t = Convert.ToInt32(Console.ReadLine());\n while (t-- > 0) \n {\n\n int[] abn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n int a = abn[0];\n int b = abn[1];\n int min = Math.Min(a, b);\n int max = Math.Max(a, b);\n int n = abn[2];\n int cnt = 0;\n int parity = 1;\n while (Math.Max(min, max) <= n)\n {\n if (parity % 2 != 0)\n {\n min += max;\n }\n else\n {\n max += min;\n }\n parity++;\n cnt++;\n }\n Console.WriteLine(cnt);\n }\n }\n\n public static int binSearchLeft(int[] a, int x)\n {\n int l = 0;\n int r = a.Length;\n while (l < r)\n {\n int mid = (l + r) / 2;\n if (a[mid] == x)\n {\n r = mid;\n }\n else if (a[mid] > x)\n {\n r = mid;\n }\n else\n {\n l = mid + 1;\n }\n }\n return l;\n }\n }\n}", "src_uid": "8001a7570766cadcc538217e941b3031"} {"source_code": "using System;\nusing System.Text;\n\nnamespace CF\n{\n class Program\n {\n static void Main(string[] args)\n {\n //string input1 = Console.ReadLine();\n //string input2 = Console.ReadLine();\n //Console.WriteLine(Solver(input1 , input2));\n //Console.ReadLine();\n\n //int num = int.Parse(Console.ReadLine());\n //for (int i = 0; i < num; i++)\n //{\n // Console.WriteLine(AWayTooLongSolver(Console.ReadLine()));\n //}\n\n //Console.WriteLine(BeautifulYear(int.Parse(Console.ReadLine())));\n //Console.ReadLine();\n string input = Console.ReadLine();\n string [] op = input.Split(' ');\n int n = int.Parse(op[0]);\n int m = int.Parse(op[1]);\n Console.WriteLine(SystemofEquations(n, m));\n\n }\n\n\n public static string Solver(string input1 , string input2) {\n\n if (input1.Length == input2.Length) { \n for (int i = 0; i < input1.Length; i++)\n {\n if (input1[i] != input2[(input1.Length - 1) - i])\n return \"NO\";\n }\n \n return \"YES\";\n }\n else return \"NO\";\n\n }\n\n public static string AWayTooLongSolver(string s) {\n\n if (s.Length > 10)\n {\n\n return s[0] + (s.Length - 2).ToString() + s[s.Length- 1] + \"\";\n }\n return s;\n }\n\n public static int StonesontheTableSolver(string input) {\n\n int res = 0;\n int index = 1;\n while (index < input.Length) {\n\n if (input[index] == input[index - 1])\n res++;\n index++;\n }\n return res;\n \n }\n\n public static int BeautifulYear(int year) {\n bool breakflag = false;\n while (true) {\n\n year++;\n breakflag = false;\n string yearstring = year.ToString();\n\n for (int j = 0; j < yearstring.Length; j++)\n {\n for (int i = j+1; i < yearstring.Length; i++)\n {\n if (yearstring[j] == yearstring[i])\n breakflag = true;\n }\n if (breakflag)\n break;\n\n }\n if (!breakflag)\n return year;\n }\n }\n\n public static int SystemofEquations(int n, int m) {\n int a=0 , b=0;\n int count = 0;\n while (a < 1000)\n {\n while (b < 1000)\n {\n if (a * a + b == n && a + b * b == m)\n count++;\n b++;\n }\n b = 0;\n a++;\n }\n return count;\n \n }\n\n\n }\n}\n", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"source_code": "using System;\n\nnamespace DataRecovery\n{\n partial class DataRecovery\n {\n static void Main(string[] args)\n {\n int n, m, min, max;\n int[] recorded;\n\n n = NextInt();\n m = NextInt();\n min = NextInt();\n max = NextInt();\n\n recorded = new int[m];\n\n for (int i = 0; i < m; i++)\n recorded[i] = NextInt();\n\n Array.Sort(recorded);\n\n if (m > n)\n Console.WriteLine(\"Incorrect\");\n else if (m == n)\n {\n if (recorded[0] == min && recorded[m - 1] == max)\n Console.WriteLine(\"Correct\");\n else\n Console.WriteLine(\"Incorrect\");\n }\n else\n {\n if (n - m == 1)\n {\n if ((recorded[0] == min && recorded[m - 1] <= max) || (recorded[m - 1] == max && recorded[0] >= min))\n Console.WriteLine(\"Correct\");\n else\n Console.WriteLine(\"Incorrect\");\n }\n else\n {\n if (recorded[0] >= min && recorded[m - 1] <= max)\n Console.WriteLine(\"Correct\");\n else\n Console.WriteLine(\"Incorrect\");\n }\n }\n }\n }\n\n partial class DataRecovery\n {\n static string[] tokens = new string[0];\n static int cur_token = 0;\n\n static void ReadArray(char sep)\n {\n cur_token = 0;\n tokens = Console.ReadLine().Split(sep);\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int NextInt()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return int.Parse(tokens[cur_token++]);\n }\n\n static long NextLong()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return long.Parse(tokens[cur_token++]);\n }\n\n static double NextDouble()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return double.Parse(tokens[cur_token++]);\n }\n\n static decimal NextDecimal()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return decimal.Parse(tokens[cur_token++]);\n }\n\n static string NextToken()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return tokens[cur_token++];\n }\n\n static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n}\n", "src_uid": "99f9cdc85010bd89434f39b78f15b65e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces\n{\n class Program\n {\n static void Main()\n {\n Problem2A();\n }\n\n static void Problem2A()\n {\n\n var first = Console.ReadLine().Split(' ');\n var second = Console.ReadLine().Split(' ');\n\n var numProblems = Int64.Parse(first[0]);\n var skillLevel = Int64.Parse(first[1]);\n\n var difficulties = new List();\n\n for(var i=0; i 0 && difficulties.First() <= skillLevel)\n {\n difficulties.RemoveAt(0);\n }\n while(difficulties.Count > 0 && difficulties.Last() <= skillLevel)\n {\n difficulties.RemoveAt(difficulties.Count - 1);\n }\n\n Console.WriteLine(numProblems - difficulties.Count);\n Console.ReadLine();\n }\n\n static void ProblemC()\n {\n var n = Int32.Parse(Console.ReadLine());\n var inputs = new List();\n\n for (int i = 0; i < n; i++)\n {\n inputs.Add(Console.ReadLine());\n }\n //Console.WriteLine(\"Read complete\");\n\n var parities = new List();\n var solns = 0;\n\n for (var i = 0; i < n; i++)\n parities.Add(GetBracketParity(inputs[i]));\n\n for (var i = 0; i < n; i++)\n for (var j = 0; j < n; j++)\n {\n if (parities[i] + parities[j] == 0 && IsValid(inputs[i], inputs[j]))\n solns++;\n }\n\n Console.WriteLine(solns);\n }\n static bool IsValid(string A, string B)\n {\n var arr = (A + B).ToCharArray();\n var parity = 0;\n\n foreach (var c in arr)\n {\n if (c == '(')\n parity++;\n else if (c == ')')\n parity--;\n else\n throw new ArgumentException();\n\n if (parity < 0)\n return false;\n }\n return true;\n }\n\n static int GetBracketParity(string input)\n {\n var inputArr = input.ToCharArray();\n var parity = 0;\n\n foreach (var c in inputArr)\n {\n if (c == '(')\n parity++;\n else if (c == ')')\n parity--;\n else\n throw new ArgumentException();\n }\n\n return parity;\n }\n\n\n static void ProblemB(string A, string B)\n {\n var first = A.Split(' ').Select(x => Int32.Parse(x)).ToList();\n var sizes = B.Split(' ').Select(x => Int32.Parse(x)).ToList();\n\n var n = first[0]; //bacteria\n var K = first[1];\n\n sizes.Sort();\n var bacteriaLeft = new List();\n\n var thisBatch = 1; //count identical sizes\n\n for (var i = 0; i < n - 1; i++)\n {\n if (sizes[i] == sizes[i + 1])\n {\n thisBatch++;\n continue;\n }\n else\n {\n if (sizes[i] + K < sizes[i + 1])\n bacteriaLeft.AddRange(Enumerable.Repeat(sizes[i], thisBatch));\n\n thisBatch = 1;\n }\n }\n bacteriaLeft.AddRange(Enumerable.Repeat(sizes[n - 1], thisBatch));\n Console.WriteLine(bacteriaLeft.Count);\n\n\n }\n\n static void ProblemA()\n {\n var first = Console.ReadLine().Split(' ');\n //var second = Console.ReadLine();\n\n var numBoxes = Int64.Parse(first[0]);\n var numDeleg = Int64.Parse(first[1]);\n\n var buildFee = Int32.Parse(first[2]);\n var demolFee = Int32.Parse(first[3]);\n\n\n //need numBoxes to be divisible by numDeleg\n var r = numBoxes % numDeleg;\n var q = numBoxes / numDeleg;\n //Console.WriteLine(r + \" \" + q);\n\n //first calculate the cost of demolishing.\n var demolCost = r * demolFee;\n //Console.WriteLine(\"Demolish for \" + demolCost);\n\n //and building\n var buildCost = (numDeleg - r) * buildFee;\n //Console.WriteLine(\"Build for \" + buildCost\n\n if (buildCost < demolCost)\n Console.WriteLine(buildCost);\n else\n Console.WriteLine(demolCost);\n }\n }\n}\n", "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"source_code": "/*\n * Маленький полярный медвежонок Лимак строит башни из блоков. Каждый блок является кубиком с целочисленной длиной стороны. \n * У Лимака есть неограниченное количество любых блоков.\n * Блок со стороной a имеет объём a^3. Объём башни, составленной из блоков со сторонами a1, a2, ..., ak, равен суммарному объёму всех этих блоков a1^3 + a2^3 + ... + ak^3.\n * Лимак собирается построить башню. Сначала он просит вас назвать целое положительное число X — требуемый объём башни. Затем Лимак строит башню жадно, \n * каждый раз выбирая самый большой блок, который можно добавить к текущей башне так, чтобы её объём не превысил X.\n * Лимак просит вас выбрать некоторое X, не превосходящее m, таким образом, чтобы количество блоков, использованных для постройки башни (по жадному алгоритму), \n * было максимально возможным. Из всех таких X он просит вас выбрать максимальное.\n * Можете ли вы помочь Лимаку? Найдите максимальное количество блоков, которое может быть использовано при постройке башни объёма X ≤ m, и максимальное подходящее число X, \n * для которого достигается этот результат.\n * \n * Входные данные\n * В единственной строке входных данных записано целое число m (1 ≤ m ≤ 10^15), означающее, что вы должны выбрать число X в диапазоне от 1 до m включительно.\n * \n * Выходные данные\n * Выведите два целых числа — максимально возможное количество блоков в башне и максимальное значение X, на котором это количество блоков достигается.\n * \n * Примеры\n * Входные данные\n * 48\n * Выходные данные\n * 9 42\n * \n * \n * Входные данные\n * 6\n * Выходные данные\n * 6 6\n * \n * Решение\n * Let's find the maximum a that a3 ≤ m. Then, it's optimal to choose X that the first block will have side a or a - 1. Let's see why.\n\n If the first block has side a then we are left with m2 = m - first_block = m - a^3.\n \n If the first block has side a - 1 then the initial X must be at most a^3 - 1 \n (because otherwise we would take a block with side a), so we are left with m2 = a^3 - 1 - first_block = a^3 - 1 - (a - 1)^3\n \n If the first blocks has side a - 2 then the initial X must be at most (a - 1)^3 - 1, so we are left with m2 = (a - 1)^3 - 1 - first_block = (a - 1)^3 - 1 - (a - 2)^3.\n\n * We want to first maximize the number of blocks we can get with new limit m2. Secondarily, we want to have the biggest initial X. \n * You can analyze the described above cases and see that the first block with side (a - 2)3 must be a worse choice than (a - 1)3. \n * It's because we start with smaller X and we are left with smaller m2. The situation for even smaller side of the first block would be even worse.\n * Now, you can notice that the answer will be small. From m of magnitude a3 after one block we get m2 of magnitude a2. So, \n * from m we go to m2 / 3, which means that the answer is O(loglog(m)). The exact maximum answer turns out to be 18.\n * The intended solution is to use the recursion and brutally check both cases: taking a3 and taking (a - 1)3 where a is maximum that a3 ≤ m. \n * It's so fast that you can even find a in O(m1 / 3), increasing a by one.\n*/ \nusing System;\nusing System.Globalization;\nusing System.Text;\nusing System.Collections.Generic;\n\n\nnamespace D\n{\n\tclass MainClass\n\t{\n\t\tpublic static ulong FindCubicRoot(ulong x)\n\t\t{\n\t\t\tulong h = x;\n\t\t\tulong l = 1;\n\t\t\twhile (h > l) {\n\t\t\t\tulong m = (h + l) >> 1;\n\t\t\t\tif (l + 1 == h) {\n\t\t\t\t\tif (h * h * h > x)\n\t\t\t\t\t\treturn l;\n\t\t\t\t\treturn h;\n\t\t\t\t}\n\t\t\t\tif (x / m > m * m) {\n\t\t\t\t\t// m * m < x div m <= x / m \n\t\t\t\t\tl = m;\n\t\t\t\t} else {\n\t\t\t\t\th = m;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn h;\n\t\t}\n\t\tpublic static bool IsCubic(ulong x)\n\t\t{\n\t\t\tulong root = FindCubicRoot(x);\n\t\t\treturn root * root * root == x;\n\t\t}\n\n\t\tpublic static void Solve(ulong x, out ulong a, out ulong b)\n\t\t{\n\t\t\tif (x == 0) {\n\t\t\t\ta = 0;\n\t\t\t\tb = 0;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (IsCubic(x + 1)) {\n\t\t\t\tulong root = FindCubicRoot(x);\n\t\t\t\tulong aa, bb;\n\t\t\t\tSolve(x - root * root * root, out aa, out bb);\n\t\t\t\ta = aa + 1;\n\t\t\t\tb = bb + root * root * root;\n\t\t\t\t// Console.WriteLine (\"x={0} root={1} aa={2} bb={3}\", x, root, aa, bb);\n\t\t\t} else {\n\t\t\t\tulong root = FindCubicRoot(x);\n\t\t\t\tulong aa, bb;\n\t\t\t\tSolve(x - root * root * root, out aa, out bb);\n\t\t\t\ta = aa + 1;\n\t\t\t\tb = bb + root * root * root;\n\t\t\t\t// Console.WriteLine (\"x={0} root={1} aa={2} bb={3}\", x, root, aa, bb);\n\t\t\t\tSolve(root * root * root - 1, out aa, out bb);\n\t\t\t\tif (aa > a) {\n\t\t\t\t\ta = aa;\n\t\t\t\t\tb = bb;\n\t\t\t\t}\n\t\t\t\t// Console.WriteLine (\"x={0} root={1} aa={2} bb={3}\", x, root, aa, bb);\n\t\t\t}\n\t\t}\n\n\t\tpublic static void Main (string[] args)\n\t\t{\n\t\t\tulong a , x ;\n\t\t\tulong m;\n\t\t\tbool err;\n\n\t\t\terr = ulong.TryParse (Console.ReadLine (), out m);\n\t\t\tif (err == false) {\n\t\t\t\tConsole.Error.WriteLine (\"Ошибка в чтении данных\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tSolve(m, out a, out x);\n\n\t\t\t// Вывод\n\t\t\tConsole.Write (\"{0} {1}\", a, x);\n\t\t}\n\t}\n}\n", "src_uid": "385cf3c40c96f0879788b766eeb25139"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Text.RegularExpressions;\nusing System.IO;\nusing System.Numerics;\nusing System.Globalization;\nusing System.Threading;\n\n\nnamespace probleme {\n class Program {\n static void Main(string[] args) {\n //Console.SetIn(new StreamReader(\"file.txt\"));\n bool ans = true;\n for (int i = 0; i < 8; i++) {\n char[] s = Console.ReadLine().ToCharArray();\n for (int j = 1; j < 8; j++) {\n if (s[j] == s[j - 1]) {\n ans = false;\n break;\n }\n }\n if (!ans) {\n break;\n }\n }\n string ds = (ans) ? \"YES\" : \"NO\";\n Console.Write(ds);\n //Console.ReadKey();\n }\n }\n}\n", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Util;\nusing System.Threading;\n\npublic class Program\n{\n private string S, T;\n private int N, M;\n\n public void Solve()\n {\n var sc = new Scanner();\n S = sc.Next();\n T = sc.Next();\n N = S.Length;\n M = T.Length;\n\n int[] front = new int[N + 1];\n for (int i = 0; i < N; i++)\n {\n front[i + 1] = front[i];\n if (front[i] < M && T[front[i]] == S[i]) front[i + 1]++;\n }\n\n int[] back = new int[N + 1];\n for (int i = N; i >= 1; i--)\n {\n back[i - 1] = back[i];\n if (back[i] < M && T[M - 1 - back[i]] == S[i - 1]) back[i - 1]++;\n }\n\n int ans = 0;\n for (int i = 0; i <= N; i++)\n {\n int ok = i;\n int ng = N + 1;\n while (ng - ok > 1)\n {\n int mid = (ok + ng) / 2;\n if (front[i] + back[mid] >= M) ok = mid;\n else ng = mid;\n }\n\n // Console.WriteLine($\"{i} {front[i]} {ok} {back[ok]}\");\n if (ok <= N) ans = Math.Max(ans, ok - i);\n }\n\n Console.WriteLine(ans);\n }\n\n public static void Main(string[] args) => new Program().Solve();\n // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Collections;\nusing System.Linq;\n\n\n\n\nnamespace contest\n{\n\n class contest\n {\n\n\n static void Main(string[] args)\n {\n\n\n //int n = int.Parse(Console.ReadLine());\n //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();\n\n //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();\n\n\n\n\n var num = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int a = num[0];\n int target = num[1];\n int dif = num[2];\n\n if (a == target) Console.WriteLine(\"YES\");\n else if (dif == 0) Console.WriteLine(\"NO\");\n else if (target > a && dif < 0) Console.WriteLine(\"NO\");\n else if (target < a && dif > 0) Console.WriteLine(\"NO\");\n else if ((target - a) % dif == 0) Console.WriteLine(\"YES\");\n else Console.WriteLine(\"NO\");\n\n\n\n\n //Console.WriteLine();\n\n\n\n\n\n //Console.Read();\n\n\n }\n\n \n\n\n }\n\n\n}\n", "src_uid": "9edf42c20ddf22a251b84553d7305a7d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace run\n{\n class Program\n {\n private static int Swap(ref int a, ref int b)\n {\n if (a < b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n return 0;\n }\n\n private static int gcd(int a, int b)\n {\n Swap(ref a, ref b);\n\n while (a % b != 0)\n {\n a %= b;\n Swap(ref a, ref b);\n }\n\n return b;\n\n }\n\n private const long MOD = 1000000009;\n\n private static void Main(string[] args)\n {\n \n var nstr = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();\n int n = nstr[0], m = nstr[1], k = nstr[2];\n int l = n - m;\n long result = 0;\n long good = 0;\n long count = (long)k * (long)l;\n if (n - count <= 0)\n {\n Console.WriteLine(m);\n return;\n\n }\n\n long num = (n - count) / k;\n\n \n //long kjk = BinPow(2, num + 1);\n \n long SUMM = k * 2 * (BinPow(2, num) - 1) % MOD;\n SUMM %= MOD;\n result += SUMM;\n\n\n\n /*for (int i = k; i <= n - count; i += k)\n {\n result += k;\n good = k;\n if (good == k)\n {\n result <<= 1;\n good = 0;\n if (result >= MOD) result -= MOD;\n }\n }*/\n\n result += ((n - count) % k);\n result %= MOD;\n\n result += count - l;\n result %= MOD;\n\n Console.WriteLine(result);\n\n }\n\n private static long BinPow(long a, long degr)\n {\n if (degr == 0) return 1;\n if ((degr & 1) == 1) return a * (BinPow(a, degr - 1) % MOD);\n else\n {\n long value = BinPow(a, degr >> 1) % MOD;\n return value * value % MOD;\n }\n }\n }\n}\n", "src_uid": "9cc1aecd70ed54400821c290e2c8018e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A.Dasha_and_Stairs\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n here: int a =int.Parse(s[0]);\n int b = int.Parse(s[1]);\n if(a<0||b>100)\n {\n goto here;\n }\n if((a==b&&a!=0)||a==b+1||b==a+1)\n {\n Console.WriteLine(\"YES\");\n }\n else\n {\n Console.WriteLine(\"NO\");\n }\n }\n }\n}\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Testerka\n{\n class Program\n {\n static void Main(string[] args)\n {\n int ans = 0;\n string input = Console.ReadLine();\n string[] numba = input.Split(' ');\n int k2 = Convert.ToInt32(numba[0]);\n int k3 = Convert.ToInt32(numba[1]);\n int k5 = Convert.ToInt32(numba[2]);\n int k6 = Convert.ToInt32(numba[3]);\n for(; ; )\n {\n\n if (k2 > 0 && k5 > 0 && k6 > 0)\n {\n ans = ans + 256;\n k2--;\n k5--;\n k6--;\n }\n else if (k2 > 0 && k3 > 0) \n {\n ans = ans + 32;\n k2--;\n k3--;\n }\n else break;\n }\n Console.WriteLine(ans);\n }\n }\n}", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n int[] KMP(string s)\n {\n int n = s.Length;\n var pi = new int[n];\n\t for (int i = 1; i < n; ++i) \n {\n\t\t int j = pi[i - 1];\n\t\t while (j > 0 && s[i] != s[j])\n\t\t\t j = pi[j - 1];\n\t\t if (s[i] == s[j])\n j++;\n\t\t pi[i] = j;\n\t }\n\t return pi;\n }\n\n public object Solve()\n {\n string s1 = ReadToken();\n string s2 = ReadToken();\n string s3 = ReadToken();\n\n int n1 = s1.Length;\n int n2 = s2.Length;\n int n3 = s3.Length;\n\n var dp = new int[n1 + 1, n2 + 1, n3];\n var path = new Tuple[n1 + 1, n2 + 1, n3];\n for (int i1 = 1; i1 <= n1; i1++)\n for (int i2 = 1; i2 <= n2; i2++)\n for (int i3 = 0; i3 < n3; i3++)\n {\n if (s1[i1 - 1] == s2[i2 - 1])\n {\n if (s3[i3] == s1[i1 - 1])\n {\n if (i3 + 1 < n3)\n {\n dp[i1, i2, i3 + 1] = dp[i1 - 1, i2 - 1, i3] + 1;\n path[i1, i2, i3 + 1] = Tuple.Create(i1 - 1, i2 - 1, i3, s1[i1 - 1]);\n }\n }\n else\n {\n int jump = KMP(s3.Substring(0, i3) + s1[i1 - 1])[i3];\n if (dp[i1 - 1, i2 - 1, i3] + 1 > dp[i1, i2, jump])\n {\n dp[i1, i2, jump] = dp[i1 - 1, i2 - 1, i3] + 1;\n path[i1, i2, jump] = Tuple.Create(i1 - 1, i2 - 1, i3, s1[i1 - 1]);\n }\n }\n }\n if (dp[i1 - 1, i2, i3] >= dp[i1, i2, i3])\n {\n dp[i1, i2, i3] = dp[i1 - 1, i2, i3];\n path[i1, i2, i3] = Tuple.Create(i1 - 1, i2, i3, (char)0);\n }\n if (dp[i1, i2 - 1, i3] >= dp[i1, i2, i3])\n {\n dp[i1, i2, i3] = dp[i1, i2 - 1, i3];\n path[i1, i2, i3] = Tuple.Create(i1, i2 - 1, i3, (char)0);\n }\n }\n\n int max = -1;\n int nmax = -1;\n for (int i = 0; i < n3; i++)\n {\n if (dp[n1, n2, i] > max)\n {\n max = dp[n1, n2, i];\n nmax = i;\n }\n }\n if (max == 0)\n return 0;\n\n var list = new List();\n var c = Tuple.Create(n1, n2, nmax, (char)0);\n while (c.Item1 > 0 && c.Item2 > 0)\n {\n c = path[c.Item1, c.Item2, c.Item3];\n if (c.Item4 > 0)\n list.Add(c.Item4);\n }\n list.Reverse();\n\n// for (int i = 0; i < n3; i++)\n// {\n// for (int j = 0; j <= n1; j++)\n// {\n// for (int k = 0; k <= n2; k++)\n// {\n// Console.Write(dp[j, k, i]);\n// }\n// Console.WriteLine();\n// }\n// Console.WriteLine(\"-----------\");\n// }\n\n\n return new string(list.ToArray());\n }\n\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n#endif\n try\n {\n var ts = DateTime.Now;\n object result = new Solver().Solve();\n if (result != null)\n writer.WriteLine(result);\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read/Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n #endregion\n}", "src_uid": "391c2abbe862139733fcb997ba1629b8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\n\nnamespace CodeForces.Solutions.c331_AbbyyCupFinal\n{\n\tpublic class ProgramC\n\t{\n\t\tpublic static void Main()\n\t\t{\n\t\t\tchecked\n\t\t\t{\n\t\t\t var subs = new int[1000001];\n\n\t\t\t for (int i = 1; i < subs.Length; i++)\n\t\t\t {\n\t\t\t subs[i] = int.MaxValue;\n\t\t\t var tmp = i;\n while (tmp > 0)\n {\n var d = tmp%10;\n if (d != 0)\n subs[i] = Math.Min(subs[i], subs[i - d] + 1);\n tmp /= 10;\n }\n\t\t\t }\n\n\t\t\t var n = long.Parse(Console.ReadLine());\n\t\t\t Console.WriteLine(subs[n]);\n\t\t\t}\n\t\t}\n\t}\n}", "src_uid": "fc5765b9bd18dc7555fa76e91530c036"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nnamespace Codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n UInt16 n = Convert.ToUInt16(Console.ReadLine());\n string a = new string(Console.ReadLine().Replace(\"4\", \"322\").Replace(\"6\", \"53\").Replace(\"8\", \"7222\").Replace(\"9\", \"7332\").OrderByDescending(c => c).ToArray()).TrimEnd('1', '0');\n Console.WriteLine(a);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Tlqkf_zheld_whdk\n{\n class Program\n {\n static StringBuilder sb = new StringBuilder();\n static void Main(string[] args)\n {\n int num = int.Parse(Console.ReadLine());\n char[] str = Console.ReadLine().ToCharArray();\n\n char lst0 = 'a';\n char lst1 = 'a';\n\n for(int i =0; i= lst0)\n {\n sb.Append(0);\n lst0 = str[i];\n }else if(str[i] >= lst1)\n {\n sb.Append(1);\n lst1 = str[i];\n }\n else\n {\n Console.WriteLine(\"NO\");\n return;\n }\n }\n\n Console.WriteLine(\"YES\");\n Console.WriteLine(sb.ToString());\n }\n }\n}\n", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Numerics;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n BigInteger a = BigInteger.Parse(s[0]);\n BigInteger b = BigInteger.Parse(s[1]);\n while (a != 0 && b!= 0) {\n if(a >= 2*b)\n {\n a = a % (2 * b);\n }\n else if(b >= 2 * a)\n {\n b = b % (2 * a);\n }\n else\n {\n break;\n }\n }\n Console.WriteLine(a + \" \" + b);\n return;\n }\n }\n}\n", "src_uid": "1f505e430eb930ea2b495ab531274114"} {"source_code": "using System;\nusing static System.Console;\nusing static System.Math;\nusing static System.Array;\n\n//string[] a = ReadLine().Split(' ')\n//int[] b = new int [a.Length]\n/*for(int i=0;i();\n for (int i = 1; i <= k; i++)\n {\n if (!h.Add(n%i))\n return false;\n }\n\n return true;\n }\n\n private static long Next()\n {\n int c;\n long res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"source_code": "using System;\npublic class Program\n {\n public static void Main(string[] args)\n {\n long l1, r1, l2, r2, k;\n {\n string[] input = Console.ReadLine().Split(new char[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n l1 = long.Parse(input[0]);\n r1 = long.Parse(input[1]);\n l2 = long.Parse(input[2]);\n r2 = long.Parse(input[3]);\n k = long.Parse(input[4]);\n }\n if(r1=l1 && k<=r1?0:1);\n Console.WriteLine(l2);\n }\n }\n }", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.Round66\n{\n class A\n {\n public static void Main()\n {\n var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss=>long.Parse(sss));\n long k = xs[3];\n Array.Sort(xs, 0, 3);\n long[] ys = new long[3];\n for (int i = 0; i < 3; i++)\n {\n ys[i] = 1 + Math.Min((k + 2-i) / (3-i), xs[i] - 1);\n k -= ys[i] - 1;\n //Console.WriteLine(\"{0} {1} {2}\", k, i, ys[i]);\n }\n Console.WriteLine(ys[0]*ys[1]*ys[2]);\n }\n }\n}\n", "src_uid": "8787c5d46d7247d93d806264a8957639"} {"source_code": "// Problem: 1085A - Right-Left Cipher\n// Author: Gusztav Szmolik\n\nusing System;\n\nclass RightLeftCipher\n\t{\n\tstatic int Main ()\n\t\t{\n\t\tstring line = Console.ReadLine ();\n\t\tif (line == null)\n\t\t\treturn -1;\n\t\tchar[] delims = {' ', '\\t'};\n\t\tstring[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);\n\t\tif (words.Length != 1)\n\t\t\treturn -1;\n\t\tstring t = words[0];\n\t\tbyte tLength = Convert.ToByte (t.Length);\n\t\tif (tLength > 50)\n\t\t\treturn -1;\n\t\tfor (byte i = 0; i < tLength; i++)\n\t\t\tif (!Char.IsLower (t[i]))\n\t\t\t\treturn -1;\n\t\tbyte iBegin = Convert.ToByte (tLength%2 == 0 ? (tLength-2)/2 : (tLength-1)/2);\n\t\tsbyte offset = 0;\n\t\tfor (byte i = 0; i < tLength; i++)\n\t\t\t{\n\t\t\tConsole.Write (t[iBegin+offset]);\n\t\t\toffset = Convert.ToSByte (i%2 == 0 ? -offset+1 : -offset);\n\t\t\t}\n\t\tConsole.WriteLine ();\n\t\treturn 0;\n\t\t}\n\t}\n", "src_uid": "992ae43e66f1808f19c86b1def1f6b41"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections;\nusing System.Collections.Generic;\n\nnamespace G4\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] Steps = new int[10];\n Steps[0] = 1;\n for (int i = 1; i < 10; i++)\n {\n Steps[i] = Steps[i - 1] * 10;\n }\n\n string sin = Console.ReadLine();\n char[] FO = new char[sin.Length];\n\n byte n = 97;\n for (int i = 0; i < sin.Length; i++)\n {\n if (((byte)sin[i] <= n) && (n < 123))\n {\n FO[i] = (char)n;\n n++;\n }\n else\n {\n FO[i] = sin[i];\n }\n }\n\n if (n > 122)\n {\n Console.Write(buffer : FO);\n }\n else\n {\n Console.Write(\"-1\");\n }\n }\n }\n}", "src_uid": "f8ad543d499bcc0da0121a71a26db854"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nnamespace ConsoleApp1\r\n{\r\n\r\n class Program\r\n {\r\n\r\n static int mod(int a, int m)\r\n {\r\n return a < 0 ? a + m : a >= m ? a - m : a;\r\n }\r\n\r\n static void Main(string[] args)\r\n {\r\n var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();\r\n int n = input[0], m = input[1];\r\n var g = new int[n + 1];\r\n var f = new int[n + 1];\r\n f[1] = 1;\r\n for(int i=2;i <= n; i++)\r\n {\r\n f[i] = i == 2 ? 2 : mod(mod(2*f[i - 1] + 1,m) + g[i],m);\r\n var mis = mod(f[i] - f[i - 1], m);\r\n for(int j = i+i; j <= n; j += i)\r\n {\r\n g[j] = mod(g[j] + mis, m);\r\n }\r\n }\r\n Console.WriteLine(f[n]);\r\n }\r\n }\r\n}\r\n", "src_uid": "77443424be253352aaf2b6c89bdd4671"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static Template;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing Pi = Pair;\n\nclass Solver\n{\n public void Solve(Scanner sc)\n {\n int x, y, a, b;sc.Make(out x, out y, out a, out b);\n WriteLine(Max(Abs(x - a),Abs(y - b)));\n }\n}\n\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver().Solve(new Scanner());\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static U Unify(this T[] A, Func f, U init = default(U)) { for (int i = 0; i < A.Length; i++) init = f(init, A[i]);return init; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\n\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n //public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n //public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n //public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }\n}\n#endregion", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Util;\n\npublic class Program\n{\n int N, M;\n int[] K;\n int[] D, T;\n int[] index;\n public void Solve()\n {\n var sc = new Scanner();\n N = sc.NextInt();\n M = sc.NextInt();\n K = sc.IntArray();\n D = new int[M];\n T = new int[M];\n for (int i = 0; i < M; i++)\n {\n D[i] = sc.NextInt();\n T[i] = sc.NextInt() - 1;\n }\n index = new int[M];\n for (int i = 0; i < M; i++)\n {\n index[i] = i;\n }\n\n Array.Sort(index, (l, r) => D[l].CompareTo(D[r]));\n\n // n種類ある\n // 毎日1獲得\n // 通常2 セール中は1支払えば買える\n // 種類iを丁度k[i]個買う\n // 毎日0個以上注文できる\n // 種類t[j]はd[j]日にセール\n\n // \n int ng = -1;\n int ok = 400000;\n while (ok - ng > 1)\n {\n int mid = (ok + ng) / 2;\n if (C(mid)) ok = mid;\n else ng = mid;\n }\n\n Console.WriteLine(ok);\n }\n\n // day日に達成できるか?\n bool C(int day)\n {\n // 区間内セール\n // 種類ごと一番最後\n // 前から\n\n int[] s = new int[N];\n for (int i = 0; i < N; i++)\n {\n s[i] = int.MaxValue;\n }\n\n for (int i = 0; i < M; i++)\n {\n if (D[index[i]] <= day)\n {\n s[T[index[i]]] = D[index[i]];\n }\n }\n\n var tmp = new int[N];\n for (int i = 0; i < N; i++)\n {\n tmp[i] = i;\n }\n Array.Sort(tmp, (l, r) => s[l].CompareTo(s[r]));\n //if (day == 8)\n //{\n // Console.WriteLine(\"-----\");\n // Console.WriteLine(day);\n // Console.WriteLine(string.Join(\" \", s));\n // Console.WriteLine(string.Join(\" \", tmp));\n //}\n int nokori = 0;\n int m = 0;\n int p = 0;\n for (int i = 0; i < N; i++)\n {\n if (s[tmp[i]] == int.MaxValue)\n {\n nokori += K[tmp[i]];\n }\n else\n {\n // 買える分\n // s[i] - m \n \n int tt = Math.Min(K[tmp[i]], s[tmp[i]] - m);\n p += tt;\n m += tt;\n nokori += K[tmp[i]] - tt;\n //if (day == 8)\n //{\n // Console.WriteLine($\"{tmp[i]} {tt} {m}\");\n //}\n }\n }\n //if(day == 8)\n //{\n // Console.WriteLine(\"aaaa\" + m);\n //}\n return nokori * 2 <= day - m;\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n while (_index >= _line.Length)\n {\n _line = Console.ReadLine().Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n _line = Console.ReadLine().Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace prob1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n, d;\n string[] str1 = Console.ReadLine().Split(' ');\n n = Convert.ToInt32(str1[0]);\n d = Convert.ToInt32(str1[1]);\n\n int[] a = new int[n];\n string[] str3=Console.ReadLine().Split(' ');\n for (int i = 0; i < n; i++)\n a[i] = Convert.ToInt32(str3[i]);\n int m = Convert.ToInt32(Console.ReadLine());\n int sum=0;\n int res = 0;\n Array.Sort(a);\n if (m <= n)\n {\n for (int i = 0; i < m; i++)\n sum += a[i];\n res = sum;\n }\n else\n {\n for (int i = 0; i < n; i++)\n sum += a[i];\n\n res = sum + ((n - m) * d);\n }\n Console.WriteLine(res);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "5c21e2dd658825580522af525142397d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n List lst = new List();\n int[] inp = new int[3];\n string[] inp1 = Console.ReadLine().Split();\n inp[0] = Int32.Parse(inp1[0]);\n inp[1] = Int32.Parse(inp1[1]);\n inp[2] = Int32.Parse(inp1[2]);\n\n lst.Add((inp[0] + inp[1]) * 2);\n lst.Add((inp[1] + inp[2]) * 2);\n lst.Add((inp[0] + inp[2]) * 2);\n lst.Add(inp[0] + inp[2] + inp[1]);\n\n lst.Sort();\n\n Console.WriteLine(lst[0]);\n }\n }\n}\n", "src_uid": "26cd7954a21866dbb2824d725473673e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Test\n{\n class IOHelper : IDisposable\n {\n StreamReader reader;\n StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding)\n {\n StreamReader iReader;\n StreamWriter oWriter;\n if (inputFile == null)\n iReader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n iReader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n oWriter = new StreamWriter(outputFile, false, encoding);\n\n reader = iReader;\n writer = oWriter;\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public string ReadNextToken()\n {\n if (curTokenIdx >= curLine.Length)\n {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n if (curTokenIdx >= curLine.Length)\n return null;\n\n return curLine[curTokenIdx++];\n }\n\n public int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n public double ReadNextDouble()\n {\n var nextToken = ReadNextToken();\n var result = 0.0;\n nextToken = nextToken.Replace(\".\", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);\n result = double.Parse(nextToken);\n return result;\n }\n\n public void Write(string stringToWrite)\n {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(string stringToWrite)\n {\n writer.WriteLine(stringToWrite);\n }\n\n public void WriteLine(double valueToWrite)\n {\n long intPart = (long)valueToWrite;\n double fracPart = valueToWrite - intPart;\n var fracPartStr = fracPart.ToString(\"F8\");\n if (fracPartStr.Length > 1)\n fracPartStr = fracPartStr.Substring(2);\n var strToWrite = string.Format(\"{0}.{1}\", intPart, fracPartStr);\n writer.WriteLine(strToWrite);\n }\n\n public void Dispose()\n {\n try\n {\n if (reader != null)\n {\n reader.Dispose();\n }\n if (writer != null)\n {\n writer.Dispose();\n }\n }\n catch { };\n }\n\n\n public void Flush()\n {\n if (writer != null)\n {\n writer.Flush();\n }\n }\n }\n\n class Program\n {\n protected IOHelper ioHelper;\n\n int w, h;\n int u1, d1;\n int u2, d2;\n\n\n public void Solve()\n {\n w = ioHelper.ReadNextInt();\n h = ioHelper.ReadNextInt();\n u1 = ioHelper.ReadNextInt();\n d1 = ioHelper.ReadNextInt();\n u2 = ioHelper.ReadNextInt();\n d2 = ioHelper.ReadNextInt();\n\n int i=h;\n\n while (i > 0)\n {\n w += i;\n if (i == d1)\n w -= u1;\n if (i == d2)\n w -= u2;\n if (w < 0)\n w = 0;\n i--;\n }\n \n ioHelper.WriteLine(w.ToString());\n ioHelper.Flush();\n\n //Console.ReadKey();\n }\n\n public Program(string inputFile, string outputFile)\n {\n ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);\n Solve();\n ioHelper.Dispose();\n }\n\n static void Main(string[] args)\n {\n Program myProgram = new Program(null, null);\n }\n }\n}", "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Text;\n\nclass Modular\n{\n private const int M = 998244353;\n private long value;\n public Modular(long value) { this.value = value; }\n public static implicit operator Modular(long a)\n {\n var m = a % M;\n return new Modular((m < 0) ? m + M : m);\n }\n public static Modular operator +(Modular a, Modular b)\n {\n return a.value + b.value;\n }\n public static Modular operator -(Modular a, Modular b)\n {\n return a.value - b.value;\n }\n public static Modular operator *(Modular a, Modular b)\n {\n return a.value * b.value;\n }\n public static Modular Pow(Modular a, int n)\n {\n switch (n)\n {\n case 0:\n return 1;\n case 1:\n return a;\n default:\n var p = Pow(a, n / 2);\n return p * p * Pow(a, n % 2);\n }\n }\n public static Modular operator /(Modular a, Modular b)\n {\n return a * Pow(b, M - 2);\n }\n private static readonly List facs = new List { 1 };\n public static Modular Fac(int n)\n {\n for (int i = facs.Count; i <= n; ++i)\n {\n facs.Add((int)(Math.BigMul(facs.Last(), i) % M));\n }\n return facs[n];\n }\n public static Modular Ncr(int n, int r)\n {\n return (n < r) ? 0\n : (n == r) ? 1\n : Fac(n) / (Fac(r) * Fac(n - r));\n }\n public static explicit operator int(Modular a)\n {\n return (int)a.value;\n }\n}\n\nclass MyClass\n{\n public static void Solve()\n {\n var input = Console.ReadLine().Split().Select(int.Parse).ToArray();\n Modular n = input[0];\n Modular m = input[1];\n var k = input[2];\n if (input[0] == 1)\n {\n Console.WriteLine((int)Modular.Pow(n, k));\n return;\n }\n var dp = new Modular[k + 1];\n var poly = new Modular[k + 1];\n for (int i = 0; i < k + 1; i++)\n {\n poly[i] = 0;\n }\n poly[1] = 1;\n for (int i = 1; i < k + 1; i++)\n {\n var num = Modular.Pow(1 / m, i);\n for (int j = 0; j < i; j++)\n {\n num *= n - j;\n }\n for (int j = 1; j < i; j++)\n {\n num -= poly[j] * dp[j];\n }\n dp[i] = num;\n if (i == k)\n {\n break;\n }\n poly[i + 1] = 1;\n for (int j = i; j >= 1; j--)\n {\n poly[j] = -i * poly[j] + poly[j - 1];\n }\n }\n Console.WriteLine((int)dp[k]);\n }\n\n public static void Main()\n {\n var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };\n Console.SetOut(sw);\n Solve();\n Console.Out.Flush();\n }\n}", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n static void Main(string[] args)\n {\n int n = RI();\n int m = RI();\n int k = RI() - 1;\n\n int row = 1 + (k / (2 * m));\n k %= (2 * m);\n int col = 1 + (k / 2);\n k %= 2;\n\n Console.WriteLine(row + \" \" + col + \" \" + ((k == 1) ? \"R\" : \"L\"));\n }\n\n private const int Mod = 1000000000 + 7;\n\n #region Data Read\n private static char ReadSign()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans == '+' || ans == '-' || ans == '?')\n return (char)ans;\n }\n }\n\n private static long GCD(long a, long b)\n {\n if (a % b == 0) return b;\n return GCD(b, a % b);\n }\n\n private static List[] ReadGraph(int n, int m)\n {\n List[] g = new List[n];\n for (int i = 0; i < g.Length; i++) g[i] = new List();\n for (int i = 0; i < m; i++)\n {\n int a = RI() - 1;\n int b = RI() - 1;\n\n g[a].Add(b);\n g[b].Add(a);\n }\n\n return g;\n }\n\n private static int[,] ReadGraphAsMatrix(int n, int m)\n {\n int[,] matrix = new int[n + 1, n + 1];\n for (int i = 0; i < m; i++)\n {\n int a = RI();\n int b = RI();\n matrix[a, b] = matrix[b, a] = 1;\n }\n\n return matrix;\n }\n\n private static void Sort(ref int a, ref int b)\n {\n if (a > b) Swap(ref a, ref b);\n }\n\n private static void Swap(ref int a, ref int b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n private const int BufferSize = 1 << 16;\n private static StreamReader consoleReader;\n private static MemoryStream testData;\n\n private static int RI()\n {\n int ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static ulong RUL()\n {\n ulong ans = 0;\n int chr;\n do\n {\n chr = consoleReader.Read();\n if (chr == -1)\n return 0;\n } while (chr < '0' || chr > '9');\n\n ans = (uint)(chr - '0');\n while (true)\n {\n chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans;\n ans = ans * 10 + (uint)(chr - '0');\n }\n }\n\n private static long RL()\n {\n long ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static int[] RIA(int n)\n {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = RI();\n return ans;\n }\n\n private static long[] RLA(int n)\n {\n long[] ans = new long[n];\n for (int i = 0; i < n; i++)\n ans[i] = RL();\n return ans;\n }\n\n private static char[] ReadWord()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n List s = new List();\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s.ToArray();\n }\n\n private static char[] ReadString(int n)\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n char[] s = new char[n];\n int pos = 0;\n do\n {\n s[pos++] = (char)ans;\n if (pos == n) break;\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s;\n }\n\n private static char[] ReadStringLine()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (ans == 10 || ans == 13);\n\n List s = new List();\n\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while (ans != 10 && ans != 13 && ans != -1);\n\n return s.ToArray();\n }\n\n private static char ReadLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))\n return (char)ans;\n }\n }\n private static char ReadNonLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))\n return (char)ans;\n }\n }\n\n private static char ReadAnyOf(IEnumerable allowed)\n {\n while (true)\n {\n char ans = (char)consoleReader.Read();\n if (allowed.Contains(ans))\n return ans;\n }\n }\n\n private static char ReadDigit()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans >= '0' && ans <= '9')\n return (char)ans;\n }\n }\n\n private static int ReadDigitInt()\n {\n return ReadDigit() - (int)'0';\n }\n\n private static char ReadAnyChar()\n {\n return (char)consoleReader.Read();\n }\n\n private static string DoubleToString(double x)\n {\n return x.ToString(CultureInfo.InvariantCulture);\n }\n\n private static double DoubleFromString(string x)\n {\n return double.Parse(x, CultureInfo.InvariantCulture);\n }\n\n static Program()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n }\n\n private static void PushTestData(StringBuilder sb)\n {\n PushTestData(sb.ToString());\n }\n private static void PushTestData(string data)\n {\n#if TOLYAN_TEST\n if (testData == null)\n {\n testData = new MemoryStream();\n consoleReader = new StreamReader(testData);\n }\n\n var pos = testData.Position;\n var bytes = Encoding.UTF8.GetBytes(data);\n testData.Write(bytes, 0, bytes.Length);\n testData.Flush();\n testData.Position = pos;\n#endif\n }\n #endregion\n}", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass TEST{\n\tstatic void Main(){\n\t\tSol mySol =new Sol();\n\t\tmySol.Solve();\n\t}\n}\n\nclass Sol{\n\tpublic void Solve(){\n\t\t\n\t\tint cnt=0;\n\t\twhile(true){\n\t\t\tint idx=0;\n\t\t\tint max=A[0];\n\t\t\tfor(int i=1;iint.Parse(e));}\n\tstatic long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}\n\tstatic double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}\n}\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Solver.Ex;\nusing Watch = System.Diagnostics.Stopwatch;\nusing StringBuilder = System.Text.StringBuilder;\nnamespace Solver\n{\n\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Long();\n var m = sc.Long();\n var k = (n % m == 0) ? 0 : 1;\n var max = (n - m + 1) * (n - m) / 2;\n var min = (n % m) * ((n / m + k) * ((n / m) + k - 1) / 2)\n + ((m - (n % m)) * (n / m) * ((n / m) - 1) / 2);\n IO.Printer.Out.PrintLine(new long[] { min, max });\n }\n internal IO.StreamScanner sc;\n }\n\n #region Main and Settings\n static class Program\n {\n static void Main(string[] arg)\n {\n#if DEBUG\n var errStream = new System.IO.FileStream(@\"..\\..\\dbg.out\", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);\n System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, \"debugStream\"));\n System.Diagnostics.Debug.AutoFlush = false;\n var sw = new Watch();\n sw.Start();\n try\n {\n#endif\n var solver = new Solver();\n solver.sc = new IO.StreamScanner(Console.OpenStandardInput());\n IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n solver.Solve();\n IO.Printer.Out.Flush();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.Error.WriteLine(ex.Message);\n Console.Error.WriteLine(ex.StackTrace);\n }\n finally\n {\n sw.Stop();\n Console.ForegroundColor = ConsoleColor.Green;\n Console.Error.WriteLine(\"Time:{0}ms\", sw.ElapsedMilliseconds);\n System.Diagnostics.Debug.Close();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n }\n#endif\n }\n\n\n }\n #endregion\n}\n#region IO Helper\nnamespace Solver.IO\n{\n public class Printer\n {\n static Printer()\n {\n Out = new Printer(Console.Out);\n }\n public static Printer Out { get; set; }\n private readonly System.IO.TextWriter writer;\n private readonly System.Globalization.CultureInfo info;\n public string Separator { get; set; }\n public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? \"\\n\"; } }\n public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)\n {\n writer = tw ?? System.IO.TextWriter.Null;\n info = ci ?? System.Globalization.CultureInfo.InvariantCulture;\n NewLine = newLine;\n Separator = separator ?? \" \";\n }\n public void Print(int num) { writer.Write(num.ToString(info)); }\n public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(long num) { writer.Write(num.ToString(info)); }\n public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(double num) { writer.Write(num.ToString(\"F12\", info)); }\n public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(string str) { writer.Write(str); }\n public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }\n public void Print(string format, IEnumerable sources) { writer.Write(format, sources.OfType().ToArray()); }\n public void Print(IEnumerable sources) { writer.Write(sources.AsString()); }\n public void Print(IEnumerable sources)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.Write(res.ToString(0, res.Length - Separator.Length));\n }\n public void PrintLine() { writer.WriteLine(); }\n public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }\n public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }\n public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(double num) { writer.WriteLine(num.ToString(\"F12\", info)); }\n public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(string str) { writer.WriteLine(str); }\n public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }\n public void PrintLine(string format, IEnumerable sources) { writer.WriteLine(format, sources.OfType().ToArray()); }\n public void PrintLine(IEnumerable sources)\n {\n var res = new StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (!string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.WriteLine(res.ToString(0, res.Length - Separator.Length));\n }\n public void Flush() { writer.Flush(); }\n }\n public class StreamScanner\n {\n public StreamScanner(System.IO.Stream stream)\n {\n iStream = stream;\n }\n private readonly System.IO.Stream iStream;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n private bool eof = false;\n public bool EndOfStream { get { return eof; } }\n private byte readByte()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n if (ptr >= len)\n {\n ptr = 0;\n len = iStream.Read(buf, 0, 1024);\n if (len <= 0)\n {\n eof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n private bool inSpan(byte c)\n {\n const byte lb = 33, ub = 126;\n return !(c >= lb && c <= ub);\n }\n private byte skip()\n {\n byte b = 0;\n do b = readByte();\n while (!eof && inSpan(b));\n return b;\n }\n public char Char()\n {\n return (char)skip();\n }\n public char[] Char(int n)\n {\n var a = new char[n];\n for (int i = 0; i < n; i++)\n a[i] = (char)skip();\n return a;\n }\n public char[][] Char(int n, int m)\n {\n var a = new char[n][];\n for (int i = 0; i < n; i++)\n a[i] = Char(m);\n return a;\n }\n public string Scan()\n {\n\n const byte lb = 33, ub = 126;\n if (eof) throw new System.IO.EndOfStreamException();\n\n do\n {\n while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))\n {\n ptr++;\n }\n if (ptr < len)\n break;\n ptr = 0;\n len = iStream.Read(buf, 0, 1024);\n if (len <= 0)\n {\n eof = true;\n return null;\n }\n continue;\n } while (true);\n\n StringBuilder sb = null;\n do\n {\n var i = ptr;\n while (i < len)\n {\n if (buf[i] < lb || ub < buf[i])\n {\n string s;\n if (sb != null)\n {\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n s = sb.ToString();\n }\n else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n ptr = i + 1;\n return s;\n }\n i++;\n }\n i = len - ptr;\n if (sb == null) sb = new StringBuilder(i + 32);\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));\n ptr = 0;\n } while ((len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true;\n return sb.ToString();\n }\n public string[] Scan(int n)\n {\n var a = new string[n];\n for (int i = 0; i < n; i++)\n a[i] = Scan();\n return a;\n }\n public string ScanLine()\n {\n const byte el = 10, cr = 13;\n if (eof) throw new System.IO.EndOfStreamException();\n StringBuilder sb = null;\n do\n {\n var i = ptr;\n while (i < len)\n {\n if (buf[i] == cr || buf[i] == el)\n {\n string s;\n if (sb != null)\n {\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n s = sb.ToString();\n }\n else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n if (buf[i] == cr) i++;\n if (buf[i] == el) i++;\n ptr = i;\n return s;\n }\n i++;\n }\n i = len - ptr;\n if (sb == null) sb = new StringBuilder(i + 32);\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));\n ptr = 0;\n } while ((len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true;\n return sb.ToString();\n }\n public double Double()\n {\n return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);\n }\n public double[] Double(int n)\n {\n var a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = Double();\n return a;\n }\n public int Integer()\n {\n var ret = 0;\n byte b = 0;\n bool isMynus = false;\n const byte zero = 48, nine = 57, mynus = 45;\n do b = readByte();\n while (!eof && !((b >= zero && b <= nine) || b == mynus));\n\n if (b == mynus)\n {\n isMynus = true;\n b = readByte();\n }\n while (true)\n {\n if (b >= zero && b <= nine)\n {\n ret = ret * 10 + b - zero;\n }\n else return isMynus ? -ret : ret;\n b = readByte();\n }\n\n }\n public int[] Integer(int n)\n {\n var a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = Integer();\n return a;\n }\n public long Long()\n {\n long ret = 0;\n byte b = 0;\n bool isMynus = false;\n const byte zero = 48, nine = 57, mynus = 45;\n do b = readByte();\n while (!eof && !((b >= zero && b <= nine) || b == mynus));\n if (b == '-')\n {\n isMynus = true;\n b = readByte();\n }\n while (true)\n {\n if (b >= zero && b <= nine)\n ret = ret * 10 + (b - zero);\n else return isMynus ? -ret : ret;\n b = readByte();\n }\n\n }\n public long[] Long(int n)\n {\n var a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = Long();\n return a;\n }\n public void Flush()\n {\n iStream.Flush();\n }\n\n }\n\n}\n#endregion\n#region Extension\nnamespace Solver.Ex\n{\n static public partial class EnumerableEx\n {\n static public string AsString(this IEnumerable source)\n {\n return new string(source.ToArray());\n }\n static public string AsJoinedString(this IEnumerable source, string separator = \" \")\n {\n return string.Join(separator, source);\n }\n static public T[] Enumerate(this int n, Func selector)\n {\n var res = new T[n];\n for (int i = 0; i < n; i++)\n res[i] = selector(i);\n return res;\n }\n }\n}\n#endregion\n", "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"source_code": "using System;\n class Program\n {\n public static void Main(string[] args)\n {\n string input = Console.In.ReadToEnd().Split(new char[] { ' ', '\\t', '\\n', '\\r'}, StringSplitOptions.RemoveEmptyEntries)[1];\n int res = 0, curr=0, lg=1;\n for(int i = input.Length-1; i>-1; --i)\n {\n if (input[i] == '1') curr++;\n else { res += curr * lg; lg *= 10; curr = 0; }\n }\n Console.WriteLine(res += curr * lg);\n }\n }", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"} {"source_code": "using System;\n\nclass Program\n{\n static void Main(string[] args)\n {\n int n, m;\n string[] input = Console.ReadLine().Split(' ');\n n = int.Parse(input[0]);\n m = int.Parse(input[1]);\n int min = Math.Min(n, m);\n int max = n + m - min;\n int ans1 = max - 1;\n int ans2 = (min % 2 == 0 ? min : (min / 2) * 2 + 1);\n Console.WriteLine(ans1 + \" \" + ans2);\n Console.ReadLine();\n }\n}\n", "src_uid": "c8378e6fcaab30d15469a55419f38b39"} {"source_code": "#if DEBUG\nusing System.Reflection;\nusing System.Threading.Tasks;\n#endif\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Numerics;\nusing System.Globalization;\n\n\nnamespace _208a\n{\n class Program\n {\n static string _inputFilename = \"input.txt\";\n static string _outputFilename = \"output.txt\";\n static bool _useFileInput = false;\n\n\n static void Main(string[] args)\n {\n StreamWriter file = null;\n#if DEBUG\n\t\t\tConsole.SetIn(getInput());\n#else\n if (_useFileInput)\n {\n Console.SetIn(File.OpenText(_inputFilename));\n file = new StreamWriter(_outputFilename);\n Console.SetOut(file);\n }\n#endif\n\n try\n {\n solution();\n }\n finally\n {\n if (_useFileInput)\n {\n file.Close();\n }\n }\n }\n\n static void solution()\n {\n #region SOLUTION\n var n = readInt();\n var a = readIntArray();\n var can = true;\n for (int i = 0; i < n - 1; i++)\n {\n var next = a[i];\n var end = a[i + 1];\n if (end < next)\n {\n var t = next;\n next = end;\n end = t;\n }\n\n for (int j = i - 1; j >= 1; j--)\n {\n var prev = a[j];\n var ps = a[j - 1];\n if (ps > prev)\n {\n var t = prev;\n prev = ps;\n ps = t;\n }\n\n if (prev > next && prev < end && ps < next)\n {\n can = false;\n break;\n }\n\n if (ps > next && ps < end && prev > end)\n {\n can = false;\n break;\n }\n }\n\n if (!can)\n {\n break;\n }\n }\n\n if (can)\n {\n Console.WriteLine(\"no\");\n }\n else\n {\n Console.WriteLine(\"yes\");\n }\n\n //var n = readInt();\n //var m = readInt();\n\n //var a = readIntArray();\n //var b = readIntArray();\n #endregion\n }\n\n static int readInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long readLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int[] readIntArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n }\n\n static long[] readLongArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n }\n\n#if DEBUG\n\t\tstatic StreamReader getInput()\n\t\t{\n\t\t\tvar resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n\t\t\tvar resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);\n\n\t\t\treturn new StreamReader(resource);\n\t\t}\n#endif\n }\n}\n", "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] nm = Console.ReadLine().Split().Select(t => Convert.ToInt32(t)).ToArray();\n (int n, int m) = (nm[0], nm[1]);\n int res = 1;\n if (m > 0)\n res = n / m >= 2 ? m : n - m;\n Console.WriteLine(res);\n }\n }\n}\n", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"} {"source_code": "using System;\n\nnamespace Sol_V\n{\n\tclass Program\n\t{\n\t\tpublic static void Main(string[] args)\n\t\t{\n\t\t\tbool[] ms=new bool[1000001];\n\t\t\tfor(int i=2;i<1000001;i++)\n\t\t\t{\n\t\t\t\tif(!ms[i])\n\t\t\t\t\tfor(int y=i*2;y<1000001;y+=i)\n\t\t\t\t\t\tms[y]=true;\n\t\t\t}\n\t\t\tint k=int.Parse(Console.ReadLine());\n\t\t\tfor(int i=1;k*i+1<100001;i++)\n\t\t\t{\n\t\t\t\tif(ms[k*i+1])\n\t\t\t\t{\n\t\t\t\t\tConsole.WriteLine(i);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Graph\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] str = Console.ReadLine().Split(' ');\n int a = int.Parse(str[0]);\n int b = int.Parse(str[1]);\n int c = int.Parse(str[2]);\n\n int[] nTable = new int[1000001];\n for (int i = 1; i < 1000000; i++)\n {\n for (int j = i; j < 1000000; j += i)\n {\n\n nTable[j]++;\n }\n }\n\n for (int i = 1; i < 1000005; i++)\n {\n //Console.WriteLine(nTable[i]);\n }\n\n Console.WriteLine(f(a, b, c, nTable));\n\n }\n\n public static long f(int a, int b, int c, int[] table)\n {\n long summ = 0;\n\n for (int i = 1; i <= a; i++)\n {\n for (int j = 1; j <= b; j++)\n {\n for (int k = 1; k <= c; k++)\n {\n //Console.WriteLine(i + \" \" + j + \" \" + k + \" = \" + (i * j * k) + \" = \" + table[i * j * k]);\n summ += d(i * j * k);\n }\n }\n }\n\n return summ % 1073741824;\n }\n\n\n\n public static long d(long a)\n {\n long[] prime = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541 };\n int N = 100;\n long count1 = 1, count2 = 1, k = 0, i;\n if (a == 1 || a == 2)\n return a;\n while ((a & 1) == 0)\n {\n k++;\n a >>= 1;\n }\n if (a == 1)\n return k + 1;\n else\n count1 = k + 1;\n for (i = 0; i < N && prime[i] * prime[i] <= a; i++)\n {\n k = 0;\n while (a % prime[i] == 0)\n {\n k++;\n a /= prime[i];\n }\n count1 *= (k + 1);\n }\n if (a == 1)\n return count1;\n if (i < N)\n return count1 << 1;\n\n for (i = prime[N - 1] + 2; i * i <= a; i += 2)\n {\n k = 0;\n while (a % i == 0)\n {\n k++;\n a /= i;\n }\n count2 *= (k + 1);\n }\n if (a > 1)\n count2 <<= 1;\n return count1 * count2;\n }\n }\n}\n", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Text;\nusing System.Linq;\nusing System.Globalization;\n\nclass Program\n{\n private static int[] GetCounts(int[] l, int max)\n {\n int[] count = new int[max + 1];\n for (int i = 0; i < n; i++) count[l[i]]++;\n return count;\n }\n\n private static Dictionary distsCache = new Dictionary();\n private static int[] GetDists(int vv)\n {\n if (distsCache.ContainsKey(vv))\n return distsCache[vv];\n\n int[] l = new int[n];\n\n List buf = new List() { vv };\n l[vv] = 1;\n int p = 0;\n while (p < buf.Count)\n {\n int v = buf[p++];\n foreach (var child in g[v])\n if (l[child] == 0)\n {\n l[child] = l[v] + 1;\n buf.Add(child);\n if (buf.Count == n)\n {\n for (int i = 0; i < n; i++) l[i]--;\n distsCache.Add(vv, l);\n return l;\n }\n }\n }\n\n for (int i = 0; i < n; i++) l[i]--;\n distsCache.Add(vv, l);\n\n return l;\n }\n\n private static double Try(int v)\n {\n var l = GetDists(v);\n int max = l.Max();\n\n int[] countByL = new int[max + 1];\n for (int i = 0; i < n; i++) countByL[l[i]]++;\n\n double ans = 0;\n\n double[] qq = new double[n];\n int[] id = new int[n];\n int nextId = 1;\n List vv = new List();\n\n for (int i = 0; i <= max; i++)\n {\n double p1 = 1 / (1.0 * n);\n if (countByL[i] == 1)\n {\n ans += p1;\n continue;\n }\n\n double[] q = new double[n];\n bool[] used = new bool[n];\n vv.Clear();\n\n for (int j = 0; j < n; j++)\n if (l[j] == i)\n {\n double delta = 1 / (1.0 * (n * g[j].Count));\n foreach (var ch in g[j])\n {\n q[ch] += delta;\n if (!used[ch])\n {\n used[ch] = true;\n vv.Add(ch);\n }\n }\n }\n\n double p2 = q.Max();\n\n double p3 = 0;\n for (int j = 0; j < n; j++)\n {\n nextId++;\n var l2 = GetDists(j);\n\n double qSum = 0;\n for (int ii = 0; ii < vv.Count; ii++)\n {\n int vertex = vv[ii];\n if (id[l2[vertex]] != nextId || q[vertex] > qq[l2[vertex]])\n {\n if (id[l2[vertex]] == nextId)\n qSum -= qq[l2[vertex]];\n else\n id[l2[vertex]] = nextId;\n\n qSum += q[vertex];\n qq[l2[vertex]] = q[vertex];\n }\n }\n\n p3 = Math.Max(qSum, p3);\n }\n\n ans += Math.Max(Math.Max(p1, p2), p3);\n }\n\n return ans;\n }\n\n private static int n;\n private static List[] g;\n static void Main(string[] args)\n {\n n = ReadInt();\n int m = ReadInt();\n g = ReadGraph(n, m);\n\n double best = 0;\n for (int i = 0; i < n; i++)\n {\n best = Math.Max(best, Try(i));\n if (best + 1e-7 > 1) break;\n }\n\n Console.Write(DoubleToString(best));\n }\n\n private static int Mod = 1000000007;\n private static List[] ReadGraph(int n, int m)\n {\n List[] g = new List[n];\n for (int i = 0; i < n; i++) g[i] = new List();\n for (int i = 0; i < m; i++)\n {\n int a = ReadInt() - 1;\n int b = ReadInt() - 1;\n\n g[a].Add(b);\n g[b].Add(a);\n }\n\n return g;\n }\n\n private static int[,] ReadGraphAsMatrix(int n, int m)\n {\n int[,] matrix = new int[n + 1, n + 1];\n for (int i = 0; i < m; i++)\n {\n int a = ReadInt();\n int b = ReadInt();\n matrix[a, b] = matrix[b, a] = 1;\n }\n\n return matrix;\n }\n\n private static void Sort(ref int a, ref int b)\n {\n if (a > b) Swap(ref a, ref b);\n }\n\n private static void Swap(ref int a, ref int b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n private const int BufferSize = 1 << 16;\n private static StreamReader consoleReader;\n private static MemoryStream testData;\n\n private static int ReadInt()\n {\n int ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static ulong ReadULong()\n {\n ulong ans = 0;\n int chr;\n do\n {\n chr = consoleReader.Read();\n if (chr == -1)\n return 0;\n } while (chr < '0' || chr > '9');\n\n ans = (uint)(chr - '0');\n while (true)\n {\n chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans;\n ans = ans * 10 + (uint)(chr - '0');\n }\n }\n\n private static long ReadLong()\n {\n long ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static int[] ReadIntArray(int n)\n {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = ReadInt();\n return ans;\n }\n\n private static long[] ReadLongArray(int n)\n {\n long[] ans = new long[n];\n for (int i = 0; i < n; i++)\n ans[i] = ReadLong();\n return ans;\n }\n\n private static char[] ReadString()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n List s = new List();\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s.ToArray();\n }\n\n private static char[] ReadString(int n)\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n char[] s = new char[n];\n int pos = 0;\n do\n {\n s[pos++] = (char)ans;\n if (pos == n) break;\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s;\n }\n\n private static char ReadLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))\n return (char)ans;\n }\n }\n private static char ReadNonLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))\n return (char)ans;\n }\n }\n\n private static char ReadDigit()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans >= '0' && ans <= '9')\n return (char)ans;\n }\n }\n\n private static int ReadDigitInt()\n {\n return ReadDigit() - (int)'0';\n }\n\n private static char ReadAnyChar()\n {\n return (char)consoleReader.Read();\n }\n\n private static string DoubleToString(double x)\n {\n return x.ToString(CultureInfo.InvariantCulture);\n }\n\n private static double DoubleFromString(string x)\n {\n return double.Parse(x, CultureInfo.InvariantCulture);\n }\n\n static Program()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n }\n\n private static void PushTestData(string data)\n {\n#if !ONLINE_JUDGE\n if (testData == null)\n {\n testData = new MemoryStream();\n consoleReader = new StreamReader(testData);\n }\n\n var pos = testData.Position;\n var bytes = Encoding.UTF8.GetBytes(data);\n testData.Write(bytes, 0, bytes.Length);\n testData.Flush();\n testData.Position = pos;\n#endif\n }\n}", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\n\nclass Program\n{\n private static long Solve(int a, int b, int c)\n {\n if (a >= b + c) return int.MaxValue;\n if (b >= a + c) return int.MaxValue;\n if (c >= a + b) return int.MaxValue;\n if (a == b && b == c && a == y) return 0;\n\n long ans = int.MaxValue;\n\n if (a y && a > aa)\n ans = Math.Min(ans, 1 + Solve(aa, b, c));\n\n int bb = Math.Max(y, Math.Max(a, c) - Math.Min(a, c) + 1);\n if (b > y && b > bb)\n ans = Math.Min(ans, 1+ Solve(a, bb, c));\n\n int cc = Math.Max(y, Math.Max(a, b) - Math.Min(a, b) + 1);\n if (c > y && c > cc)\n ans = Math.Min(ans, 1 + Solve(a, b, cc));\n\n return ans;\n }\n\n\n private static int x, y;\n static void Main(string[] args)\n {\n x = RI();\n y = RI();\n\n List m = new List() { y, y, y };\n int count = 0;\n while (m.Min() < x)\n {\n count++;\n m.Sort();\n m[0] = m[1] + m[2] - 1;\n }\n\n Console.WriteLine(count);\n }\n\n private const int Mod = 1000000000 + 7;\n\n #region Data Read\n private static char ReadSign()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans == '+' || ans == '-')\n return (char)ans;\n }\n }\n\n private static long GCD(long a, long b)\n {\n if (a % b == 0) return b;\n return GCD(b, a % b);\n }\n\n private static List[] ReadGraph(int n, int m)\n {\n List[] g = new List[n];\n for (int i = 0; i < n; i++) g[i] = new List();\n for (int i = 0; i < m; i++)\n {\n int a = RI() - 1;\n int b = RI() - 1;\n\n g[a].Add(b);\n g[b].Add(a);\n }\n\n return g;\n }\n\n private static int[,] ReadGraphAsMatrix(int n, int m)\n {\n int[,] matrix = new int[n + 1, n + 1];\n for (int i = 0; i < m; i++)\n {\n int a = RI();\n int b = RI();\n matrix[a, b] = matrix[b, a] = 1;\n }\n\n return matrix;\n }\n\n private static void Sort(ref int a, ref int b)\n {\n if (a > b) Swap(ref a, ref b);\n }\n\n private static void Swap(ref int a, ref int b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n private const int BufferSize = 1 << 16;\n private static StreamReader consoleReader;\n private static MemoryStream testData;\n\n private static int RI()\n {\n int ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static ulong RUL()\n {\n ulong ans = 0;\n int chr;\n do\n {\n chr = consoleReader.Read();\n if (chr == -1)\n return 0;\n } while (chr < '0' || chr > '9');\n\n ans = (uint)(chr - '0');\n while (true)\n {\n chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans;\n ans = ans * 10 + (uint)(chr - '0');\n }\n }\n\n private static long RL()\n {\n long ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static int[] RIA(int n)\n {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = RI();\n return ans;\n }\n\n private static long[] RLA(int n)\n {\n long[] ans = new long[n];\n for (int i = 0; i < n; i++)\n ans[i] = RL();\n return ans;\n }\n\n private static char[] ReadString()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n List s = new List();\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s.ToArray();\n }\n\n private static char[] ReadString(int n)\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n char[] s = new char[n];\n int pos = 0;\n do\n {\n s[pos++] = (char)ans;\n if (pos == n) break;\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s;\n }\n\n private static char[] ReadStringLine()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (ans == 10 || ans == 13);\n\n List s = new List();\n\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while (ans != 10 && ans != 13);\n\n return s.ToArray();\n }\n\n private static char ReadLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))\n return (char)ans;\n }\n }\n private static char ReadNonLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))\n return (char)ans;\n }\n }\n\n private static char ReadDigit()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans >= '0' && ans <= '9')\n return (char)ans;\n }\n }\n\n private static int ReadDigitInt()\n {\n return ReadDigit() - (int)'0';\n }\n\n private static char ReadAnyChar()\n {\n return (char)consoleReader.Read();\n }\n\n private static string DoubleToString(double x)\n {\n return x.ToString(CultureInfo.InvariantCulture);\n }\n\n private static double DoubleFromString(string x)\n {\n return double.Parse(x, CultureInfo.InvariantCulture);\n }\n\n static Program()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n }\n\n private static void PushTestData(string data)\n {\n#if TOLYAN_TEST\n if (testData == null)\n {\n testData = new MemoryStream();\n consoleReader = new StreamReader(testData);\n }\n\n var pos = testData.Position;\n var bytes = Encoding.UTF8.GetBytes(data);\n testData.Write(bytes, 0, bytes.Length);\n testData.Flush();\n testData.Position = pos;\n#endif\n }\n #endregion\n}", "src_uid": "8edf64f5838b19f9a8b19a14977f5615"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Malek_Dance_Club\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n string s = reader.ReadLine();\n\n long prev = 0;\n long count = 1;\n int mod = 1000000007;\n for (int i = s.Length - 1; i >= 0; i--)\n {\n long next;\n if (s[i] == '1')\n {\n next = (count*count)%mod;\n next += 2*prev;\n }\n else\n {\n next = 2*prev;\n }\n\n count = (count*2)%mod;\n prev = next%mod;\n }\n\n writer.WriteLine(prev);\n writer.Flush();\n }\n }\n}", "src_uid": "89b51a31e00424edd1385f2120028b9d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace CF_9C\n{\n class Program\n {\n static void Main(string[] args)\n {\n var strInp = Console.ReadLine();\n var digitCnt = strInp.Count();\n var totCases = Math.Pow(2, digitCnt) - 1; //Not considering 0\n var inp = UInt64.Parse(strInp);\n\n while(inp < (UInt64)ConvertToDecimalValue((int)totCases)){\n totCases--;\n }\n Console.WriteLine(totCases);\n }\n \n static int ConvertToDecimalValue(int totCases)\n {\n var strInpRev = ConvertToBinaryValue((UInt64)totCases).ToArray();\n int no = 0;\n for (int i = 0; i < strInpRev.Length; i++)\n {\n no += (int)(strInpRev[i] - '0') * (int)Math.Pow(10, i);\n }\n return no;\n }\n static string ConvertToBinaryValue(UInt64 inp)\n {\n string str = \"\";\n while(inp > 0){\n str += inp%2;\n inp = inp/2;\n }\n return str;\n }\n }\n}\n", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"source_code": "using System;\nusing System.Text;\n\n class Program\n {\n static void Main(string[] args)\n {\n int[,] m;\n var n = Int32.Parse(Console.ReadLine());\n m = new int[n, n];\n for (int i = 0; i < n; i++)\n {\n var s = Console.ReadLine().Split(' ');\n for (int j = 0; j < n; j++)\n m[i, j] = Int32.Parse(s[j]);\n }\n int sum = 0;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n if (i == j || n - i == j + 1 || n - j == i + 1 || i == (n - 1) / 2 || j == (n - 1) / 2)\n sum+=m[i,j];\n\n Console.WriteLine(sum);\n }\n \n \n }", "src_uid": "5ebfad36e56d30c58945c5800139b880"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces {\n\tclass Program {\n\t\tstatic void Main(string[] args) {\n\t\t\tstring line;\n\t\t\tint n, m;\n\n\t\t\tline = Console.ReadLine();\n\t\t\tn = int.Parse(line.Split(' ')[0]); // dospeli\n\t\t\tm = int.Parse(line.Split(' ')[1]); // deti\n\n\t\t\tif (n == 0 && m > 0) {\n\t\t\t\tConsole.WriteLine(\"Impossible\");\n\t\t\t} else if (n > 0 && m == 0) {\n\t\t\t\tConsole.WriteLine(n + \" \" + n);\n\t\t\t} else if(n == 0 && m == 0) {\n\t\t\t\tConsole.WriteLine(\"0 0\");\n\t\t\t} else if (n >= m) {\n\t\t\t\tint min = n;\n\t\t\t\tint max = n + m - 1;\n\n\t\t\t\tConsole.WriteLine(min + \" \" + max);\n\t\t\t} else if (n < m) {\n\t\t\t\tint min = n + (m - n);\n\t\t\t\tint max = n + m - 1;\n\n\t\t\t\tConsole.WriteLine(min + \" \" + max);\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "1e865eda33afe09302bda9077d613763"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _577A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string str = Console.ReadLine();\n\n int n = Convert.ToInt32(str.Split(' ')[0]);\n int x = Convert.ToInt32(str.Split(' ')[1]);\n int count = 0;\n if (n >= x)\n {\n for (int i = 1; i <= n; i++)\n {\n if (x % i == 0)\n {\n count++;\n }\n }\n }\n else\n {\n int k = 0;\n if (x % n == 0)\n {\n k = x / n;\n }\n else\n {\n k = (x / n) + 1;\n }\n for (int i = k; i <= n; i++)\n {\n if (x % i == 0)\n {\n count++;\n }\n }\n }\n Console.Write(count);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Data.SqlTypes;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace CodeForces800\r\n{\r\n internal static class Program\r\n {\r\n public static long prime = 1000000007;\r\n public static long[] bprime = new long[2];\r\n public static Dictionary invar = new Dictionary();\r\n public static long[] fact = new long[1];\r\n public static void Main()\r\n {\r\n var cur = prime - 2;\r\n var list = new List();\r\n while (cur != 0)\r\n {\r\n list.Add(cur % 2);\r\n cur = cur / 2;\r\n }\r\n bprime = list.ToArray();\r\n var str = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();\r\n var n = str[0];\r\n var k = str[1];\r\n long res = 0;\r\n fact = new long[n + 1];\r\n fact[0] = 1;\r\n for (var i = 1; i < n + 1; i++)\r\n {\r\n fact[i] = (long)((long)fact[i - 1] * i) % prime;\r\n }\r\n for (var i = 0; i <= Math.Min(n,k); i++)\r\n {\r\n res += C(n, i);\r\n res = res % prime;\r\n }\r\n Console.WriteLine(res);\r\n }\r\n private static long C(long n, long k)\r\n {\r\n if (n >= k)\r\n {\r\n long res = fact[n];\r\n res = res * calcInv(fact[n - k]);\r\n res = res % prime;\r\n res = res * calcInv(fact[k]);\r\n res = res % prime;\r\n return (long)res;\r\n }\r\n else return 0;\r\n }\r\n\r\n public static long calcInv(long n)\r\n {\r\n if (invar.TryGetValue(n, out var invn))\r\n return invn;\r\n else\r\n {\r\n var ost = new long[bprime.Length];\r\n ost[0] = n;\r\n for (var i = 1; i < bprime.Length; i++)\r\n {\r\n ost[i] = (ost[i - 1] * ost[i - 1]) % prime;\r\n }\r\n long inv = 1;\r\n for (var i = 0; i < bprime.Length; i++)\r\n {\r\n inv *= (bprime[i] == 1) ? ost[i] : 1;\r\n inv = inv % prime;\r\n }\r\n invar.Add(n, (long)inv);\r\n\r\n return (long)inv;\r\n }\r\n }\r\n }\r\n}", "src_uid": "dc7b887afcc2e95c4e90619ceda63071"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces415A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] inp = Console.ReadLine().Split();\n int n = Convert.ToInt32(inp[0]);\n int m = Convert.ToInt32(inp[1]);\n string[] inp2 = Console.ReadLine().Split();\n int[] b = new int[m];\n int[] outp = new int[n];\n\n for (int i = 0; i < m; i++)\n {\n b[i] = Convert.ToInt32(inp2[i]);\n }\n\n for (int i = 0; i < m; i++)\n {\n int max = i == 0 ? n : b[i - 1]-1;\n\n if (i>0 && b[i] > b[i - 1])\n continue;\n\n for (int j = b[i]-1; j < max; j++)\n {\n if (outp[j] != 0)\n break;\n outp[j] = b[i];\n }\n }\n\n string outp_str = \"\";\n for (int i = 0; i < n; i++)\n {\n outp_str += outp[i] + \" \";\n }\n\n Console.WriteLine(outp_str.Trim());\n //inp = Console.ReadLine().Split();\n }\n }\n}\n", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\n\nnamespace ConsoleApplication15\n{\n class Hello2018_1\n {\n static void Main(string[] args)\n {\n#if MY_DEBUG\n Console.SetIn(new StreamReader(@\"D:\\Sergey\\Code\\1.txt\"));\n //var writer = new StreamWriter(@\"D:\\Sergey\\Code\\out.txt\");\n //Console.SetOut(writer);\n#endif\n int n = int.Parse(Console.ReadLine());\n int m = int.Parse(Console.ReadLine());\n\n if (n > 28)\n {\n Console.WriteLine(m);\n return;\n }\n\n int r = m % (int)Math.Pow(2, n);\n\n Console.WriteLine(r);\n#if MY_DEBUG\n //writer.Close();\n#endif\n } // main\n\n }\n}\n", "src_uid": "c649052b549126e600691931b512022f"} {"source_code": "\nusing System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Trace;\nusing SB = System.Text.StringBuilder;\nusing static System.Math;\nusing static System.Numerics.BigInteger;\nusing static Program.IO.Scanner;\n\nusing Number = System.Int64;\n#region IO\nnamespace Program.IO {\n\tusing System.IO;\n\tusing System.Text;\n\tusing System.Globalization;\n\n\tpublic class Printer : StreamWriter {\n\t\tpublic override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n\t\tpublic Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n\t}\n\tstatic public class Scanner {\n\t\tpublic static StreamScanner sc = new StreamScanner(Console.OpenStandardInput());\n\t\tpublic static int ri => sc.Integer();\n\t\tpublic static long rl => sc.Long();\n\t\tpublic static string rs => sc.Scan();\n\t\tpublic static double rd => sc.Double();\n\t}\n\tpublic class StreamScanner {\n\t\tpublic StreamScanner(Stream stream) { str = stream; }\n\n\t\tpublic readonly Stream str;\n\t\tprivate readonly byte[] buf = new byte[1024];\n\t\tprivate int len, ptr;\n\t\tpublic bool isEof = false;\n\t\tpublic bool IsEndOfStream { get { return isEof; } }\n\n\t\tprivate byte read() {\n\t\t\tif (isEof) return 0;\n\t\t\tif (ptr >= len) {\n\t\t\t\tptr = 0;\n\t\t\t\tif ((len = str.Read(buf, 0, 1024)) <= 0) {\n\t\t\t\t\tisEof = true;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[ptr++];\n\t\t}\n\n\t\tpublic char Char() {\n\t\t\tbyte b = 0;\n\t\t\tdo b = read(); while ((b < 33 || 126 < b) && !isEof);\n\t\t\treturn (char)b;\n\t\t}\n\t\tpublic string Scan() {\n\t\t\tvar sb = new StringBuilder();\n\t\t\tfor (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);\n\t\t\treturn sb.ToString();\n\t\t}\n\t\tpublic string ScanLine() {\n\t\t\tvar sb = new StringBuilder();\n\t\t\tfor (var b = Char(); b != '\\n' && b != 0; b = (char)read()) if (b != '\\r') sb.Append(b);\n\t\t\treturn sb.ToString();\n\t\t}\n\t\tpublic long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }\n\t\tpublic int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }\n\t\tpublic double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }\n\t}\n\n}\n\n#endregion\n\n#region main\nstatic class Ex {\n\tstatic public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n\tstatic public string AsJoinedString(this IEnumerable ie, string st = \" \") {\n\t\treturn string.Join(st, ie);\n\t}\n\n\tstatic public void Main() {\n\t\tConsole.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });\n\t\tvar solver = new Program.Solver();\n\t\tvar t = new System.Threading.Thread(solver.Solve, 50000000);\n\t\tt.Start();\n\t\tt.Join();\n\t\t//*/\n\t\t//solver.Solve();\n\t\tConsole.Out.Flush();\n\t}\n}\n#endregion\n\nnamespace Program {\n\tpublic class Solver {\n\t\tRandom rnd = new Random(0);\n\t\tpublic void Solve() {\n\n\t\t\tvar n = ri;\n\t\t\tvar k = ri - 1;\n\t\t\tvar dp = new ModInt[n + 1];\n\t\t\tdp[0] = 1;\n\t\t\tvar binom = Enumerate(n + 5, x => new ModInt[n + 5]);\n\t\t\tbinom[0][0] = 1;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tbinom[i + 1][j] += binom[i][j];\n\t\t\t\t\tbinom[i + 1][j + 1] += binom[i][j];\n\t\t\t\t}\n\t\t\tvar powK = Enumerate(n + 5, x => 1.m());\n\t\t\tfor (int i = 1; i < powK.Length; i++)\n\t\t\t\tpowK[i] = powK[i - 1] * k.m();\n\t\t\tvar powK2 = Enumerate(n + 5, x => 1.m());\n\t\t\tfor (int i = 1; i < powK2.Length; i++)\n\t\t\t\tpowK2[i] = powK2[i - 1] * (k + 1).m();\n\n\t\t\tfor (int _ = 0; _ < n; _++) {\n\t\t\t\tvar next = new ModInt[n + 1];\n\t\t\t\tfor (int j = 0; j < dp.Length; j++) if (dp[j].num != 0)\n\t\t\t\t\t\tfor (int d = 0; j + d <= n; d++) {\n\t\t\t\t\t\t\tModInt coef = binom[n - j][d];\n\t\t\t\t\t\t\tcoef *= powK[n - j - d];\n\t\t\t\t\t\t\tif (d != 0) coef *= powK2[j];\n\t\t\t\t\t\t\telse coef *= powK2[j] - powK[j];\n\t\t\t\t\t\t\t//Debug.WriteLine($\"{j} -> {j + d} {dp[j]} {binom[n - j, d]} {powK[n - j - d]} {coef}\");\n\t\t\t\t\t\t\tnext[j + d] += dp[j] * coef;\n\t\t\t\t\t\t}\n\t\t\t\tdp = next;\n\t\t\t\t// Debug.WriteLine(dp.AsJoinedString());\n\t\t\t}\n\n\t\t\tConsole.WriteLine(dp[n]);\n\t\t}\n\t\tconst long INF = 1L << 60;\n\t\tstatic int[] dx = { -1, 0, 1, 0 };\n\t\tstatic int[] dy = { 0, 1, 0, -1 };\n\t\tstatic T[] Enumerate(int n, Func f) {\n\t\t\tvar a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a;\n\t\t}\n\t\tstatic T[][] Enumerate(int n, int m, Func f) {\n\t\t\treturn Enumerate(n, x => Enumerate(m, y => f(x, y)));\n\t\t}\n\t\tstatic public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n\t}\n}\n#region ModInt\n/// \n/// [0,) までの値を取るような数\n/// \npublic struct ModInt {\n\tpublic const long Mod = (int)1e9 + 7;\n\tpublic long num;\n\tpublic ModInt(long n) { num = n; }\n\tpublic override string ToString() { return num.ToString(); }\n\tpublic static ModInt operator +(ModInt l, ModInt r) { return new ModInt(l.num + r.num < Mod ? l.num + r.num : l.num + r.num - Mod); }\n\tpublic static ModInt operator -(ModInt l, ModInt r) { return new ModInt(l.num + Mod - r.num < Mod ? l.num + Mod - r.num : l.num - r.num); }\n\tpublic static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }\n\tpublic static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); }\n\tpublic static implicit operator ModInt(long n) { return n.mod(); }\n\tpublic static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }\n\tpublic static ModInt Pow(long v, long k) {\n\t\tlong ret = 1;\n\t\tfor (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n\t\t\tif ((k & 1) == 1) ret = ret * v % Mod;\n\t\treturn new ModInt(ret);\n\t}\n\tpublic static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }\n}\npublic static partial class ModIntEx {\n\tpublic static ModInt mod(this long v) {\n\t\tv %= ModInt.Mod;\n\t\tif (v < 0) v += ModInt.Mod;\n\t\treturn new ModInt(v);\n\t}\n\tpublic static ModInt mod(this int v) {\n\t\tvar u = v % ModInt.Mod;\n\t\tif (u < 0) u += ModInt.Mod;\n\t\treturn new ModInt(u);\n\t}\n\tpublic static ModInt m(this long v) { return new ModInt(v); }\n\tpublic static ModInt m(this int v) { return new ModInt(v); }\n}\n#endregion\n\n#region Binomial Coefficient\npublic class BinomialCoefficient {\n\tpublic ModInt[] fact, ifact;\n\tpublic BinomialCoefficient(int n) {\n\t\tfact = new ModInt[n + 1];\n\t\tifact = new ModInt[n + 1];\n\t\tfact[0] = 1.m();\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfact[i] = fact[i - 1] * i.m();\n\t\tifact[n] = ModInt.Inverse(fact[n]);\n\t\tfor (int i = n - 1; i >= 0; i--)\n\t\t\tifact[i] = ifact[i + 1] * (i + 1).m();\n\t\tifact[0] = ifact[1];\n\t}\n\tpublic ModInt this[int n, int r] {\n\t\tget {\n\t\t\tif (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;\n\t\t\treturn fact[n] * ifact[n - r] * ifact[r];\n\t\t}\n\t}\n\tpublic ModInt RepeatedCombination(int n, int k) {\n\t\tif (k == 0) return 1.m();\n\t\treturn this[n + k - 1, k];\n\t}\n}\n#endregion\n", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"} {"source_code": "// problem here: http://codeforces.com/problemset/problem/895/A\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\n\npublic class MainClass{\n public static void Main(string[] args){\n int n = Int32.Parse(Console.ReadLine());\n List list = Console.ReadLine().Split().Select(\n x => Int32.Parse(x)).ToList();\n List minDiffs = new List();\n\n for (int j = 0; j < n; j++) {\n list.Add(list[0]);\n list.RemoveAt(0);\n int diff = 360;\n int head = 0;\n int tail = 360;\n for (int i = 0; i < n; i++) {\n head += list[i];\n tail -= list[i];\n if (Math.Abs(head - tail) < diff) {\n diff = Math.Abs(head - tail);\n } else {\n minDiffs.Add(diff);\n break;\n }\n //Console.Write(list[i] + \" \");\n }\n //Console.WriteLine();\n }\n Console.WriteLine(minDiffs.Min());\n }\n}\n", "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing static System.Math;\nusing System.Text;\nusing System.Threading;\nusing System.Globalization;\nusing System.Runtime.CompilerServices;\nusing Library;\n\nnamespace Program\n{\n public static class CODEFORCES1\n {\n static public int numberOfRandomCases = 0;\n static public void MakeTestCase(List _input, List _output, ref Func _outputChecker)\n {\n }\n static public void Solve()\n {\n var n = NN;\n var m = NN;\n var L = NN;\n var R = NN;\n LIB_Mod._mod = 998244353;\n if (R - L == 0)\n {\n Console.WriteLine(1);\n return;\n }\n var tmp = LIB_Mod.Pow(LIB_Mod.Pow(R - L + 1, n), m);\n Console.WriteLine(((n * m) % 2 == 0) ? (tmp + ((R - L + 1) % 2)) / 2 : tmp);\n }\n class Printer : StreamWriter\n {\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }\n public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }\n }\n static LIB_FastIO fastio = new LIB_FastIODebug();\n static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }\n static long NN => fastio.Long();\n static double ND => fastio.Double();\n static string NS => fastio.Scan();\n static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();\n static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();\n static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();\n static IEnumerable OrderByRand(this IEnumerable x) => x.OrderBy(_ => xorshift);\n static long Count(this IEnumerable x, Func pred) => Enumerable.Count(x, pred);\n static IEnumerable Repeat(T v, long n) => Enumerable.Repeat(v, (int)n);\n static IEnumerable Range(long s, long c) => Enumerable.Range((int)s, (int)c);\n static IEnumerable OrderBy(this IEnumerable x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase);\n static IEnumerable OrderBy(this IEnumerable x, Func selector) => x.OrderBy(selector, StringComparer.OrdinalIgnoreCase);\n static IEnumerable OrderByDescending(this IEnumerable x) => x.OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);\n static IEnumerable OrderByDescending(this IEnumerable x, Func selector) => x.OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);\n static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }\n static IEnumerator _xsi = _xsc();\n static IEnumerator _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; } }\n }\n}\nnamespace Library {\n struct LIB_Mod : IEquatable, IEquatable\n {\n static public long _mod = 1000000007; long v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public LIB_Mod(long x)\n {\n if (x < _mod && x >= 0) v = x;\n else if ((v = x % _mod) < 0) v += _mod;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public implicit operator LIB_Mod(long x) => new LIB_Mod(x);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public implicit operator long(LIB_Mod x) => x.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Add(LIB_Mod x) { if ((v += x.v) >= _mod) v -= _mod; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Sub(LIB_Mod x) { if ((v -= x.v) < 0) v += _mod; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Mul(LIB_Mod x) => v = (v * x.v) % _mod;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Div(LIB_Mod x) => v = (v * Inverse(x.v)) % _mod;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator +(LIB_Mod x, LIB_Mod y) { var t = x.v + y.v; return t >= _mod ? new LIB_Mod { v = t - _mod } : new LIB_Mod { v = t }; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator -(LIB_Mod x, LIB_Mod y) { var t = x.v - y.v; return t < 0 ? new LIB_Mod { v = t + _mod } : new LIB_Mod { v = t }; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator *(LIB_Mod x, LIB_Mod y) => x.v * y.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator /(LIB_Mod x, LIB_Mod y) => x.v * Inverse(y.v);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public bool operator ==(LIB_Mod x, LIB_Mod y) => x.v == y.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public bool operator !=(LIB_Mod x, LIB_Mod y) => x.v != y.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public long Inverse(long x)\n {\n long b = _mod, r = 1, u = 0, t = 0;\n while (b > 0)\n {\n var q = x / b;\n t = u;\n u = r - q * u;\n r = t;\n t = b;\n b = x - q * b;\n x = t;\n }\n return r < 0 ? r + _mod : r;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Equals(LIB_Mod x) => v == x.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Equals(long x) => v == x;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override bool Equals(object x) => x == null ? false : Equals((LIB_Mod)x);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override int GetHashCode() => v.GetHashCode();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override string ToString() => v.ToString();\n static List _fact = new List() { 1 };\n static long _factm = _mod;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static void B(long n)\n {\n if (_factm != _mod) _fact = new List() { 1 };\n if (n >= _fact.Count)\n for (int i = _fact.Count; i <= n; ++i)\n _fact.Add(_fact[i - 1] * i);\n _factm = _mod;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod Comb(long n, long k)\n {\n B(n);\n if (n == 0 && k == 0) return 1;\n if (n < k || n < 0) return 0;\n return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod CombOK(long n, long k)\n {\n LIB_Mod ret = 1;\n for (var i = 0; i < k; i++) ret *= n - i;\n for (var i = 1; i <= k; i++) ret /= i;\n return ret;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod Perm(long n, long k)\n {\n B(n);\n if (n == 0 && k == 0) return 1;\n if (n < k || n < 0) return 0;\n return _fact[(int)n] / _fact[(int)(n - k)];\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod Pow(LIB_Mod x, long y)\n {\n LIB_Mod a = 1;\n while (y != 0)\n {\n if ((y & 1) == 1) a.Mul(x);\n x.Mul(x);\n y >>= 1;\n }\n return a;\n }\n }\n class LIB_FastIO\n {\n public LIB_FastIO() { str = Console.OpenStandardInput(); }\n readonly Stream str;\n readonly byte[] buf = new byte[1024];\n int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n byte read()\n {\n if (isEof) throw new EndOfStreamException();\n if (ptr >= len)\n {\n ptr = 0;\n if ((len = str.Read(buf, 0, 1024)) <= 0)\n {\n isEof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n char Char()\n {\n byte b = 0;\n do b = read();\n while (b < 33 || 126 < b);\n return (char)b;\n }\n virtual public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n virtual public long Long()\n {\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != '-' && (b < '0' || '9' < b));\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }\n }\n class LIB_FastIODebug : LIB_FastIO\n {\n Queue param = new Queue();\n string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }\n public LIB_FastIODebug() { }\n public override string Scan() => NextString();\n public override long Long() => long.Parse(NextString());\n public override double Double() => double.Parse(NextString());\n }\n}\n", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Util;\n\npublic class Program\n{\n\n public void Solve()\n {\n var sc = new Scanner();\n int a = sc.NextInt();\n int b = sc.NextInt();\n int c = sc.NextInt();\n\n int w = Math.Min(a / 3, Math.Min(b / 2, c / 2));\n\n a -= w * 3;\n b -= w * 2;\n c -= w * 2;\n int max = int.MinValue;\n for (int be = 0; be < 7; be++)\n {\n int ta = a;\n int tb = b;\n int tc = c;\n int cnt = 0;\n bool f = true;\n for (int i = 0; f && i < 7; i++)\n {\n switch ((i + be) % 7)\n {\n case 0:\n case 3:\n case 6:\n if (ta == 0)\n {\n f = false;\n break;\n }\n ta--;\n cnt++;\n break;\n case 1:\n case 5:\n if (tb == 0)\n {\n f = false;\n break;\n }\n tb--;\n cnt++;\n break;\n case 2:\n case 4:\n if (tc == 0)\n {\n f = false;\n break;\n }\n tc--;\n cnt++;\n break;\n }\n }\n\n\n max = Math.Max(max, cnt);\n }\n\n Console.WriteLine(w * 7 + max);\n }\n\n public static void Main(string[] args) => new Program().Solve();\n // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"source_code": "using System;\n class Program\n {\n public static void Main(string[] args)\n {\n int a = int.Parse(Console.ReadLine());\n int b = a / 2 + 1;\n a = a % 2 == 0 ? a / 2 - 1 : a / 2;\n if(a%2==0 && b%2==0) { a--; b++; }\n Console.WriteLine(\"{0} {1}\", a, b);\n }\n }", "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForce97\n{\n\tclass ClassC\n\t{\n\t\tstatic long Pow10(int p)\n\t\t{\n\t\t\tlong ans = 1;\n\t\t\tfor (int i = 0; i < p; i++)\n\t\t\t\tans *= 10;\n\t\t\treturn ans;\n\t\t}\n\t\tstatic long a(string s)\n\t\t{\n\t\t\tlong ans = 0;\n\t\t\tif (s.Length == 1)\n\t\t\t\treturn int.Parse(s);\n\n\t\t\tint d1 = int.Parse(s[0].ToString());\n\t\t\tint l = s.Length;\n\n\t\t\tans = 9;\n\t\t\tfor (int i = 1; i s[s.Length - 1])\n\t\t\t\t\tans--;\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tstring[] ss = Console.ReadLine().Split(' ');\n\t\t\tstring sl = ss[0];\n\t\t\tstring sr = ss[1];\n\n\t\t\tlong ll = a(sl);\n\t\t\tlong lr = a(sr);\n\t\t\tlong ans = lr - ll;\n\t\t\tif (sl[0] == sl[sl.Length - 1])\n\t\t\t\tans++;\n\n\t\t\tConsole.WriteLine(ans);\n\n//\t\t\tConsole.ReadKey();\n\t\t}\n\t}\n\n}\n", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Some7\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tint n;\n\t\t\tstring[] a = new string[8];\n\n\t\t\tfor (int i = 0; i < 8; i++)\n\t\t\t{\n\t\t\t\ta[i] = Console.ReadLine();\n\t\t\t}\n\t\t\tint ans = 15;\n\t\t\tint row=8, col=8;\n\t\t\tfor (int i = 0; i < 8; i++)\n\t\t\t{\n\t\t\t\tint s_row = 0, s_col = 0;\n\t\t\t\tfor (int j = 0; j < 8; j++)\n\t\t\t\t{\n\t\t\t\t\tif (a[i][j] == 'B')\n\t\t\t\t\t{\n\t\t\t\t\t\ts_row++;\n\t\t\t\t\t}\n\t\t\t\t\tif (a[j][i] == 'B')\n\t\t\t\t\t{\n\t\t\t\t\t\ts_col++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trow = min(row, s_row);\n\t\t\t\tcol = min(s_col, col);\n\t\t\t\tans = min(ans, row + col);\n\n\t\t\t}\n\t\t\tif (ans == 15)\n\t\t\t{\n\t\t\t\tans = 8;\n\t\t\t}\n\t\t\tConsole.WriteLine(\"{0}\", ans);\n\t\t\ta[0] = Console.ReadLine();\n\n\t\t}\n\n\t\tprivate static int min(int s_col, int col)\n\t\t{\n\t\t\treturn s_col < col ? s_col : col;\n\t\t}\n\t}\n}\n", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _6A\n{\n class Program\n {\n static void Main(string[] args)\n {\n CultureInfo culture = new CultureInfo(\"en-US\");\n int[] data = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x, culture)).ToArray();\n\n var list = data.ToList();\n list.Sort();\n\n if (list[0] + list[1] > list[2] || list[1] + list[2] > list[3])\n {\n Console.WriteLine(\"TRIANGLE\");\n }\n else if (list[0] + list[1] == list[2] || list[1] + list[2] == list[3])\n {\n Console.WriteLine(\"SEGMENT\");\n }\n else\n {\n Console.WriteLine(\"IMPOSSIBLE\");\n }\n }\n }\n}\n", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Text;\nusing System.IO;\n\n\n\n\n\nclass Program\n{\n \n void solve()\n {\n int n = nextInt();\n string s = nextString();\n long[,] dp = new long[n + 1, n + 1];\n char[,] by = new char[n + 1, n + 1];\n for (int i = 0; i <= n; i++)\n for (int j = 0; j <= n; j++)\n dp[i, j] = -1;\n long res = go(0, 0, 0, n, s, dp, by);\n {\n int i = 0;\n int j = 0;\n string seq = \"\";\n while (i != n || j != n)\n {\n seq += by[i, j];\n if (by[i, j] == 'H')\n {\n i++;\n }\n else\n j++;\n }\n println(seq);\n }\n }\n\n private long go(int l1, int l2,int at, int n, string s,long[,]dp,char[,]by)\n {\n if (dp[l1,l2] != -1)\n return dp[l1,l2];\n if (l1 == n && l2 == n)\n return dp[l1,l2] = 0;\n long res = -1;\n if (l1 != n)\n {\n long cur = pow(n - l1-1) * (s[at] - '0');\n cur += go(l1 + 1, l2, at + 1, n, s, dp,by);\n if (cur > res)\n {\n res = cur;\n by[l1, l2] = 'H';\n \n }\n \n }\n if (l2 != n)\n {\n long cur = pow(n - l2 - 1) * (s[at] - '0');\n cur += go(l1, l2+1, at + 1, n, s, dp,by);\n if (cur > res)\n {\n res = cur;\n by[l1, l2] = 'M';\n }\n }\n \n return dp[l1, l2]=res;\n }\n\n private long pow(int p)\n {\n if (p == 0)\n return 1;\n return pow(p - 1) * 10;\n }\n\n\n ////////////\n private void println(string Stringst)\n {\n Console.WriteLine(Stringst);\n }\n private void println(char charnum)\n {\n Console.WriteLine(charnum);\n }\n private void println(int Intnum)\n {\n Console.WriteLine(Intnum);\n }\n private void println(long Longnum)\n {\n Console.WriteLine(Longnum);\n }\n private void println(double Doublenum)\n {\n string s = Doublenum.ToString(CultureInfo.InvariantCulture);\n Console.WriteLine(s);\n }\n\n private void print(string Stringst)\n {\n Console.Write(Stringst);\n }\n private void print(int Intnum)\n {\n Console.Write(Intnum);\n }\n private void print(char charnum)\n {\n Console.Write(charnum);\n }\n private void print(long Longnum)\n {\n Console.Write(Longnum);\n }\n private void print(double Doublenum)\n {\n Console.Write(Doublenum);\n }\n\n\n string[] inputLine = new string[0];\n int inputInd = 0;\n string nextLine()\n {\n return Console.ReadLine();\n }\n void readInput()\n {\n if (inputInd != inputLine.Length)\n throw new Exception();\n inputInd = 0;\n inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n if (inputLine.Length == 0)\n readInput();\n\n }\n int nextInt()\n {\n if (inputInd == inputLine.Length)\n readInput();\n return int.Parse(inputLine[inputInd++]);\n }\n long nextLong()\n {\n if (inputInd == inputLine.Length)\n readInput();\n return long.Parse(inputLine[inputInd++]);\n }\n double nextDouble()\n {\n if (inputInd == inputLine.Length)\n readInput();\n return double.Parse(inputLine[inputInd++]);\n }\n string nextString()\n {\n if (inputInd == inputLine.Length)\n readInput();\n return inputLine[inputInd++];\n }\n static void Main(string[] args)\n {\n new Program().solve();\n }\n}\n\n\n", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Util;\n\npublic class Program\n{\n public void Solve()\n {\n var sc = new Scanner();\n string s = sc.Next();\n bool f = s.Count(c => c == '1') >= 2;\n for (int i = 0;; i++)\n {\n // 1 0が2*i個\n\n int len = 1 + 2 * i;\n\n if (s.Length < len || (s.Length == len && !f))\n {\n Console.WriteLine(i);\n break;\n }\n }\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CodeForces\n{\n public class Program\n {\n private static void Main(string[] args)\n {\n var mod = (int) 1e9 + 7;\n var data = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();\n var a = data[0];\n var b = data[1];\n var k = data[2];\n var t = data[3];\n\n var nbFinalValues = 2*k*t + 1;\n var nbPathToValue = new long[nbFinalValues];\n var sumWinningPathForValue = new long[nbFinalValues + 1];\n\n nbPathToValue[k * t] = 1;\n for (var i = k*t + 1; i < sumWinningPathForValue.Length; ++i)\n {\n sumWinningPathForValue[i] = 1;\n }\n\n for (var i = 0; i < t; ++i)\n {\n var nextNbPathToValue = new long[nbFinalValues];\n var nextSumWinningPathForValue = new long[nbFinalValues + 1];\n for (var j = 0; j < nbPathToValue.Length; ++j)\n {\n var leftIndex = Math.Max(0, j - k);\n var rightIndex = Math.Min(nbPathToValue.Length - 1, j + k);\n nextNbPathToValue[j] = (mod + sumWinningPathForValue[rightIndex+1] - sumWinningPathForValue[leftIndex]) % mod;\n nextSumWinningPathForValue[j + 1] = (mod + nextSumWinningPathForValue[j] + nextNbPathToValue[j]) % mod;\n }\n sumWinningPathForValue = nextSumWinningPathForValue;\n nbPathToValue = nextNbPathToValue;\n }\n\n long result = 0;\n for (var i = Math.Max(0, b - a + 1); i new Program().Solve();\n // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "76659c0b7134416452585c391daadb16"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n string[] ar = new string[10];\n for(int i = 0; i<10; i++)\n {\n ar[i] = Console.ReadLine();\n }\n string res = \"\";\n for (int i = 0; i < 8; i++ )\n {\n string sub = s.Substring(i * 10, 10);\n for (int j = 0; j < 10; j++ )\n {\n if(sub.Equals(ar[j]))\n {\n res += (j);\n }\n }\n }\n Console.WriteLine(res);\n }\n }\n}\n", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "#define Online\n\nusing System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Threading;\n\ndelegate double F(double x);\ndelegate decimal Fdec(decimal x);\n\nclass Program\n{\n static int Compare(long x, long y)\n {\n if (x > y) return 1;\n if (x < y) return -1;\n return 0;\n }\n static void Main(string[] args)\n {\n\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if FileIO\n StreamReader sr = new StreamReader(\"forest.in\");\n StreamWriter sw = new StreamWriter(\"forest.out\");\n Console.SetIn(sr);\n Console.SetOut(sw);\n#endif \n long n = long.Parse(Console.ReadLine());\n const long m = 1000000000;\n List div = new List();\n\n for (long i = 1; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n div.Add(i);\n div.Add(n / i);\n }\n }\n div.Sort(Compare);\n long min = long.MaxValue;\n long max = long.MinValue;\n long a,b,c;\n for (int i = 0; i < div.Count; i++)\n {\n a = div[i] + 1;\n for (int j = 0; j < div.Count; j++)\n {\n b = div[j] + 2;\n if ((a - 1) * (b - 2) > n) break;\n for (int z = 0; z < div.Count; z++)\n {\n c = div[z] + 2;\n if ((a - 1) * (b - 2) * (c - 2) > n) break;\n if ((a - 1) * (b - 2) * (c - 2) != n) continue;\n min = Math.Min(min, a * b * c - (a - 1) * (b - 2) * (c - 2));\n max = Math.Max(max, a * b * c - (a - 1) * (b - 2) * (c - 2));\n }\n }\n }\n Console.WriteLine(min + \" \" + max);\n#if Online\n Console.ReadLine();\n#endif\n\n#if FileIO\n sr.Close();\n sw.Close();\n#endif\n }\n\n static string[] ReadArray()\n {\n return Console.ReadLine().Split(' ');\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static decimal Sqrt(decimal x)\n {\n decimal mid;\n decimal right = (x <= 1 ? 1 : x);\n decimal left = 0;\n decimal eps = 0.00000000000000000001m;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2m);\n if (Math.Sign(mid * mid - x) != Math.Sign(left * left - x))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2m;\n }\n\n}\n\nstatic class ArrayUtils\n{\n public static int BinarySearch(int[] a, int val)\n {\n int left = 0;\n int right = a.Length - 1;\n int mid;\n\n while (left < right)\n {\n mid = left + ((right - left) >> 1);\n if (val <= a[mid])\n {\n right = mid;\n }\n else\n {\n left = mid + 1;\n }\n }\n\n if (a[left] == val)\n return left;\n else\n return -1;\n }\n\n public static double Bisection(F f, double left, double right, double eps)\n {\n double mid;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2d);\n if (Math.Sign(f(mid)) != Math.Sign(f(left)))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2d;\n }\n\n\n public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)\n {\n decimal m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3m;\n m2 = r - (r - l) / 3m;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static double TernarySearch(F f, double eps, double l, double r, bool isMax)\n {\n double m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3d;\n m2 = r - (r - l) / 3d;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static void Merge(int[] A, int p, int q, int r, int[] L, int[] R)\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (L[i] <= R[j])\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(int[] A, int p, int r, int[] L, int[] R)\n {\n if (!(p < r)) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R);\n Merge_Sort(A, q + 1, r, L, R);\n Merge(A, p, q, r, L, R);\n }\n}", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Flea_travel\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int n = Next();\n\n var nn = new int[n,n];\n int index = 0;\n int jump = 1;\n while (true)\n {\n int next = (index + jump)%n;\n if (nn[index, next] == 1)\n {\n break;\n }\n nn[index, next] = 1;\n index = next;\n jump++;\n }\n\n for (int i = 0; i < n; i++)\n {\n bool ok = false;\n for (int j = 0; j < n; j++)\n {\n if (nn[i, j] == 1)\n {\n ok = true;\n break;\n }\n }\n if (ok == false)\n {\n writer.WriteLine(\"NO\");\n writer.Flush();\n return;\n }\n }\n\n writer.WriteLine(\"YES\");\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "4bd174a997707ed3a368bd0f2424590f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n string[] y = Console.ReadLine().Split();\n int n = int.Parse(y[0]);\n int k = int.Parse(y[1]);\n string[] s = Console.ReadLine().Split();\n int[] m = new int[k];\n for (int i = 0; i < k; i++)\n {\n m[i] = int.Parse(s[i]);\n }\n Array.Sort(m);\n int a = 0;\n int min = int.MaxValue;\n \n for (int i = 0; i < k - n + 1; i++)\n {\n a = Math.Abs(m[i] - m[i + n-1]);\n if (a < min)\n {\n min = a;\n }\n }\n Console.WriteLine(min);\n\n \n\n\n }\n }\n}\n", "src_uid": "7830aabb0663e645d54004063746e47f"} {"source_code": "using System;\n\nnamespace Codeforces.TaskD\n{\n public class Task\n {\n public static void Main()\n {\n var task = new Task();\n try\n {\n task.Solve();\n }\n catch (Exception ex)\n {\n Console.ForegroundColor = ConsoleColor.Red;\n Console.WriteLine(ex);\n throw;\n }\n }\n\n void Solve()\n {\n var arr = Console.ReadLine().Split();\n var N = int.Parse(arr[0]);\n var K = int.Parse(arr[1]);\n const int mod = 1000000007;\n\n var d = new int[K + 1, N + 2];\n\n for (var n = 1; n <= N; n++)\n d[1, n] = 1;\n\n for (var k = 2; k <= K; k++)\n for (var n = 1; n <= N; n++)\n for (var i = n; i <= N; i += n)\n d[k, i] = (d[k, i] + d[k - 1, n]) % mod;\n\n var result = 0;\n for (var i = 1; i <= N; i++)\n result = (result + d[K, i]) % mod;\n Console.WriteLine(result);\n }\n }\n}\n", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nnamespace ConsoleApplication3\n{\n class Program\n {\n static void Main(string[] args)\n {\n try\n {\n int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n string s = Console.ReadLine();\n int ig = 0;\n // int it = 0;\n int step = nk[1];\n int it = 0;\n int i = 0;\n for ( i = 0; i < s.Length; i++)\n {\n if (s[i] == 'G')\n ig = i;\n if (s[i] == 'T')\n it = i;\n }\n i = 0;\n if(it it ; i -= nk[1])\n {\n if (s[i] == '#')\n break;\n }\n }\n else\n {\n for (i = ig + nk[1]; i < it ; i += nk[1])\n {\n if (s[i] == '#')\n break;\n }\n }\n if(i==it)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n \n Console.ReadKey();\n }\n\n catch { }\n }\n \n }\n}", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Debug = System.Diagnostics.Debug;\nusing SB = System.Text.StringBuilder;\nusing Number = System.Int64;\nusing System.Numerics;\nusing static System.Math;\nnamespace Program {\n public class Solver {\n Random rnd = new Random ();\n public void Solve () {\n var n = rl;\n var k = rl;\n var m = rl;\n var d = rl;\n BigInteger ans = 0;\n for (var i = 1; i <= d + 1; i++) {\n BigInteger min = n;\n BigInteger kk = k;\n kk *= i;\n min /= kk;\n kk = k;\n kk *= i - 1;\n kk += 1;\n var max = i == 1 ? m : (n / kk);\n min = BigInteger.Min (BigInteger.Max (1, min), m);\n max = BigInteger.Min (BigInteger.Max (1, max), m);\n\n foreach (var x in new BigInteger[] { min, max }) {\n BigInteger V = n;\n BigInteger u = x;\n u *= k;\n var cnt = 0;\n while (V >= x && cnt <= d) {\n V -= u;\n cnt++;\n }\n //Console.WriteLine ($\"{min} {max} {x} {cnt}\");\n\n if (cnt <= d) ans = BigInteger.Max (ans, cnt * x);\n }\n }\n System.Console.WriteLine (ans);\n\n }\n const long INF = 1L << 60;\n //static int[] dx = { -1, 0, 1, 0 };\n //static int[] dy = { 0, 1, 0, -1 };\n\n int ri { get { return sc.Integer (); } }\n long rl { get { return sc.Long (); } }\n double rd { get { return sc.Double (); } }\n string rs { get { return sc.Scan (); } }\n public IO.StreamScanner sc = new IO.StreamScanner (Console.OpenStandardInput ());\n\n static T[] Enumerate (int n, Func f) {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f (i);\n return a;\n }\n static public void Swap (ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n#region main\nstatic class Ex {\n static public string AsString (this IEnumerable ie) { return new string (ie.ToArray ()); }\n static public string AsJoinedString (this IEnumerable ie, string st = \" \") {\n return string.Join (st, ie);\n }\n static public void Main () {\n Console.SetOut (new Program.IO.Printer (Console.OpenStandardOutput ()) { AutoFlush = false });\n var solver = new Program.Solver ();\n try {\n solver.Solve ();\n Console.Out.Flush ();\n } catch { }\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO {\n using System.Globalization;\n using System.IO;\n using System.Text;\n\n public class Printer : StreamWriter {\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer (Stream stream) : base (stream, new UTF8Encoding (false, true)) { }\n }\n\n public class StreamScanner {\n public StreamScanner (Stream stream) { str = stream; }\n\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n\n private byte read () {\n if (isEof) return 0;\n if (ptr >= len) {\n ptr = 0;\n if ((len = str.Read (buf, 0, 1024)) <= 0) {\n isEof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n\n public char Char () {\n byte b = 0;\n do b = read (); while ((b < 33 || 126 < b) && !isEof);\n return (char) b;\n }\n public string Scan () {\n var sb = new StringBuilder ();\n for (var b = Char (); b >= 33 && b <= 126; b = (char) read ()) sb.Append (b);\n return sb.ToString ();\n }\n public string ScanLine () {\n var sb = new StringBuilder ();\n for (var b = Char (); b != '\\n' && b != 0; b = (char) read ())\n if (b != '\\r') sb.Append (b);\n return sb.ToString ();\n }\n public long Long () { return isEof ? long.MinValue : long.Parse (Scan ()); }\n public int Integer () { return isEof ? int.MinValue : int.Parse (Scan ()); }\n public double Double () { return isEof ? double.NaN : double.Parse (Scan (), CultureInfo.InvariantCulture); }\n }\n}\n#endregion", "src_uid": "ac2e795cd44061db8da13e3947ba791b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace TestConsole\n{\n\n class Program\n {\n\n public static void Main(string[] args)\n {\n int[] input = readIntArray(System.Console.ReadLine().Split(' '));\n int a = input[0];\n int b = input[1];\n int k = input[2];\n\n bool[] seive = new bool[b + 1];\n for (int i = 2; i < b + 1; i++)\n {\n seive[i] = true;\n }\n\n for (int i = 2; i < b + 1; i++)\n {\n if (seive[i])\n {\n if (((long)i) * i < b + 1)\n {\n for (int j = i * i; j < b + 1; j += i)\n {\n seive[j] = false;\n }\n }\n }\n }\n\n int result = -1;\n\n int left = k;\n int right = b - a + 2;\n\n while (left < right)\n {\n int l = (right + left) / 2;\n\n int firstWindow = 0;\n for (int i = a; i <= a + l - 1 && i < seive.Length; i++)\n {\n if (seive[i]) firstWindow++;\n }\n\n bool forAllX = firstWindow >= k;\n\n if (forAllX)\n {\n for (int x = a + 1; x <= b - l + 1; x++)\n {\n if (seive[x - 1]) firstWindow--;\n if (seive[x + l - 1]) firstWindow++;\n if (firstWindow < k)\n {\n forAllX = false;\n break;\n }\n }\n }\n if (forAllX)\n {\n result = l;\n right = l;\n }\n else\n {\n left = l + 1;\n }\n }\n Console.WriteLine(result);\n }\n\n static int[] readIntArray(string[] inArray)\n {\n return inArray.Select(i => Int32.Parse(i)).ToArray();\n }\n\n }\n\n}", "src_uid": "3e1751a2990134f2132d743afe02a10e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp10\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int k = inp[0];\n int a = inp[1];\n int b = inp[2];\n int u = a / k + b / k;\n if ((a>=k&&b>=k)||(a%k==0&&a!=0)||(b%k==0&&b!=0))\n {\n Console.WriteLine(u);\n }\n else\n {\n Console.WriteLine(-1);\n }\n\n\n }\n\n }\n}", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace A\n{\n public static class Program\n {\n public static void Main()\n {\n var n = int.Parse(Console.ReadLine());\n var s = Console.ReadLine().Reverse().ToArray();\n\n var min = 0;\n var curr = min;\n foreach (var m in s)\n {\n if (m == '-')\n {\n curr++;\n } else\n {\n curr--;\n }\n if (curr < 0)\n {\n curr = 0;\n min++;\n }\n }\n Console.WriteLine(min);\n }\n }\n}\n", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Numerics;\nusing E = System.Linq.Enumerable;\n\nnamespace ProbA {\n class Program {\n protected IOHelper io;\n\n public Program(string inputFile, string outputFile) {\n io = new IOHelper(inputFile, outputFile, Encoding.Default);\n\n int n=io.NextInt(), p=io.NextInt();\n string[] cmd = new string[n];\n for (int i = 0; i < n; i++) cmd[i] = io.NextToken();\n long has = 0, half = 0;\n for (int i = n - 1; i >= 0; i--) {\n if (cmd[i] == \"half\") {\n has *= 2;\n } else {\n has = has * 2 + 1;\n half++;\n }\n }\n io.WriteLine(has * p - p / 2 * half);\n io.Dispose();\n }\n\n static void Main(string[] args) {\n Program myProgram = new Program(null, null);\n }\n }\n\n class IOHelper : IDisposable {\n public StreamReader reader;\n public StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding) {\n if (inputFile == null)\n reader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n reader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n writer = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n writer = new StreamWriter(outputFile, false, encoding);\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public bool hasNext() {\n if (curTokenIdx >= curLine.Length) {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n return curTokenIdx < curLine.Length;\n }\n\n public string NextToken() {\n return hasNext() ? curLine[curTokenIdx++] : null;\n }\n\n public int NextInt() {\n return int.Parse(NextToken());\n }\n\n public double NextDouble() {\n string tkn = NextToken();\n return double.Parse(tkn, System.Globalization.CultureInfo.InvariantCulture);\n }\n\n public void Write(double val, int precision) {\n writer.Write(val.ToString(\"F\" + precision, System.Globalization.CultureInfo.InvariantCulture));\n }\n\n public void Write(object stringToWrite) {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(double val, int precision) {\n writer.WriteLine(val.ToString(\"F\" + precision, System.Globalization.CultureInfo.InvariantCulture));\n }\n\n public void WriteLine(object stringToWrite) {\n writer.WriteLine(stringToWrite);\n }\n\n public void Dispose() {\n try {\n if (reader != null) {\n reader.Dispose();\n }\n if (writer != null) {\n writer.Flush();\n writer.Dispose();\n }\n } catch { };\n }\n\n\n public void Flush() {\n if (writer != null) {\n writer.Flush();\n }\n }\n }\n}\n", "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Task66A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string str = Console.ReadLine();\n sbyte b = 0;\n bool bl = sbyte.TryParse(str,out b);\n if (bl==true)\n {\n Console.WriteLine(\"byte\");\n return;\n }\n short s = 0;\n bl = short.TryParse(str, out s);\n if (bl == true)\n {\n Console.WriteLine(\"short\");\n return;\n }\n int i = 0;\n bl = int.TryParse(str, out i);\n if (bl == true)\n {\n Console.WriteLine(\"int\");\n return;\n }\n long l = 0;\n bl = long.TryParse(str, out l);\n if (bl == true)\n {\n Console.WriteLine(\"long\");\n return;\n }\n Console.WriteLine(\"BigInteger\");\n }\n }\n}\n", "src_uid": "33041f1832fa7f641e37c4c638ab08a1"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Text;\nusing System.Linq;\n\nusing E = System.Linq.Enumerable;\nusing System.Numerics;\n\ninternal partial class Solver {\n public void Run() {\n var x0 = nl();\n var y0 = nl();\n var ax = nl();\n var ay = nl();\n var bx = nl();\n var by = nl();\n var xs = nl();\n var ys = nl();\n var t = nl();\n\n var x = new List { x0 };\n var y = new List { y0 };\n while (true) {\n if (x[x.Count - 1] >= long.MaxValue) break;\n if (y[y.Count - 1] >= long.MaxValue) break;\n var nx = x[x.Count - 1] * ax + bx;\n var ny = y[y.Count - 1] * ay + by;\n x.Add(nx);\n y.Add(ny);\n }\n //x.Dump();\n //y.Dump();\n int ans = 0;\n for (int i = 0; i < x.Count; i++) {\n for (int j = i; j < x.Count; j++) {\n var di = BigInteger.Abs(xs - x[i]) + BigInteger.Abs(ys - y[i]);\n var dj = BigInteger.Abs(xs - x[j]) + BigInteger.Abs(ys - y[j]);\n var dij = BigInteger.Abs(x[i] - x[j]) + BigInteger.Abs(y[i] - y[j]);\n int num = j - i + 1;\n if (di + dij <= t || dj + dij <= t) {\n ans = Math.Max(ans, num);\n }\n }\n }\n cout.WriteLine(ans);\n }\n}\n\n// PREWRITEN CODE BEGINS FROM HERE\ninternal partial class Solver : Scanner {\n public static void Main(string[] args) {\n#if LOCAL\n byte[] inputBuffer = new byte[1000000];\n var inputStream = Console.OpenStandardInput(inputBuffer.Length);\n using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {\n Console.SetIn(reader);\n new Solver(Console.In, Console.Out).Run();\n }\n#else\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver(Console.In, Console.Out).Run();\n Console.Out.Flush();\n#endif\n }\n\n#pragma warning disable IDE0052\n private readonly TextReader cin;\n private readonly TextWriter cout;\n#pragma warning restore IDE0052\n\n public Solver(TextReader reader, TextWriter writer)\n : base(reader) {\n cin = reader;\n cout = writer;\n }\n public Solver(string input, TextWriter writer)\n : this(new StringReader(input), writer) {\n }\n\n#pragma warning disable IDE1006\n#pragma warning disable IDE0051\n private int ni() { return NextInt(); }\n private int[] ni(int n) { return NextIntArray(n); }\n private long nl() { return NextLong(); }\n private long[] nl(int n) { return NextLongArray(n); }\n private double nd() { return NextDouble(); }\n private double[] nd(int n) { return NextDoubleArray(n); }\n private string ns() { return Next(); }\n private string[] ns(int n) { return NextArray(n); }\n#pragma warning restore IDE1006\n#pragma warning restore IDE0051\n}\n\ninternal static class LinqPadExtension {\n [Conditional(\"DEBUG\")]\n public static void Dump(this T obj) {\n#if DEBUG\n LINQPad.Extensions.Dump(obj);\n#endif\n }\n}\n\npublic class Scanner {\n private readonly TextReader Reader;\n private readonly CultureInfo ci = CultureInfo.InvariantCulture;\n\n private readonly char[] buffer = new char[2 * 1024];\n private int cursor = 0, length = 0;\n private string Token;\n private readonly StringBuilder sb = new StringBuilder(1024);\n\n public Scanner()\n : this(Console.In) {\n }\n\n public Scanner(TextReader reader) {\n Reader = reader;\n }\n\n public int NextInt() { return (int)NextLong(); }\n public long NextLong() {\n var s = Next();\n long r = 0;\n int i = 0;\n bool negative = false;\n if (s[i] == '-') {\n negative = true;\n i++;\n }\n for (; i < s.Length; i++) {\n r = r * 10 + (s[i] - '0');\n#if DEBUG\n if (!char.IsDigit(s[i])) throw new FormatException();\n#endif\n }\n return negative ? -r : r;\n }\n public double NextDouble() { return double.Parse(Next(), ci); }\n public string[] NextArray(int size) {\n string[] array = new string[size];\n for (int i = 0; i < size; i++) {\n array[i] = Next();\n }\n\n return array;\n }\n public int[] NextIntArray(int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = NextInt();\n }\n\n return array;\n }\n\n public long[] NextLongArray(int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; i++) {\n array[i] = NextLong();\n }\n\n return array;\n }\n\n public double[] NextDoubleArray(int size) {\n double[] array = new double[size];\n for (int i = 0; i < size; i++) {\n array[i] = NextDouble();\n }\n\n return array;\n }\n\n public string Next() {\n if (Token == null) {\n if (!StockToken()) {\n throw new InvalidOperationException();\n }\n }\n var token = Token;\n Token = null;\n return token;\n }\n\n public bool HasNext() {\n if (Token != null) {\n return true;\n }\n\n return StockToken();\n }\n\n private bool StockToken() {\n while (true) {\n sb.Clear();\n while (true) {\n if (cursor >= length) {\n cursor = 0;\n if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {\n break;\n }\n }\n var c = buffer[cursor++];\n if (33 <= c && c <= 126) {\n sb.Append(c);\n } else {\n if (sb.Length > 0) break;\n }\n }\n\n if (sb.Length > 0) {\n Token = sb.ToString();\n return true;\n }\n\n return false;\n }\n }\n}", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Multiplication_Table\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] r = Console.ReadLine().Split(' ');\n int n = int.Parse(r[0]);\n int m = int.Parse(r[1]);\n long k = long.Parse(r[2]);\n int nn = Math.Min(n, m);\n int mm = n + m - nn;\n long levo = 1;\n long desno = 250000000000;\n long resenje = 0;\n while (levo <= desno)\n {\n long sredina = (levo + desno) / 2;\n long fsred = 0;\n for (int i = 1; i <= nn; i++)\n {\n if (sredina >= i + 1) fsred += Math.Min((sredina - 1) / i, mm);\n else break;\n }\n fsred++;\n if (fsred <= k) { resenje = sredina; levo = sredina + 1; }\n else desno = sredina - 1;\n }\n Console.WriteLine(resenje);\n }\n }\n}\n", "src_uid": "13a918eca30799b240ceb9de47507a26"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n class Edge\n {\n public int To, Inv;\n public T Capacity, Cost, Flow;\n public Edge(int to, int inv, T capacity, T cost, T flow)\n {\n To = to;\n Inv = inv;\n Capacity = capacity;\n Cost = cost;\n Flow = flow;\n }\n }\n\n static void AddEdge(List>[] g, int from, int to, int capacity, int cost)\n {\n g[from].Add(new Edge(to, g[to].Count, capacity, cost, 0));\n g[to].Add(new Edge(from, g[from].Count - 1, 0, -cost, 0));\n }\n\n int MinCost(List>[] g, int source, int sink, int limit)\n {\n const int INF = int.MaxValue / 2;\n\n int n = g.Length;\n int flow = 0, cost = 0;\n while (flow < limit)\n {\n var id = new int[n];\n var dist = Enumerable.Repeat(INF, n).ToArray();\n var q = new int[n];\n var path = new int[n];\n var epath = new int[n];\n int qh = 0, qt = 0;\n q[qt++] = source;\n dist[source] = 0;\n while (qh != qt)\n {\n int v = q[qh++];\n if (qh == n)\n qh = 0;\n id[v] = 2;\n for (int i = 0; i < g[v].Count; i++)\n {\n var r = g[v][i];\n if (r.Flow < r.Capacity && dist[v] + r.Cost < dist[r.To])\n {\n dist[r.To] = dist[v] + r.Cost;\n if (id[r.To] == 0)\n {\n q[qt++] = r.To;\n if (qt == n)\n qt = 0;\n }\n else if (id[r.To] == 2)\n {\n if (--qh == -1)\n qh = n - 1;\n q[qh] = r.To;\n }\n id[r.To] = 1;\n path[r.To] = v;\n epath[r.To] = i;\n }\n }\n }\n if (dist[sink] == INF)\n break;\n int addflow = limit - flow;\n for (int v = sink; v != source; v = path[v])\n {\n int pv = path[v];\n int pr = epath[v];\n addflow = Math.Min(addflow, g[pv][pr].Capacity - g[pv][pr].Flow);\n }\n for (int v = sink; v != source; v = path[v])\n {\n int pv = path[v];\n int pr = epath[v], r = g[pv][pr].Inv;\n g[pv][pr].Flow += addflow;\n g[v][r].Flow -= addflow;\n cost += g[pv][pr].Cost * addflow;\n }\n flow += addflow;\n }\n return cost;\n }\n\n private int[] dr = {1, 0, -1, 0};\n private int[] dc = {0, 1, 0, -1};\n\n public void Solve()\n {\n int n = ReadInt();\n int m = ReadInt();\n var a = ReadIntMatrix(n);\n\n var g = Enumerable.Repeat(0, n * m + 2).Select(x => new List>()).ToArray();\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n {\n int x = i * m + j;\n if ((i + j) % 2 == 0)\n {\n AddEdge(g, n * m, x, 1, 0);\n for (int k = 0; k < 4; k++)\n {\n int ii = i + dr[k];\n int jj = j + dc[k];\n if (ii < 0 || ii == n || jj < 0 || jj == m)\n continue;\n AddEdge(g, x, ii * m + jj, 1, a[i][j] == a[ii][jj] ? 0 : 1);\n }\n }\n else\n {\n AddEdge(g, x, n * m + 1, 1, 0);\n }\n }\n\n Write(MinCost(g, n * m, n * m + 1, n * m / 2));\n }\n \n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"game.in\");\n //writer = new StreamWriter(\"game.out\");\n#endif\n try\n {\n var thread = new Thread(new Solver().Solve, 1024 * 1024 * 256);\n thread.Start();\n thread.Join();\n //new Solver().Solve();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n Console.WriteLine(ex);\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params object[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n\n #endregion\n}", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Runtime.CompilerServices;\nusing static System.Math;\nusing System.Text;\n\nnamespace Program\n{\n public static class CODEFORCES2\n {\n static public void Solve()\n {\n var list = NSList(3);\n var s = new List();\n var m = new List();\n var p = new List();\n foreach (var item in list)\n {\n if (item[1] == 'm')\n {\n m.Add(int.Parse(item[0].ToString()));\n }\n if (item[1] == 's')\n {\n s.Add(int.Parse(item[0].ToString()));\n }\n if (item[1] == 'p')\n {\n p.Add(int.Parse(item[0].ToString()));\n }\n }\n Func, int> sameCount = x =>\n {\n var ans = 0;\n foreach (var item in x)\n {\n ans = Max(ans, x.Count(e => e == item));\n }\n return ans;\n };\n Func, int> junCount = x =>\n {\n var x2 = x.OrderBy(e => e).ToArray();\n if (x.Count == 0) return 0;\n if (x.Count == 1) return 1;\n if (x.Count == 2)\n {\n if (x2[0] + 1 == x2[1])\n {\n return 2;\n }\n if (x2[0] + 2 == x2[1]) return 2;\n return 1;\n }\n if (x2[0] + 1 == x2[1])\n {\n if (x2[1] + 1 == x2[2])\n {\n return 3;\n }\n return 2;\n }\n if (x2[1] + 1 == x2[2])\n {\n return 2;\n }\n if (x2[0] + 2 == x2[1]) return 2;\n if (x2[0] + 2 == x2[2]) return 2;\n return 1;\n };\n var max = 0;\n max = Max(max, sameCount(m));\n max = Max(max, sameCount(s));\n max = Max(max, sameCount(p));\n max = Max(max, junCount(m));\n max = Max(max, junCount(s));\n max = Max(max, junCount(p));\n Console.WriteLine(3 - max);\n\n }\n\n static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); }\n static Random rand = new Random();\n static class Console_\n {\n static Queue param = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }\n }\n static long NN => long.Parse(Console_.NextString());\n static double ND => double.Parse(Console_.NextString());\n static string NS => Console_.NextString();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static IEnumerable OrderByRand(this IEnumerable x) => x.OrderBy(_ => rand.Next());\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static IEnumerable Repeat(T v, long n) => Enumerable.Repeat(v, (int)n);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static IEnumerable Range(long s, long c) => Enumerable.Range((int)s, (int)c);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static void RevSort(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static void RevSort(T[] l, Comparison comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static IEnumerable Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static IEnumerable Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static IEnumerable Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; }\n static long LCM(long a, long b) => a * b / GCD(a, b);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static Mat Pow(Mat x, long y) => Mat.Pow(x, y);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static T Pow(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; }\n static List _fact = new List() { 1 };\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }\n class PQ where T : IComparable\n {\n List h; Comparison c; public T Peek => h[0]; public int Count => h.Count;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(int cap, Comparison c, bool asc = true) { h = new List(cap); this.c = asc ? c : (x, y) => c(y, x); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(Comparison c, bool asc = true) { h = new List(); this.c = asc ? c : (x, y) => c(y, x); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) { }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) { }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; }\n }\n class PQ where TK : IComparable\n {\n PQ> q; public Tuple Peek => q.Peek; public int Count => q.Count;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(int cap, Comparison c, bool asc = true) { q = new PQ>(cap, (x, y) => c(x.Item1, y.Item1), asc); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(Comparison c, bool asc = true) { q = new PQ>((x, y) => c(x.Item1, y.Item1), asc); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) { }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) { }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tuple Pop() => q.Pop();\n }\n public class UF\n {\n long[] d;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public UF(long s) { d = Repeat(-1L, s).ToArray(); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool IsSame(long x, long y) => Root(x) == Root(y);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public long Count(long x) => -d[Root(d[x])];\n }\n struct Mod : IEquatable\n {\n static public long _mod = 1000000007; long _val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; }\n static public implicit operator Mod(long x) => new Mod(x);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public implicit operator long(Mod x) => x._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mod operator +(Mod x, Mod y) => x._val + y._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mod operator -(Mod x, Mod y) => x._val - y._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mod operator *(Mod x, Mod y) => x._val * y._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public bool operator ==(Mod x, Mod y) => x._val == y._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public bool operator !=(Mod x, Mod y) => x._val != y._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n bool IEquatable.Equals(object obj) => obj == null ? false : Equals((Mod)obj);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override int GetHashCode() => _val.GetHashCode();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override string ToString() => _val.ToString();\n static List _fact = new List() { 1 };\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; }\n }\n struct Mat\n {\n T[,] m;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Mat(T[,] v) { m = (T[,])v.Clone(); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public implicit operator Mat(T[,] v) => new Mat(v);\n public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat operator +(Mat a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat operator +(Mat a, Mat b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat operator -(Mat a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat operator -(Mat a, Mat b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat operator *(Mat a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat operator *(Mat a, Mat b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public Mat Pow(Mat x, long y) { var n = x.m.GetLength(0); var t = (Mat)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; }\n }\n class Tree\n {\n long N; int l; List[] p; int[] d; long[][] pr; long r; Tuple[] e; Tuple[] b; bool lca; bool euler; bool bfs;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tree(List[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tuple[] FromRoot() { if (!bfs) { var nb = new List>(); var q = new Queue(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tuple[] FromLeaf() => FromRoot().Reverse().ToArray();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tuple[] Euler() { if (!euler) { var ne = new List>(); var s = new Stack>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; }\n }\n class BT where T : IComparable\n {\n class Node { public Node l; public Node r; public T v; public bool b; }\n Comparison c; Node r; bool ch; T lm;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public BT(Comparison _c) { c = _c; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public BT() : this((x, y) => x.CompareTo(y)) { }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n bool R(Node n) => n != null && !n.b;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n bool B(Node n) => n != null && n.b;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Add(T x) { r = A(r, x); r.b = true; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } var r = c(x, n.v); if (r < 0) { n.l = A(n.l, x); return Bl(n); } if (r > 0) { n.r = A(n.r, x); return Bl(n); } ch = false; return n; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tuple FindUpper(T x) { var v = FU(r, x); return v == null ? Tuple.Create(false, default(T)) : v; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Tuple FU(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0) return FU(n.r, x); return Tuple.Create(true, n.v); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public Tuple FindLower(T x) { var v = FL(r, x); return v == null ? Tuple.Create(false, default(T)) : v; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n Tuple FL(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) return FL(n.l, x); if (r > 0) { var v = FL(n.r, x); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Any() => r != null;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CountSlow() => L(r).Count();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public IEnumerable List() => L(r);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n IEnumerable L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; }\n }\n }\n}\n", "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"source_code": "using System;\n\nnamespace ConsoleApp15\n{\n class Program\n {\n static void Main(string[] args)\n {\n var t = int.Parse(Console.ReadLine());\n\n while (t-- > 0)\n {\n var n = int.Parse(Console.ReadLine());\n\n if (n % 2 == 0)\n {\n var a = n / 2;\n Console.WriteLine(a + \" \" + a);\n continue;\n }\n var b = true;\n for (int i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n Console.WriteLine((n / i) + \" \" + (n - (n / i)));\n b = false;\n break;\n }\n }\n\n if (b) { Console.WriteLine(\"1 \"+(n-1)); }\n\n\n }\n }\n }\n}\n", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int money = int.Parse(Console.ReadLine());\n\n int[,] guardData = new int[4, 4];\n\n for (int i = 0; i < 4; i++)\n {\n var input = Console.ReadLine();\n var input2 = input.Split(' ');\n for (int a = 0; a < 4; a++)\n {\n guardData[i, a] = int.Parse(input2[a]);\n }\n }\n\n int min;\n int min2;\n int spot = 0;\n int i1 = 0;\n int i2 = 0;\n for (int i = 0; i < 4; i++)\n {\n min = Math.Min(guardData[i, 0], guardData[i, 1]);\n min2 = Math.Min(guardData[i, 2], guardData[i, 3]);\n\n if ((min + min2) <= money)\n {\n if (min == guardData[i, 0])\n {\n i1 = guardData[i, 0];\n }\n else\n {\n i1 = guardData[i, 1];\n }\n\n if (min2 == guardData[i, 2])\n {\n i2 = guardData[i, 2];\n }\n else\n {\n i2 = guardData[i, 3];\n }\n spot = i + 1;\n\n if (min+min2 < money);\n {\n i2 += (money-(min+min2));\n }\n }\n }\n if (spot > 0)\n {\n Console.WriteLine(spot + \" \" + i1 + \" \" + i2);\n }\n else\n {\n Console.WriteLine(-1);\n }\n //Console.ReadLine();\n }\n }\n}\n", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Reflection;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Linq;\nusing System.Globalization;\n\npublic class Solution\n{\n public TextInput cin;\n public TextOutput cout;\n public TextOutput cerr;\n public virtual void Solve()\n {\n var n = cin.Read();\n var k = cin.Read();\n\n k = Math.Min(n / 2, k);\n\n var ans = 0L;\n for (var i = 0; i < k; i++)\n {\n var nn = n - 2 * i;\n\n ans += nn - 1;\n ans += nn - 2;\n }\n\n cout.WriteLine(ans);\n }\n}\n\n#region Core\nstatic class MainClass\n{\n public static readonly TextInput cin = new TextInput(Console.In);\n public static readonly TextOutput cout = new TextOutput(Console.Out);\n public static readonly TextOutput cerr = new TextOutput(Console.Error);\n#if !DEBUG\n static void Main()\n {\n new Solution\n {\n cin = cin,\n cout = cout,\n cerr = cerr\n }.Solve();\n }\n#endif\n}\npublic class SDictionary : Dictionary\n{\n public new TValue this[TKey key]\n {\n get\n {\n TValue res;\n base.TryGetValue(key, out res);\n return res;\n }\n set\n {\n base[key] = value;\n }\n }\n}\npublic static class Ext\n{\n\n #region Prewriten\n public static void Foreach(this IEnumerable elements, Action action)\n {\n foreach(var element in elements)\n {\n action(element);\n }\n }\n public static void Foreach(this IEnumerable elements, Action action)\n {\n var index = 0;\n foreach(var element in elements)\n {\n action(element, index++);\n }\n }\n public static void Do(int from, int n, Action action)\n {\n for (var i = from; i < n; i++) action(i);\n }\n public static IEnumerable Init(int n) where T : new()\n {\n for (var i = 0; i < n; i++)\n {\n yield return new T();\n }\n }\n public static IEnumerable Init(int n, T defaultValue = default(T))\n {\n for (var i = 0; i < n; i++)\n {\n yield return defaultValue;\n }\n }\n public static IEnumerable Init(int n, Func builder)\n {\n for (var i = 0; i < n; i++)\n {\n yield return builder(i);\n }\n }\n public static bool IsEmpty(this string s)\n {\n return string.IsNullOrEmpty(s);\n }\n public static string Safe(this string s)\n {\n return s.IsEmpty() ? string.Empty : s;\n }\n public static void Swap(ref T a, ref T b)\n {\n T c = a;\n a = b;\n b = c;\n }\n public static long Gcd(long a, long b)\n {\n while (a > 0)\n {\n b %= a;\n Swap(ref a, ref b);\n }\n return b;\n }\n public static int[] ZFunction(string s)\n {\n var z = new int[s.Length];\n for (int i = 1, l = 0, r = 0; i < s.Length; ++i)\n {\n if (i <= r)\n {\n z[i] = Math.Min(r - i + 1, z[i - l]);\n }\n while (i + z[i] < s.Length && s[z[i]] == s[i + z[i]])\n {\n z[i]++;\n }\n if (i + z[i] - 1 > r)\n {\n l = i;\n r = i + z[i] - 1;\n }\n }\n return z;\n }\n public static long Pow(long a, long p)\n {\n var b = 1L;\n while (p > 0)\n {\n if ((p & 1) == 0)\n {\n a *= a;\n p >>= 1;\n }\n else\n {\n b *= a;\n p--;\n }\n }\n return b;\n }\n #endregion\n}\n\npublic delegate bool TryParseDelegate(string s, NumberStyles style, IFormatProvider format, out T value);\npublic class TextInput\n{\n private static Dictionary primitiveParsers = new Dictionary\n {\n { typeof(sbyte), new TryParseDelegate(sbyte.TryParse) },\n { typeof(short), new TryParseDelegate(short.TryParse) },\n { typeof(int), new TryParseDelegate(int.TryParse) },\n { typeof(long), new TryParseDelegate(long.TryParse) },\n\n { typeof(byte), new TryParseDelegate(byte.TryParse) },\n { typeof(ushort), new TryParseDelegate(ushort.TryParse) },\n { typeof(uint), new TryParseDelegate(uint.TryParse) },\n { typeof(ulong), new TryParseDelegate(ulong.TryParse) },\n\n { typeof(float), new TryParseDelegate(float.TryParse) },\n { typeof(double), new TryParseDelegate(double.TryParse) },\n { typeof(decimal), new TryParseDelegate(decimal.TryParse) },\n\n { typeof(char), new TryParseDelegate(CharParser) },\n { typeof(string), new TryParseDelegate(StringParser) }\n };\n private static bool CharParser(string s, NumberStyles style, IFormatProvider format, out char res)\n {\n res = char.MinValue;\n if (string.IsNullOrEmpty(s))\n {\n return false;\n }\n else\n {\n res = s[0];\n return true;\n }\n }\n private static bool StringParser(string s, NumberStyles style, IFormatProvider format, out string res)\n {\n res = s == null ? string.Empty : s;\n return true;\n }\n\n\n private string line = null;\n private int pos = 0;\n\n public IFormatProvider FormatProvider { get; set; }\n public NumberStyles NumberStyle { get; set; }\n public TextReader TextReader { get; set; }\n\n public TextInput(string path) : this(path, NumberStyles.Any, CultureInfo.InvariantCulture)\n {\n }\n public TextInput(string path, NumberStyles numberStyle, IFormatProvider formatProvider) : this(new StreamReader(path), numberStyle, formatProvider)\n {\n\n }\n public TextInput(TextReader textReader) : this(textReader, NumberStyles.Any, CultureInfo.InvariantCulture)\n {\n\n }\n public TextInput(TextReader textReader, NumberStyles numberStyle, IFormatProvider formatProvider)\n {\n TextReader = textReader;\n NumberStyle = numberStyle;\n FormatProvider = formatProvider;\n }\n\n public bool IsEof\n {\n get\n {\n return (line == null || pos >= line.Length) && TextReader.Peek() == -1;\n }\n }\n public void SkipWhiteSpace()\n {\n while (!IsEof)\n {\n if (line != null && pos < line.Length && !char.IsWhiteSpace(line[pos]))\n {\n return;\n }\n if (line == null || pos >= line.Length)\n {\n Next();\n continue;\n }\n while (pos < line.Length && char.IsWhiteSpace(line[pos]))\n {\n pos++;\n }\n }\n }\n private void SkipWhiteSpace(bool force)\n {\n if (force)\n {\n SkipWhiteSpace();\n }\n else\n {\n SkipWhiteSpace();\n }\n }\n\n public T[] ReadArray()\n {\n var length = Read();\n return ReadArray(length);\n }\n public T[] ReadArray(int length)\n {\n var array = new T[length];\n\n var parser = GetParser();\n var style = NumberStyle;\n var format = FormatProvider;\n\n for (var i = 0; i < length; i++)\n {\n array[i] = Read(parser, style, format);\n }\n return array;\n }\n\n public bool TryReadArray(out T[] array)\n {\n return TryReadArray(GetParser(), NumberStyle, FormatProvider, out array);\n }\n public bool TryReadArray(out T[] array, int length)\n {\n return TryReadArray(GetParser(), NumberStyle, FormatProvider, out array, length);\n }\n public bool TryReadArray(T[] array, int offset, int length)\n {\n return TryReadArray(GetParser(), NumberStyle, FormatProvider, array, offset, length);\n }\n public bool TryReadArray(TryParseDelegate parser, NumberStyles style, IFormatProvider format, out T[] array)\n {\n var length = 0;\n if (!TryRead(out length))\n {\n array = null;\n return false;\n }\n array = new T[length];\n return TryReadArray(parser, style, format, array, 0, length);\n }\n public bool TryReadArray(TryParseDelegate parser, NumberStyles style, IFormatProvider format, out T[] array, int length)\n {\n array = new T[length];\n return TryReadArray(parser, style, format, array, 0, length);\n }\n public bool TryReadArray(TryParseDelegate parser, NumberStyles style, IFormatProvider format, T[] array, int offset, int length)\n {\n var result = true;\n for (var i = 0; i < length && result; i++)\n {\n result &= TryRead(parser, style, format, out array[offset + i]);\n }\n return result;\n }\n\n private TryParseDelegate GetParser()\n {\n var type = typeof(T);\n return (TryParseDelegate)primitiveParsers[type];\n }\n public T Read()\n {\n return Read(GetParser());\n }\n public T Read(NumberStyles style, IFormatProvider format)\n {\n return Read(GetParser(), style, format);\n }\n public T Read(TryParseDelegate parser)\n {\n return Read(parser, NumberStyle, FormatProvider);\n }\n public T Read(TryParseDelegate parser, NumberStyles style, IFormatProvider format)\n {\n T result;\n if (!TryRead(parser, style, format, out result))\n {\n throw new FormatException();\n }\n return result;\n }\n public bool TryRead(out T value)\n {\n return TryRead(GetParser(), out value);\n }\n public bool TryRead(NumberStyles style, IFormatProvider format, out T value)\n {\n return TryRead(GetParser(), style, format, out value);\n }\n public bool TryRead(TryParseDelegate parser, out T value)\n {\n return parser(ReadToken(), NumberStyle, FormatProvider, out value);\n }\n public bool TryRead(TryParseDelegate parser, NumberStyles style, IFormatProvider format, out T value)\n {\n return parser(ReadToken(), style, format, out value);\n }\n public string ReadToken()\n {\n SkipWhiteSpace(false);\n if (IsEof)\n {\n throw new EndOfStreamException();\n }\n\n if (pos >= line.Length || char.IsWhiteSpace(line[pos])) return string.Empty;\n\n var start = pos;\n while (pos < line.Length && !char.IsWhiteSpace(line[pos]))\n {\n pos++;\n }\n return line.Substring(start, pos - start);\n }\n public string ReadLine()\n {\n if (IsEof)\n {\n throw new EndOfStreamException();\n }\n if (line == null || pos >= line.Length)\n {\n Next();\n }\n\n var ans = line.Substring(pos);\n pos = line.Length;\n return ans;\n }\n\n private void Next()\n {\n line = TextReader.ReadLine();\n pos = 0;\n }\n}\n\npublic class TextOutput\n{\n public IFormatProvider FormatProvider { get; set; }\n public TextWriter TextWriter { get; set; }\n\n public TextOutput(string path) : this(path, CultureInfo.InvariantCulture)\n {\n }\n public TextOutput(string path, IFormatProvider formatProvider) : this(new StreamWriter(path), formatProvider)\n {\n\n }\n public TextOutput(TextWriter textWriter) : this(textWriter, CultureInfo.InvariantCulture)\n {\n\n }\n public TextOutput(TextWriter textWriter, IFormatProvider formatProvider)\n {\n TextWriter = textWriter;\n FormatProvider = formatProvider;\n }\n\n public TextOutput WriteArray(params T[] array)\n {\n return WriteArray(array, true);\n }\n public TextOutput WriteArray(T[] array, bool appendLine)\n {\n return WriteArray(array, 0, array.Length, appendLine);\n }\n public TextOutput WriteArray(T[] array, int offset, int length, bool appendLine = true)\n {\n var sb = new StringBuilder();\n for (var i = 0; i < length; i++)\n {\n sb.Append(Convert.ToString(array[offset + i], FormatProvider));\n if (i + 1 < length)\n {\n sb.Append(' ');\n }\n }\n return appendLine ? WriteLine(sb.ToString()) : Write(sb.ToString());\n }\n\n public TextOutput WriteLine(object obj)\n {\n return WriteLine(Convert.ToString(obj, FormatProvider));\n }\n public TextOutput WriteLine(string text, params object[] args)\n {\n return WriteLine(string.Format(FormatProvider, text, args));\n }\n public TextOutput WriteLine(string text)\n {\n TextWriter.WriteLine(text);\n return this;\n }\n public TextOutput WriteLine(char[] buffer)\n {\n TextWriter.WriteLine(buffer);\n return this;\n }\n public TextOutput WriteLine(char[] buffer, int offset, int length)\n {\n TextWriter.WriteLine(buffer, offset, length);\n return this;\n }\n public TextOutput WriteLine()\n {\n TextWriter.WriteLine();\n return this;\n }\n\n public TextOutput Write(object obj)\n {\n return Write(Convert.ToString(obj, FormatProvider));\n }\n public TextOutput Write(string text, params object[] args)\n {\n return Write(string.Format(FormatProvider, text, args));\n }\n public TextOutput Write(string text)\n {\n TextWriter.Write(text);\n return this;\n }\n public TextOutput Write(char[] buffer)\n {\n TextWriter.Write(buffer);\n return this;\n }\n public TextOutput Write(char[] buffer, int offset, int length)\n {\n TextWriter.Write(buffer, offset, length);\n return this;\n }\n}\n#endregion", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\t\t\t\t\t\npublic class Program\n{\n\tpublic static void Main()\n\t{\n\t\tstring[] line = Console.ReadLine().Split(' ');\n\t\tint n = int.Parse(line[0]);\n\t\tint m = int.Parse(line[1]);\n\t\tvar containers = new List();\n\t\t\n\t\tfor(int i = 0; i < m; i++)\n\t\t{\n\t\t\tline = Console.ReadLine().Split(' ');\n\t\t\tint mBoxes = int.Parse(line[0]);\n\t\t\tint matches = int.Parse(line[1]);\n\t\t\t\n\t\t\tvar container = new Container(mBoxes, matches);\n\t\t\tcontainers.Add(container);\n\t\t}\n\t\t\n\t\tvar sortContainers = containers.OrderByDescending(c => c.Matches).ToList();\n\t\tint result = 0;\n\t\tint freeSpace = n;\n\t\t\n\t\tforeach(var container in sortContainers)\n\t\t{\n\t\t\tif(container.MatchBoxes > freeSpace)\n\t\t\t{\n\t\t\t\tresult += freeSpace * container.Matches;\n\t\t\t\tfreeSpace = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult += container.MatchBoxes * container.Matches;\n\t\t\t\tfreeSpace -= container.MatchBoxes;\n\t\t\t}\n\t\t\t\n\t\t\tif(freeSpace == 0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tConsole.WriteLine(result);\n\t}\n}\n\npublic class Container\n{\n\tpublic int MatchBoxes{get;set;}\n\tpublic int Matches{get;set;}\n\t\n\tpublic Container(int mBoxes, int matches)\n\t{\n\t\tMatchBoxes = mBoxes;\n\t\tMatches = matches;\n\t}\n}", "src_uid": "c052d85e402691b05e494b5283d62679"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace King_Moves\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n if ((s == \"a1\" || s == \"a8\" || s == \"h1\" || s == \"h8\"))\n Console.WriteLine(\"3\");\n else if (s[1] == '1' || s[1] == '8' || s[0] == 'a' || s[0] == 'h')\n Console.WriteLine(\"5\");\n else\n Console.WriteLine(\"8\");\n\n }\n }\n}\n", "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace KlonirovanijeIgrushek\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n int x = int.Parse(s[0]);\n int y = int.Parse(s[1]);\n\n if (y == 1 && x > 0)\n Console.Write(\"no\");\n else if ((x - y + 1) % 2 == 0 && (y - 1 <= x) && y > 0)\n Console.Write(\"yes\");\n else\n Console.Write(\"no\");\n \n }\n }\n}\n", "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n bool Fun(int w0, int h0, int w1, int h1, int w2, int h2)\n {\n return w1 + w2 <= w0 && Math.Max(h1, h2) <= h0 || h1 + h2 <= h0 && Math.Max(w1, w2) <= w0;\n }\n\n void Solve()\n {\n var a = ReadIntMatrix(3);\n Write(Fun(a[0][0], a[0][1], a[1][0], a[1][1], a[2][0], a[2][1]) || \n Fun(a[0][0], a[0][1], a[1][1], a[1][0], a[2][0], a[2][1]) || \n Fun(a[0][0], a[0][1], a[1][0], a[1][1], a[2][1], a[2][0]) || \n Fun(a[0][0], a[0][1], a[1][1], a[1][0], a[2][1], a[2][0]) ? \"YES\" : \"NO\");\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"hull.in\");\n //writer = new StreamWriter(\"hull.out\");\n#endif\n try\n {\n // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n // thread.Start();\n // thread.Join();\n checked\n {\n new Solver().Solve();\n }\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\n\npublic static class MyExtension\n{\n public class Solution\n {\n /* Head ends here */\n\n public const int PAD_FACTOR = 3;\n\n List Helper()\n {\n var arr = NewArray(n, ReadInt_UNSIGNED);\n var ans = new List(n);\n var sum = 0;\n Range(0, n - 2)\n .ForEach(i =>\n {\n var val = arr[i + 1] - arr[i];\n ans.Add(val);\n sum += val;\n });\n ans.Add(L - sum);\n return ans;\n }\n\n int n, L;\n List a, b;\n\n public void zStart()\n {\n n = ReadInt_UNSIGNED(); //1..50\n L = ReadInt_UNSIGNED(); //1..100 >= n\n a = Helper();\n b = Helper();\n //\n foreach (var _ in Range(0, n + 1))\n {\n if (a.SequenceEqual(b))\n {\n Console.WriteLine(\"YES\");\n return;\n }\n var temp = a[0];\n a.RemoveAt(0);\n a.Add(temp);\n }\n Console.WriteLine(\"NO\");\n\n //System.Diagnostics.Debug.WriteLine(GC.GetTotalMemory(false) / 1024 / 1024, \"RAM usage (MB)\");\n }\n\n /* Tail starts here */\n }\n\n #region STDIO\n\n static void Main(String[] args)\n {\n#if TORIQ\n zTestSuite();\n //new Solution().zInternalTestSuite();\n return;\n#endif\n new Solution().zStart();\n }\n\n static T[] ReadLineSplitConvert(Converter convert)\n {\n var line = Console.ReadLine();\n if (line == null)\n return new T[0];\n return Array.ConvertAll(line.Split(), convert);\n }\n\n static int ReadInt_UNSIGNED() { return ReadInt_UNSIGNED(Console.Read); }\n static int ReadInt_UNSIGNED(string s) { return ReadInt_UNSIGNED(Reader.Singleton(s)); }\n class Reader\n {\n static Reader singleton = new Reader();\n public static Func Singleton(string s)\n { return singleton.Setup(s).Read; }\n\n string s; int index;\n Reader Setup(string s) { index = 0; this.s = s; return this; }\n int Read() { return (index == s.Length) ? -1 : s[index++]; }\n }\n static int ReadInt_UNSIGNED(Func read)\n {\n int cin;\n var empty = true;\n var ans = 0;\n while ((cin = read()) > -1)\n {\n var c = (char)cin;\n if (c == ' ' || c == '\\n' || c == '\\r' || c == '\\t')\n {\n if (empty) continue;\n else break;\n }\n if (ans >= 2e8 || ans >= 1e9)\n throw new OverflowException(\"Exceeds Int32.\");\n var temp = c - '0';\n if (temp < 0 || temp > 9) throw new FormatException(string.Format(\n \"Invalid char : {0} ({1})\",\n c, temp));\n ans *= 10;\n ans += temp;\n empty = false;\n }\n if (empty)\n throw new EndOfStreamException(\"Unable to get any digit.\");\n return ans;\n }\n\n #endregion\n #region LOOP\n static int Count(int startIncl, int endIncl) { return endIncl - startIncl + 1; }\n static IEnumerable ForEach(this IEnumerable range, Action action)\n { foreach (var elem in range) action(elem); return range; }\n static IEnumerable Range(int start, int endIncl)\n { for (var i = start; i <= endIncl; i++) yield return i; }\n static IEnumerable RangeReverse(int upIncl, int downIncl)\n { for (var i = upIncl; i >= downIncl; i--) yield return i; }\n #endregion\n #region ARRAY / LIST / RANDOM-ACCESS\n static T[] ToPreallocatedArray(this IEnumerable stream, int minMemorySpace)\n {\n var arr = new T[minMemorySpace + Solution.PAD_FACTOR];\n var idx = 0;\n foreach (var elem in stream) arr[idx++] = elem;\n return arr;\n }\n static T[] NewArray(int minSize, Func setValue = null)\n {\n var ans = new T[minSize + Solution.PAD_FACTOR];\n if (setValue != null)\n {\n for (var i = 0; i < minSize; i++)\n ans[i] = setValue();\n }\n return ans;\n }\n static T[][] NewArray(int minSize, T[] prototype) where T : struct\n {\n return NewArray(minSize, () =>\n {\n var arr = new T[prototype.Length];\n Array.Copy(prototype, arr, prototype.Length);\n return arr;\n });\n }\n static T NewArrayMultiDimension(params int[] sizes) where T : class, System.Collections.IList\n {\n for (var i = 0; i < sizes.Length; i++) sizes[i] += Solution.PAD_FACTOR;\n return Array.CreateInstance(typeof(T), sizes) as T;\n }\n static T RefElementIndexed(this T[] arr, Func transformer, int index)\n { var ans = transformer(arr[index]); arr[index] = ans; return ans; }\n static T RefElementIndexed(this Array arr, Func transformer, params int[] indices)\n { var ans = transformer((T)arr.GetValue(indices)); arr.SetValue(ans, indices); return ans; }\n #endregion\n}", "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"source_code": "using System;\nclass Test {\n static void Main(){\n int k = Int32.Parse(Console.ReadLine());\n double ans = cal(k);\n Console.WriteLine(ans);\n }\n static double cal(double n){\n if(n<=1){\n return 1;\n }else{\n return ((3*cal(n-1))%(1000000+3));\n }\n }\n}", "src_uid": "1a335a9638523ca0315282a67e18eec7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp2\n{\n class Program\n {\n static void Main(string[] args)\n {\n long[] F = new long[100001];\n F[0] = 1;\n F[1] = 1;\n for(long i = 2; i<100001; i++)\n {\n F[i] = (F[i - 1] + F[i - 2])%(long)(1e9 +7);\n }\n string[] str = Console.ReadLine().Split();\n long n = long.Parse(str[0]);\n long m = long.Parse(str[1]);\n Console.WriteLine((2*(F[m] + F[n] - 1)) % (long)(1e9 + 7));\n }\n }\n}\n", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace Round257\n{\n class B\n {\n static int mod(int a, int n)\n {\n int result = a % n;\n\n if (result != 0 && ((a < 0 && n > 0) || (a > 0 && n < 0)))\n result += n;\n\n return result;\n }\n\n static void Main(string[] args)\n {\n int x, y, n;\n ReadIntegers(out x, out y);\n ReadInteger(out n);\n\n int row = (n + 2) / 3;\n if (row % 2 == 0)\n {\n x = -x;\n y = -y;\n }\n\n int remainder = 0;\n int modulo = 1000000007;\n if (n % 3 == 1)\n {\n remainder = mod(x, modulo);\n }\n else if (n % 3 == 2)\n {\n remainder = mod(y, modulo);\n }\n else\n {\n remainder = mod(y - x, modulo);\n }\n\n Console.WriteLine(remainder);\n }\n\n #region InputRoutines\n static string RString()\n {\n return Console.ReadLine();\n }\n\n static void ReadInteger(out int a)\n {\n a = int.Parse(Console.ReadLine());\n }\n\n static void ReadIntegers(out int a, out int b)\n {\n int[] inputInt = ReadIntegerArray();\n\n a = inputInt[0];\n b = inputInt[1];\n }\n\n static void ReadIntegers(out int a, out int b, out int c)\n {\n int[] inputInt = ReadIntegerArray();\n\n a = inputInt[0];\n b = inputInt[1];\n c = inputInt[2];\n }\n\n static int[] ReadIntegerArray()\n {\n List integerList = new List();\n RString().Split(\" \".ToArray())\n .ToList()\n .ForEach(e => integerList.Add(int.Parse(e)));\n\n return integerList.ToArray();\n }\n\n static long[] ReadLongArray()\n {\n List longList = new List();\n RString().Split(\" \".ToArray())\n .ToList()\n .ForEach(e => longList.Add(long.Parse(e)));\n\n return longList.ToArray();\n }\n\n static List ReadIntegerList()\n {\n List integerList = new List();\n RString().Split(\" \".ToArray())\n .ToList()\n .ForEach(e => integerList.Add(int.Parse(e)));\n\n return integerList;\n }\n #endregion\n }\n}", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "using System;\nusing System.Linq;\nusing System.Diagnostics;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\n\nnamespace Program\n{\n\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Integer();\n var a = sc.Integer(4);\n var cnt = 0;\n for (int i = 1; i <= n; i++)\n {\n var v = a[0] + a[1] + i;\n var ok = true;\n ok &= a[0] + a[2] + n >= v;\n ok &= a[0] + a[2] + 1 <= v;\n ok &= a[1] + a[3] + n >= v;\n ok &= a[1] + a[3] + 1 <= v;\n ok &= a[2] + a[3] + n >= v;\n ok &= a[2] + a[3] + 1 <= v;\n if (ok) cnt++;\n }\n long ans = n;\n IO.Printer.Out.WriteLine(ans * cnt);\n }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n\n#region main\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Text;\n using System.Globalization;\n public class Printer : StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, T[] source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, T[] source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }\n\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n'; b = (char)read())\n if (b == 0) break;\n else if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != 0 && b != '-' && (b < '0' || '9' < b));\n if (b == 0) return long.MinValue;\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { var s = Scan(); return s != \"\" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public char[] Char(int n) { return enumerate(n, Char); }\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n }\n}\n#endregion\n", "src_uid": "b732869015baf3dee5094c51a309e32c"} {"source_code": "#define Online\n\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace CF\n{\n delegate double F(double x);\n delegate decimal Fdec(decimal x);\n\n partial class Program\n {\n\n static void Main(string[] args)\n {\n\n#if FileIO\n StreamReader sr = new StreamReader(\"input.txt\");\n StreamWriter sw = new StreamWriter(\"output.txt\");\n Console.SetIn(sr);\n Console.SetOut(sw);\n#endif\n\n C();\n\n#if Online\n Console.ReadLine();\n#endif\n\n#if FileIO\n sr.Close();\n sw.Close();\n#endif\n }\n\n static void A()\n {\n \n\n }\n\n static void B()\n {\n \n }\n\n static void C()\n {\n long r, h;\n ReadArray(' ');\n r = NextLong();\n h = NextLong();\n long ans = (h / r) * 2;\n if (2 * (h % r) >= r) ans += 2;\n if ((double)((ans / 2) * r) + Math.Sqrt(3) * (double)r / 2d <= (double)(h + r))\n ans++;\n Console.WriteLine(ans);\n }\n\n static void D()\n {\n\n }\n\n static void E()\n {\n \n } \n\n static void TestGen()\n {\n for (int i = 0; i < 99999; i += 3)\n {\n Console.Write(1 + \" \" + 2 + \" \" + 4 + \" \");\n }\n }\n\n }\n\n public static class MyMath\n {\n public static long BinPow(long a, long n, long mod)\n {\n long res = 1;\n while (n > 0)\n {\n if ((n & 1) == 1)\n {\n res = (res * a) % mod;\n }\n a = (a * a) % mod;\n n >>= 1;\n }\n return res;\n }\n\n public static long GCD(long a, long b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static int GCD(int a, int b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static long LCM(long a, long b)\n {\n return (a * b) / GCD(a, b);\n }\n\n public static int LCM(int a, int b)\n {\n return (a * b) / GCD(a, b);\n }\n }\n\n static class ArrayUtils\n {\n public static int BinarySearch(int[] a, int val)\n {\n int left = 0;\n int right = a.Length - 1;\n int mid;\n\n while (left < right)\n {\n mid = left + ((right - left) >> 1);\n if (val <= a[mid])\n {\n right = mid;\n }\n else\n {\n left = mid + 1;\n }\n }\n\n if (a[left] == val)\n return left;\n else\n return -1;\n }\n\n public static double Bisection(F f, double left, double right, double eps)\n {\n double mid;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2d);\n if (Math.Sign(f(mid)) != Math.Sign(f(left)))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2d;\n }\n\n\n public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)\n {\n decimal m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3m;\n m2 = r - (r - l) / 3m;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static double TernarySearch(F f, double eps, double l, double r, bool isMax)\n {\n double m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3d;\n m2 = r - (r - l) / 3d;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R, Comparison comp)\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (comp(L[i], R[j]) <= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R, Comparison comp)\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R, comp);\n Merge_Sort(A, q + 1, r, L, R, comp);\n Merge(A, p, q, r, L, R, comp);\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (L[i].CompareTo(R[j]) <= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R) where T : IComparable\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R);\n Merge_Sort(A, q + 1, r, L, R);\n Merge(A, p, q, r, L, R);\n }\n\n public static void Merge_Sort1(T[] A, int p, int r, T[] L, T[] R) where T : IComparable\n {\n int k = 1;\n while (k < r - p + 1)\n {\n int i = 0;\n while (i < r)\n {\n int _r = Math.Min(i + 2 * k - 1, r);\n int q = Math.Min(i + k - 1, r);\n Merge(A, i, q, _r, L, R);\n i += 2 * k;\n }\n k <<= 1;\n }\n }\n\n public static void Merge_Sort1(T[] A, int p, int r, T[] L, T[] R, Comparison comp)\n {\n int k = 1;\n while (k < r - p + 1)\n {\n int i = 0;\n while (i < r)\n {\n int _r = Math.Min(i + 2 * k - 1, r);\n int q = Math.Min(i + k - 1, r);\n Merge(A, i, q, _r, L, R, comp);\n i += 2 * k;\n }\n k <<= 1;\n }\n }\n\n static void Shake(T[] a)\n {\n Random rnd = new Random(Environment.TickCount);\n T temp;\n int b;\n for (int i = 0; i < a.Length; i++)\n {\n b = rnd.Next(i, a.Length);\n temp = a[b];\n a[b] = a[i];\n a[i] = temp;\n }\n }\n }\n\n partial class Program\n {\n static string[] tokens;\n static int cur_token = 0;\n\n static void ReadArray(char sep)\n {\n cur_token = 0;\n tokens = Console.ReadLine().Split(sep);\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int NextInt()\n {\n return int.Parse(tokens[cur_token++]);\n }\n\n static long NextLong()\n {\n return long.Parse(tokens[cur_token++]);\n }\n\n static double NextDouble()\n {\n return double.Parse(tokens[cur_token++]);\n }\n\n static decimal NextDecimal()\n {\n return decimal.Parse(tokens[cur_token++]);\n }\n\n static string NextToken()\n {\n return tokens[cur_token++];\n }\n\n static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n}", "src_uid": "ae883bf16842c181ea4bd123dee12ef9"} {"source_code": "using System;\nusing System.Buffers;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\nusing System.Runtime.Intrinsics.X86;\nusing CodeforcesRound678Div2.Questions;\nusing ModInt = CodeforcesRound678Div2.Questions.StaticModInt;\n\nnamespace CodeforcesRound678Div2.Questions\n{\n public class QuestionC : AtCoderQuestionBase\n {\n [MethodImpl(MethodImplOptions.AggressiveOptimization)]\n public override void Solve(IOManager io)\n {\n var n = io.ReadInt();\n var x = io.ReadInt();\n var pos = io.ReadInt();\n\n var more = n - x;\n var less = x - 1;\n\n var left = 0;\n var right = n;\n ModInt result = ModInt.One;\n \n while (left < right)\n {\n var middle = (left + right) / 2;\n\n if (middle > pos)\n {\n if (more > 0)\n {\n result *= ModInt.Raw(more);\n more--;\n }\n else\n {\n result = ModInt.Zero;\n }\n right = middle;\n }\n else if (middle < pos)\n {\n if (less > 0)\n {\n result *= ModInt.Raw(less);\n less--;\n }\n else\n {\n result = ModInt.Zero;\n }\n left = middle + 1;\n }\n else\n {\n left = middle + 1;\n }\n }\n\n for (int i = 1; i <= more + less; i++)\n {\n result *= ModInt.Raw(i);\n }\n\n io.WriteLine(result);\n }\n }\n\n /// \n /// コンパイル時に決定する mod を表します。\n /// \n /// \n /// \n /// public readonly struct Mod1000000009 : IStaticMod\n /// {\n /// public uint Mod => 1000000009;\n /// public bool IsPrime => true;\n /// }\n /// \n /// \n public interface IStaticMod\n {\n /// \n /// mod を取得します。\n /// \n uint Mod { get; }\n\n /// \n /// mod が素数であるか識別します。\n /// \n bool IsPrime { get; }\n }\n\n public readonly struct Mod1000000007 : IStaticMod\n {\n public uint Mod => 1000000007;\n public bool IsPrime => true;\n }\n\n public readonly struct Mod998244353 : IStaticMod\n {\n public uint Mod => 998244353;\n public bool IsPrime => true;\n }\n\n /// \n /// 実行時に決定する mod の ID を表します。\n /// \n /// \n /// \n /// public readonly struct ModID123 : IDynamicModID { }\n /// \n /// \n public interface IDynamicModID { }\n\n public readonly struct ModID0 : IDynamicModID { }\n public readonly struct ModID1 : IDynamicModID { }\n public readonly struct ModID2 : IDynamicModID { }\n\n /// \n /// 四則演算時に自動で mod を取る整数型。mod の値はコンパイル時に決定している必要があります。\n /// \n /// 定数 mod を表す構造体\n /// \n /// \n /// using ModInt = AtCoder.StaticModInt<AtCoder.Mod1000000007>;\n ///\n /// void SomeMethod()\n /// {\n /// var m = new ModInt(1);\n /// m -= 2;\n /// Console.WriteLine(m); // 1000000006\n /// }\n /// \n /// \n public readonly struct StaticModInt : IEquatable> where T : struct, IStaticMod\n {\n private readonly uint _v;\n\n /// \n /// 格納されている値を返します。\n /// \n public int Value => (int)_v;\n\n /// \n /// mod を返します。\n /// \n public static int Mod => (int)default(T).Mod;\n\n public static StaticModInt Zero => new StaticModInt();\n public static StaticModInt One => new StaticModInt(1u);\n\n /// \n /// に対して mod を取らずに StaticModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// 定数倍高速化のための関数です。 に 0 未満または mod 以上の値を入れた場合の挙動は未定義です。\n /// 制約: 0≤||<mod\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt Raw(int v)\n {\n var u = unchecked((uint)v);\n Debug.Assert(u < Mod);\n return new StaticModInt(u);\n }\n\n /// \n /// StaticModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// が 0 未満、もしくは mod 以上の場合、自動で mod を取ります。\n /// \n public StaticModInt(long v) : this(Round(v)) { }\n\n private StaticModInt(uint v) => _v = v;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static uint Round(long v)\n {\n var x = v % default(T).Mod;\n if (x < 0)\n {\n x += default(T).Mod;\n }\n return (uint)x;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator ++(StaticModInt value)\n {\n var v = value._v + 1;\n if (v == default(T).Mod)\n {\n v = 0;\n }\n return new StaticModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator --(StaticModInt value)\n {\n var v = value._v;\n if (v == 0)\n {\n v = default(T).Mod;\n }\n return new StaticModInt(v - 1);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator +(StaticModInt lhs, StaticModInt rhs)\n {\n var v = lhs._v + rhs._v;\n if (v >= default(T).Mod)\n {\n v -= default(T).Mod;\n }\n return new StaticModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator -(StaticModInt lhs, StaticModInt rhs)\n {\n unchecked\n {\n var v = lhs._v - rhs._v;\n if (v >= default(T).Mod)\n {\n v += default(T).Mod;\n }\n return new StaticModInt(v);\n }\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator *(StaticModInt lhs, StaticModInt rhs)\n {\n return new StaticModInt((uint)((ulong)lhs._v * rhs._v % default(T).Mod));\n }\n\n /// \n /// 除算を行います。\n /// \n /// \n /// - 制約: に乗法の逆元が存在する。(gcd(, mod) = 1)\n /// - 計算量: O(log(mod))\n /// \n public static StaticModInt operator /(StaticModInt lhs, StaticModInt rhs) => lhs * rhs.Inverse();\n\n public static StaticModInt operator +(StaticModInt value) => value;\n public static StaticModInt operator -(StaticModInt value) => new StaticModInt() - value;\n public static bool operator ==(StaticModInt lhs, StaticModInt rhs) => lhs._v == rhs._v;\n public static bool operator !=(StaticModInt lhs, StaticModInt rhs) => lhs._v != rhs._v;\n public static implicit operator StaticModInt(int value) => new StaticModInt(value);\n public static implicit operator StaticModInt(long value) => new StaticModInt(value);\n\n /// \n /// 自身を x として、x^ を返します。\n /// \n /// \n /// 制約: 0≤||\n /// 計算量: O(log())\n /// \n public StaticModInt Pow(long n)\n {\n Debug.Assert(0 <= n);\n var x = this;\n var r = Raw(1);\n\n while (n > 0)\n {\n if ((n & 1) > 0)\n {\n r *= x;\n }\n x *= x;\n n >>= 1;\n }\n\n return r;\n }\n\n /// \n /// 自身を x として、 xy≡1 なる y を返します。\n /// \n /// \n /// 制約: gcd(x, mod) = 1\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public StaticModInt Inverse()\n {\n if (default(T).IsPrime)\n {\n Debug.Assert(_v > 0);\n return Pow(default(T).Mod - 2);\n }\n else\n {\n var (g, x) = InternalMath.InvGCD(_v, default(T).Mod);\n Debug.Assert(g == 1);\n return new StaticModInt(x);\n }\n }\n\n public override string ToString() => _v.ToString();\n public override bool Equals(object obj) => obj is StaticModInt && Equals((StaticModInt)obj);\n public bool Equals(StaticModInt other) => Value == other.Value;\n public override int GetHashCode() => _v.GetHashCode();\n }\n\n /// \n /// 四則演算時に自動で mod を取る整数型。実行時に mod が決まる場合でも使用可能です。\n /// \n /// \n /// 使用前に DynamicModInt<>.Mod に mod の値を設定する必要があります。\n /// \n /// mod の ID を表す構造体\n /// \n /// \n /// using AtCoder.ModInt = AtCoder.DynamicModInt<AtCoder.ModID0>;\n ///\n /// void SomeMethod()\n /// {\n /// ModInt.Mod = 1000000009;\n /// var m = new ModInt(1);\n /// m -= 2;\n /// Console.WriteLine(m); // 1000000008\n /// }\n /// \n /// \n public readonly struct DynamicModInt : IEquatable> where T : struct, IDynamicModID\n {\n private readonly uint _v;\n private static Barrett bt;\n\n /// \n /// 格納されている値を返します。\n /// \n public int Value => (int)_v;\n\n /// \n /// mod を返します。\n /// \n public static int Mod\n {\n get => (int)bt.Mod;\n set\n {\n Debug.Assert(1 <= value);\n bt = new Barrett((uint)value);\n }\n }\n\n /// \n /// に対して mod を取らずに DynamicModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// 定数倍高速化のための関数です。 に 0 未満または mod 以上の値を入れた場合の挙動は未定義です。\n /// 制約: 0≤||<mod\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt Raw(int v)\n {\n var u = unchecked((uint)v);\n Debug.Assert(bt != null, $\"使用前に {nameof(DynamicModInt)}<{nameof(T)}>.{nameof(Mod)} プロパティに mod の値を設定してください。\");\n Debug.Assert(u < Mod);\n return new DynamicModInt(u);\n }\n\n /// \n /// DynamicModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// - 使用前に DynamicModInt<>.Mod に mod の値を設定する必要があります。\n /// - が 0 未満、もしくは mod 以上の場合、自動で mod を取ります。\n /// \n public DynamicModInt(long v) : this(Round(v)) { }\n\n private DynamicModInt(uint v) => _v = v;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static uint Round(long v)\n {\n Debug.Assert(bt != null, $\"使用前に {nameof(DynamicModInt)}<{nameof(T)}>.{nameof(Mod)} プロパティに mod の値を設定してください。\");\n var x = v % bt.Mod;\n if (x < 0)\n {\n x += bt.Mod;\n }\n return (uint)x;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator ++(DynamicModInt value)\n {\n var v = value._v + 1;\n if (v == bt.Mod)\n {\n v = 0;\n }\n return new DynamicModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator --(DynamicModInt value)\n {\n var v = value._v;\n if (v == 0)\n {\n v = bt.Mod;\n }\n return new DynamicModInt(v - 1);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator +(DynamicModInt lhs, DynamicModInt rhs)\n {\n var v = lhs._v + rhs._v;\n if (v >= bt.Mod)\n {\n v -= bt.Mod;\n }\n return new DynamicModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator -(DynamicModInt lhs, DynamicModInt rhs)\n {\n unchecked\n {\n var v = lhs._v - rhs._v;\n if (v >= bt.Mod)\n {\n v += bt.Mod;\n }\n return new DynamicModInt(v);\n }\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator *(DynamicModInt lhs, DynamicModInt rhs)\n {\n uint z = bt.Mul(lhs._v, rhs._v);\n return new DynamicModInt(z);\n }\n\n /// \n /// 除算を行います。\n /// \n /// \n /// - 制約: に乗法の逆元が存在する。(gcd(, mod) = 1)\n /// - 計算量: O(log(mod))\n /// \n public static DynamicModInt operator /(DynamicModInt lhs, DynamicModInt rhs) => lhs * rhs.Inverse();\n\n public static DynamicModInt operator +(DynamicModInt value) => value;\n public static DynamicModInt operator -(DynamicModInt value) => new DynamicModInt() - value;\n public static bool operator ==(DynamicModInt lhs, DynamicModInt rhs) => lhs._v == rhs._v;\n public static bool operator !=(DynamicModInt lhs, DynamicModInt rhs) => lhs._v != rhs._v;\n public static implicit operator DynamicModInt(int value) => new DynamicModInt(value);\n public static implicit operator DynamicModInt(long value) => new DynamicModInt(value);\n\n /// \n /// 自身を x として、x^ を返します。\n /// \n /// \n /// 制約: 0≤||\n /// 計算量: O(log())\n /// \n public DynamicModInt Pow(long n)\n {\n Debug.Assert(0 <= n);\n var x = this;\n var r = Raw(1);\n\n while (n > 0)\n {\n if ((n & 1) > 0)\n {\n r *= x;\n }\n x *= x;\n n >>= 1;\n }\n\n return r;\n }\n\n /// \n /// 自身を x として、 xy≡1 なる y を返します。\n /// \n /// \n /// 制約: gcd(x, mod) = 1\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public DynamicModInt Inverse()\n {\n var (g, x) = InternalMath.InvGCD(_v, bt.Mod);\n Debug.Assert(g == 1);\n return new DynamicModInt(x);\n }\n\n public override string ToString() => _v.ToString();\n public override bool Equals(object obj) => obj is DynamicModInt && Equals((DynamicModInt)obj);\n public bool Equals(DynamicModInt other) => Value == other.Value;\n public override int GetHashCode() => _v.GetHashCode();\n }\n\n /// \n /// Fast moduler by barrett reduction\n /// \n /// \n public class Barrett\n {\n public uint Mod { get; private set; }\n private ulong IM;\n public Barrett(uint m)\n {\n Mod = m;\n IM = unchecked((ulong)-1) / m + 1;\n }\n\n /// \n /// * mod m\n /// \n public uint Mul(uint a, uint b)\n {\n ulong z = a;\n z *= b;\n if (!Bmi2.X64.IsSupported) return (uint)(z % Mod);\n var x = Bmi2.X64.MultiplyNoFlags(z, IM);\n var v = unchecked((uint)(z - x * Mod));\n if (Mod <= v) v += Mod;\n return v;\n }\n }\n\n public static class InternalMath\n {\n /// \n /// g=gcd(a,b),xa=g(mod b) となるような 0≤x<b/g の(g, x)\n /// \n /// \n /// 制約: 1≤\n /// \n public static (long, long) InvGCD(long a, long b)\n {\n a = SafeMod(a, b);\n if (a == 0) return (b, 0);\n\n long s = b, t = a;\n long m0 = 0, m1 = 1;\n\n long u;\n while (true)\n {\n if (t == 0)\n {\n if (m0 < 0) m0 += b / s;\n return (s, m0);\n }\n u = s / t;\n s -= t * u;\n m0 -= m1 * u;\n\n if (s == 0)\n {\n if (m1 < 0) m1 += b / t;\n return (t, m1);\n }\n u = t / s;\n t -= s * u;\n m1 -= m0 * u;\n }\n }\n\n public static long SafeMod(long x, long m)\n {\n x %= m;\n if (x < 0) x += m;\n return x;\n }\n }\n\n public class ModCombination where T : struct, IStaticMod\n {\n readonly StaticModInt[] _factorials;\n readonly StaticModInt[] _invFactorials;\n\n public ModCombination(int max = 1000000)\n {\n if (max >= default(T).Mod)\n {\n ThrowArgumentOutOfRangeException();\n }\n\n _factorials = new StaticModInt[max + 1];\n _invFactorials = new StaticModInt[max + 1];\n\n _factorials[0] = _factorials[1] = StaticModInt.Raw(1);\n _invFactorials[0] = _invFactorials[1] = StaticModInt.Raw(1);\n\n for (int i = 2; i < _factorials.Length; i++)\n {\n _factorials[i] = _factorials[i - 1] * StaticModInt.Raw(i);\n }\n\n _invFactorials[^1] = _factorials[^1].Inverse();\n\n for (int i = _invFactorials.Length - 2; i >= 0; i--)\n {\n _invFactorials[i] = _invFactorials[i + 1] * StaticModInt.Raw(i + 1);\n }\n }\n\n public StaticModInt Factorial(int n) => _factorials[n];\n\n public StaticModInt Permutation(int n, int k) => _factorials[n] * _invFactorials[n - k];\n\n public StaticModInt Combination(int n, int k) => _factorials[n] * _invFactorials[k] * _invFactorials[n - k];\n\n public StaticModInt CombinationWithRepetition(int n, int k) => Combination(n + k - 1, k);\n\n public void ThrowArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException();\n }\n}\n\nnamespace CodeforcesRound678Div2\n{\n class Program\n {\n static void Main(string[] args)\n {\n IAtCoderQuestion question = new QuestionC();\n using var io = new IOManager(Console.OpenStandardInput(), Console.OpenStandardOutput());\n question.Solve(io);\n }\n }\n}\n\n#region Base Class\n\nnamespace CodeforcesRound678Div2.Questions\n{\n public interface IAtCoderQuestion\n {\n string Solve(string input);\n void Solve(IOManager io);\n }\n\n public abstract class AtCoderQuestionBase : IAtCoderQuestion\n {\n public string Solve(string input)\n {\n var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(input));\n var outputStream = new MemoryStream();\n using var manager = new IOManager(inputStream, outputStream);\n\n Solve(manager);\n manager.Flush();\n\n outputStream.Seek(0, SeekOrigin.Begin);\n var reader = new StreamReader(outputStream);\n return reader.ReadToEnd();\n }\n\n public abstract void Solve(IOManager io);\n }\n}\n\n#endregion\n\n#region Utils\n\nnamespace CodeforcesRound678Div2\n{\n public class IOManager : IDisposable\n {\n private readonly BinaryReader _reader;\n private readonly StreamWriter _writer;\n private bool _disposedValue;\n private byte[] _buffer = new byte[1024];\n private int _length;\n private int _cursor;\n private bool _eof;\n\n const char ValidFirstChar = '!';\n const char ValidLastChar = '~';\n\n public IOManager(Stream input, Stream output)\n {\n _reader = new BinaryReader(input);\n _writer = new StreamWriter(output) { AutoFlush = false };\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private char ReadAscii()\n {\n if (_cursor == _length)\n {\n _cursor = 0;\n _length = _reader.Read(_buffer);\n\n if (_length == 0)\n {\n if (!_eof)\n {\n _eof = true;\n return char.MinValue;\n }\n else\n {\n ThrowEndOfStreamException();\n }\n }\n }\n\n return (char)_buffer[_cursor++];\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public char ReadChar()\n {\n char c;\n while (!IsValidChar(c = ReadAscii())) { }\n return c;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public string ReadString()\n {\n var builder = new StringBuilder();\n char c;\n while (!IsValidChar(c = ReadAscii())) { }\n\n do\n {\n builder.Append(c);\n } while (IsValidChar(c = ReadAscii()));\n\n return builder.ToString();\n }\n\n public int ReadInt() => (int)ReadLong();\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public long ReadLong()\n {\n long result = 0;\n bool isPositive = true;\n char c;\n\n while (!IsNumericChar(c = ReadAscii())) { }\n\n if (c == '-')\n {\n isPositive = false;\n c = ReadAscii();\n }\n\n do\n {\n result *= 10;\n result += c - '0';\n } while (IsNumericChar(c = ReadAscii()));\n\n return isPositive ? result : -result;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private Span ReadChunk(Span span)\n {\n var i = 0;\n char c;\n while (!IsValidChar(c = ReadAscii())) { }\n\n do\n {\n span[i++] = c;\n } while (IsValidChar(c = ReadAscii()));\n\n return span.Slice(0, i);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public double ReadDouble() => double.Parse(ReadChunk(stackalloc char[32]));\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public decimal ReadDecimal() => decimal.Parse(ReadChunk(stackalloc char[32]));\n\n public int[] ReadIntArray(int n)\n {\n var a = new int[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadInt();\n }\n return a;\n }\n\n public long[] ReadLongArray(int n)\n {\n var a = new long[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadLong();\n }\n return a;\n }\n\n public double[] ReadDoubleArray(int n)\n {\n var a = new double[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadDouble();\n }\n return a;\n }\n\n public decimal[] ReadDecimalArray(int n)\n {\n var a = new decimal[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadDecimal();\n }\n return a;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void WriteLine(T value) => _writer.WriteLine(value.ToString());\n\n public void WriteLine(IEnumerable values, char separator)\n {\n var e = values.GetEnumerator();\n if (e.MoveNext())\n {\n _writer.Write(e.Current.ToString());\n\n while (e.MoveNext())\n {\n _writer.Write(separator);\n _writer.Write(e.Current.ToString());\n }\n }\n\n _writer.WriteLine();\n }\n\n public void WriteLine(Span values, char separator) => WriteLine((ReadOnlySpan)values, separator);\n\n public void WriteLine(ReadOnlySpan values, char separator)\n {\n for (int i = 0; i < values.Length - 1; i++)\n {\n _writer.Write(values[i]);\n _writer.Write(separator);\n }\n\n if (values.Length > 0)\n {\n _writer.Write(values[^1]);\n }\n\n _writer.WriteLine();\n }\n\n public void Flush() => _writer.Flush();\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static bool IsValidChar(char c) => ValidFirstChar <= c && c <= ValidLastChar;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static bool IsNumericChar(char c) => ('0' <= c && c <= '9') || c == '-';\n\n private void ThrowEndOfStreamException() => throw new EndOfStreamException();\n\n protected virtual void Dispose(bool disposing)\n {\n if (!_disposedValue)\n {\n if (disposing)\n {\n _reader.Dispose();\n _writer.Flush();\n _writer.Dispose();\n }\n\n _disposedValue = true;\n }\n }\n\n public void Dispose()\n {\n Dispose(disposing: true);\n GC.SuppressFinalize(this);\n }\n }\n\n public static class UtilExtensions\n {\n public static bool ChangeMax(ref this T value, T other) where T : struct, IComparable\n {\n if (value.CompareTo(other) < 0)\n {\n value = other;\n return true;\n }\n return false;\n }\n\n public static bool ChangeMin(ref this T value, T other) where T : struct, IComparable\n {\n if (value.CompareTo(other) > 0)\n {\n value = other;\n return true;\n }\n return false;\n }\n\n public static void SwapIfLargerThan(ref this T a, ref T b) where T : struct, IComparable\n {\n if (a.CompareTo(b) > 0)\n {\n (a, b) = (b, a);\n }\n }\n\n public static void SwapIfSmallerThan(ref this T a, ref T b) where T : struct, IComparable\n {\n if (a.CompareTo(b) < 0)\n {\n (a, b) = (b, a);\n }\n }\n\n public static void Sort(this T[] array) where T : IComparable => Array.Sort(array);\n public static void Sort(this T[] array, Comparison comparison) => Array.Sort(array, comparison);\n }\n\n\n public static class CollectionExtensions\n {\n private class ArrayWrapper\n {\n#pragma warning disable CS0649\n public T[] Array;\n#pragma warning restore CS0649\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static Span AsSpan(this List list)\n {\n return Unsafe.As>(list).Array.AsSpan(0, list.Count);\n }\n\n public static void Fill(this T[] array, T value) => array.AsSpan().Fill(value);\n public static void Fill(this T[,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0], array.Length).Fill(value);\n public static void Fill(this T[,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length).Fill(value);\n public static void Fill(this T[,,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0, 0], array.Length).Fill(value);\n }\n}\n\n#endregion\n\n", "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing static System.Console;\nusing static System.Convert;\n\nnamespace OJ\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s;\n s = ReadLine();\n char[] a = s.ToCharArray();\n int k;\n char c='a';\n k = s.Length;\n int count = 0;\n char[] b = new char[26];\n for (int i = 0; i < 26; i++)\n {\n b[i] = c;\n c++;\n }\n for (int i = 0; i < k; i++)\n {\n for (int j = 0; j < 26; j++)\n {\n if(b[j]==a[i])\n {\n count++;\n b[j] = '0';\n }\n }\n }\n\n if (count % 2 == 0)\n WriteLine(\"CHAT WITH HER!\");\n else\n WriteLine(\"IGNORE HIM!\");\n\n }\n }\n}", "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Text.RegularExpressions;\r\nusing System.Threading.Tasks;\r\nusing System.Diagnostics;\r\nusing static System.Math;\r\nusing static System.Console;\r\n\r\nnamespace Codeforces\r\n{\r\n internal class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n int t = Int(ReadLine());\r\n List res = new List();\r\n\r\n for (int i = 0; i < t; i++)\r\n {\r\n // int len = Int(ReadLine());\r\n //List n = GetLongs(ReadLine());\r\n long n = Long(ReadLine());\r\n\r\n Solve(n, res); \r\n\r\n }\r\n\r\n foreach (string s in res) WriteLine(s);\r\n\r\n\r\n //foreach (string s in list) Console.WriteLine(s);\r\n //string[] nums = Console.ReadLine().Split(' ');\r\n\r\n //for (int i = 0; i < n; i++)\r\n //{\r\n // list.Add(Int(nums[i]));\r\n //}\r\n\r\n // Solve(word);\r\n //Console.WriteLine(res);\r\n ReadLine();\r\n }\r\n\r\n\r\n private static void Solve(long n, List res)\r\n {\r\n\r\n double cubes = F(n);\r\n double sqrs = Sqrt(n);\r\n double six = Sqrt(cubes);\r\n \r\n long re = (long)(Floor(cubes) + Floor(sqrs) - Floor(six));\r\n \r\n res.Add(re.ToString());\r\n }\r\n\r\n private static string Divisors(long num, int div, string s)\r\n {\r\n if (num < 2) return s;\r\n if (num % div == 0)\r\n {\r\n return Divisors(num / div, 2, s + \" \" + div.ToString());\r\n }\r\n return Divisors(num, div + 1, s);\r\n }\r\n\r\n private static string ReverseString(string x)\r\n {\r\n if (x.Length <= 1) return x;\r\n return ReverseString(x.Substring(1)) + x[0]; \r\n }\r\n private static double F(long x)\r\n {\r\n double sm = Pow(10, -10);\r\n double h = Pow(x, (double)1 / 3);\r\n double rh = Round(h);\r\n return Abs(rh - h) <= sm ? rh: h;\r\n\r\n }\r\n /* --------------------------------------------------------------------------------------------------------------*/\r\n /* --------------------------------------------------------------------------------------------------------------*/\r\n /* --------------------------------------------------------------------------------------------------------------*/\r\n /* --------------------------------------------------------------------------------------------------------------*/\r\n private static int BinarySearch(int t, List nums, int l, int r)\r\n {\r\n int mid = (l + r) / 2;\r\n if(r= nums[mid] && t < nums[mid+1]) return mid + 1;\r\n else if(t < nums[mid] && t >= nums[mid>0?mid - 1:r]) return mid;\r\n else if (t < nums[mid]) return BinarySearch(t, nums, l, mid-1);\r\n else return BinarySearch(t, nums, mid+1, r);\r\n }\r\n\r\n\r\n static List Lis(string list)\r\n {\r\n List l = new List();\r\n\r\n string[] a = list.Split(' ');\r\n foreach (var item in a)\r\n\r\n {\r\n l.Add(Int(item));\r\n }\r\n return l;\r\n }\r\n static List GetInts(string str)\r\n {\r\n string[] arr = str.Split(' ');\r\n List list = new List();\r\n for (int i = 0; i < arr.Length; i++)\r\n {\r\n list.Add(Int(arr[i]));\r\n }\r\n return list;\r\n }\r\n\r\n static List GetLongs(string str)\r\n {\r\n string[] arr = str.Split(' ');\r\n List list = new List();\r\n for (int i = 0; i < arr.Length; i++)\r\n {\r\n list.Add(Long(arr[i]));\r\n }\r\n return list;\r\n }\r\n static long Long(string a)\r\n {\r\n return Int64.Parse(a);\r\n }\r\n\r\n static int Int(string a)\r\n {\r\n return Int32.Parse(a);\r\n }\r\n }\r\n public class P\r\n {\r\n public int x { get; set; }\r\n public int y { get; set; }\r\n public P(int a, int b)\r\n {\r\n x = a;\r\n y = b;\r\n }\r\n }\r\n}", "src_uid": "015afbefe1514a0e18fcb9286c7b6624"} {"source_code": "// Submitted by Silithus @ Macau\nusing System;\nusing System.IO;\nusing System.Collections.Generic;\nusing CCF_XOI;\n\nnamespace CodeForces\n{\n\tclass CF624A\n\t{\n\t\tpublic void Solve(XOI xoi)\n\t\t{\n\t\t\tint L, D, V1, V2;\n\t\t\tdouble ans;\n\n\t\t\tD = xoi.ReadInt();\n\t\t\tL = xoi.ReadInt();\n\t\t\tV1 = xoi.ReadInt();\n\t\t\tV2 = xoi.ReadInt();\n\n\t\t\tans = (double)(L - D) / (double)(V1 + V2);\n\n\t\t\txoi.o.WriteLine(ans.ToString(\"F6\", System.Globalization.CultureInfo.InvariantCulture));\n\t\t}\n\t}\n\n\tclass CodeForcesMain\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\t(new CF624A()).Solve(new XOI());\n\t\t}\n\t}\n}\n\nnamespace CCF_XOI\n{ // version 2014.06.20\n\tclass XOI\n\t{\n\t\tprotected StreamReader sr;\n\t\tpublic StreamWriter o;\n\t\tprotected Queue buf = new Queue();\n\t\tpublic bool EOF = false;\n\n\t\tpublic XOI()\n\t\t{\n\t\t\tthis.sr = new StreamReader(Console.OpenStandardInput());\n\t\t\tthis.o = new StreamWriter(Console.OpenStandardOutput());\n\t\t\tthis.o.AutoFlush = true;\n\t\t}\n\n\t\tpublic XOI(string in_path, string out_path)\n\t\t{\n\t\t\tthis.sr = new StreamReader(in_path);\n\t\t\tthis.o = new StreamWriter(out_path);\n\t\t\tthis.o.AutoFlush = true;\n\t\t}\n\n\t\tpublic int ReadInt()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\tif (s == null) return -1;\n\t\t\telse return Int32.Parse(s);\n\t\t}\n\n\t\tpublic long ReadLong()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\tif (s == null) return -1;\n\t\t\telse return Int64.Parse(s);\n\t\t}\n\n\t\tpublic double ReadDouble()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\tif (s == null) return -1;\n\t\t\telse return Double.Parse(s, System.Globalization.CultureInfo.InvariantCulture);\n\t\t}\n\n\t\tpublic string ReadString()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\treturn (s == null ? null : s);\n\t\t}\n\n\t\tpublic string ReadLine()\n\t\t{ // I will ignore current buffer and read a new line\n\t\t\tstring s = \"\";\n\t\t\twhile (s == \"\" && !this.EOF)\n\t\t\t{\n\t\t\t\ts = sr.ReadLine();\n\t\t\t\tthis.EOF = (s == null);\n\t\t\t}\n\t\t\treturn (this.EOF ? null : s);\n\t\t}\n\n\t\tprotected string GetNext()\n\t\t{\n\t\t\tif (buf.Count == 0)\n\t\t\t{\n\t\t\t\twhile (buf.Count == 0 && !this.EOF)\n\t\t\t\t{\n\t\t\t\t\tstring s = sr.ReadLine();\n\t\t\t\t\tif (s == null)\n\t\t\t\t\t\tthis.EOF = true;\n\t\t\t\t\telse\n\t\t\t\t\t\tforeach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))\n\t\t\t\t\t\t\tbuf.Enqueue(ss);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn (this.EOF ? null : buf.Dequeue());\n\t\t}\n\t}\n}\n", "src_uid": "f34f3f974a21144b9f6e8615c41830f5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static int[] ReadInt(int size)\n {\n string[] input = Console.ReadLine().Split(' ');\n int[] res = new int[size]; \n for (int i=0; i b ? a : b);\n } \n\n static void Main(string[] args)\n {\n String input = ReadString();\n String[] value = input.Split('+');\n Array.Sort(value);\n String res = \"\";\n foreach (String temp in value)\n {\n res += temp + \"+\";\n }\n res = res.Remove(res.Length - 1, 1); \n Console.WriteLine(res);\n }\n }\n}\n", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\npublic class CodeForces87\n{\n#if TEST\n // To set this go to Project -> Properties -> Build -> General -> Conditional compilation symbols: -> enter 'TEST' into text box.\n const bool testing = false;\n#else\nconst bool testing = false;\n#endif\n \n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);\n\n\n struct Node\n {\n public int Index { get; set; }\n public double A { get; set; }\n public double T { get; set; }\n }\n\n static void program(TextReader input)\n {\n var n = double.Parse(reader.ReadLine().TrimEnd());\n var data = reader.ReadLine().TrimEnd();\n\n var possible = false;\n for(var i = 0; i < data.Length; i++)\n {\n if(data[i] == '1')\n {\n continue;\n } else\n {\n var prev = i > 0 ? data[i - 1] : '0';\n var next = i == n-1 ? '0' : data[i + 1];\n if (prev == '0' && next == '0')\n {\n possible = true;\n }\n }\n }\n\n Console.WriteLine(!data.Contains(\"11\") && !possible ? \"Yes\": \"No\");\n }\n\n public static void Main(string[] args)\n {\n CultureInfo nonInvariantCulture = new CultureInfo(\"en-US\");\n Thread.CurrentThread.CurrentCulture = nonInvariantCulture;\n if (!testing)\n { // set testing to false when submiting to codeforces\n program(Console.In); // write your program in 'program' function (its your new main !)\n return;\n }\n\n Console.WriteLine(\"Test Case(1) => expected :\");\n Console.WriteLine(\"3\\n2\\n4\\n\");\n Console.WriteLine(\"Test Case(1) => found :\");\n program(new StringReader(\"4 3\\n2\\n3\\n4\\n\"));\n Console.WriteLine();\n\n Console.WriteLine(\"Test Case(2) => expected :\");\n Console.WriteLine(\"13\\n3\\n8\\n9\\n\");\n Console.WriteLine(\"Test Case(2) => found :\");\n program(new StringReader(\"13 4\\n10\\n5\\n4\\n8\\n\"));\n Console.WriteLine();\n\n }\n}", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"source_code": "using System;\n\nnamespace VaniaAndLight\n{\n class Program\n {\n static void Main(string[] args)\n {\n int x, y, z, a, b, c;\n string[] arrayXYZ = Console.ReadLine().Split(new char[] { ' '}, StringSplitOptions.RemoveEmptyEntries);\n string[] arrayABC = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n x = int.Parse(arrayXYZ[0]);\n y = int.Parse(arrayXYZ[1]);\n z = int.Parse(arrayXYZ[2]);\n a = int.Parse(arrayABC[0]);\n b = int.Parse(arrayABC[1]);\n c = int.Parse(arrayABC[2]);\n\n if (x > a)\n {\n Console.WriteLine(\"NO\");\n return;\n }\n else\n {\n a -= x;\n }\n\n if (y > (a + b))\n {\n Console.WriteLine(\"NO\");\n return;\n }\n else\n {\n if (y - a > 0)\n {\n y -= a;\n a = 0;\n b -= y;\n }\n else\n {\n a -= y;\n }\n }\n\n if (z > (a + b + c))\n {\n Console.WriteLine(\"NO\");\n return;\n }\n else\n {\n Console.WriteLine(\"YES\");\n }\n }\n\n static int rank(int key, int[] a)\n {\n int lo = 0;\n int hi = a.Length;\n\n while (lo <= hi)\n {\n int mid = lo + (hi - lo) / 2;\n if (key < a[mid])\n {\n hi = mid - 1;\n }\n else if (key > a[mid])\n {\n lo = mid + 1;\n }\n else\n {\n return mid;\n }\n }\n return -1;\n }\n }\n}\n", "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"source_code": "using System; using System.Linq;\n\nclass P {\n static void Main() {\n var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n if (a[1] - a[0] == a[2] - a[1] && a[2]-a[1] == a[3] - a[2]){\n Console.Write(a[3] + a[2] - a[1]); return; \n }\n if (a[2]*a[0] == a[1]*a[1] && a[2]*a[2] == a[3]*a[1]) {\n var d = a[3]*a[3];\n if (d % a[2] == 0) {\n Console.Write(d/a[2]); return; }\n }\n Console.Write(42); \n }\n}", "src_uid": "68a9508d49fec672f9c61766d6051047"} {"source_code": "using System;\nusing System.Linq;\n\nclass Program {\n static void Main() {\n var n = int.Parse(Console.ReadLine());\n var x = Console.ReadLine().Split(' ').Select(int.Parse).Sum();\n var res = Enumerable.Range(1, 5).Count(i => (i + x) % (n+1) != 1);\n Console.WriteLine(res);\n }\n}", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp9\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n string s = Console.ReadLine();\n int res = 0;\n int count = 0;\n List temp = new List();\n for(int i = 0; i < s.Length; i++)\n {\n if(char.IsLower(s[i]))\n {\n if (temp.Contains(s[i]))\n continue;\n else\n {\n temp.Add(s[i]);\n count++;\n if (count > res)\n res = count;\n }\n }\n else if(char.IsUpper(s[i]))\n {\n count = 0;\n temp.Clear();\n }\n }\n Console.WriteLine(res);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp6\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int n = inp0[0];\n int k = inp0[1];\n int[] a1 = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();\n List a = new List(a1);\n int j = k-1;\n bool f = true;\n Array.Sort(b);\n for (int i = 0; i < n-1; i++)\n {\n if (a[i]>=a[i+1]&&a[i+1]!=0)\n {\n f = false;\n break;\n }\n }\n if (f)\n {\n\n\n for (int i = 0; i < n; i++)\n {\n if (a[i] == 0)\n {\n\n a[i] = b[j];\n j--;\n\n }\n }\n\n for (int i = 0; i < n - 1; i++)\n {\n if (a[i] >= a[i + 1])\n {\n f = false;\n break;\n }\n }\n }\n\n if (!f)\n {\n Console.WriteLine(\"Yes\");\n }\n else\n {\n Console.WriteLine(\"No\");\n }\n }\n }\n}\n", "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Contest\n{\n class Program\n {\n\n static void Main()\n {\n var a = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);\n int n = a[0], p = a[1];\n for(int i=1; ; i++)\n {\n int k = n - i * p;\n if (k <= 0) { Console.WriteLine(-1); return; }\n if (check(k) <= i&&i<=k) { Console.WriteLine(i); return; }\n\n }\n\n\n }\n\n private static int check(int k)\n {\n int t = 0;\n while (k > 0)\n {\n if (k % 2 == 1) t++;\n k /= 2;\n }\n return t;\n }\n }\n}\n\n", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\n\nnamespace ConsoleApp5\n{\n class Program\n {\n \n static void Main(string[] args)\n {\n long[] values = Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray();\n long target = values[0] * 6;\n var current = values[1] * values[2];\n var max = Math.Max(values[1], values[2]);\n if (current >= target)\n {\n Console.WriteLine(current);\n Console.WriteLine(values[1] + \" \" + values[2]);\n return;\n }\n\n var start = Math.Min(values[1], values[2]);\n var end = Math.Max(values[1], values[2]);\n bool isAFirst = values[1] < values[2];\n long minFound = long.MaxValue;\n long a=0, b=0;\n var root = (long)Math.Sqrt(target);\n for (long i = start; end <= target / i&&i<=root; i++)\n {\n long other = target / i + (target % i == 0 ? 0 : 1);\n var currentArea = i * other;\n if (currentArea < minFound)\n {\n a = i;\n b = other;\n minFound = currentArea;\n }\n if (minFound == target)\n {\n break;\n }\n\n }\n Console.WriteLine(minFound);\n if (isAFirst)\n {\n Console.WriteLine(a + \" \" + b);\n }\n else\n {\n Console.WriteLine(b + \" \" + a);\n }\n\n }\n }\n}", "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\npublic class Solver\n{\n public object Solve()\n {\n int n = ReadInt();\n int m = ReadInt();\n\n int[] id = new int[m];\n int?[] status = new int?[n];\n\n int cand = -1;\n for (int i = 0; i < m; i++)\n {\n bool action = ReadToken() == \"+\";\n id[i] = ReadInt() - 1;\n if (status[id[i]] == null)\n {\n status[id[i]] = action ? 1 : 2;\n if (!action)\n cand = id[i];\n }\n }\n if (cand == -1)\n cand = id[0];\n\n var set = new SortedSet(Enumerable.Range(1, n).Where(i => status[i - 1] == null));\n bool[] on = Enumerable.Range(0, n).Select(i => status[i] == 2).ToArray();\n int onCount = status.Count(s => s == 2);\n int step;\n for (step = 0; step < m; step++)\n {\n if (id[step] == cand)\n {\n if (on[cand] && onCount > 1)\n break;\n }\n else if (!on[cand])\n break;\n on[id[step]] = !on[id[step]];\n if (on[id[step]])\n onCount++;\n else\n onCount--;\n }\n if (step == m)\n set.Add(cand + 1);\n\n writer.WriteLine(set.Count);\n WriteArray(set);\n\n return null;\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = Console.In;\n writer = Console.Out;\n#endif\n try\n {\n object result = new Solver().Solve();\n if (result != null)\n {\n writer.WriteLine(result);\n }\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read/Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] {' ', '\\t'}, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n if (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n #endregion\n}", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\n\nnamespace ConsoleApplication1\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tMain main = new Main();\n\t\t\t\tmain.ReadData();\n\t\t\t\tmain.Process();\n\t\t\t\tmain.WriteAnswer();\n\t\t\t}\n\t\t\tcatch (Exception e)\n\t\t\t{\n\t\t\t\tConsole.WriteLine(e);\n\t\t\t}\n\t\t}\n\t}\n\n\tclass Main\n\t{\n\t\tprivate int _y;\n\t\tprivate long _result;\n\n\t\tpublic void Process()\n\t\t{\n\t\t\tint day = 0;\n\t\t\tconst int remCommon = 365 % 7;\n\t\t\tconst int remHigh = 366 % 7;\n\t\t\tbool is_high = isHigh(_y);\n\n\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\t_y++;\n\t\t\t\tif (isHigh(_y))\n\t\t\t\t{\n\t\t\t\t\tday = (day + remHigh) % 7;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tday = (day + remCommon) % 7;\n\t\t\t\t}\n\t\t\t\tif (day == 0 && is_high == isHigh(_y))\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t_result = _y;\n\t\t}\n\n\t\tprivate bool isHigh(int year)\n\t\t{\n\t\t\tif (year%400 == 0 || (year%4 == 0 && year%100 != 0))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tpublic void ReadData()\n\t\t{\n\t\t\tTextReader textReader = Console.In;\n\t\t\t//TextReader textReader = new StreamReader(\"input.txt\");\n\t\t\tusing (TextReader reader = textReader)\n\t\t\t{\n\t\t\t\tstring readLine = reader.ReadLine();\n\t\t\t\t//string[] strings1 = readLine.Split(' ');\n\n\t\t\t\t_y = int.Parse(readLine);\n\t\t\t}\n\t\t}\n\n\t\tpublic void WriteAnswer()\n\t\t{\n\t\t\tusing (TextWriter writer = Console.Out)\n\t\t\t{\n\t\t\t\twriter.WriteLine(_result);\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace _Permutations\n{\n class ProgramPermutations\n {\n public static int[] Digits(int num)\n {\n var d = new Stack();\n if (num == 0) d.Push(0);\n\n while (num > 0)\n {\n d.Push(num % 10);\n num /= 10;\n }\n\n return d.ToArray();\n }\n\n public static int DigitsToNum(int[] digits)\n {\n var result = 0;\n var mult = 1;\n for (var i = digits.Length - 1; i >= 0; i--)\n {\n result += digits[i] * mult;\n mult *= 10;\n }\n\n return result;\n }\n\n static IEnumerable GetPerms(List seq)\n {\n seq.Sort();\n var len = seq.Count();\n var n = len - 1;\n var lst = new List {seq.ToArray()};\n\n while (true)\n {\n var k = -1;\n for (var i = 0; i < n; i++)\n {\n if (seq[i] < seq[i + 1]) k = i;\n }\n if (k == -1) break;\n var l = -1;\n for (var i = 0; i < len; i++)\n {\n if (seq[k] < seq[i]) l = i;\n }\n var temp = seq[k];\n seq[k] = seq[l];\n seq[l] = temp;\n\n var seqNext = new int[len];\n for (var i = 0; i <= k; i++)\n {\n seqNext[i] = seq[i];\n }\n for (var i = n; i > k; i--)\n {\n seqNext[k + len - i] = seq[i];\n }\n lst.Add(seqNext);\n seq = new List(seqNext);\n //Console.WriteLine(DigitsToNum(seqNext));\n }\n\n return lst;\n }\n\n static bool GreaterThan(IList num1, IList num2, int k)\n {\n for (var i = 0; i < k; i++)\n {\n if (num1[i] < num2[i]) return false;\n if (num1[i] > num2[i]) return true;\n }\n return false;\n }\n\n static bool LessThan(IList num1, IList num2, int k)\n {\n for (var i=0; i num2[i]) return false;\n if (num1[i] < num2[i]) return true;\n }\n return false;\n }\n\n static void Main(string[] args)\n {\n if (args.Count() > 0)\n {\n var r = new Random(1021);\n\n Console.WriteLine(\"{0} {1}\", args[0], args[1]);\n for (var i=0; i>();\n for (var i = 0; i < n; i++)\n {\n var strNum = Console.ReadLine();\n if (string.IsNullOrEmpty(strNum)) return;\n var num = strNum.Select(c => c - 48).ToList();\n nums.Add(num);\n }\n\n // Numbers from 0..k-1 in order\n var seq = new List();\n for (var i=0; i();\n var minNum = new List();\n for (var i = 0; i < k; i++)\n {\n maxNum.Add(0);\n minNum.Add(9);\n }\n\n foreach (var i in nums)\n {\n var permDigits = new int[k];\n for (var j = 0; j < k; j++)\n {\n permDigits[j] = i[perm[j]];\n }\n if (GreaterThan(permDigits, maxNum, k)) maxNum = new List(permDigits);\n if (LessThan(permDigits, minNum, k)) minNum = new List(permDigits);\n //var newNum = DigitsToNum(permDigits);\n //if (newNum > maxNum) maxNum = newNum;\n //if (newNum < minNum) minNum = newNum;\n }\n var diff = DigitsToNum(maxNum.ToArray()) - DigitsToNum(minNum.ToArray());\n //Console.WriteLine(\"{0} - {1} = {2}\", DigitsToNum(maxNum.ToArray()), DigitsToNum(minNum.ToArray()), diff);\n if (diff < minDifference) minDifference = diff;\n }\n Console.WriteLine(minDifference);\n }\n }\n}\n", "src_uid": "08f85cd4ffbd135f0b630235209273a4"} {"source_code": "// 1673 ms !!! long is much slower than double\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\n\nnamespace sar_cs\n{\n class Program\n {\n class Parser\n {\n const int BufSize = 25000;\n TextReader s;\n char[] buf = new char[BufSize];\n int bufPos;\n int bufDataSize;\n bool eos; // eos read to buffer\n int lastChar = -2;\n int nextChar = -2;\n StringBuilder sb = new StringBuilder();\n\n void FillBuf()\n {\n if (eos) return;\n bufDataSize = s.Read(buf, 0, BufSize);\n if (bufDataSize == 0) eos = true;\n bufPos = 0;\n }\n\n int Read()\n {\n if (nextChar != -2)\n {\n lastChar = nextChar;\n nextChar = -2;\n }\n else\n {\n if (bufPos == bufDataSize) FillBuf();\n if (eos) lastChar = -1;\n else lastChar = buf[bufPos++];\n }\n return lastChar;\n }\n\n void Back()\n {\n if (lastChar == -2) throw new Exception(); // no chars were ever read\n nextChar = lastChar;\n }\n\n public Parser()\n {\n s = Console.In;\n }\n\n public int ReadInt()\n {\n int res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return checked(res * sign);\n }\n\n public long ReadLong()\n {\n long res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n checked\n {\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = res * 10 - c;\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return res * sign;\n }\n }\n\n public double ReadDouble()\n {\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n\n int sign = 1;\n if (c == '-')\n {\n sign = -1;\n c = Read();\n }\n\n sb.Length = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = Read();\n }\n\n Back();\n double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);\n return res * sign;\n }\n\n public string ReadLine()\n {\n int c = Read();\n sb.Length = 0;\n while (c != -1 && c != 13 && c != 10)\n {\n sb.Append((char)c);\n c = Read();\n }\n if (c == 13)\n {\n c = Read();\n if (c != 10) Back();\n }\n return sb.ToString();\n }\n\n public bool EOF\n {\n get\n {\n if (Read() == -1) return true;\n Back();\n return false;\n }\n }\n\n public bool SeekEOF\n {\n get\n {\n L0:\n int c = Read();\n if (c == -1) return true;\n if (char.IsWhiteSpace((char)c)) goto L0;\n Back();\n return false;\n }\n }\n }\n\n static void pe()\n {\n Console.WriteLine(\"???\");\n Environment.Exit(0);\n }\n\n static void re()\n {\n Environment.Exit(55);\n }\n\n static int nosol()\n {\n Console.WriteLine(\"ERROR\");\n return 0;\n }\n\n static Stopwatch sw = Stopwatch.StartNew();\n\n static void Test()\n {\n Random rand = new Random(52345235);\n for (int i = 0; i < 2e6; i++)\n {\n }\n }\n\n struct Pos\n {\n public int X, Y;\n\n public Pos(int x, int y)\n {\n X = x; Y = y;\n }\n\n public Pos(string s)\n {\n X = (int)(s[0] - 'a');\n Y = (int)(s[1] - '0' - 1);\n }\n\n public bool Neighbor(Pos o)\n {\n return (X != o.X || Y != o.Y) && Math.Abs(X - o.X) <= 1 && Math.Abs(Y - o.Y) <= 1;\n }\n\n }\n\n static void LadyaFill(int[,] field, Pos l)\n {\n for (int x = l.X + 1; x < 8; x++)\n {\n int t = field[l.Y, x];\n field[l.Y, x] |= 2;\n if ((t & 1) == 1) break;\n }\n for (int x = l.X - 1; x >= 0; x--)\n {\n int t = field[l.Y, x];\n field[l.Y, x] |= 2;\n if ((t & 1) == 1) break;\n }\n\n for (int y = l.Y + 1; y < 8; y++)\n {\n int t = field[y, l.X];\n field[y, l.X] |= 2;\n if ((t & 1) == 1) break;\n }\n\n for (int y = l.Y - 1; y >= 0; y--)\n {\n int t = field[y, l.X];\n field[y, l.X] |= 2;\n if ((t & 1) == 1) break;\n }\n }\n\n static int Main(string[] args)\n {\n //Test(); return 0;\n //Console.SetIn(File.OpenText(\"_input\"));\n //Console.SetOut(File.CreateText(\"_out\"));\n Parser parser = new Parser();\n\n while (!parser.SeekEOF)\n {\n string line = parser.ReadLine();\n string[] ll = line.Split(' ');\n if (ll.Length != 4) pe();\n\n Pos wl1 = new Pos(ll[0]);\n Pos wl2 = new Pos(ll[1]);\n Pos wk = new Pos(ll[2]);\n Pos bk = new Pos(ll[3]);\n\n int[,] field = new int[8, 8];\n field[wl1.Y, wl1.X] = 1;\n field[wl2.Y, wl2.X] = 1;\n field[wk.Y, wk.X] = 1;\n //field[bk.Y,bk.X]='b';\n\n LadyaFill(field, wl1);\n LadyaFill(field, wl2);\n\n for (int y = 0; y < 8; y++)\n for (int x = 0; x < 8; x++)\n if (wk.Neighbor(new Pos(x, y))) field[y, x] |= 2;\n\n bool underAttack = (field[bk.Y, bk.X] & 2) != 0;\n\n bool canMove = false;\n for (int y = 0; y < 8; y++)\n for (int x = 0; x < 8; x++)\n if (bk.Neighbor(new Pos(x, y)))\n canMove |= (field[y, x] & 2) == 0;\n\n string res = underAttack && !canMove ? \"CHECKMATE\" : \"OTHER\";\n Console.WriteLine(res);\n\n }\n sw.Stop();\n return 0;\n }\n }\n}", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace APlayingwithPaper\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] ab = Console.ReadLine().Split();\n\n long a = long.Parse(ab[0]);\n long b = long.Parse(ab[1]);\n\n long temp = 0;\n long count = 0;\n\n while (b!=0)\n {\n if (a= tokens.Length)\n {\n tokens = NextLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n pointer = 0;\n }\n return tokens[pointer++];\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public int NextInt()\n {\n return Next();\n }\n\n public long NextLong()\n {\n return Next();\n }\n\n public T Next()\n {\n return (T)Convert.ChangeType(NextString(), typeof(T));\n }\n\n\n public IEnumerable NextSeq(int n)\n {\n for (int i = 0; i < n; i++)\n yield return Next();\n }\n\n public void Print(string format, params object[] args)\n {\n outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));\n }\n\n public void PrintLine(string format, params object[] args)\n {\n Print(format, args);\n\n outputStream.WriteLine();\n }\n\n public void Print(bool o)\n {\n Print(o ? \"YES\" : \"NO\");\n }\n\n public void PrintLine(bool o)\n {\n PrintLine(o ? \"YES\" : \"NO\");\n }\n\n public void Print(T o)\n {\n outputStream.Write(o);\n }\n\n\n public void PrintLine(T o)\n {\n outputStream.WriteLine(o);\n }\n\n public void Close()\n {\n inputStream.Close();\n outputStream.Close();\n }\n\n void IDisposable.Dispose()\n {\n Close();\n\n#if LOCAL_TEST\n Console.ReadLine();\n#endif\n }\n }\n\n\n public static class ListExtensions\n {\n public static T CycleGet(this IList self, int index)\n {\n return self[index % self.Count];\n }\n\n public static IList Shuffle(this IList self)\n {\n var rnd = new Random(DateTime.Now.Millisecond);\n\n var n = self.Count;\n\n while (n > 1)\n {\n n--;\n var k = rnd.Next(n + 1);\n var value = self[k];\n self[k] = self[n];\n self[n] = value;\n }\n\n return self;\n }\n\n public static IList Fill(this IList self, T val)\n {\n for (int i = 0; i < self.Count; i++)\n {\n self[i] = val;\n }\n\n return self;\n }\n }\n\n public static class P\n {\n public static P Create(T1 key, T2 val)\n {\n return new P(key, val);\n }\n }\n\n public class P\n {\n private class PComparer : IComparer>\n {\n private readonly bool? byKey;\n\n public PComparer(bool? byKey)\n {\n this.byKey = byKey;\n }\n\n\n public int Compare(P x, P y)\n {\n x = x ?? new P();\n y = y ?? new P();\n\n\n if (byKey == true)\n return Comparer.Default.Compare(x.Key, y.Key);\n else if (byKey == false)\n return Comparer.Default.Compare(x.Value, y.Value);\n else\n {\n var tr = Comparer.Default.Compare(x.Key, y.Key);\n\n if (tr != 0)\n tr = Comparer.Default.Compare(x.Value, y.Value);\n\n return tr;\n }\n }\n }\n\n\n public P()\n {\n }\n\n public P(T1 key, T2 val)\n {\n this.Key = key;\n this.Value = val;\n }\n\n\n public T1 Key\n {\n get;\n set;\n }\n\n public T2 Value\n {\n get;\n set;\n }\n\n public P Clone()\n {\n return new P(Key, Value);\n }\n\n public static IComparer> KeyComparer\n {\n get { return new PComparer(true); }\n }\n\n public static IComparer> ValueComparer\n {\n get { return new PComparer(false); }\n }\n\n public static implicit operator T1(P obj)\n {\n return obj.Key;\n }\n\n public static implicit operator T2(P obj)\n {\n return obj.Value;\n }\n\n public P SetKey(T1 key)\n {\n Key = key;\n return this;\n }\n\n public P SetValue(T2 value)\n {\n Value = value;\n return this;\n }\n\n public override string ToString()\n {\n return string.Format(\"Key: {0}, Value: {1}\", Key, Value);\n }\n\n public override int GetHashCode()\n {\n int hash = 17;\n hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());\n hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());\n return hash;\n\n }\n }\n\n #endregion\n\n\n internal class Program\n {\n #region Program\n\n private readonly MyIo io;\n\n public Program(MyIo io)\n {\n this.io = io;\n }\n\n public static void Main(string[] args)\n {\n using (MyIo io = new MyIo())\n {\n new Program(io)\n .Solve();\n }\n }\n\n\n\n #endregion\n public const long MOD = 1000000007;\n public const double EPS = 1e-14;\n\n private void Solve()\n {\n var a = io.NextInt();\n var b = io.NextInt();\n\n var sa = io.NextSeq(a).Select(x => x - 1).ToArray();\n var isb = new int[1000000];\n\n isb.Fill(-1);\n\n for (int i = 0; i < b; i++)\n isb[io.NextInt() - 1] = i;\n\n var res = 0;\n\n long[] q = new long[2 * a];\n\n for (int i = 0, j = 0; j < 2 * a; ++j)\n {\n q[j] = isb[sa.CycleGet(j)];\n \n if (q[j] == -1)\n {\n i = j + 1;\n continue;\n }\n\n if (j > 0 && q[j] < q[j - 1])\n {\n long cycles = (q[j - 1] - q[j] + b - 1) / b;\n q[j] += cycles * b;\n }\n\n\n while (i <= j && q[j] - q[i] >= b || j - i + 1 > a)\n {\n i++;\n }\n res = Math.Max(res, j - i + 1);\n }\n\n io.PrintLine(res);\n }\n }\n\n}\n\n", "src_uid": "13cd1aafbb1ba76be9ee10eaf8d8aef5"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace Fox_Dividing_Cheese\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int a = Next();\n int b = Next();\n\n var divs = new[] {2, 3, 5};\n var na = new int[divs.Length];\n var nb = new int[divs.Length];\n for (int i = 0; i < divs.Length; i++)\n {\n while (a%divs[i] == 0)\n {\n a /= divs[i];\n na[i]++;\n }\n while (b%divs[i] == 0)\n {\n b /= divs[i];\n nb[i]++;\n }\n }\n if (a == b)\n {\n writer.WriteLine(na.Select((t, i) => Math.Abs(t - nb[i])).Sum());\n }\n else\n {\n writer.WriteLine(\"-1\");\n }\n\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Collections.Specialized;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Linq;\n\npublic class CasketOfStar\n{\n\n public static void ans(int m, int n)\n {\n long k = 1;\n for (int i = 0; i < n; i++) {\n k *= m ;\n k %= 1000000007;\n } \n Console.WriteLine(k);\n }\n \npublic static void Main(string[] args)\n {\n int [] arr = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();\n if(arr[2] == 1 || arr[2] > arr[0])\n {\n //m^n\n ans(arr[1], arr[0]);\n }\n else if(arr[2] == arr[0])\n {\n //m^(n+1)/2\n ans(arr[1], (arr[0]+1)/2);\n }\n else if(arr[2] % 2 ==0)\n {\n \n ans(arr[1], 1);\n }\n else\n {\n ans(arr[1], 2);\n \n }\n \n }\n \n\n}\n", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CSharp\n{\n public class _723B\n {\n public static void Main()\n {\n int n = int.Parse(Console.ReadLine());\n string[] tokens = Console.ReadLine().Split('(', ')').ToArray();\n\n int longest = Enumerable.Range(0, tokens.Length).Where(i => i % 2 == 0).SelectMany(i => tokens[i].Split('_')).Max(word => word.Length);\n int count = Enumerable.Range(0, tokens.Length).Where(i => i % 2 == 1).SelectMany(i => tokens[i].Split('_')).Count(word => word.Length > 0);\n\n Console.WriteLine($\"{longest} {count}\");\n }\n }\n}", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing static System.Console;\nusing static System.Math;\n\nnamespace Olymp\n{\n public class ProblemSolver\n {\n private readonly Tokenizer input;\n\n public void Solve()\n {\n var q1x = new int[4];\n var q1y = new int[4];\n var q2x = new int[4];\n var q2y = new int[4];\n for (var i = 0; i < 4; i++)\n {\n q1x[i] = input.ReadInt();\n q1y[i] = input.ReadInt();\n }\n for (var i = 0; i < 4; i++)\n {\n q2x[i] = input.ReadInt();\n q2y[i] = input.ReadInt();\n }\n var x1min = q1x.Min();\n var y1min = q1y.Min();\n var x1max = q1x.Max();\n var y1max = q1y.Max();\n var x2min = q2x.Min();\n var y2min = q2y.Min();\n var x2max = q2x.Max();\n var y2max = q2y.Max();\n var d = (x2max - x2min) / 2;\n for (var x = Max(x1min, x2min); x <= Min(x1max, x2max); x++)\n {\n for (var y = Max(y1min, y2min); y <= Min(y1max, y2max); y++)\n {\n if (x >= x1min && x <= x1max &&\n y >= y1min && y <= y1max &&\n x >= x2min && x <= x2max &&\n y >= y2min && y <= y2max)\n {\n var x0 = x - x2min - d;\n var y0 = y - y2min - d;\n if (x0 + y0 <= d &&\n x0 + y0 >= -d &&\n y0 - x0 <= d &&\n y0 - x0 >= -d)\n {\n Write(\"YES\");\n return;\n }\n }\n }\n }\n Write(\"NO\");\n }\n\n public ProblemSolver(TextReader input)\n {\n this.input = new Tokenizer(input);\n }\n }\n\n #region Service classes\n\n public class Tokenizer\n {\n private readonly TextReader reader;\n\n public string ReadToEnd()\n {\n return reader.ReadToEnd();\n }\n\n public int ReadInt()\n {\n var c = SkipWS();\n if (c == -1)\n throw new EndOfStreamException();\n var isNegative = false;\n if (c == '-' || c == '+')\n {\n isNegative = c == '-';\n c = reader.Read();\n if (c == -1)\n throw new EndOfStreamException(\"Digit expected, but end of stream occurs\");\n }\n if (!char.IsDigit((char)c))\n throw new InvalidOperationException($\"Digit expected, but was: '{(char)c}'\");\n var result = (char)c - '0';\n c = reader.Read();\n while (c > 0 && !char.IsWhiteSpace((char)c))\n {\n if (!char.IsDigit((char)c))\n throw new InvalidOperationException($\"Digit expected, but was: '{(char)c}'\");\n result = result * 10 + (char)c - '0';\n c = reader.Read();\n }\n if (isNegative)\n result = -result;\n return result;\n }\n\n public string ReadLine()\n {\n return reader.ReadLine();\n }\n\n public long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public int[] ReadIntArray(int n)\n {\n var a = new int[n];\n for (var i = 0; i < n; i++)\n a[i] = ReadInt();\n return a;\n }\n\n public (int, int) Read2Int() =>\n (ReadInt(), ReadInt());\n\n public (int, int, int) Read3Int() =>\n (ReadInt(), ReadInt(), ReadInt());\n\n public (int, int, int, int) Read4Int() =>\n (ReadInt(), ReadInt(), ReadInt(), ReadInt());\n\n public long[] ReadLongArray(int n)\n {\n var a = new long[n];\n for (var i = 0; i < n; i++)\n a[i] = ReadLong();\n return a;\n }\n\n public double[] ReadDoubleArray(int n)\n {\n var a = new double[n];\n for (var i = 0; i < n; i++)\n a[i] = ReadDouble();\n return a;\n }\n\n public string ReadToken()\n {\n var c = SkipWS();\n if (c == -1)\n return null;\n var sb = new StringBuilder();\n while (c > 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = reader.Read();\n }\n return sb.ToString();\n }\n\n private int SkipWS()\n {\n var c = reader.Read();\n if (c == -1)\n return c;\n while (c > 0 && char.IsWhiteSpace((char)c))\n c = reader.Read();\n return c;\n }\n\n public Tokenizer(TextReader reader)\n {\n this.reader = reader;\n }\n }\n\n internal class Program\n {\n public static void Main()\n {\n var solver = new ProblemSolver(In);\n solver.Solve();\n }\n }\n\n #endregion\n}\n", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\nusing System.IO;\n\nnamespace Codeforces305_C\n{\n\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tusing (var io = new ContestIO())\n\t\t\t{\n\t\t\t\tvar Console = 1;\n\n\t\t\t\tvar m = io.ReadL();\n\t\t\t\tvar a = io.ReadListL(2);\n\t\t\t\tvar axy = io.ReadListL(2);\n\t\t\t\tvar b = io.ReadListL(2);\n\t\t\t\tvar bxy = io.ReadListL(2);\n\n\t\t\t\tlong a1 = -1, a2 = -1, b1 = -1, b2 = -1;\n\n\t\t\t\tfor (var i = 1; i <= 2 * m + 1; i++)\n\t\t\t\t{\n\t\t\t\t\ta[0] = Next(a, axy, m);\n\t\t\t\t\tb[0] = Next(b, bxy, m);\n\t\t\t\t\tif (a[0] == a[1])\n\t\t\t\t\t{\n\t\t\t\t\t\tif (a1 == -1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ta1 = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (a2 == -1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ta2 = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (i == b1 || i == b2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tio.Write(i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (b[0] == b[1])\n\t\t\t\t\t{\n\t\t\t\t\t\tif (b1 == -1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tb1 = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (b2 == -1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tb2 = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (i == a1 || i == a2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tio.Write(i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (a1 != -1 && a2 != -1 && b1 != -1 && b2 != -1)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (a1 == -1 || a2 == -1 || b1 == -1 || b2 == -1)\n\t\t\t\t{\n\t\t\t\t\tio.Write(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tvar da = a2 - a1;\n\t\t\t\tvar db = b2 - b1;\n\t\t\t\tfor (var i = 0; i <= m; i++)\n\t\t\t\t{\n\t\t\t\t\tlong x = a1 + da * i;\n\t\t\t\t\tlong k = x - b1;\n\t\t\t\t\tif (k < 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif (k % db == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tio.Write(x);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tio.Write(-1);\n\t\t\t}\n\t\t}\n\n\t\tstatic long Next(long[] v, long[] xy, long m)\n\t\t{\n\t\t\treturn (xy[0] * v[0] + xy[1]) % m;\n\t\t}\n\t}\n\n\tclass ContestIO : IDisposable\n\t{\n\t\tconst int BufferSize = 1024 * 8;\n\n\t\tstatic StreamReader reader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n\t\tstatic StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(BufferSize), Encoding.ASCII, BufferSize);\n\n\t\tstatic bool IsDigit(int c)\n\t\t{\n\t\t\treturn c >= '0' && c <= '9';\n\t\t}\n\t\tstatic int Next()\n\t\t{\n\t\t\treturn reader.Read();\n\t\t}\n\n\t\tpublic int Read()\n\t\t{\n\t\t\tint c = Next();\n\t\t\twhile (!IsDigit(c))\n\t\t\t{\n\t\t\t\tc = Next();\n\t\t\t}\n\t\t\tint r = 0;\n\t\t\twhile (IsDigit(c))\n\t\t\t{\n\t\t\t\tr = r * 10 + (c - '0');\n\t\t\t\tc = Next();\n\t\t\t}\n\t\t\treturn r;\n\t\t}\n\t\tpublic long ReadL()\n\t\t{\n\t\t\treturn (long)Read();\n\t\t}\n\t\tpublic int[] ReadList(int size)\n\t\t{\n\t\t\tvar r = new int[size];\n\t\t\tfor (var i = 0; i < size; i++)\n\t\t\t\tr[i] = Read();\n\t\t\treturn r;\n\t\t}\n\t\tpublic long[] ReadListL(int size)\n\t\t{\n\t\t\tvar r = new long[size];\n\t\t\tfor (var i = 0; i < size; i++)\n\t\t\t\tr[i] = ReadL();\n\t\t\treturn r;\n\t\t}\n\n\t\tpublic void Write(int v)\n\t\t{\n\t\t\twriter.Write(v);\n\t\t\twriter.WriteLine();\n\t\t}\n\t\tpublic void Write(long v)\n\t\t{\n\t\t\twriter.Write(v);\n\t\t\twriter.WriteLine();\n\t\t}\n\t\tpublic void Write(IEnumerable arr)\n\t\t{\n\t\t\tforeach (var v in arr)\n\t\t\t{\n\t\t\t\twriter.Write(v);\n\t\t\t\twriter.Write(' ');\n\t\t\t}\n\t\t\twriter.WriteLine();\n\t\t}\n\n\t\tpublic void Dispose()\n\t\t{\n\t\t\twriter.Flush();\n\t\t}\n\t}\n\n}\n", "src_uid": "7225266f663699ff7e16b726cadfe9ee"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\nnamespace CP_CS\n{\n\n class Task\n {\n\n static void Solve()\n {\n int n = ReadInt();\n for (int i = (int)Math.Ceiling(Math.Sqrt(n)); i >= 1; i--)\n {\n if (n % i == 0)\n {\n if (i > n/i)\n {\n continue;\n }\n Write($\"{i} {n/i}\");\n return;\n } \n }\n }\n\n static string[] Split(string str, int chunkSize)\n {\n return Enumerable.Range(0, str.Length / chunkSize)\n .Select(i => str.Substring(i * chunkSize, chunkSize)).ToArray();\n }\n\n #region -- Main -- \n\n private static TextReader reader;\n private static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n //reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"pluses.in\");\n //writer = new StreamWriter(\"pluses.out\");\n#endif\n try\n {\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n Solve();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n #region -- Read / Write --\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n private static string[] ReadAndSplitLine(char divisor)\n {\n return reader.ReadLine().Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0) currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n //public static BigInteger ReadBigInteger()\n //{\n // return BigInteger.Parse(ReadToken());\n //}\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static bool[] ReadBoolArray()\n {\n return ReadAndSplitLine().ToString().ToCharArray().Select(chr => chr == '1').ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static bool[][] ReadBoolMatrix(int numberOfRows)\n {\n bool[][] matrix = new bool[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadBoolArray();\n return matrix;\n }\n\n public static bool[][] TransposeBoolMatrix(bool[][] array, int numberOfRows)\n {\n bool[][] matrix = array;\n bool[][] ret = new bool[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new bool[numberOfRows];\n for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params object[] array)\n {\n WriteArray(array);\n }\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array) writer.WriteLine(a);\n }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new()\n {\n var ret = new T[size];\n for (int i = 0; i < size; i++) ret[i] = new T();\n return ret;\n }\n #endregion\n }\n}\n", "src_uid": "f52af273954798a4ae38a1378bfbf77a"} {"source_code": "/* Date: 11.01.2019 * Time: 21:45 */\n// *\n\n/*\n�\tfflush(stdout) � ����� C++; \n�\tSystem.out.flush() � Java; \n�\tstdout.flush() � Python; \n�\tflush(output) � Pascal; \n\n*/\n\nusing System;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nclass Example\n{\n\tpublic static void Main (string[] args)\n\t{\n# if ( ! ONLINE_JUDGE )\n\t\tStreamReader sr = new StreamReader (\"C:\\\\TRR\\\\2019\\\\Task\\\\07 Codeforces\\\\000\\\\A.TXT\");\n\t\tStreamWriter sw = new StreamWriter (\"C:\\\\TRR\\\\2019\\\\Task\\\\07 Codeforces\\\\000\\\\A.OUT\");\n# endif\n\n\t\tNumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;\n\t\tstring s;\n\n# if ( ONLINE_JUDGE )\n\t\ts = Console.ReadLine ();\n# else\n\t\ts = sr.ReadLine ();\n# endif\n\n\t\tstring [] ss = s.Split (' ');\n\n\t\tint n = int.Parse (ss [0]);\n\t\tint\tk = int.Parse (ss [1]);\n\n\t\tint m = k / n + ( k % n > 0 ? 1 : 0 );\n\n# if ( ONLINE_JUDGE )\n\t\tConsole.WriteLine (m);\n# else\n\t\tsw.WriteLine (m);\n\t\tsw.Close ();\n# endif\n\t}\n}\n", "src_uid": "04c067326ec897091c3dbcf4d134df96"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces.R276D\n{\n public static class Solver\n {\n public static void Main()\n {\n using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })\n {\n Solve(Console.In, sw);\n }\n }\n\n public static void Solve(TextReader tr, TextWriter tw)\n {\n var lr = tr.ReadLine().Split().Select(x => long.Parse(x)).ToArray();\n var l = lr[0];\n var r = lr[1];\n\n tw.WriteLine(Calc(l, r));\n }\n\n private static long Calc(long l, long r)\n {\n var x = 1L;\n while (x <= (l ^ r))\n x <<= 1;\n\n return x - 1;\n }\n }\n}\n", "src_uid": "d90e99d539b16590c17328d79a5921e0"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\n\nnamespace Codeforces\n{\n\tinternal class Template\n\t{\n\t\tprivate void Solve()\n\t\t{\n\t\t\tvar t = new BigInteger(cin.NextLong());\n\t\t\tvar w = new BigInteger(cin.NextLong());\n\t\t\tvar b = new BigInteger(cin.NextLong());\n\t\t\tvar tie = Lcm(w, b);\n\t\t\tvar extra = BigInteger.Min(w, b) - 1;\n\t\t\tvar result = t/tie*(extra + 1);\n\t\t\tvar left = t%tie;\n\t\t\tresult += BigInteger.Min(left, extra);\n\n\t\t\tvar gcd = Gcd(t, result);\n\n\t\t\tConsole.WriteLine(result / gcd + \"/\" + t / gcd);\n\t\t}\n\n\t\tstatic BigInteger Gcd(BigInteger a, BigInteger b)\n\t\t{\n\t\t\treturn b == 0 ? a : Gcd(b, a % b);\n\t\t}\n\n\t\tstatic BigInteger Lcm(BigInteger num1, BigInteger num2)\n\t\t{\n\t\t\treturn (num1 * num2) / Gcd(num1, num2);\n\t\t}\n\n\t\tprivate static readonly Scanner cin = new Scanner();\n\n\t\tprivate static void Main()\n\t\t{\n#if DEBUG\n\t\t\tConsole.SetIn(new StreamReader(@\"..\\..\\input.txt\"));\n#endif\n\t\t\tnew Template().Solve();\n\t\t\tConsole.ReadLine();\n#if DEBUG\n\t\t\tConsole.ReadKey();\n#endif\n\t\t}\n\t}\n\n\tinternal class Scanner\n\t{\n\t\tprivate string[] s = new string[0];\n\t\tprivate int i;\n\t\tprivate readonly char[] cs = { ' ' };\n\n\t\tpublic string NextString()\n\t\t{\n\t\t\tif (i < s.Length) return s[i++];\n\t\t\tvar line = Console.ReadLine() ?? string.Empty;\n\t\t\ts = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n\t\t\ti = 1;\n\t\t\treturn s.First();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn double.Parse(NextString());\n\t\t}\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn int.Parse(NextString());\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn long.Parse(NextString());\n\t\t}\n\t}\n}", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp5\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] toks = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n int n = toks[0];\n int x = toks[1];\n int[] arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n Array.Sort(arr);\n int count = 0;\n for(int i = 0; i <= x; i++) \n {\n if (!arr.Contains(i) && i != x)\n {\n count++;\n }\n\n if (i == x && arr.Contains(x))\n count++;\n }\n Console.WriteLine(count);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "21f579ba807face432a7664091581cd8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Linq;\nusing System.Collections;\n\nnamespace Task\n{\n class Subj\n {\n public long a, b;\n public int c;\n }\n\n class Program\n {\n Subj[] subjects;\n\n bool[, ,] done;\n long[, ,] memo;\n\n int[, ,] nextSubjId;\n int[, ,] nextComplexityShift;\n\n int n;\n int k;\n\n long getMax(int day, int lastSubjId, int complexityShift)\n {\n if (day == n)\n return 0;\n\n if (!done[day, lastSubjId, complexityShift])\n {\n long ans = -1;\n int bestNextSubjId = -1;\n int bestComplexityShift = -1;\n\n for (int nextSubjId = 0; nextSubjId < subjects.Length; nextSubjId++)\n {\n Subj nextSubj = subjects[nextSubjId];\n if (day != 0 && subjects[lastSubjId].c >= nextSubj.c)\n continue;\n\n if (day == 0)\n {\n for (long complexity = nextSubj.a; complexity <= nextSubj.b; complexity++)\n {\n int nextShift = (int)(complexity - nextSubj.a);\n long temp = getMax(day + 1, nextSubjId, nextShift);\n if (temp == -1)\n continue;\n\n temp += complexity;\n if (temp > ans)\n {\n ans = temp;\n bestNextSubjId = nextSubjId;\n bestComplexityShift = nextShift;\n }\n }\n }\n else\n {\n Subj lastSubj = subjects[lastSubjId];\n for (int mode = 0; mode < 2; mode++)\n {\n long nextComplexity = mode == 0 ? (lastSubj.a + complexityShift) * k : ((lastSubj.a + complexityShift) + k);\n if (nextComplexity < nextSubj.a || nextComplexity > nextSubj.b)\n continue;\n\n\n int nextShift = (int)(nextComplexity - nextSubj.a);\n long temp = getMax(day + 1, nextSubjId, nextShift);\n if (temp == -1)\n continue;\n\n temp += nextComplexity;\n if (temp > ans)\n {\n ans = temp;\n bestNextSubjId = nextSubjId;\n bestComplexityShift = nextShift;\n }\n }\n }\n }\n\n memo[day, lastSubjId, complexityShift] = ans;\n\n if (ans >= 0)\n {\n nextSubjId[day, lastSubjId, complexityShift] = bestNextSubjId;\n nextComplexityShift[day, lastSubjId, complexityShift] = bestComplexityShift;\n }\n\n\n done[day, lastSubjId, complexityShift] = true;\n \n }\n\n return memo[day, lastSubjId, complexityShift];\n\n }\n\n\n void Solve()\n {\n // Place your code here\n n = io.NextInt();\n int m = io.NextInt();\n k = io.NextInt();\n\n subjects = new Subj[m];\n\n for (int i = 0; i < m; i++)\n {\n Subj s = new Subj();\n s.a = io.NextLong();\n s.b = io.NextLong();\n s.c = io.NextInt();\n subjects[i] = s;\n }\n\n done = new bool[n, m, 101];\n memo = new long[n, m, 101];\n nextSubjId = new int[n, m, 101];\n nextComplexityShift = new int[n, m, 101];\n\n long ans = getMax(0, 0, 0);\n\n if (ans == -1)\n {\n io.Print(\"NO\");\n return;\n }\n\n io.Print(\"YES\");\n int curSubj = 0;\n int curShift = 0;\n for (int day = 0; day < n; day++)\n {\n int nextSubj = nextSubjId[day, curSubj, curShift];\n int nextShift = nextComplexityShift[day, curSubj, curShift];\n\n io.PrintLine(\"\");\n io.Print(\"{0} {1}\", nextSubj + 1, nextShift + subjects[nextSubj].a);\n\n curSubj = nextSubj;\n curShift = nextShift;\n }\n\n }\n\n MyIo io = new MyIo();\n\n static void Main(string[] args)\n {\n var p = new Program();\n\n p.Solve();\n p.io.Close();\n }\n }\n\n class MyIo\n {\n char[] separators = new char[] { ' ', '\\t' };\n\n#if TEST\n TextReader inputStream = new StreamReader(\"..\\\\..\\\\input.txt\");\n#else\n TextReader inputStream = System.Console.In;\n#endif\n TextWriter outputStream = Console.Out;\n\n string[] tokens;\n int pointer;\n\n public string NextLine()\n {\n try\n {\n return inputStream.ReadLine();\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public string NextString()\n {\n try\n {\n while (tokens == null || pointer >= tokens.Length)\n {\n tokens = NextLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);\n pointer = 0;\n }\n return tokens[pointer++];\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public int NextInt()\n {\n return int.Parse(NextString());\n }\n\n public long NextLong()\n {\n return long.Parse(NextString());\n }\n\n public void Print(string format, params object[] args)\n {\n outputStream.Write(format, args);\n }\n\n public void PrintLine(string format, params object[] args)\n {\n outputStream.WriteLine(format, args);\n }\n\n public void Print(T o)\n {\n outputStream.Write(o);\n }\n\n public void PrintLine(T o)\n {\n outputStream.WriteLine(o);\n }\n\n public void Close()\n {\n inputStream.Close();\n outputStream.Close();\n }\n }\n}\n", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace B_Mahmud_and_triangle\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int[] inp = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n\n List ribs = inp.ToList();\n ribs.Sort();\n\n for (int i = 0; i < inp.Length - 2; i++)\n if (ribs[i] + ribs[i + 1] > ribs[i + 2]) { Console.WriteLine(\"YES\"); return; }\n Console.WriteLine(\"NO\");\n }\n }\n}\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace B.Mancala\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] input = Console.ReadLine().Split(' ');\n long[] Holes = new long[14];\n for (int i = 0; i < 14; i++)\n {\n Holes[i] = int.Parse(input[i]);\n }\n\n long score = 0;\n for (int i = 0; i < 14; i++)\n {\n if (Holes[i] == 0)\n {\n continue;\n }\n long[] temp = (long[])Holes.Clone();\n long num = Holes[i];\n temp[i] = 0;\n long add = num / 14;\n long bonus = num % 14;\n for (int y = i+1; y <= i+14; y++)\n {\n temp[y % 14] += add;\n if (bonus > 0)\n {\n temp[y % 14]++;\n bonus--;\n }\n }\n long tempScore = SumAll(temp);\n if (tempScore > score)\n {\n score = tempScore;\n }\n }\n Console.WriteLine(score);\n //Console.ReadKey();\n }\n\n static long SumAll(long[] Holes)\n {\n long sum = 0;\n for (int i = 0; i < 14; i++)\n {\n if (Holes[i] % 2 == 0)\n sum += Holes[i];\n }\n\n return sum;\n }\n }\n\n}\n", "src_uid": "1ac11153e35509e755ea15f1d57d156b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\n\nnamespace CodeforcesTemplate\n{\n public static class Permutation\n {\n private static bool Next(ref int[] arr)\n {\n int k, j, l;\n for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }\n if (j == -1)\n {\n arr = arr.OrderBy(c => c).ToArray();\n return false;\n }\n for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }\n var tmp = arr[j];\n arr[j] = arr[l];\n arr[l] = tmp;\n for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)\n {\n tmp = arr[k];\n arr[k] = arr[l];\n arr[l] = tmp;\n }\n return true;\n }\n public static IEnumerable AllPermutations(int[] arr)\n {\n do yield return arr;\n while (Next(ref arr));\n }\n }\n\n class Program\n {\n private const string FILENAME = \"distance4\";\n\n private const string INPUT = FILENAME + \".in\";\n\n private const string OUTPUT = FILENAME + \".out\";\n\n private static Stopwatch _stopwatch = new Stopwatch();\n\n private static StreamReader _reader = null;\n private static StreamWriter _writer = null;\n\n private static string[] _curLine;\n private static int _curTokenIdx;\n\n private static char[] _whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n static int Count(string source, string key)\n {\n\n\n List indices = new List();\n\n int index = source.IndexOf(key, 0);\n\n while (index > -1)\n {\n indices.Add(index);\n index = source.IndexOf(key, index + key.Length);\n }\n\n return indices.Count();\n }\n\n public static string Check(string s)\n {\n string letters = \"aeiouy\";\n\n while (true)\n {\n bool used = false;\n\n for (int i = 0; i < s.Length - 1; i++)\n {\n if (letters.Contains(s[i].ToString()) && letters.Contains(s[i + 1].ToString()))\n {\n s = s.Remove(i + 1, 1);\n\n used = true;\n }\n }\n\n if (!used)\n {\n return s;\n }\n }\n }\n\n private static string ReadNextToken()\n {\n if (_curTokenIdx >= _curLine.Length)\n {\n //Read next line\n string line = _reader.ReadLine();\n if (line != null)\n _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n _curLine = new string[] { };\n _curTokenIdx = 0;\n }\n\n if (_curTokenIdx >= _curLine.Length)\n return null;\n\n return _curLine[_curTokenIdx++];\n }\n\n private static int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n private static void RunTimer()\n {\n#if (DEBUG)\n\n _stopwatch.Start();\n\n#endif\n }\n\n private static void Main(string[] args)\n {\n\n#if (DEBUG)\n double before = GC.GetTotalMemory(false);\n#endif\n int n = int.Parse(Console.ReadLine());\n\n string a = Console.ReadLine();\n\n string a1 = string.Empty;\n string a2 = string.Empty;\n\n int count = a.Length;\n\n if (n % 2 != 0)\n {\n for (int i = (n - 1) / 2; i >= 0; i--)\n {\n a1 = a.Substring(0, i);\n\n a2 = a.Substring(i, i);\n\n if (a1 == a2 && i > 0)\n {\n count = count - a1.Length + 1;\n break;\n }\n }\n }\n else\n {\n for (int i = n / 2; i >= 0; i--)\n {\n a1 = a.Substring(0, i);\n\n a2 = a.Substring(i, i);\n if (a1 == a2 && i > 0)\n {\n count = count - a1.Length + 1;\n break;\n }\n }\n\n }\n\n Console.WriteLine(count);\n\n\n\n\n\n\n#if (DEBUG)\n _stopwatch.Stop();\n\n double after = GC.GetTotalMemory(false);\n\n double consumedInMegabytes = (after - before) / (1024 * 1024);\n\n Console.WriteLine($\"Time elapsed: {_stopwatch.Elapsed}\");\n\n Console.WriteLine($\"Consumed memory (MB): {consumedInMegabytes}\");\n\n Console.ReadKey();\n#endif\n\n\n }\n\n private static int CountLeadZeros(string source)\n {\n int countZero = 0;\n\n for (int i = source.Length - 1; i >= 0; i--)\n {\n if (source[i] == '0')\n {\n countZero++;\n }\n\n else\n {\n break;\n }\n\n }\n\n return countZero;\n }\n\n private static string ReverseString(string source)\n {\n char[] reverseArray = source.ToCharArray();\n\n Array.Reverse(reverseArray);\n\n string reversedString = new string(reverseArray);\n\n return reversedString;\n }\n\n\n private static int[] CopyOfRange(int[] src, int start, int end)\n {\n int len = end - start;\n int[] dest = new int[len];\n Array.Copy(src, start, dest, 0, len);\n return dest;\n }\n\n private static string StreamReader()\n {\n\n if (_reader == null)\n _reader = new StreamReader(INPUT);\n string response = _reader.ReadLine();\n if (_reader.EndOfStream)\n _reader.Close();\n return response;\n\n\n }\n\n private static void StreamWriter(string text)\n {\n\n if (_writer == null)\n _writer = new StreamWriter(OUTPUT);\n _writer.WriteLine(text);\n\n\n }\n\n\n\n\n\n private static int BFS(int start, int end, int[,] arr)\n {\n Queue> queue = new Queue>();\n List visited = new List();\n for (int i = 0; i < arr.GetLength(0); i++)\n {\n visited.Add(false);\n }\n\n queue.Enqueue(new KeyValuePair(start, 0));\n KeyValuePair node;\n int level = 0;\n bool flag = false;\n\n while (queue.Count != 0)\n {\n node = queue.Dequeue();\n if (node.Key == end)\n {\n return node.Value;\n }\n flag = false;\n for (int i = 0; i < arr.GetLength(0); i++)\n {\n\n if (arr[node.Key, i] == 1)\n {\n if (visited[i] == false)\n {\n if (!flag)\n {\n level = node.Value + 1;\n flag = true;\n }\n queue.Enqueue(new KeyValuePair(i, level));\n visited[i] = true;\n }\n }\n }\n\n }\n return 0;\n\n }\n\n\n\n private static void Write(string source)\n {\n File.WriteAllText(OUTPUT, source);\n }\n\n private static string ReadString()\n {\n return File.ReadAllText(INPUT);\n }\n\n private static void WriteStringArray(string[] source)\n {\n File.WriteAllLines(OUTPUT, source);\n }\n\n private static string[] ReadStringArray()\n {\n return File.ReadAllLines(INPUT);\n }\n\n private static int[] GetIntArray()\n {\n return ReadString().Split(' ').Select(int.Parse).ToArray();\n }\n\n private static double[] GetDoubleArray()\n {\n return ReadString().Split(' ').Select(double.Parse).ToArray();\n }\n\n private static int[,] ReadINT2XArray(List lines)\n {\n int[,] arr = new int[lines.Count, lines.Count];\n\n for (int i = 0; i < lines.Count; i++)\n {\n int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();\n\n for (int j = 0; j < lines.Count; j++)\n {\n arr[i, j] = row[j];\n }\n }\n\n return arr;\n }\n }\n}\n", "src_uid": "ed8725e4717c82fa7cfa56178057bca3"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);\n \n static void Main(String[] args)\n {\n var data = Console.ReadLine().Split(' ').Select(long.Parse).ToList();\n //var n = int.Parse(Console.ReadLine());\n var a = data[0];\n var b = data[1];\n var h = data[2];\n var w = data[3];\n var n = data[4];\n\n data = Console.ReadLine().Split(' ').Select(long.Parse).ToList();\n data.Sort();\n data.Reverse();\n var all = new Dictionary>>();\n all[0] = new List>();\n all[0].Add(new Tuple(h, w));\n for(var i = 0; i < Math.Min(60, n); i++)\n {\n var cur = data[i];\n all[i + 1] = new List>();\n var used = new Dictionary();\n foreach (var prev in all[i])\n {\n if ((prev.Item1 >= a && prev.Item2 >= b) || (prev.Item2 >= a && prev.Item1 >= b))\n {\n Console.WriteLine(i);\n return;\n }\n if(prev.Item1 * cur < 0|| prev.Item2 * cur < 0)\n {\n Console.WriteLine(-1);\n return;\n }\n var new1 = new Tuple(prev.Item1 * cur, prev.Item2);\n var new2 = new Tuple(prev.Item1, prev.Item2 * cur);\n //if (prev.Item1 < a && prev.Item2 < b)\n //{\n if (!used.ContainsKey(new1.Item1 + \"#\" + new1.Item2))\n {\n all[i + 1].Add(new1);\n used[new1.Item1 + \"#\" + new1.Item2] = true;\n }\n if (!used.ContainsKey(new2.Item1 + \"#\" + new2.Item2))\n {\n all[i + 1].Add(new2);\n used[new2.Item1 + \"#\" + new2.Item2] = true;\n }\n \n \n }\n }\n\n foreach (var prev in all[(int)Math.Min(60, n)])\n {\n if (prev.Item1 >= a && prev.Item2 >= b)\n {\n Console.WriteLine((int)Math.Min(60, n));\n return;\n }\n }\n\n Console.WriteLine(-1);\n }\n}", "src_uid": "18cb436618b2b85c3f5dc348c80882d5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp1\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tstring[] str = Console.ReadLine().Split(new char[] { ' ' });\n\n\t\t\tlong x = Convert.ToInt64(str[0]);\n\t\t\tlong n = Convert.ToInt64(str[1]);\n\n\t\t\tList primes = new List();\n\t\t\t\n\t\t\tfor (long i = 2; i * i <= x; ++i)\n\t\t\t{\n\t\t\t\tif (x % i == 0 && isPrime(i))\n\t\t\t\t\tprimes.Add(i);\n\n\t\t\t\tif (x % i == 0 && isPrime(x / i) && !primes.Contains(x / i))\n\t\t\t\t\tprimes.Add(x / i);\n\t\t\t}\n\n\t\t\tif (isPrime(x))\n\t\t\t\tprimes.Add(x);\n\n\t\t\tlong mod = 1000000007;\n\t\t\tlong res = 1;\n\n\t\t\tList powers = new List();\n\n\t\t\tfor (int i = 0; i < primes.Count(); ++i)\n\t\t\t{\n\t\t\t\tpowers.Add(powerInFact(n, primes[i]));\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < primes.Count(); ++i)\n\t\t\t{\n\t\t\t\tif (powers[i] != 0)\n\t\t\t\t{\n\t\t\t\t\tres = (res * (binpow(primes[i], powers[i], mod) % mod)) % mod;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tConsole.WriteLine(res);\n\t\t\tConsole.ReadLine();\n\t\t}\n\n\t\tpublic static bool isPrime(long n)\n\t\t{\n\t\t\tfor (long i = 2; i * i <= n; ++i)\n\t\t\t{\n\t\t\t\tif (n % i == 0)\n\t\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic static long powerInFact(long n, long k)\n\t\t{\n\t\t\tlong res = 0;\n\t\t\twhile (n > 0)\n\t\t\t{\n\t\t\t\tn /= k;\n\t\t\t\tres += n;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic static long binpow(long a, long n, long mod)\n\t\t{\n\t\t\tif (n == 0)\n\t\t\t\treturn 1;\n\t\t\tif (n % 2 == 1)\n\t\t\t\treturn ((binpow(a, n - 1, mod) % mod) * a) % mod;\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong b = binpow(a, n / 2, mod) % mod;\n\t\t\t\treturn (b * b) % mod;\n\t\t\t}\n\t\t}\n\t}\n}\n\n", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace B_Sum\n{\n public class Sum\n {\n static int GetNotation(string input)\n {\n int max = 0;\n foreach (char c in input)\n max = Math.Max(max, (int)c);\n return max - 47;\n }\n\n static int Calculate(int notation, int result_10)\n {\n int output = 0;\n int temp = result_10;\n\n do\n {\n output++;\n temp = temp / notation;\n } while (temp >= notation);\n output++;\n return output;\n\n }\n\n static int Convert_10(int notation, string x)\n {\n\n int count = 0;\n int output = 0;\n for (int i = x.Length - 1; i >= 0; i--)\n {\n int temp = ((int)x[i] - 48) * Pow(notation, count);\n count++;\n output += temp;\n }\n return output;\n }\n\n static int Pow(int x, int g)\n {\n if (g == 0) return 1;\n else return x * Pow(x, g - 1);\n }\n\n static public int MaxLength(string input)\n {\n int notation = GetNotation(input);\n string[] s = input.Split(' ');\n int x = Convert_10(notation, s[0]);\n int y = Convert_10(notation, s[1]);\n return Calculate(notation, x + y);\n }\n }\n class Program\n {\n \n static void Main(string[] args)\n {\n Sum X = new Sum();\n Console.WriteLine(Sum.MaxLength(Console.ReadLine()));\n //Console.WriteLine(Convert_10(9, \"78\"));\n }\n }\n}\n", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Text;\n\nnamespace Primes_or_Palindromes\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n var pals = new List();\n\n for (int j = 1; j < 10; j++)\n {\n pals.Add(j);\n }\n for (int i = 1; i < 1000; i++)\n {\n string s = i.ToString();\n char[] cc = s.ToCharArray();\n Array.Reverse(cc);\n var sr = new string(cc);\n\n pals.Add(int.Parse(s + sr));\n for (int j = 0; j < 10; j++)\n {\n pals.Add(int.Parse(s + j + sr));\n }\n }\n\n pals.Sort();\n\n\n var primes = new List {2, 3, 5, 7};\n for (int i = 11; i < 2000000; i += 2)\n {\n bool f = false;\n for (int j = 0; primes[j]*primes[j] <= i; j++)\n {\n if (i%primes[j] == 0)\n {\n f = true;\n break;\n }\n }\n if (!f)\n primes.Add(i);\n }\n\n long p = Next();\n long q = Next();\n\n int l = 1;\n for (int i = 1; i < 2000000; i++)\n {\n int index1 = primes.BinarySearch(i);\n if (index1 < 0)\n index1 = ~index1;\n else\n {\n index1++;\n }\n int index2 = pals.BinarySearch(i);\n if (index2 < 0)\n index2 = ~index2;\n else\n {\n index2++;\n }\n\n if (q*index1 <= p*index2)\n {\n l = i;\n }\n }\n\n writer.WriteLine(l);\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "e6e760164882b9e194a17663625be27d"} {"source_code": "/*\ncsc -debug C.cs && mono --debug C.exe <<< \"3 3 0\"\n*/\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\n\npublic class HelloWorld {\n static public void Main () {\n SolveCodeForces();\n }\n\n public static void SolveCodeForces() {\n var sc = new Scanner();\n var n = sc.NextInt();\n var m = sc.NextUlong();\n var k = sc.NextInt();\n\n const ulong MOD = 998244353ul;\n\n var S = new ulong[n, k+1];\n S[0, 0] = m;\n\n for (var i = 1; i < n; i++) {\n\n S[i, 0] = m;\n\n for (var j = 1; j <= k; j++) {\n S[i, j] = ( S[i-1, j-1] * (m-1) + S[i-1, j] ) % MOD;\n }\n\n }\n\n System.Console.WriteLine(S[n-1, k]);\n }\n}\n\npublic static class Helpers {\n public static T[] CreateArray(int length, Func itemCreate) {\n var result = new T[length];\n for (var i = 0; i < result.Length; i++)\n result[i] = itemCreate(i);\n return result;\n }\n\n public static T ElementWithMax(this IEnumerable seq, Func func) {\n var bi = default(T);\n var bv = long.MinValue;\n foreach (var item in seq) {\n var v = func(item);\n if (v > bv) {\n bi = item;\n bv = v;\n }\n }\n return bi;\n }\n\n public static IEnumerable IndicesWhere(this IEnumerable seq, Func cond) {\n var i = 0;\n foreach (var item in seq) {\n if (cond(item)) yield return i;\n i++;\n }\n }\n}\n\npublic class Scanner\n{\n private string[] line = new string[0];\n private int index = 0;\n\n public string Next() {\n if (line.Length <= index) {\n line = Console.ReadLine().Split(' ');\n index = 0;\n }\n var res = line[index];\n index++;\n return res;\n }\n\n public int NextInt() {\n return int.Parse(Next());\n }\n\n public long NextLong() {\n return long.Parse(Next());\n }\n\n public ulong NextUlong() {\n return ulong.Parse(Next());\n }\n\n public string[] Array() {\n line = Console.ReadLine().Split(' ');\n index = line.Length;\n return line;\n }\n\n public int[] IntArray() {\n var array = Array();\n var result = new int[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = int.Parse(array[i]);\n return result;\n }\n\n public long[] LongArray() {\n var array = Array();\n var result = new long[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = long.Parse(array[i]);\n return result;\n }\n\n public ulong[] UlongArray() {\n var array = Array();\n var result = new ulong[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = ulong.Parse(array[i]);\n return result;\n }\n}", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b"} {"source_code": "using System;\nusing System.Diagnostics.Contracts;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces.R316D1\n{\n public struct ModInteger : IEquatable\n {\n readonly int mod;\n readonly long value;\n public ModInteger(int mod, long value = 0L)\n {\n this.mod = mod;\n this.value = value % mod;\n if (value < 0)\n {\n this.value = value + mod;\n }\n }\n\n public bool Equals(ModInteger other)\n {\n return mod == other.mod && value == other.value;\n }\n\n public override bool Equals(object obj)\n {\n if (!(obj is ModInteger))\n {\n return false;\n }\n var other = (ModInteger)obj;\n return Equals(other);\n }\n\n public override int GetHashCode()\n {\n return (int)value;\n }\n\n public static bool operator ==(ModInteger left, ModInteger right)\n {\n return left.Equals(right);\n }\n\n public static bool operator !=(ModInteger left, ModInteger right)\n {\n return !(left == right);\n }\n\n public static ModInteger LeftShift(ModInteger left, int right)\n {\n return left << right;\n }\n\n public static ModInteger operator <<(ModInteger left, int right)\n {\n if (right > 32)\n {\n return left << 32 << (right - 32);\n }\n return new ModInteger(left.mod, left.value << right);\n }\n\n public static ModInteger Add(ModInteger left, int right)\n {\n return left + right;\n }\n\n public static ModInteger operator +(ModInteger left, int right)\n {\n return new ModInteger(left.mod, left.value + right);\n }\n\n public static ModInteger operator ++(ModInteger m)\n {\n return m + 1;\n }\n\n public static ModInteger Multiply(ModInteger left, int right)\n {\n return new ModInteger(left.mod, left.value * right);\n }\n\n public static ModInteger operator *(ModInteger left, int right)\n {\n return Multiply(left, right);\n }\n\n public static ModInteger Div(int left, int right, int mod)\n {\n return Pow(right, mod - 2, mod) * left;\n }\n\n public static ModInteger Pow(long x, int n, int mod)\n {\n var res = 1L;\n for (; n > 0; n >>= 1)\n {\n if ((n & 1) == 1)\n {\n res = res * x % mod;\n }\n x = x * x % mod;\n }\n return new ModInteger(mod, res);\n }\n\n public static ModInteger ToModInteger(int value)\n {\n return new ModInteger(0, value);\n }\n\n public static implicit operator int(ModInteger value)\n {\n return (int)value.value;\n }\n\n public static int ToInt32(ModInteger value)\n {\n return value;\n }\n\n public static ModInteger Increment(ModInteger item)\n {\n return ++item;\n }\n }\n public static class Solver\n {\n const int mod = 1000000007;\n public static void Main()\n {\n using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })\n {\n Solve(Console.In, sw);\n }\n }\n\n public static void Solve(TextReader tr, TextWriter tw)\n {\n Contract.Requires(tr != null);\n Contract.Requires(tw != null);\n\n tw.WriteLine(Parse(tr));\n }\n\n private static int Parse(TextReader tr)\n {\n var info = CultureInfo.InvariantCulture;\n tr.ReadLine();\n var a = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();\n\n return Calc(a);\n }\n\n private static ModInteger Calc(int[] a)\n {\n int num1 = a.Count(x => x == 1);\n int num2 = a.Length - num1;\n\n return F(num1, num2);\n }\n\n private static ModInteger F(int a, int b)\n {\n var res = new ModInteger(mod, 1);\n\n for (int i = 0; i < b; ++i)\n {\n res *= a + 1 + i;\n }\n\n if (a == 0)\n {\n return res;\n }\n\n var I = new ModInteger[a + 1];\n I[0] = new ModInteger(mod, 1);\n I[1] = new ModInteger(mod, 1);\n for (int i = 2; i <= a; ++i)\n {\n I[i] = I[i - 1] + (i - 1) * I[i - 2];\n }\n return res * I[a];\n }\n }\n}\n", "src_uid": "91e8dbe94273e255182aca0f94117bb9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Runtime.InteropServices;\nusing System.Security.Cryptography;\n\nnamespace codeforces\n{\n\tclass Program\n\t{\n\t\tpublic class User\n\t\t{\n\t\t\tpublic int c;\n\n\t\t\tpublic int r;\n\t\t}\n\n\t\tpublic class Point\n\t\t{\n\t\t\tpublic int x;\n\n\t\t\tpublic int y;\n\t\t}\n\n\t\tpublic class Comparer : IComparer\n\t\t{\n\t\t\tpublic int Compare(User x, User y)\n\t\t\t{\n\t\t\t\tif (x.c < y.c || (x.c == y.c && x.r < y.r))\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic static long getGcd(long a, long b)\n\t\t{\n\t\t\tif (b == 0)\n\t\t\t\treturn a;\n\t\t\treturn getGcd(b, a % b);\n\t\t}\n\n\t\tpublic static void WriteYESNO(bool x, string yes = \"YES\", string no = \"NO\")\n\t\t{\n\t\t\tif (x)\n\t\t\t\tConsole.WriteLine(yes);\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(no);\n\t\t\t}\n\t\t}\n\n\t\tpublic static string getString()\n\t\t{\n\t\t\treturn Console.ReadLine();\n\t\t}\n\n\t\tpublic static List getList()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(int.Parse).ToList();\n\t\t}\n\n\t\tpublic static List getLongList()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(long.Parse).ToList();\n\t\t}\n\n\t\tpublic static int Min(int x, int y)\n\t\t{\n\t\t\treturn Math.Min(x, y);\n\t\t}\n\n\t\tpublic static int Max(int x, int y)\n\t\t{\n\t\t\treturn Math.Max(x, y);\n\t\t}\n\n\t\tpublic static int Abs(int x)\n\t\t{\n\t\t\treturn Math.Abs(x);\n\t\t}\n\n\t\tpublic static int getInt()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn int.Parse(s);\n\t\t}\n\n\t\tpublic static long getLong()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn long.Parse(s);\n\t\t}\n\n\t\tpublic static bool Equal(int x, int y, int x1, int y1)\n\t\t{\n\t\t\treturn x == x1 && y == y1;\n\t\t}\n\n\t\tpublic class Edge\n\t\t{\n\t\t\tpublic int v;\n\n\t\t\tpublic int w;\n\t\t}\n\n\t\tpublic class Vertex\n\t\t{\n\t\t\tpublic List edges;\n\n\t\t\tpublic int ct;\n\n\t\t\tpublic bool was;\n\t\t}\n\n\t\tpublic static bool canAuto(string s, string s1)\n\t\t{\n\t\t\tvar l = 0;\n\t\t\tfor (var i = 0; i < s1.Length; ++i)\n\t\t\t{\n\t\t\t\twhile (l < s.Length && s[l] != s1[i])\n\t\t\t\t\tl++;\n\t\t\t\tif (l == s.Length)\n\t\t\t\t\treturn false;\n\t\t\t\tl++;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic static bool canArray(string s, string s1)\n\t\t{\n\t\t\tvar l = s.ToCharArray().ToList();\n\t\t\tvar l1 = s1.ToCharArray().ToList();\n\t\t\tl.Sort();\n\t\t\tl1.Sort();\n\t\t\tif (l.Count != l1.Count)\n\t\t\t\treturn false;\n\n\t\t\tfor (var i = 0; i < l.Count; ++i)\n\t\t\t\tif (l[i] != l1[i])\n\t\t\t\t\treturn false;\n\t\t\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic static bool canBoth(string s, string s1)\n\t\t{\n\t\t\tvar l = s.ToCharArray().ToList();\n\t\t\tvar l1 = s1.ToCharArray().ToList();\n\t\t\tl.Sort();\n\t\t\tl1.Sort();\n\t\t\tvar ll = 0;\n\t\t\tfor (var i = 0; i < l1.Count; ++i)\n\t\t\t{\n\t\t\t\twhile (ll < l.Count && l[ll] != l1[i])\n\t\t\t\t\tll++;\n\t\t\t\tif (ll == l.Count)\n\t\t\t\t\treturn false;\n\t\t\t\tll++;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\n\t\tprivate static void Main(string[] args)\n\t\t{\n/*\t\t\tvar input = new StreamReader(\"input.txt\");\n\t\t\tvar output = new StreamWriter(\"output.txt\");*/\n\t\t\tvar pos = new List>();\n\t\t\tvar ar = new List>();\n\t\t\tfor (var i = 0; i < 5; ++i)\n\t\t\t{\n\t\t\t\tpos.Add(new List());\n\t\t\t\tfor (var j = 0; j < 5; ++j)\n\t\t\t\t\tpos[i].Add(1);\n\t\t\t}\n\t\t\tar.Add(getList());\n\t\t\tar.Add(getList());\n\t\t\tar.Add(getList());\n\t\t\tfor (var i = 0; i < 3; ++i)\n\t\t\t\tfor (var j = 0; j < 3; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (ar[i][j] % 2 == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tvar x = i + 1;\n\t\t\t\t\t\tvar y = j + 1;\n\t\t\t\t\t\tpos[x - 1][y] = 1 - pos[x - 1][y];\n\t\t\t\t\t\tpos[x][y - 1] = 1 - pos[x][y - 1];\n\t\t\t\t\t\tpos[x][y] = 1 - pos[x][y];\n\t\t\t\t\t\tpos[x][y + 1] = 1 - pos[x][y + 1];\n\t\t\t\t\t\tpos[x + 1][y] = 1 - pos[x + 1][y];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (var i = 1; i <= 3; ++i)\n\t\t\t{\n\t\t\t\tfor (var j = 1; j <= 3; ++j)\n\t\t\t\t\tConsole.Write(pos[i][j]);\n\t\t\t\tConsole.WriteLine();\n\t\t\t}\n\t\t\tConsole.ReadLine();\n\t\t}\n\t}\n}\n", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\n// (づ*ω*)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n int TrailingZeroes(int x)\n {\n int ret = 0;\n while (x % 2 == 0)\n {\n ret++;\n x >>= 1;\n }\n return ret;\n }\n\n public object Solve()\n {\n int x = ReadInt();\n int k = ReadInt();\n double p = ReadInt() / 100.0;\n double q = 1 - p;\n\n const int MASK = 1 << 8;\n const int MAX_ONES = 250;\n var dp = new double[MASK, MAX_ONES];\n\n int rep;\n if (x % MASK == 0)\n rep = TrailingZeroes(x) - 8;\n else\n {\n rep = 0;\n int xx = x >> 8;\n while (xx % 2 == 1)\n {\n rep++;\n xx >>= 1;\n }\n }\n dp[x % MASK, rep] = 1;\n\n for (int step = 0; step < k; step++)\n {\n var ndp = new double[MASK, MAX_ONES];\n for (int i = 0; i < MASK; i++)\n for (int j = 0; j < MAX_ONES; j++)\n if (dp[i,j] > 0)\n {\n if (i == 0)\n {\n ndp[0, j + 1] += dp[0, j] * p;\n ndp[1, 0] += dp[0, j] * q;\n }\n else\n {\n int ii = (i << 1) % MASK;\n int jj;\n if (ii == 0)\n jj = 0;\n else\n jj = (i >> 7 & 1) == 1 ? j + 1 : 0;\n ndp[ii, jj] += dp[i, j] * p;\n\n ii = i + 1;\n if (ii == MASK)\n ndp[0, j] += dp[i, j] * q;\n else\n ndp[ii, j] += dp[i, j] * q;\n }\n }\n dp = ndp;\n }\n\n double ans = 0;\n\n for (int i = 0; i < MASK; i++)\n for (int j = 0; j < MAX_ONES; j++)\n if (i == 0)\n ans += (8 + j) * dp[0, j];\n else\n ans += TrailingZeroes(i) * dp[i, j];\n\n return ans.ToString(CultureInfo.InvariantCulture);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = Console.In;\n writer = new StreamWriter(Console.OpenStandardOutput());\n#endif\n try\n {\n object result = new Solver().Solve();\n if (result != null)\n writer.WriteLine(result);\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read/Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n #endregion\n}", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Security.AccessControl;\nusing System.Security.Cryptography;\nusing System.Web;\n\nclass Program\n{\n static int Max(int a1, int a2, int a3)\n {\n int max = a1 > a2 ? a1 : a2;\n return a3 > max ? a3 : max;\n }\n\n static int Max(int a1, int a2)\n {\n return a1 > a2 ? a1 : a2;\n }\n\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int mod = 1000000007;\n\n var a = new int[n + 1];\n var b = new int[n + 1];\n var c = new int[n + 1];\n var d = new int[n + 1];\n\n a[1] = 1;\n b[1] = 1;\n c[1] = 1;\n d[1] = 0;\n\n for (int i = 2; i <= n; i++)\n {\n a[i] = ((b[i - 1] + c[i - 1])%mod + d[i - 1])%mod;\n b[i] = ((a[i - 1] + c[i - 1])%mod + d[i - 1])%mod;\n c[i] = ((b[i - 1] + a[i - 1])%mod + d[i - 1])%mod;\n d[i] = ((b[i - 1] + c[i - 1])%mod + a[i - 1])%mod;\n }\n\n Console.WriteLine(d[n]);\n } \n\n\n}\n\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Text;\n\nnamespace prA {\n class Program {\n#if ONLINE_JUDGE\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);\n#else\n private static readonly StreamWriter writer = new StreamWriter(@\"..\\..\\output\");\n private static readonly StreamReader reader = new StreamReader(@\"..\\..\\input\");\n#endif\n\n static void Main(string[] args) {\n HashSet set = new HashSet();\n string s = reader.ReadLine();\n char[] a = s.ToCharArray();\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < s.Length; i++) {\n sb.Clear();\n for (int j = i; j < s.Length; j++) {\n sb.Append(a[j]);\n }\n for (int j = 0; j < i; j++) {\n sb.Append(a[j]);\n }\n set.Add(sb.ToString());\n }\n\n writer.Write(set.Count);\n writer.Flush();\n#if !ONLINE_JUDGE\n writer.Close();\n#endif\n }\n private static int Next() {\n int c;\n int res = 0;\n do {\n c = reader.Read();\n if(c == -1)\n return res;\n } while(c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if(c == '-') {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while(true) {\n c = reader.Read();\n if(c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}\n", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A\n{\n class Program\n {\n static void Main(string[] args)\n {\n //Console.SetIn(File.OpenText(\"in.txt\"));\n var data = Console.ReadLine().Split().Select(d => int.Parse(d)).ToArray();\n\n var x = new int[3];\n var y = new int[3];\n x[0] = data[0];\n y[0] = data[1];\n x[1] = data[2];\n y[1] = data[3];\n x[2] = data[4];\n y[2] = data[5];\n\n\n\n for (int i = 0; i < 3; i++)\n for (int j = i + 1; j < 3; j++)\n {\n var a = length(x[i], y[i], x[j], y[j]);\n var tp = getOther(i, j);\n var b = length(x[i], y[i], x[tp], y[tp]);\n var c = length(x[j], y[j], x[tp], y[tp]);\n\n if (checkPif(a, b, c))\n {\n Console.WriteLine(\"RIGHT\");\n return;\n }\n }\n\n var ixs = new int[3];\n var iys = new int[3];\n for (int i = 0; i < 3; i++)\n for (int j = i + 1; j < 3; j++)\n {\n \n var tp = getOther(i, j);\n\n ixs[0] = x[i];\n ixs[1] = x[j];\n ixs[2] = x[tp];\n\n iys[0] = y[i];\n iys[1] = y[j];\n iys[2] = y[tp];\n\n\n for (int k = 0; k < 3; k++)\n\t\t\t {\n ixs[k] ++;\n var a = length(ixs[0], iys[0], ixs[1], iys[1]);\n var b = length(ixs[0], iys[0], ixs[2], iys[2]);\n var c = length(ixs[1], iys[1], ixs[2], iys[2]);\n\n if (!checkTr(a, b, c))\n {\n ixs[k]--;\n continue;\n }\n\n if (checkPif(a, b, c))\n {\n Console.WriteLine(\"ALMOST\");\n return;\n }\n\n ixs[k]--;\n\t\t\t }\n\n for (int k = 0; k < 3; k++)\n {\n ixs[k]--;\n var a = length(ixs[0], iys[0], ixs[1], iys[1]);\n var b = length(ixs[0], iys[0], ixs[2], iys[2]);\n var c = length(ixs[1], iys[1], ixs[2], iys[2]);\n\n if (!checkTr(a, b, c))\n {\n ixs[k]++;\n continue;\n }\n\n if (checkPif(a, b, c))\n {\n Console.WriteLine(\"ALMOST\");\n return;\n }\n\n ixs[k]++;\n }\n\n for (int k = 0; k < 3; k++)\n {\n iys[k]++;\n var a = length(ixs[0], iys[0], ixs[1], iys[1]);\n var b = length(ixs[0], iys[0], ixs[2], iys[2]);\n var c = length(ixs[1], iys[1], ixs[2], iys[2]);\n\n if (!checkTr(a, b, c))\n {\n iys[k]--;\n continue;\n }\n\n if (checkPif(a, b, c))\n {\n Console.WriteLine(\"ALMOST\");\n return;\n }\n\n iys[k]--;\n }\n\n for (int k = 0; k < 3; k++)\n {\n iys[k]--;\n var a = length(ixs[0], iys[0], ixs[1], iys[1]);\n var b = length(ixs[0], iys[0], ixs[2], iys[2]);\n var c = length(ixs[1], iys[1], ixs[2], iys[2]);\n\n if (!checkTr(a, b, c))\n {\n iys[k]++;\n continue;\n }\n\n if (checkPif(a, b, c))\n {\n Console.WriteLine(\"ALMOST\");\n return;\n }\n\n iys[k]++;\n }\n }\n\n Console.WriteLine(\"NEITHER\");\n\n }\n\n static HashSet vars = new HashSet() { 0, 1, 2 };\n static int getOther(int a, int b)\n {\n var s = new HashSet { a, b };\n s.SymmetricExceptWith(vars);\n return s.FirstOrDefault();\n }\n\n static double length(int x1, int y1, int x2, int y2)\n {\n return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));\n }\n\n static bool checkTr(double a, double b, double c)\n {\n if (a + b <= c)\n {\n return false;\n }\n else if (a + c <= b)\n {\n return false;\n }\n else if (b + c <= a)\n {\n return false;\n }\n\n return true;\n }\n\n static bool checkPif(double a, double b, double c)\n {\n var a2 = a * a;\n var b2 = b * b;\n var c2 = c * c;\n if (Math.Abs(a2 + b2 - c2) < 0.0000001)\n {\n return true;\n }\n else if (Math.Abs(a2 + c2 - b2) < 0.0000001)\n {\n return true;\n }\n else if (Math.Abs(b2 + c2 - a2) < 0.0000001)\n {\n return true;\n }\n\n return false;\n }\n }\n}\n", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"} {"source_code": "using System;\r\nusing System.IO;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Numerics;\r\nusing System.Runtime.CompilerServices;\r\nusing System.Text;\r\nusing System.Globalization;\r\nusing System.Threading;\r\n\r\nusing static System.Math;\r\n\r\nnamespace FertiLib.Contest.A\r\n{\r\n\tpublic class Solver\r\n\t{\r\n\t\tScanner sr;\r\n\t\tStreamWriter sw;\r\n\r\n\t\tbool isMultipleTestCases = true;\r\n\r\n\t\tpublic void Solve()\r\n\t\t{\r\n\t\t\tvar k = sr.ReadInt();\r\n\t\t\tConsole.WriteLine(100 / GCD(k, 100 - k));\r\n\t\t}\r\n\r\n\t\tpublic static long GCD(long a, long b)\r\n\t\t{\r\n\t\t\ta = Math.Abs(a);\r\n\t\t\tb = Math.Abs(b);\r\n\t\t\twhile (a > 0)\r\n\t\t\t{\r\n\t\t\t\tb %= a;\r\n\t\t\t\tvar x = a;\r\n\t\t\t\ta = b;\r\n\t\t\t\tb = x;\r\n\t\t\t}\r\n\t\t\treturn b;\r\n\t\t}\r\n\r\n\t\tpublic Solver(Scanner cin, StreamWriter cout)\r\n\t\t{\r\n\t\t\tthis.sr = cin;\r\n\t\t\tthis.sw = cout;\r\n\t\t}\r\n\r\n\t\tpublic void Start()\r\n\t\t{\r\n\t\t\tint _t = 1;\r\n\t\t\tif (isMultipleTestCases) _t = sr.ReadInt();\r\n\t\t\twhile (_t-- > 0) Solve();\r\n\t\t}\r\n\r\n\t\tpublic static void YESNO(bool condition) => Console.WriteLine(condition ? \"YES\" : \"NO\");\r\n\t\tpublic static void YesNo(bool condition) => Console.WriteLine(condition ? \"Yes\" : \"No\");\r\n\t\tpublic static void yesno(bool condition) => Console.WriteLine(condition ? \"yes\" : \"no\");\r\n\r\n\t\tpublic static T SignOutput(int x, T pos, T zero, T neg) => x == 0 ? zero : (x > 0 ? pos : neg);\r\n\r\n\t\tpublic static T[] CreateArray(int n, Func func) => Enumerable.Range(0, n).Select(p => func(p)).ToArray();\r\n\t\tpublic static T[][] CreateArray(int h, int w, Func func) => Enumerable.Range(0, h).Select(i => Enumerable.Range(0, w).Select(j => func(i, j)).ToArray()).ToArray();\r\n\t}\r\n\r\n\tpublic static class Program\r\n\t{\r\n\t\tpublic static void Main(string[] args)\r\n\t\t{\r\n\t\t\tvar sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };\r\n\t\t\tConsole.SetOut(sw);\r\n\t\t\tvar cin = new Scanner();\r\n\t\t\tvar solver = new Solver(cin, sw);\r\n\t\t\tsolver.Start();\r\n\t\t\tConsole.Out.Flush();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class Extention\r\n\t{\r\n\t\tpublic static string Join(this IEnumerable x, string separator = \"\") => string.Join(separator, x);\r\n\r\n\t\tpublic static int UpperBound(this IList list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer.Default);\r\n\t\tpublic static int LowerBound(this IList list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer.Default);\r\n\t\tpublic static int BinarySearch(this IList list, T value, bool isUpperBound, int index, int length, Comparer comparer)\r\n\t\t{\r\n\t\t\tvar ng = index - 1;\r\n\t\t\tvar ok = index + length;\r\n\t\t\twhile (ok - ng > 1)\r\n\t\t\t{\r\n\t\t\t\tvar mid = ng + (ok - ng) / 2;\r\n\t\t\t\tvar res = comparer.Compare(list[mid], value);\r\n\t\t\t\tif (res < 0 || (isUpperBound && res == 0)) ng = mid;\r\n\t\t\t\telse ok = mid;\r\n\t\t\t}\r\n\t\t\treturn ok;\r\n\t\t}\r\n\r\n\t\tpublic static bool Chmax(ref this T a, T b) where T : struct, IComparable\r\n\t\t{\r\n\t\t\tif (a.CompareTo(b) >= 0) return false;\r\n\t\t\ta = b;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tpublic static bool Chmin(ref this T a, T b) where T : struct, IComparable\r\n\t\t{\r\n\t\t\tif (a.CompareTo(b) <= 0) return false;\r\n\t\t\ta = b;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Scanner\r\n\t{\r\n\t\tstring[] s;\r\n\t\tint i;\r\n\r\n\t\tchar[] separator = new char[] { ' ' };\r\n\r\n\t\tpublic Scanner()\r\n\t\t{\r\n\t\t\ts = new string[0];\r\n\t\t\ti = 0;\r\n\t\t}\r\n\r\n\t\tpublic string Read() => ReadString();\r\n\r\n\t\tpublic string ReadString()\r\n\t\t{\r\n\t\t\tif (i < s.Length) return s[i++];\r\n\t\t\tstring st = Console.ReadLine();\r\n\t\t\twhile (st == \"\") st = Console.ReadLine();\r\n\t\t\ts = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);\r\n\t\t\tif (s.Length == 0) return ReadString();\r\n\t\t\ti = 0;\r\n\t\t\treturn s[i++];\r\n\t\t}\r\n\r\n\t\tpublic string[] ReadStringArray(int N)\r\n\t\t{\r\n\t\t\tstring[] Array = new string[N];\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tArray[i] = ReadString();\r\n\t\t\t}\r\n\t\t\treturn Array;\r\n\t\t}\r\n\r\n\t\tpublic int ReadInt() => int.Parse(ReadString());\r\n\r\n\t\tpublic int[] ReadIntArray(int N, int add = 0)\r\n\t\t{\r\n\t\t\tint[] Array = new int[N];\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tArray[i] = ReadInt() + add;\r\n\t\t\t}\r\n\t\t\treturn Array;\r\n\t\t}\r\n\r\n\t\tpublic long ReadLong() => long.Parse(ReadString());\r\n\r\n\t\tpublic long[] ReadLongArray(int N, long add = 0)\r\n\t\t{\r\n\t\t\tlong[] Array = new long[N];\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tArray[i] = ReadLong() + add;\r\n\t\t\t}\r\n\t\t\treturn Array;\r\n\t\t}\r\n\r\n\t\tpublic double ReadDouble() => double.Parse(ReadString());\r\n\r\n\t\tpublic double[] ReadDoubleArray(int N, double add = 0)\r\n\t\t{\r\n\t\t\tdouble[] Array = new double[N];\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tArray[i] = ReadDouble() + add;\r\n\t\t\t}\r\n\t\t\treturn Array;\r\n\t\t}\r\n\r\n\t\tpublic T1 ReadValue() => (T1)Convert.ChangeType(ReadString(), typeof(T1));\r\n\r\n\t\tpublic (T1, T2) ReadValue()\r\n\t\t{\r\n\t\t\tvar inputs = ReadStringArray(2);\r\n\t\t\tvar v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));\r\n\t\t\tvar v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));\r\n\t\t\treturn (v1, v2);\r\n\t\t}\r\n\r\n\t\tpublic (T1, T2, T3) ReadValue()\r\n\t\t{\r\n\t\t\tvar inputs = ReadStringArray(3);\r\n\t\t\tvar v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));\r\n\t\t\tvar v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));\r\n\t\t\tvar v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));\r\n\t\t\treturn (v1, v2, v3);\r\n\t\t}\r\n\r\n\t\tpublic (T1, T2, T3, T4) ReadValue()\r\n\t\t{\r\n\t\t\tvar inputs = ReadStringArray(4);\r\n\t\t\tvar v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));\r\n\t\t\tvar v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));\r\n\t\t\tvar v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));\r\n\t\t\tvar v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));\r\n\t\t\treturn (v1, v2, v3, v4);\r\n\t\t}\r\n\r\n\t\tpublic (T1, T2, T3, T4, T5) ReadValue()\r\n\t\t{\r\n\t\t\tvar inputs = ReadStringArray(5);\r\n\t\t\tvar v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));\r\n\t\t\tvar v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));\r\n\t\t\tvar v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));\r\n\t\t\tvar v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));\r\n\t\t\tvar v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));\r\n\t\t\treturn (v1, v2, v3, v4, v5);\r\n\t\t}\r\n\r\n\t\tpublic (T1, T2, T3, T4, T5, T6) ReadValue()\r\n\t\t{\r\n\t\t\tvar inputs = ReadStringArray(6);\r\n\t\t\tvar v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));\r\n\t\t\tvar v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));\r\n\t\t\tvar v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));\r\n\t\t\tvar v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));\r\n\t\t\tvar v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));\r\n\t\t\tvar v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));\r\n\t\t\treturn (v1, v2, v3, v4, v5, v6);\r\n\t\t}\r\n\r\n\t\tpublic (T1, T2, T3, T4, T5, T6, T7) ReadValue()\r\n\t\t{\r\n\t\t\tvar inputs = ReadStringArray(7);\r\n\t\t\tvar v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));\r\n\t\t\tvar v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));\r\n\t\t\tvar v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));\r\n\t\t\tvar v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));\r\n\t\t\tvar v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));\r\n\t\t\tvar v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));\r\n\t\t\tvar v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));\r\n\t\t\treturn (v1, v2, v3, v4, v5, v6, v7);\r\n\t\t}\r\n\r\n\t\tpublic T1[] ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar v1 = new T1[N];\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tv1[i] = ReadValue();\r\n\t\t\t}\r\n\t\t\treturn v1;\r\n\t\t}\r\n\r\n\t\tpublic (T1[], T2[]) ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar (v1, v2) = (new T1[N], new T2[N]);\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tvar (t1, t2) = ReadValue();\r\n\t\t\t\tv1[i] = t1;\r\n\t\t\t\tv2[i] = t2;\r\n\t\t\t}\r\n\t\t\treturn (v1, v2);\r\n\t\t}\r\n\r\n\t\tpublic (T1[], T2[], T3[]) ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tvar (t1, t2, t3) = ReadValue();\r\n\t\t\t\tv1[i] = t1;\r\n\t\t\t\tv2[i] = t2;\r\n\t\t\t\tv3[i] = t3;\r\n\t\t\t}\r\n\t\t\treturn (v1, v2, v3);\r\n\t\t}\r\n\r\n\t\tpublic (T1[], T2[], T3[], T4[]) ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tvar (t1, t2, t3, t4) = ReadValue();\r\n\t\t\t\tv1[i] = t1;\r\n\t\t\t\tv2[i] = t2;\r\n\t\t\t\tv3[i] = t3;\r\n\t\t\t\tv4[i] = t4;\r\n\t\t\t}\r\n\t\t\treturn (v1, v2, v3, v4);\r\n\t\t}\r\n\r\n\t\tpublic (T1[], T2[], T3[], T4[], T5[]) ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tvar (t1, t2, t3, t4, t5) = ReadValue();\r\n\t\t\t\tv1[i] = t1;\r\n\t\t\t\tv2[i] = t2;\r\n\t\t\t\tv3[i] = t3;\r\n\t\t\t\tv4[i] = t4;\r\n\t\t\t\tv5[i] = t5;\r\n\t\t\t}\r\n\t\t\treturn (v1, v2, v3, v4, v5);\r\n\t\t}\r\n\r\n\t\tpublic (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tvar (t1, t2, t3, t4, t5, t6) = ReadValue();\r\n\t\t\t\tv1[i] = t1;\r\n\t\t\t\tv2[i] = t2;\r\n\t\t\t\tv3[i] = t3;\r\n\t\t\t\tv4[i] = t4;\r\n\t\t\t\tv5[i] = t5;\r\n\t\t\t\tv6[i] = t6;\r\n\t\t\t}\r\n\t\t\treturn (v1, v2, v3, v4, v5, v6);\r\n\t\t}\r\n\r\n\t\tpublic (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray(int N)\r\n\t\t{\r\n\t\t\tvar (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]);\r\n\t\t\tfor (int i = 0; i < N; i++)\r\n\t\t\t{\r\n\t\t\t\tvar (t1, t2, t3, t4, t5, t6, t7) = ReadValue();\r\n\t\t\t\tv1[i] = t1;\r\n\t\t\t\tv2[i] = t2;\r\n\t\t\t\tv3[i] = t3;\r\n\t\t\t\tv4[i] = t4;\r\n\t\t\t\tv5[i] = t5;\r\n\t\t\t\tv6[i] = t6;\r\n\t\t\t\tv7[i] = t7;\r\n\t\t\t}\r\n\t\t\treturn (v1, v2, v3, v4, v5, v6, v7);\r\n\t\t}\r\n\t}\r\n}\r\n", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"source_code": "//http://codeforces.com/contest/622/problem/B\nusing System;\n\nnamespace ECR7PB\n{\n class Program\n {\n static void Main(string[] args)\n {\n var time = Console.ReadLine();\n var a = int.Parse(Console.ReadLine());\n\n var parts = time.Split(':');\n var h = int.Parse(parts[0]);\n var m = int.Parse(parts[1]);\n\n h += (m + a) / 60;\n h %= 24;\n m = (m + a) % 60;\n\n Console.WriteLine(h.ToString(\"00\") + \":\" + m.ToString(\"00\"));\n }\n }\n}\n", "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"source_code": "using System;\nclass Program\n{\n\tstatic void Main()\n\t{\n\t\tstring input = Console.ReadLine(), ans = \"no\";\n\n\t\tfor(int i = 0, count = int.MinValue; i < input.Length; ++i)\n\t\t{\n\t\t\tif (input[i] == '0') count++;\n\t\t\telse if(count < 0) count = 0;\n\n\t\t\tif (count == 6)\n\t\t\t{\n\t\t\t\tans = \"yes\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tConsole.WriteLine(ans);\n\t}\n}", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp6\n{\n class Program\n {\n static void Main(string[] args)\n {\n char[] cw = { (char)94, (char)62, (char)118, (char)60 };\n char[] ccw = { (char)94, (char)60, (char)118, (char)62 };\n\n char[] s = Array.ConvertAll(Console.ReadLine().Split(), char.Parse);\n int n = int.Parse(Console.ReadLine());\n n = n % 4;\n int ndxL = Array.IndexOf(ccw, s[0]);\n int ndxR = Array.IndexOf(cw, s[0]);\n\n for(int i = 0; i < n; i++)\n {\n ndxR += 1;\n ndxL = ndxL + 1;\n if (ndxL >= ccw.Length)\n ndxL = 0;\n if (ndxR >= cw.Length)\n ndxR = 0;\n }\n if(cw[ndxR] == ccw[ndxL])\n {\n Console.WriteLine(\"undefined\");\n return;\n }\n if (cw[ndxR] == s[1])\n Console.WriteLine(\"cw\");\n else\n Console.WriteLine(\"ccw\");\n \n\n\n\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"source_code": "/*\n * Created by SharpDevelop.\n * User: tagirov2\n * Date: 12.10.2015\n * Time: 12:56\n * \n * To change this template use Tools | Options | Coding | Edit Standard Headers.\n */\nusing System;\nusing System.Globalization;\n\nnamespace CF325A\n{\n\tclass Program\n\t{\n\t\tpublic static void Main(string[] args)\n\t\t{\n//\t\t\tConsole.WriteLine(\"Hello World!\");\n\t\t\t\n\t\t\t// TODO: Implement Functionality Here\n\t\t\t\n\t\t\tint n = int.Parse (Console.ReadLine ());\n\n\t\t\tstring [] s = Console.ReadLine().Trim().Split(' ');\n\t\t\tint [] a = new int [n+2];\n\n\t\t\tfor ( int j=1; j <= n; j++ )\n\t\t\t\ta [j] = int.Parse (s [j-1]);\n\n\t\t\tint k=0, i=0;\n\t\t\tfor ( i=1; i <= n; i++ )\n\t\t\t\tif ( a [i] > 0 )\n\t\t\t\t\tbreak;\n\n\t\t\tfor ( ; i <= n; i++ )\n\t\t\t\tif ( a [i] == a [i-1] && a [i] == 0 )\n\t\t\t\t\t;\n\t\t\t\telse if ( a [i] == 1 )\n\t\t\t\t\tk++;\n\t\t\t\telse if ( a [i-1] == 1 && a [i] == 0 && a [i+1] == 1 )\n\t\t\t\t\tk++;\n\n\t\t\tConsole.WriteLine (k);\n\n//\t\t\tConsole.Write(\"Press any key to continue . . . \");\n//\t\t\tConsole.ReadKey(true);\n\t\t}\n\t}\n}\n//\n//Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n//Console.ReadLine().Split(new char[] {' ', '\\t'}, StringSplitOptions.RemoveEmptyEntries);\n//NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;\n//string [] input = Console.In.ReadToEnd().Split(new char[] {' ', '\\t', '\\n', '\\r'}, StringSplitOptions.RemoveEmptyEntries);\n\n", "src_uid": "2896aadda9e7a317d33315f91d1ca64d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\n\nclass Segtree\n{\n int n;\n T[] tree;\n Func f;\n T exnum;\n public Segtree(int m, Func f, T ex)\n {\n this.f = f;\n this.exnum = ex;\n n = 1;\n while (n < m) n <<= 1;\n\n tree = new T[(n << 1) - 1];\n for (int i = 0; i < tree.Length; i++) tree[i] = ex;\n }\n public Segtree(int m, T ini, Func f, T ex)\n {\n this.f = f;\n this.exnum = ex;\n n = 1;\n while (n < m) n <<= 1;\n\n tree = new T[(n << 1) - 1];\n for (int i = 0; i < tree.Length; i++) tree[i] = ini;\n for (int i = 0; i < m; ++i) update(i, ini);\n }\n public void update(int j, T x)\n {\n int i = j + n - 1;\n tree[i] = x;\n while (i > 0)\n {\n i = (i - 1) >> 1;\n tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);\n }\n }\n public T look(int i) { return tree[i + n - 1]; }\n\n // [s, t]\n public T run(int s, int t) { return query(s, t + 1, 0, 0, n); }\n T query(int s, int t, int k, int l, int r)\n {\n if (r <= s || t <= l) return exnum;\n if (s <= l && r <= t) return tree[k];\n\n return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));\n }\n}\n\nnamespace Codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n string[] input = Console.ReadLine().Split(' ');\n\n if (n == 1)\n {\n if (int.Parse(input[0]) == 0) Console.WriteLine(\"UP\");\n else if (int.Parse(input[0]) == 15) Console.WriteLine(\"DOWN\");\n else Console.WriteLine(-1);\n return;\n }\n int a = int.Parse(input[n - 2]);\n int b = int.Parse(input[n - 1]);\n\n if (a == 14 && b == 15) Console.WriteLine(\"DOWN\");\n else if (a == 1 && b == 0) Console.WriteLine(\"UP\");\n else if (a > b) Console.WriteLine(\"DOWN\");\n else if (a < b) Console.WriteLine(\"UP\");\n\n }\n }\n}", "src_uid": "8330d9fea8d50a79741507b878da0a75"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Numerics;\nusing System.Threading.Tasks;\nusing System.Text.RegularExpressions;\nusing static System.Math;\n\nstatic class P\n{\n static void Main()\n {\n int n = int.Parse(Console.ReadLine());\n var a = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int res = 0;\n bool top = false;\n for (int i = 1; i < a.Length; i++)\n {\n var x = Min(a[i - 1], a[i]);\n var y = Max(a[i - 1], a[i]);\n if (x == 2 && y == 3) goto Infinite;\n if (x == 1 && y == 2) res += top ? 2 : 3;\n if (x == 1 && y == 3) res += 4;\n top = a[i - 1] == 3 && a[i] == 1;\n }\n Console.WriteLine(\"Finite\");\n Console.WriteLine(res);\n return;\n Infinite:;\n Console.WriteLine(\"Infinite\");\n\n }\n}\n", "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"source_code": "using System;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Threading; \n\nnamespace CodeForces\n{\n internal class Solution\n {\n const int StackSize = 20 * 1024 * 1024;\n\n private const int MOD = 1000000000;\n\n private void No()\n {\n Out.WriteLine(\"NO\");\n return;\n }\n\n private void Yes()\n {\n Out.WriteLine(\"YES\");\n return;\n }\n\n private void Solve()\n {\n long k = NextLong();\n string input = k.ToString();\n for (int i = 0; i < input.Length; i++)\n {\n if (input[i] != '1' && input[i] != '4')\n {\n No();\n return;\n }\n\n if (input[i] == '4')\n {\n if (i == 0)\n {\n No();\n return;\n }\n if (i == 1 && input[0] != '1')\n {\n No();\n return;\n }\n if (input[i - 1] == '4' && input[i - 2] != '1')\n {\n No();\n return;\n }\n }\n }\n Yes();\n return;\n }\n\n #region Local wireup\n\n public int[] NextIntArray(int size)\n {\n var res = new int[size];\n for (int i = 0; i < size; ++i) res[i] = NextInt();\n return res;\n }\n\n public long[] NextLongArray(int size)\n {\n var res = new long[size];\n for (int i = 0; i < size; ++i) res[i] = NextLong();\n return res;\n }\n\n public double[] NextDoubleArray(int size)\n {\n var res = new double[size];\n for (int i = 0; i < size; ++i) res[i] = NextDouble();\n return res;\n }\n\n public int NextInt()\n {\n return _in.NextInt();\n }\n\n public long NextLong()\n {\n return _in.NextLong();\n }\n\n public string NextLine()\n {\n return _in.NextLine();\n }\n\n public double NextDouble()\n {\n return _in.NextDouble();\n }\n\n readonly Scanner _in = new Scanner();\n static readonly TextWriter Out = Console.Out;\n\n void Start()\n {\n#if !ONLINE_JUDGE\n var timer = new Stopwatch();\n timer.Start();\n#endif\n var t = new Thread(Solve, StackSize);\n t.Start();\n t.Join();\n#if !ONLINE_JUDGE\n timer.Stop();\n Console.WriteLine(string.Format(CultureInfo.InvariantCulture, \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0));\n Console.ReadLine();\n#endif\n }\n\n static void Main()\n {\n new Solution().Start();\n }\n\n class Scanner : IDisposable\n {\n #region Fields\n\n readonly TextReader _reader;\n readonly int _bufferSize;\n readonly bool _closeReader;\n readonly char[] _buffer;\n int _length, _pos;\n\n #endregion\n\n #region .ctors\n\n public Scanner(TextReader reader, int bufferSize, bool closeReader)\n {\n _reader = reader;\n _bufferSize = bufferSize;\n _closeReader = closeReader;\n _buffer = new char[_bufferSize];\n FillBuffer(false);\n }\n\n public Scanner(TextReader reader, bool closeReader) : this(reader, 1 << 16, closeReader) { }\n\n public Scanner(string fileName) : this(new StreamReader(fileName, Encoding.Default), true) { }\n\n#if ONLINE_JUDGE\n public Scanner() : this( Console.In, false ) { }\n#else\n public Scanner() : this(\"d:\\\\input.txt\") { }\n#endif\n\n #endregion\n\n #region IDisposable Members\n\n public void Dispose()\n {\n if (_closeReader)\n {\n _reader.Close();\n }\n }\n\n #endregion\n\n #region Properties\n\n public bool Eof\n {\n get\n {\n if (_pos < _length) return false;\n FillBuffer(false);\n return _pos >= _length;\n }\n }\n\n #endregion\n\n #region Methods\n\n private char NextChar()\n {\n if (_pos < _length) return _buffer[_pos++];\n FillBuffer(true);\n return _buffer[_pos++];\n }\n\n private char PeekNextChar()\n {\n if (_pos < _length) return _buffer[_pos];\n FillBuffer(true);\n return _buffer[_pos];\n }\n\n private void FillBuffer(bool throwOnEof)\n {\n _length = _reader.Read(_buffer, 0, _bufferSize);\n if (throwOnEof && Eof)\n {\n throw new IOException(\"Can't read beyond the end of file\");\n }\n _pos = 0;\n }\n\n public int NextInt()\n {\n var neg = false;\n int res = 0;\n SkipWhitespaces();\n if (!Eof && PeekNextChar() == '-')\n {\n neg = true;\n _pos++;\n }\n while (!Eof && !IsWhitespace(PeekNextChar()))\n {\n var c = NextChar();\n if (c < '0' || c > '9') throw new ArgumentException(\"Illegal character\");\n res = 10 * res + c - '0';\n }\n return neg ? -res : res;\n }\n\n public long NextLong()\n {\n var neg = false;\n long res = 0;\n SkipWhitespaces();\n if (!Eof && PeekNextChar() == '-')\n {\n neg = true;\n _pos++;\n }\n while (!Eof && !IsWhitespace(PeekNextChar()))\n {\n var c = NextChar();\n if (c < '0' || c > '9') throw new ArgumentException(\"Illegal character\");\n res = 10 * res + c - '0';\n }\n return neg ? -res : res;\n }\n\n public string NextLine()\n {\n SkipUntilNextLine();\n if (Eof) return \"\";\n var builder = new StringBuilder();\n while (!Eof && !IsEndOfLine(PeekNextChar()))\n {\n builder.Append(NextChar());\n }\n return builder.ToString();\n }\n\n public double NextDouble()\n {\n SkipWhitespaces();\n var builder = new StringBuilder();\n while (!Eof && !IsWhitespace(PeekNextChar()))\n {\n builder.Append(NextChar());\n }\n return double.Parse(builder.ToString(), CultureInfo.InvariantCulture);\n }\n\n private void SkipWhitespaces()\n {\n while (!Eof && IsWhitespace(PeekNextChar()))\n {\n ++_pos;\n }\n }\n\n private void SkipUntilNextLine()\n {\n while (!Eof && IsEndOfLine(PeekNextChar()))\n {\n ++_pos;\n }\n }\n\n private static bool IsWhitespace(char c)\n {\n return c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n }\n\n private static bool IsEndOfLine(char c)\n {\n return c == '\\n' || c == '\\r';\n }\n\n #endregion\n }\n\n #endregion\n }\n}\n", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A.Olesya_and_Rodion\n{\n class Program\n {\n static void Main(string[] args)\n {\n string x = Console.ReadLine();\n int[]numberanddivisible = x.Split(' ').Select(int.Parse).ToArray();\n List answer = new List();\n for (int i = 0; i < numberanddivisible[0]; i++)\n {\n if (i == 0)\n {\n if (numberanddivisible[1]==10)\n {\n answer.Add(1);\n }\n else\n answer.Add(numberanddivisible[1]);\n }\n else\n answer.Add(0);\n }\n if (numberanddivisible[1]==10 && numberanddivisible[0]==1)\n {\n Console.WriteLine(\"-1\");\n }\n else\n {\n\n for (int i = 0; i < answer.Count; i++)\n {\n Console.Write(answer[i]);\n }\n }\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\npublic class Solver\n{\n public void Solve()\n {\n int a = ReadInt();\n int b = ReadInt();\n var ans = new int[3];\n for (int i = 1; i < 7; i++)\n {\n if (Math.Abs(a - i) < Math.Abs(b - i))\n ans[0]++;\n if (Math.Abs(a - i) == Math.Abs(b - i))\n ans[1]++;\n if (Math.Abs(a - i) > Math.Abs(b - i))\n ans[2]++;\n }\n\n WriteArray(ans);\n }\n \n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"hull.in\");\n //writer = new StreamWriter(\"hull.out\");\n#endif\n try\n {\n// var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n// thread.Start();\n// thread.Join();\n new Solver().Solve(); \n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() {return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);}\n public static string ReadToken(){while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine());return currentLineTokens.Dequeue();}\n public static int ReadInt(){return int.Parse(ReadToken());}\n public static long ReadLong(){return long.Parse(ReadToken());}\n public static double ReadDouble(){return double.Parse(ReadToken(), CultureInfo.InvariantCulture);}\n public static int[] ReadIntArray(){return ReadAndSplitLine().Select(int.Parse).ToArray();}\n public static long[] ReadLongArray(){return ReadAndSplitLine().Select(long.Parse).ToArray();}\n public static double[] ReadDoubleArray(){return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();}\n public static int[][] ReadIntMatrix(int numberOfRows){int[][] matrix = new int[numberOfRows][];for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray();return matrix;}\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows){int[][] matrix = ReadIntMatrix(numberOfRows);int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++){ret[i] = new int[numberOfRows];for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i];}return ret;}\n public static string[] ReadLines(int quantity){string[] lines = new string[quantity];for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim();return lines;}\n public static void WriteArray(IEnumerable array){writer.WriteLine(string.Join(\" \", array));}\n public static void Write(params object[] array){WriteArray(array);}\n public static void WriteLines(IEnumerable array){foreach (var a in array)writer.WriteLine(a);}\n private class SDictionary : Dictionary{public new TValue this[TKey key]{\n get { return ContainsKey(key) ? base[key] : default(TValue); }set { base[key] = value; }}}\n private static T[] Init(int size) where T : new(){var ret = new T[size];for (int i = 0; i < size; i++)ret[i] = new T();return ret;}\n #endregion\n}", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp10\n{\n class Program\n {\n static void Main(string[] args)\n {\n long n = Convert.ToInt32(Console.ReadLine());\n\n long a = Convert.ToInt32(Console.ReadLine());\n\n long b = Convert.ToInt32(Console.ReadLine());\n \n for(long x = 0; x <= n; x++)\n {\n long c = n - a * x;\n\n if (c < 0)\n {\n break;\n }\n\n if (c % b == 0)\n {\n long y = c / b;\n Console.WriteLine(\"YES\\n\" + x + \" \" + y);\n return;\n }\n }\n\n Console.WriteLine(\"NO\");\n }\n }\n}\n", "src_uid": "b031daf3b980e03218167f40f39e7b01"} {"source_code": "using System;\n\nnamespace NetCore\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int[] arr = new int[n];\n for(int i = 0; i < n; i++)\n {\n arr[i] = int.Parse(Console.ReadLine());\n }\n bool valid = false;\n int mx = (1 << n);\n for(int i = 0; i < mx; i++)\n {\n int sum = 0;\n int j = 1;\n int counter = 0;\n while(counter < n)\n {\n if ((j & i) != 0) sum += arr[counter];\n else sum -= arr[counter];\n counter++;\n j <<= 1;\n sum %= 360;\n }\n if (sum == 0) valid = true;\n }\n Console.WriteLine(valid ? \"YES\" : \"NO\");\n }\n }\n}\n", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace ALGORITM_CodeForces\n{\n class Program\n {\n static void Main()\n {\n string s = Console.ReadLine();\n var n = Convert.ToInt64(s.Split(' ')[0]);\n var k = Convert.ToInt64(s.Split(' ')[1]);\n\n Console.WriteLine(To(1,n,n,k,n));\n Console.WriteLine();\n }\n static long To(long left,long right,long cur,long y,long x)\n {\n long final;\n long y1=1;\n long mid = left + (right - left) / 2;\n long plus = mid;\n long t = mid;\n while ((t/y)!=0)\n {\n t = mid / (y1=y1*y);\n plus = plus + t;\n \n }\n\n if ((mid==left) && (left==right))\n \n return mid;\n\n else if (plus < cur)\n {\n final = To(mid+1, right, cur,y,x);\n }\n else\n {\n\n final=To(left, mid, cur,y,x);\n \n }\n return final;\n }\n }\n}", "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"source_code": "using System;\n\nnamespace ConsoleApp5\n{\n\n\n class Program\n {\n\n static void Main(string[] args)\n {\n Int32 n = Int32.Parse(Console.ReadLine());\n\n \n Console.Write(n/2 +1);\n Console.ReadLine();\n \n \n }\n }\n}\n", "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CF_141A\n{\n class Program\n {\n static void Main()\n {\n var s = Console.ReadLine();\n s += Console.ReadLine();\n var sRes = Console.ReadLine();\n var s1 = s.OrderBy(x => x).ToList().Aggregate(\"\", (current, t) => current + t);\n var s2 = sRes.OrderBy(x => x).ToList().Aggregate(\"\", (current, t) => current + t);\n Console.WriteLine(string.Compare(s1, s2) == 0 ? \"YES\" : \"NO\");\n }\n }\n}\n", "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass TEST{\n\tstatic void Main(){\n\t\tSol mySol =new Sol();\n\t\tmySol.Solve();\n\t}\n}\n\nclass Sol{\n\tpublic void Solve(){\n\t\t\n\t\tint maxV = N*5*4;\n\t\tbool[][] vis = new bool[maxV][];\n\t\tfor(int i=0;i H = new HashSet();\n\t\tH.Add(enc(maxV/2,maxV/2,0));\n\t\tfor(int i=0;i nxt = new HashSet();\n\t\t\tforeach(var trc in H){\n\t\t\t\tvar r = decR(trc);\n\t\t\t\tvar c = decC(trc);\n\t\t\t\tvar t = decT(trc);\n\t\t\t\tfor(int j=1;j<=A[i];j++){\n\t\t\t\t\tvar nr = r + dy[t]*j;\n\t\t\t\t\tvar nc = c + dx[t]*j;\n\t\t\t\t\tvis[nr][nc] = true;\n\t\t\t\t}\n\t\t\t\tnxt.Add(enc(r + dy[t]*A[i], c + dx[t]*A[i], (t+1)%8));\n\t\t\t\tnxt.Add(enc(r + dy[t]*A[i], c + dx[t]*A[i], (t+7)%8));\n\t\t\t}\n\t\t\tH = nxt;\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor(int i=0;iint.Parse(e));}\n\tstatic long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}\n\tstatic double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}\n}\n", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n string a = s.Split('+', '=')[0];\n string b = s.Split('+', '=')[1];\n string c = s.Split('+', '=')[2];\n\n if (a.Length + b.Length == c.Length)\n {\n Console.WriteLine(s);\n }\n else if (a.Length + b.Length - c.Length == -2)\n {\n b += \"|\";\n c = c.Remove(c.Length - 1);\n Console.WriteLine(\"{0}+{1}={2}\", a, b, c);\n }\n else if (a.Length + b.Length - c.Length == 2)\n {\n c += \"|\";\n if (a.Length == 1)\n {\n b = b.Remove(b.Length - 1);\n }\n else\n {\n a = a.Remove(a.Length - 1);\n }\n Console.WriteLine(\"{0}+{1}={2}\", a, b, c);\n }\n else\n {\n Console.WriteLine(\"Impossible\");\n }\n }\n }\n}", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace Links_and_Pearls\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args) ? \"Yes\" : \"No\");\n writer.Flush();\n }\n\n private static bool Solve(string[] args)\n {\n string s = reader.ReadLine();\n\n int l = s.Count(c => c == '-');\n\n return s.Length - l == 0 || l%(s.Length - l) == 0;\n }\n }\n}", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"source_code": "// \n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\nusing System.Linq;\n\nnamespace sar_cs\n{\n public class Program\n {\n public class Parser\n {\n const int BufSize = 25000;\n TextReader s;\n char[] buf = new char[BufSize];\n int bufPos;\n int bufDataSize;\n bool eos; // eos read to buffer\n int lastChar = -2;\n int nextChar = -2;\n StringBuilder sb = new StringBuilder();\n\n void FillBuf()\n {\n if (eos) return;\n bufDataSize = s.Read(buf, 0, BufSize);\n if (bufDataSize == 0) eos = true;\n bufPos = 0;\n }\n\n int Read()\n {\n if (nextChar != -2)\n {\n lastChar = nextChar;\n nextChar = -2;\n }\n else\n {\n if (bufPos == bufDataSize) FillBuf();\n if (eos) lastChar = -1;\n else lastChar = buf[bufPos++];\n }\n return lastChar;\n }\n\n void Back()\n {\n if (lastChar == -2) throw new Exception(); // no chars were ever read\n nextChar = lastChar;\n }\n\n public Parser()\n {\n s = Console.In;\n }\n\n public int ReadInt()\n {\n int res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return checked(res * sign);\n }\n\n public int ReadLnInt()\n {\n int res = ReadInt(); ReadLine(); return res;\n }\n\n public long ReadLong()\n {\n long res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n checked\n {\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = res * 10 - c;\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return res * sign;\n }\n }\n\n public long ReadLnLong()\n {\n long res = ReadInt(); ReadLine(); return res;\n }\n\n public double ReadDouble()\n {\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n\n int sign = 1;\n if (c == '-')\n {\n sign = -1;\n c = Read();\n }\n\n sb.Length = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = Read();\n }\n\n Back();\n double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);\n return res * sign;\n }\n\n public string ReadLine()\n {\n int c = Read();\n sb.Length = 0;\n while (c != -1 && c != 13 && c != 10)\n {\n sb.Append((char)c);\n c = Read();\n }\n if (c == 13)\n {\n c = Read();\n if (c != 10) Back();\n }\n return sb.ToString();\n }\n\n public bool EOF\n {\n get\n {\n if (Read() == -1) return true;\n Back();\n return false;\n }\n }\n\n public bool SeekEOF\n {\n get\n {\n L0:\n int c = Read();\n if (c == -1) return true;\n if (char.IsWhiteSpace((char)c)) goto L0;\n Back();\n return false;\n }\n }\n }\n\n static void pe()\n {\n Console.WriteLine(\"???\");\n Environment.Exit(0);\n }\n\n static void re()\n {\n Environment.Exit(55);\n }\n\n static int nosol()\n {\n Console.WriteLine(\"ERROR\");\n return 0;\n }\n\n static Stopwatch sw = Stopwatch.StartNew();\n\n static StringBuilder sb = new StringBuilder();\n static Random rand = new Random(52345235);\n\n static void Swap(ref T a, ref T b)\n {\n T t = a;\n a = b;\n b = t;\n }\n\n static char[] suits = { 'C', 'D', 'H', 'S' };\n static char[] values = { '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };\n\n struct Pos\n {\n public int Y, X;\n }\n\n struct Joker\n {\n public string Name;\n public int Y, X;\n }\n\n static int h, w;\n static string[,] map;\n\n static bool Square_SameSuit(int y, int x)\n {\n char suit = '\\0';\n for (int i = 0; i < 3; i++)\n for (int j = 0; j < 3; j++)\n {\n if (suit == '\\0') suit = map[y + i, x + j][1];\n else if (suit != map[y + i, x + j][1]) return false;\n }\n return true;\n }\n\n static bool Square_DistinctValues(int y, int x)\n {\n bool[] usedValues = new bool[values.Length];\n for (int i = 0; i < 3; i++)\n for (int j = 0; j < 3; j++)\n {\n int value = Array.IndexOf(values, map[y + i, x + j][0]);\n if (value < 0) pe();\n if (usedValues[value]) return false;\n usedValues[value] = true;\n }\n return true;\n }\n\n static bool CheckSquareCombinations(out int y1, out int x1, out int y2, out int x2)\n {\n x1 = y2 = x2 = 0;\n for (y1 = 0; y1 < h - 2; y1++)\n for (x1 = 0; x1 < w - 2; x1++)\n if (Square_DistinctValues(y1, x1) || Square_SameSuit(y1, x1))\n for (y2 = 0; y2 < h - 2; y2++)\n for (x2 = 0; x2 < w - 2; x2++)\n if (x1 + 3 <= x2 || x2 + 3 <= x1 || y1 + 3 <= y2 || y2 + 3 <= y1)\n if (Square_DistinctValues(y2, x2) || Square_SameSuit(y2, x2))\n return true;\n return false;\n }\n\n static int Main(string[] args)\n {\n //MyStructs.BigNum.Test(); return 0;\n //Console.SetIn(File.OpenText(\"_input\"));\n var parser = new Parser();\n\n while (!parser.SeekEOF)\n {\n var koloda = new HashSet();\n for (int i = 0; i < suits.Length; i++)\n for (int j = 0; j < values.Length; j++)\n koloda.Add(values[j].ToString() + suits[i]);\n\n h = parser.ReadInt();\n w = parser.ReadLnInt();\n map = new string[h, w];\n var jokers = new List();\n for (int i = 0; i < h; i++)\n {\n var ss = parser.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n if (ss.Length != w) pe();\n for (int j = 0; j < w; j++)\n {\n map[i, j] = ss[j];\n if (ss[j] == \"J1\" || ss[j] == \"J2\") jokers.Add(new Joker { Name = ss[j], Y = i, X = j });\n else if (!koloda.Remove(ss[j])) pe();\n }\n }\n\n string res = null;\n int x1 = 0, y1 = 0, x2 = 0, y2 = 0;\n\n if (jokers.Count == 0)\n {\n if (CheckSquareCombinations(out y1, out x1, out y2, out x2)) res = \"There are no jokers.\";\n }\n else if (jokers.Count == 1)\n {\n foreach (var c in koloda)\n {\n map[jokers[0].Y, jokers[0].X] = c;\n if (CheckSquareCombinations(out y1, out x1, out y2, out x2))\n {\n res = string.Format(\"Replace {0} with {1}.\", jokers[0].Name, c);\n goto k0;\n }\n }\n }\n else if (jokers.Count == 2)\n {\n jokers.Sort((j1, j2) => j1.Name.CompareTo(j2.Name));\n foreach (var c1 in koloda)\n foreach (var c2 in koloda)\n if (c1 != c2)\n {\n map[jokers[0].Y, jokers[0].X] = c1;\n map[jokers[1].Y, jokers[1].X] = c2;\n if (CheckSquareCombinations(out y1, out x1, out y2, out x2))\n {\n res = string.Format(\"Replace J1 with {0} and J2 with {1}.\", c1, c2);\n goto k0;\n }\n }\n }\n else pe();\n\n k0: ;\n if (res == null)\n Console.WriteLine(\"No solution.\");\n else\n {\n Console.WriteLine(\"Solution exists.\");\n Console.WriteLine(res);\n Console.WriteLine(string.Format(\"Put the first square to ({0}, {1}).\", y1 + 1, x1 + 1));\n Console.WriteLine(string.Format(\"Put the second square to ({0}, {1}).\", y2 + 1, x2 + 1));\n }\n //Console.WriteLine();\n }\n\n\n return 0;\n }\n }\n}", "src_uid": "b3f29d9c27cbfeadb96b6ac9ffd6bc8f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Xml.Xsl;\n\nnamespace Codeforces\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tstring input1 = Console.ReadLine();\n\t\t\t//string input2 = Console.ReadLine();\n\n\t\t\t//string input3 = Console.ReadLine();\n\t\t\t//string input4 = Console.ReadLine();\n\n\t\t\t//var inputs1 = input1.Split(new[] { ' ', '}', '{' , ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();\n\t\t\t//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\t\t\t//var inputs3 = input3.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\n\t\t\tlong n = long.Parse(input1);\n\n\t\t\tint length = input1.Length;\n\t\t\tif (length < 2) \n\t\t\t{\n\t\t\t\tConsole.WriteLine(n);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlong copyN = n;\n\t\t\twhile (copyN % 10 == 0) \n\t\t\t{\n\t\t\t\tcopyN--;\n\t\t\t}\n\t\t\tlong max = 1;\n\t\t\twhile (copyN > 0)\n\t\t\t{\n\t\t\t\tmax *= copyN % 10;\n\t\t\t\tcopyN /= 10;\n\t\t\t}\n\n\t\t\tfor (int i = 1; i < length; i++) \n\t\t\t{\n\t\t\t\tcopyN = n;\n\t\t\t\tlong current = 0;\n\t\t\t\tfor (int j = 0; j < i; j++) \n\t\t\t\t{\n\t\t\t\t\tcurrent += 9 * (long)Math.Pow(10, j);\n\t\t\t\t}\n\n\t\t\t\tvar temp = copyN - current;\n\t\t\t\ttemp /= (long)Math.Pow(10, i);\n\t\t\t\tcurrent += temp * (long)Math.Pow(10, i);\n\n\t\t\t\tlong currentMax = 1;\n\t\t\t\twhile (current > 0) \n\t\t\t\t{\n\t\t\t\t\tcurrentMax *= current % 10;\n\t\t\t\t\tcurrent /= 10;\n\t\t\t\t}\n\n\t\t\t\tif (currentMax > max) \n\t\t\t\t{\n\t\t\t\t\tmax = currentMax;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tConsole.WriteLine(max);\n\t\t}\n\n\t\tstatic long Factorial(long a) \n\t\t{\n\t\t\treturn a > 1 ? a * Factorial(a - 1) : 1;\n\t\t}\n\t}\n}\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing System.Linq.Expressions;\nusing System.Text;\nnamespace Program {\n class MainClass {\n ////////////////////////////////////////////////////////////\n int N, K, T;\n void Solve() {\n io.i(out N, out K,out T);\n int ans = 0;\n if(T<=K){\n ans = Math.Min(N, T);\n }else if( N-T >= 0){\n ans = Math.Min(N, K);\n }else{\n ans = Math.Max(0, K - (T-N));\n }\n io.o(ans);\n }\n ////////////////////////////////////////////////////////////\n public static void Main() { new MainClass().Stream(); }\n IO io = new IO();\n void Stream() { Solve(); io.writeFlush(); }\n //void Stream() { Test(); io.writeFlush(); }\n void Test() { }\n #region MockMacro\n //cannot use break,continue,goto\n void FOR(int a, int b, Action act) { for (int i = a; i < b; ++i) act(i); }\n void FORR(int a, int b, Action act) { for (int i = a - 1; i >= b; --i) act(i); }\n #endregion\n ////////////////////////////////////////////////////////////\n }\n #region default\n class IO {\n TYPE tp;\n string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' };\n StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };\n public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); }\n public string Next() {\n if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];\n string st = Console.ReadLine();\n while (st == \"\") st = Console.ReadLine();\n nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n BufferCnt = 0;\n return nextBuffer[BufferCnt++];\n }\n public string String => Next();\n public char Char => char.Parse(String);\n public int Int => int.Parse(String);\n public long Long => long.Parse(String);\n public double Double => double.Parse(String);\n public string[] arr => Console.ReadLine().Split(' ');\n public char[] arrChar => Array.ConvertAll(arr, char.Parse);\n public int[] arrInt => Array.ConvertAll(arr, int.Parse);\n public long[] arrLong => Array.ConvertAll(arr, long.Parse);\n public double[] arrDouble => Array.ConvertAll(arr, double.Parse);\n public T i() { return tp.suitType(String); }\n public void i(out T v) { v = tp.suitType(String); }\n public void i(out T v1, out U v2) { i(out v1); i(out v2); }\n public void i(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); }\n public void i(out T v1, out U v2, out V v3, out W v4) {\n i(out v1); i(out v2); i(out v3); i(out v4);\n }\n public void i(out T v1, out U v2, out V v3, out W v4, out X v5) {\n i(out v1); i(out v2); i(out v3); i(out v4); i(out v5);\n }\n public void ini(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType(String); }\n public void ini(out T[] a, out U[] b, int n) {\n a = new T[n]; b = new U[n]; for (int i = 0; i < n; i++) { a[i] = i(); b[i] = i(); }\n }\n public void ini(out T[] a, out U[] b, out V[] c, int n) {\n a = new T[n]; b = new U[n]; c = new V[n];\n for (int i = 0; i < n; i++) { a[i] = i(); b[i] = i(); c[i] = i(); }\n }\n public void ini(out T[,] a, int h, int w) {\n a = new T[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i, j] = i();\n }\n public void o(T v) { Console.WriteLine(v); }\n public void o(params T[] a) { Array.ForEach(a, n => o(n)); }\n public void o(T[,] a) { a.GetLength(0).REP(i => { a.GetLength(1).REP(j => or(a[i, j] + \" \")); br(); }); }\n public void ol(T v) { Console.Write(v + \" \"); }\n public void ol(params T[] a) { o(connect(a)); }\n public void or(T a) { Console.Write(a); }\n public void br() { o(\"\"); }\n public void writeFlush() { Console.Out.Flush(); }\n private string connect(params T[] s) { return string.Join(\" \", s); }\n }\n class TYPE {\n public bool typeEQ() { return typeof(T).Equals(typeof(U)); }\n public T convertType(U v) { return (T)Convert.ChangeType(v, typeof(T)); }\n public T suitType(string s) {\n if (typeEQ()) return convertType(int.Parse(s));\n if (typeEQ()) return convertType(long.Parse(s));\n if (typeEQ()) return convertType(double.Parse(s));\n if (typeEQ()) return convertType(char.Parse(s));\n return convertType(s);\n }\n }\n class PQueue where T : IComparable {\n public List heap; private Comparison comp; private IComparer comparer;\n private int size; private int type;//type=0->min\n public PQueue(int type = 0) : this(Comparer.Default) { this.type = type; }\n public PQueue(IComparer comparer) : this(16, comparer.Compare) { this.comparer = comparer; }\n public PQueue(Comparison comparison) : this(16, comparison) { }\n public PQueue(int capacity, Comparison comparison) { this.heap = new List(capacity); this.comp = comparison; }\n public void Enqueue(T item) {\n this.heap.Add(item); var i = size++;\n while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; }\n this.heap[i] = item;\n }\n public T Dequeue() {\n var ret = this.heap[0]; var x = this.heap[--size]; var i = 0;\n while ((i << 1) + 1 < size) {\n var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b;\n if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a;\n }\n heap[i] = x; heap.RemoveAt(size);\n return ret;\n }\n public T Peek() { return heap[0]; }\n public int Count { get { return size; } }\n public bool Any() { return size > 0; }\n public bool Empty() { return !Any(); }\n public bool Contains(T v) { return heap.Contains(v); }\n private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); }\n }\n #endregion\n #region other\n class Mat {\n public long mod = 1000000007;//10^9+7\n public long Pow(long a, long b) {\n if (b == 0) return 1;\n if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod;\n else return Pow(a * a % mod, b / 2) % mod;\n }\n public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; }\n public long ModC(long n, long r) {\n if (r == 0 || n == r) return 1;\n if (n == 0) return 0;\n if (n < 0 || n < r) throw new ArgumentException(\"n,r invalid\");\n else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod;\n }\n public long[,] C(int N) {\n long[,] Co = new long[N + 1, N + 1];\n (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j]));\n return Co;\n }\n public long DupC(long n, long r) { return ModC(n + r - 1, r); }\n public long P(long n, long r) { return Fact(n) / (Fact(n - r)); }//test\n public bool isPrime(long n) {\n if (n == 2) return true; if (n < 2 || n % 2 == 0) return false;\n for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false;\n return true;\n }\n public long LCM(long a, long b) { return a * (b / GCD(a, b)); }\n public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }\n public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); }\n public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); }\n public T Max(params T[] a) { return a.Max(); }\n public T Min(params T[] a) { return a.Min(); }\n public void Swap(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }\n public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); }\n public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); }\n public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; }\n public long DigArr2Num(IEnumerable enu) { return enu.Aggregate((v, n) => v * 10 + n); }\n public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }\n public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); }\n public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }\n public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; }\n public long[] enuDivsor(long N) {\n var ret = new SortedSet();\n for (long i = 1; i * i <= N; i++)\n if (N % i == 0) { ret.Add(i); ret.Add(N / i); }\n return ret.ToArray();\n }\n public IEnumerable enuP(int[] Arr, int Use = -1) {//列挙順列\n Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break;\n var s = new Stack>();\n Arr.Length.REPR(i => s.Push(new List() { i }));\n while (s.Count > 0) {\n var cur = s.Pop();\n if (cur.Count == Use) {\n var ret = new List(); cur.ForEach(X => ret.Add(Arr[X]));\n yield return ret.ToArray();\n } else\n Arr.Length.REPR(i => { if (!cur.Contains(i)) s.Push(new List(cur) { i }); });\n }\n }\n public IEnumerable enuC(int[] Arr, int Use = -1) {//列挙組み合わせ\n Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break;\n var s = new Stack>>();\n Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List() { Arr[i] })));\n while (s.Count > 0) {\n var cur = s.Pop();\n if (cur.Item2.Count == Use) yield return cur.Item2.ToArray();\n else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)\n s.Push(Tuple.Create(i, new List(cur.Item2) { Arr[i] }));\n }\n }\n public IEnumerable enuDupP(int[] Arr, int Use = -1) {//列挙重複順列\n Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack>();\n Arr.Length.REPR(i => s.Push(new List() { Arr[i] }));\n while (s.Count > 0) {\n var cur = s.Pop();\n if (cur.Count == Use) yield return cur.ToArray();\n else Arr.Length.REPR(i => s.Push(new List(cur) { Arr[i] }));\n }\n }\n public IEnumerable enuDupC(int[] Arr, int Use = -1) {//列挙組み合わせ\n Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break;\n var s = new Stack>>();\n Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List() { Arr[i] })));\n while (s.Count > 0) {\n var cur = s.Pop();\n if (cur.Item2.Count == Use) yield return cur.Item2.ToArray();\n else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)\n s.Push(Tuple.Create(i, new List(cur.Item2) { Arr[i] }));\n }\n }\n public IEnumerable enuPart(string str) {\n var s = new Stack, int>>();\n s.Push(Tuple.Create(str[0].ToString(), new List(), 1));\n while (s.Count > 0) {\n var cur = s.Pop();\n if (cur.Item3 >= str.Length) yield return (new List(cur.Item2) { cur.Item1.toLong() }).ToArray();\n else {\n s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List(cur.Item2), cur.Item3 + 1));\n s.Push(Tuple.Create(str[cur.Item3].ToString(), new List(cur.Item2) { cur.Item1.toLong() }, cur.Item3 + 1));\n }\n }\n }\n }\n class Time {\n public int[] M = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };\n public int[] D = { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n public Time() { D[1] = 28; }\n public Time(int y) { D[1] = isLeapYear(y) ? 29 : 28; }\n public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); }\n }\n #endregion\n #region Data\n class AssociativeArray : IEnumerable {\n public Dictionary dic;\n public AssociativeArray() { dic = new Dictionary(); }\n public AssociativeArray(params T[] a) { dic = new Dictionary(); Add(a); }\n public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; }\n public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); }\n public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; }\n public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); }\n public T[] Keys() { return dic.Keys.ToArray(); }\n public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }\n public int ValSum => dic.Values.Sum();\n public int KeyNum => dic.Keys.Count;\n public int MaxVal => dic.Values.Max();\n public int MinVal => dic.Values.Min();\n public T MaxKey => MaxK();\n public T MinKey => MinK();\n public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; }\n public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; }\n public bool conK(T k) { return dic.ContainsKey(k); }\n public bool anyK(params T[] k) { return k.Any(key => conK(key)); }\n public bool allK(params T[] k) { return k.All(key => conK(key)); }\n public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + \" : \" + v.Value); } }\n public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; }\n public T[] ValueSortedKey(bool inc = true) {//test\n return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value)))\n .ThenBy(kp => kp.Key).ToDictionary(kp => kp.Key, kp => kp.Value).Keys.ToArray();\n }\n //:sort->array\n }\n class Index {\n public int[] Comp(int[] bef) {\n int[] aft = new int[bef.Length];\n var tmp = bef.Distinct().OrderBy(v => v).Select((v, i) => new { v, i }).ToDictionary(p => p.v, p => p.i);\n aft = bef.Select(v => tmp[v]).ToArray();\n return aft;\n }\n }\n class TreeDis {//TODO:shortestPath\n public List>[] g; public long[] a2other; private int type;\n public TreeDis(int type = 0) { this.type = type; }//0->bfs,other->dfs\n public void Init(long n) { g = new List>[n + 1]; g.Length.REP(i => g[i] = new List>()); }\n public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); }\n public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); }\n public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; }\n private void BFS(long a) {\n var q = new Queue>(); q.Enqueue(Tuple.Create(a, -1L));\n while (q.Count > 0) {\n var c = q.Dequeue();\n foreach (var v in g[c.Item1]) {\n if (v.Item1 == c.Item2) continue;\n a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1));\n }\n }\n }\n private void DFS(long a) {\n var s = new Stack>(); s.Push(Tuple.Create(a, -1L));\n while (s.Count > 0) {\n var c = s.Pop();\n foreach (var v in g[c.Item1]) {\n if (v.Item1 == c.Item2) continue;\n a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1));\n }\n }\n }\n }\n class ShortestPath {\n public long INF = (long)1e15; protected int I = -1; protected int V; protected int E; public long[] cost;\n public List>[] Adj; protected bool isNonDir = true;\n public void Init(int n) { I = n + 1; V = n; Adj = new List>[I]; I.REP(i => Adj[i] = new List>()); }\n public void AddPath(int f, int t, long c) {\n E++;\n if (isNonDir) {\n Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c));\n } else {\n Adj[f].Add(Tuple.Create(t, c));\n }\n }\n public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); }\n }\n class Dijkstra : ShortestPath {//隣接対応後検証不足,有向とか\n public long MinCost(int f, int t) {\n cost = new long[I]; cost.Set(INF); cost[f] = 0;\n var pq = new PQueue>(); pq.Enqueue(Tuple.Create(f, 0L));//(from,cost)\n while (pq.Count > 0) {\n var cur = pq.Dequeue();\n if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => {\n var tmp = Adj[cur.Item1][i];\n if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {\n cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));\n }\n });\n }\n return cost[t];\n }\n }\n class BellmanFord : ShortestPath {\n private bool[] neg;\n public BellmanFord() { }\n public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; }\n public long MinCost(int f, int t) {\n cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I];\n for (int i = 0; i < I - 1; i++) {\n I.REP(j => Adj[j].Count.REP(k => {\n var cur = Adj[j][k];\n if (cost[cur.Item1] > cost[j] + cur.Item2)\n cost[cur.Item1] = cost[j] + cur.Item2;\n }));\n }\n for (int i = 0; i < I; i++) {\n I.REP(j => Adj[j].Count.REP(k => {\n var cur = Adj[j][k];\n if (cost[cur.Item1] > cost[j] + cur.Item2) {\n cost[cur.Item1] = cost[j] + cur.Item2;\n neg[cur.Item1] = true;\n }\n if (neg[j]) neg[cur.Item1] = true;\n }));\n }\n return cost[t];\n }\n public bool loopExist() { return neg[I - 1]; }\n }\n class WarshallFloyd {//そのうちAdjとどっちがいいか...TODO:ジェネリック\n private int E; private int INF = (int)1e9; public long[,] G;\n public void Init(int n) { E = n + 1; G = new long[E, E]; G.Set(INF); E.REP(i => G[i, i] = 0); }\n public void AddPath(int f, int t, long c) { G[f, t] = c; G[t, f] = c; }\n public void AddPath(int[] f, int[] t) { f.Length.REP(i => AddPath(f[i], t[i], 1)); }\n public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); }\n public void Run() { G = MinCostArr(); }\n public long[,] MinCostArr() { E.REP(i => E.REP(j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k])))); return G; }\n }\n class UnionFind {\n public long[] parent; public long[] depth; private int I;\n public void Init(int n) { I = n + 1; parent = new long[I]; depth = new long[I]; I.REP(i => parent[i] = i); }\n public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); }\n public void Unite(long x, long y) {\n x = Find(x); y = Find(y); if (x == y) return;\n if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; }\n }\n public bool Same(int a, int b) { return Find(a) == Find(b); }\n public long Size(int x) { return depth[Find(x)]; }\n }\n class Kruskal : ShortestPath {//TODO:test,\n public long Run() {\n var L = Adj.Select((l, i) => Tuple.Create(i, l[i].Item1, l[i].Item2)).OrderBy(t => t.Item3).ToList();\n //var li = new List>();\n //I.REP(i =>{ foreach (var t in Adj[i]) li.Add(Tuple.Create(i, t.Item1, t.Item2));});\n //li = li.OrderBy(t => t.Item3).ToList();//li = li.OrderByDescending(t => t.Item3).ToList();\n var uf = new UnionFind(); uf.Init(V); long ret = 0;\n foreach (var t in L) {\n if (!uf.Same(t.Item1, t.Item2)) {\n ret += t.Item3; uf.Unite(t.Item1, t.Item2);\n }\n }\n return ret;\n }\n }\n #endregion\n #region Ex\n static class StringEX {\n public static string Reversed(this string s) { return string.Join(\"\", s.Reverse()); }\n public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); }\n public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; }\n public static int toInt(this char c) { return toInt(c.ToString()); }\n public static int toInt(this char[] c) { return toInt(new string(c)); }\n public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; }\n public static long toLong(this char c) { return toLong(c.ToString()); }\n public static long toLong(this char[] c) { return toLong(new string(c)); }\n public static string toString(this char[] c) { return new string(c); }\n }\n static class NumericEx {\n public static string pad0(this T v, int n) { return v.ToString().PadLeft(n, '0'); }\n public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); }\n public static bool Odd(this int v) { return v % 2 != 0; }\n public static bool Odd(this long v) { return v % 2 != 0; }\n public static void REP(this int v, Action act) { for (int i = 0; i < v; ++i) act(i); }\n public static void REPR(this int v, Action act) { for (int i = v - 1; i >= 0; --i) act(i); }\n }\n static class ArrayEX {\n public static T[] Sort(this T[] a) { Array.Sort(a); return a; }\n public static T[] SortR(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; }\n public static void Set(this T[] a, T v) { a.Length.REP(i => a[i] = v); }\n public static void Set(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); }\n }\n static class BitEx {\n public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; }\n public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; }\n public static bool None(this BitArray b) { return !Any(b); }\n public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); }\n }\n static class IEnumerableEx {\n //\n }\n #endregion\n}", "src_uid": "7e614526109a2052bfe7934381e7f6c2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\n\nclass Program\n{\n public static int[] Read(string str)\n {\n string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n int[] ret = new int[tokens.Length];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = int.Parse(tokens[i]);\n }\n\n return ret;\n }\n\n public static long[] ReadLong(string str)\n {\n string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n long[] ret = new long[tokens.Length];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = long.Parse(tokens[i]);\n }\n\n return ret;\n }\n\n public static double[] ReadDouble(string str)\n {\n string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n double[] ret = new double[tokens.Length];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = double.Parse(tokens[i], CultureInfo.InvariantCulture);\n }\n\n return ret;\n }\n\n static string Reverse(string s)\n {\n char[] a = s.ToCharArray();\n Array.Reverse(a);\n return new string(a);\n }\n\n static bool Check(string t)\n {\n for (int i = 0; i < t.Length; i++)\n {\n if (char.IsLetterOrDigit(t[i]) == false && t[i] != '_')\n {\n return false;\n }\n }\n\n return true;\n }\n\n static void Main(string[] args)\n {\n int[] abc = Read(Console.ReadLine());\n int[] def = Read(Console.ReadLine());\n\n if ((abc[0] == 0 && abc[1] == 0 && abc[2] != 0) || (def[0] == 0 && def[1] == 0 && def[2] != 0))\n {\n Console.WriteLine(\"0\");\n return;\n }\n \n if (abc[0] * def[1] == abc[1] * def[0])\n {\n if (abc[0] * def[2] == abc[2] * def[0] && abc[1] * def[2] == abc[2] * def[1])\n {\n Console.WriteLine(\"-1\");\n }\n else\n {\n Console.WriteLine(\"0\");\n }\n }\n else\n {\n Console.WriteLine(\"1\");\n }\n }\n}\n", "src_uid": "c8e869cb17550e888733551c749f2e1a"} {"source_code": "using System;\n\nnamespace codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n int a1 = int.Parse(Console.ReadLine());\n int a2 = int.Parse(Console.ReadLine());\n int k1 = int.Parse(Console.ReadLine());\n int k2 = int.Parse(Console.ReadLine());\n int n = int.Parse(Console.ReadLine());\n\n int r = a1 * (k1 - 1) + a2 * (k2 - 1);\n int min = (n - r < 0 ? 0 : n-r);\n int max = 0;\n int minCard, maxCard, minTeam, maxTeam;\n if (k1 < k2)\n {\n minCard = k1; minTeam = a1;\n maxCard = k2; maxTeam = a2;\n }\n else\n {\n minCard = k2; minTeam = a2;\n maxCard = k1; maxTeam = a1;\n }\n max = Math.Min(n/minCard,minTeam);\n n -= max*minCard;\n max += Math.Min(n / maxCard, maxTeam);\n\n Console.WriteLine($\"{min} {max}\");\n }\n }\n}", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split(' ');\n int fl = int.Parse(s[0]);\n int fr = int.Parse(s[1]);\n bool can = false ;\n s = Console.ReadLine().Split(' ');\n int ml = int.Parse(s[0]);\n int mr = int.Parse(s[1]);\n if (fr *2+2 >= ml && fr <= ml + 1) \n {\n can = true;\n } if (fl * 2+2 >= mr && fl <= mr + 1)\n {\n can = true;\n }\n if (can)\n {\n Console.WriteLine(\"YES\");\n }\n else \n {\n Console.WriteLine(\"NO\");\n }\n }\n\n \n }\n}\n", "src_uid": "36b7478e162be6e985613b2dad0974dd"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace RM_B_298\n{\n class Program : InputReader\n {\n static void Main(string[] args)\n {\n string[] s = f.ReadLine().Split(' ');\n int v1 = int.Parse(s[0]), v2 = int.Parse(s[1]);\n s = f.ReadLine().Split(' ');\n int t = int.Parse(s[0]), d = int.Parse(s[1]);\n\n int[] a = new int[t];\n a[0] = v1;\n a[t - 1] = v2;\n for (int i = 1; i < t - 1; i++)\n {\n a[i] = a[i - 1] + d;\n }\n\n for (int i = t - 2; i > 0; i--)\n {\n if (a[i] > (a[i + 1] + d))\n {\n a[i] = a[i + 1] + d;\n }\n }\n int ans = 0;\n for (int i = 0; i < t; i++)\n {\n ans += a[i];\n }\n Console.WriteLine(ans);\n Console.ReadLine();\n }\n }\n\n class InputReader\n {\n //public static TextReader f = new StreamReader(\"input.txt\");\n public static TextReader f = Console.In;\n }\n}\n", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace TechnoCup3A\n{\n public class Program\n {\n static void Main(string[] args)\n {\n string[] str = Console.ReadLine().Split();\n int[] arr = new int[6];\n int max = 0;\n bool flag = false;\n for (int i = 0; i < 6; i++)\n {\n arr[i] = Int32.Parse(str[i]);\n max += arr[i];\n }\n for (int i = 1; i < 6; i++)\n {\n int max1 = arr[0];\n max1 += arr[i];\n for (int j = i + 1; j < 6; j++)\n {\n max1 += arr[j];\n if (max1 == max - max1)\n {\n Console.Write(\"YES\");\n flag = true;\n break;\n \n }\n max1 = arr[0] + arr[i];\n }\n if (flag == true) break;\n }\n if (flag == false) Console.Write(\"NO\");\n //Console.ReadKey();\n\n }\n }\n}\n", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"source_code": "using System;\n\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int zobmieCount = Convert.ToInt32(Console.ReadLine());\n\n int brainCount;\n\n if (zobmieCount % 2 != 0)\n if (zobmieCount == 1)\n {\n Console.WriteLine(\"1\");\n return;\n }\n else\n brainCount = (int)(zobmieCount / 2) + 1;\n else\n brainCount = zobmieCount / 2;\n\n Console.WriteLine(brainCount);\n //Console.ReadKey();\n }\n }\n}\n", "src_uid": "30e95770f12c631ce498a2b20c2931c7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Web.UI.WebControls;\n\nnamespace Codeforces\n{\n class Program : IDisposable\n {\n private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());\n private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());\n\n \n private void Solve()\n {\n var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n var c = s[0];\n var v = s[1];\n var vMax = s[2];\n var a = s[3];\n var l = s[4];\n\n int cnt = v;\n int res = 1;\n int multiplier = 1;\n while (cnt < c)\n {\n if (v + multiplier*a < vMax)\n {\n cnt+= (v + multiplier * a - l);\n }\n else\n {\n cnt+= vMax-l;\n }\n multiplier++;\n res++;\n }\n Console.WriteLine(res);\n }\n\n int BinarySearch(int[] arr, int q)\n {\n var l = 0;\n var r = arr.Length - 1;\n //int med = -1;\n while (l <= r)\n {\n var med = l + (r - l) / 2;\n if (arr[med] == q)\n {\n return med;\n }\n if (q < arr[med])\n {\n r = med - 1;\n }\n else\n {\n l = med + 1;\n }\n }\n return -1;\n }\n\n \n \n static void Main(string[] args)\n {\n var p = new Program();\n p.Solve();\n // Console.ReadLine();\n p.Dispose();\n }\n\n #region Helpers\n\n private static int ReadInt()\n {\n return int.Parse(textReader.ReadLine());\n }\n\n private static long ReadLong()\n {\n return long.Parse(textReader.ReadLine());\n }\n\n private static int[] ReadIntArray()\n {\n return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();\n }\n #endregion\n\n public void Dispose()\n {\n textReader.Close();\n textWriter.Close();\n }\n }\n \n public class ListNode\n {\n public int val;\n public ListNode next;\n public ListNode(int x) { val = x; }\n }\n\n}\n", "src_uid": "b743110117ce13e2090367fd038d3b50"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Numerics;\n\n\nclass PairVariable : IComparable\n{\n public int a, b;\n public int c;\n public PairVariable()\n {\n a = b = 0;\n c = 0;\n }\n public PairVariable(string s)\n {\n string[] q = s.Split();\n a = int.Parse(q[0]);\n b = int.Parse(q[1]);\n c = 0;\n\n }\n\n public PairVariable(int a, int b, int c)\n {\n this.a = a;\n this.b = b;\n this.c = c;\n\n }\n\n\n\n public int CompareTo(PairVariable other)\n {\n return this.c.CompareTo(other.c);\n }\n}\n\nnamespace ConsoleApplication3\n{\n class Program\n {\n\n\n static bool isPrime(int n)\n {\n for (int i = 2; i <= Math.Sqrt(n); i++)\n {\n if (n % i == 0)\n {\n return false;\n }\n }\n return true;\n }\n static int gcd(int a, int b)\n {\n if (b == 0)\n {\n return a;\n }\n else\n {\n return gcd(b, a % b);\n }\n }\n \n static int[] mark;\n static Dictionary> d = new Dictionary>();\n static void dfs(int v)\n {\n mark[v] = 1;\n for (int i = 0; i < d[v].Count; i++)\n {\n if (mark[d[v][i]] == 0)\n {\n dfs(d[v][i]);\n }\n }\n }\n static void Main(string[] args)\n {\n long ans = 0;\n string[] ss = Console.ReadLine().Split();\n int n = int.Parse(ss[0]);\n string[] s = Console.ReadLine().Split();\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n {\n a[i] = int.Parse(s[i]);\n }\n Array.Sort(a);\n for (int i = n - 1; i >= 0; i--)\n {\n for (int e = i - 1; e >= 0; e--)\n {\n if (a[e] >= a[i])\n {\n a[e] = Math.Max(0, a[i] - 1);\n }\n }\n }\n for (int i = 0; i < n; i++)\n {\n ans += a[i];\n }\n Console.WriteLine(ans);\n }\n }\n}", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces0710B\n{\n class Program\n {\n\n static bool isprime(long a)\n {\n\n for(long i = 2;i<=Math.Sqrt(a);i++)\n {\n if (a % i == 0)\n return false;\n }\n\n return true;\n }\n static void Main(string[] args)\n {\n\n int testCases;\n testCases = int.Parse(Console.ReadLine());\n\n while (testCases-- > 0)\n {\n\n string read;\n read = Console.ReadLine();\n long a = long.Parse(read.Split(' ').ToList()[0]);\n long b = long.Parse(read.Split(' ').ToList()[1]);\n\n bool flag = true;\n\n if (a % 2 == 1 && b % 2 == 1)\n {\n flag = false;\n }\n\n if (a % 2 == 0 && b % 2 == 0)\n {\n flag = false;\n }\n\n if (a - b > 1)\n {\n flag = false;\n }\n\n if(flag)\n {\n flag = isprime(a + b);\n }\n\n if(flag)\n {\n Console.WriteLine(\"YES\");\n }\n else\n {\n Console.WriteLine(\"NO\");\n }\n\n }\n }\n }\n}\n", "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"source_code": "using System;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n public static long Rec(long ss, long i, long s, long l, long r, long x, long n, long[] mas, long k)\n {\n s += mas[i];\n if ((s <= r) && (s >= l) && ((mas[i] - mas[k]) >= x))\n {\n ss++;\n }\n if (s < r)\n {\n for (long j = i + 1; j < n; j++)\n {\n ss = Rec(ss, j, s, l, r, x, n, mas, k);\n }\n }\n return ss;\n }\n static void Main(string[] args)\n {\n long n, l, r, x;\n\n string[] lines = Console.ReadLine().Split(' ');\n n = long.Parse(lines[0]);\n l = long.Parse(lines[1]);\n r = long.Parse(lines[2]);\n x = long.Parse(lines[3]);\n long[] mas;\n mas = new long[n];\n string[] lines1 = Console.ReadLine().Split(' ');\n for (long i = 0; i < n; i++)\n mas[i] = long.Parse(lines1[i]);\n\n for (long i = 0; i < mas.Length; i++)\n {\n for (long j = 0; j < mas.Length - 1; j++)\n {\n if (mas[j] > mas[j + 1])\n {\n long z = mas[j];\n mas[j] = mas[j + 1];\n mas[j + 1] = z;\n }\n }\n }\n long s = 0, ss = 0, sl = 0;\n for (long jj = 0; jj < (n - 1); jj++)\n {\n sl = Rec(0, jj, s, l, r, x, n, mas, jj);\n ss += sl;\n }\n Console.WriteLine(ss);\n // Console.ReadLine();\n }\n\n\n }\n}", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n public void Solve()\n {\n int n = ReadInt();\n\n var a = new bool[n, n];\n for (int m = ReadInt(); m > 0; m--)\n {\n int u = ReadInt() - 1;\n int v = ReadInt() - 1;\n a[u, v] = a[v, u] = true;\n }\n\n var g = Init>(n);\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n if (i != j && !a[i, j])\n g[i].Add(j);\n\n var ans = new char[n];\n bool f = false;\n for (int i = 0; i < n; i++)\n if (ans[i] == 0)\n {\n if (g[i].Count == 0)\n {\n ans[i] = 'b';\n continue;\n }\n if (f)\n {\n Write(\"No\");\n return;\n }\n f = true;\n var q = new Queue();\n q.Enqueue(i);\n ans[i] = 'a';\n while (q.Count > 0)\n {\n int x = q.Dequeue();\n foreach (int e in g[x])\n if (ans[e] != 0)\n {\n if (ans[e] == ans[x])\n {\n Write(\"No\");\n return;\n }\n }\n else\n {\n ans[e] = ans[x] == 'a' ? 'c' : 'a';\n q.Enqueue(e);\n }\n }\n }\n\n for (int i = 0; i < n; i++)\n for (int j = i + 1; j < n; j++)\n if ((ans[i] == 'a' && ans[j] == 'c' || ans[i] == 'c' && ans[j] == 'a') && a[i, j])\n {\n Write(\"No\");\n return; \n }\n\n Write(\"Yes\");\n Write(new string(ans));\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"input.txt\");\n //writer = new StreamWriter(\"output.txt\");\n#endif\n try\n {\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n new Solver().Solve();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "e71640f715f353e49745eac5f72e682a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp5\n{\n class Program\n {\n static Stack GetBinaryNumber(long number)\n {\n Stack result = new Stack();\n while (number != 0)\n {\n result.Push(number % 2 == 1);\n number /= 2;\n }\n return result;\n }\n static long FastDegree(long number, long pow)\n {\n long result = 1;\n Stack StackPow = GetBinaryNumber(pow);\n while (StackPow.Count != 0)\n {\n result *= result;\n result %= (int)(1e9 + 7);\n if (StackPow.Pop())\n {\n result *= number;\n result %= (int)(1e9 + 7);\n }\n }\n return result;\n }\n\n static int GetCountOne(int number)\n {\n int result = 0;\n while (number != 0)\n {\n if ((number & 1) == 1)\n result++;\n number /= 2;\n }\n return result;\n }\n static void Main(string[] args)\n {\n string[] str = Console.ReadLine().Split();\n int n = int.Parse(str[0]);\n int m = int.Parse(str[1]);\n if (n < 7)\n {\n Console.WriteLine(m);\n }\n else\n {\n List> G = new List>();\n for (int i = 0; i < 7; i++)\n {\n G.Add(new HashSet());\n }\n int temp = m;\n while(temp-- !=0)\n {\n str = Console.ReadLine().Split();\n int first = int.Parse(str[0]) - 1;\n int second = int.Parse(str[1]) - 1;\n G[first].Add(second);\n G[second].Add(first);\n }\n int min = 6;\n for(int i =0; i= 3 || aux[i] <= 1)\n {\n f = true;\n break;\n }\n }\n\n if(f)\n {\n Console.WriteLine(\"WIN\");\n }\n else\n {\n Console.WriteLine(\"FAIL\");\n }\n }\n }\n}\n", "src_uid": "2bc18799c85ecaba87564a86a94e0322"} {"source_code": "using System;\n\nnamespace TaskB {\n internal class Program {\n private static void Main(string[] args) {\n int n = int.Parse(Console.ReadLine());\n Console.WriteLine(2 * n / 4 * 3);\n }\n }\n}", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1.Combynatorycs\n{\n class _776\n {\n static void Main(String[] args)\n {\n var n = int.Parse(Console.ReadLine());\n var data1 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();\n var data2 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();\n\n var res1 = new int[6];\n var res2 = new int[6];\n\n for(var i = 0; i < data1.Count; i++)\n {\n res1[data1[i]]++;\n res2[data2[i]]++;\n }\n\n var result = 0;\n for(var i = 1; i <= 5; i++)\n {\n var c = res1[i] + res2[i];\n if (c % 2 != 0)\n {\n Console.WriteLine(-1);\n return;\n }\n result += Math.Abs(res1[i] - res2[i]) / 2;\n }\n\n if (result % 2 != 0)\n {\n Console.WriteLine(-1);\n return;\n }\n\n Console.WriteLine(result/2);\n\n }\n }\n}\n", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"source_code": "using System;\nusing System.Linq;\nusing System.IO;\nusing System.Collections.Generic;\n// Powered by caide (code generator, tester, and library code inliner)\n\nclass Solution {\n public void solve(TextReader input, TextWriter output) {\n string s1 = input.ReadLine();\n string s2 = input.ReadLine();\n int index = 0;\n foreach(char c in s2)\n {\n if(c == s1[index])\n {\n index++;\n }\n }\n output.Write(index + 1);\n }\n}\n\nclass CaideConstants {\n public const string InputFile = null;\n public const string OutputFile = null;\n}\npublic class Program {\n public static void Main(string[] args) {\n Solution solution = new Solution();\n using (System.IO.TextReader input =\n CaideConstants.InputFile == null ? System.Console.In :\n new System.IO.StreamReader(CaideConstants.InputFile))\n using (System.IO.TextWriter output =\n CaideConstants.OutputFile == null ? System.Console.Out:\n new System.IO.StreamWriter(CaideConstants.OutputFile))\n\n solution.solve(input, output);\n }\n}\n\n", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace A.Theatre_Square\n{\n class Program\n {\n static int sq2(int k)\n {\n return (1 << k) - 1;\n }\n\n static void Main(string[] args)\n {\n string[] data = Console.ReadLine().Trim().Split(' ');\n int n = Int32.Parse(data[0]);\n int h = Int32.Parse(data[1]);\n Int64[,] f=new Int64[36,36];\n f[0, 0] = 1;\n f[1, 1] = 1;\n for (int i = 2; i <= n; i++)\n {\n for (int j = i; j <= n; j++)\n {\n for (int k = 0; k <= j - 1; k++)\n {\n for (int l = (int)Math.Ceiling(Math.Log(k + 1, 2)); l <= k; l++)\n {\n for (int r = (int)Math.Ceiling(Math.Log(j - k, 2)); r <= j - k - 1; r++)\n {\n if((l==i-1 || r==i-1)&&(l 0 && b d.Length)\n {\n int L = b-d.Length;\n kq = kq + d;\n for (int i = 1; i <= L; i++)\n {\n kq = kq + \"0\";\n }\n }\n else if (a == b && a == 0)\n {\n kq = \"0\";\n }\n Console.WriteLine(kq);\n }\n}", "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"source_code": "using System;\n\nclass Program {\n\tpublic static void Main() {\n#if DVORAK\n\t\tConsole.SetIn(new System.IO.StreamReader(\"..\\\\..\\\\in.txt\"));\n#endif\n\t\tString[] mon = { \"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\" };\n\n\t\tConsole.WriteLine(mon[(Array.IndexOf(mon, Console.ReadLine()) + Int32.Parse(Console.ReadLine())) % mon.Length]);\n\t}\n}\n", "src_uid": "a307b402b20554ce177a73db07170691"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces\n{\n\tinternal class Template\n\t{\n\t\tprivate Dictionary, long> dp; \n\n\t\tprivate void Solve()\n\t\t{\n\t\t\tdp = new Dictionary, long>();\n\n\t\t\tvar n = cin.NextLong();\n\t\t\tvar l = cin.NextLong();\n\t\t\tvar r = cin.NextLong();\n\n\t\t\tif (n == 0)\n\t\t\t{\n\t\t\t\tConsole.WriteLine(0);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar count = Count(n, l-1, r-1);\n\t\t\tConsole.WriteLine(count);\n\t\t}\n\n\t\tprivate long Count(long n, long l, long r)\n\t\t{\n\t\t\tif (n == 1)\n\t\t\t{\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tif (dp.ContainsKey(Tuple.Create(n, l, r)))\n\t\t\t{\n\t\t\t\treturn dp[Tuple.Create(n, l, r)];\n\t\t\t}\n\n\t\t\tvar idx = 0;\n\t\t\tvar nn = n;\n\t\t\twhile (nn > 1)\n\t\t\t{\n\t\t\t\tidx++;\n\t\t\t\tnn/=2;\n\t\t\t}\n\t\t\tvar len = 1L;\n\t\t\tfor (var i = 0; i < idx; i++)\n\t\t\t{\n\t\t\t\tlen *= 2;\n\t\t\t\tlen++;\n\t\t\t}\n\t\t\tvar middle = len/2;\n\t\t\tvar sum = 0L;\n\t\t\tif (l <= middle && r >= middle)\n\t\t\t{\n\t\t\t\tsum += n%2;\n\t\t\t\tif (l < middle)\n\t\t\t\t{\n\t\t\t\t\tsum += Count(n/2, l, middle - 1);\n\t\t\t\t}\n\t\t\t\tif (r > middle)\n\t\t\t\t{\n\t\t\t\t\tsum += Count(n/2, 0, r - middle - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (l < middle)\n\t\t\t{\n\t\t\t\tsum += Count(n/2, l, r);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsum += Count(n/2, l - middle - 1, r - middle - 1);\n\t\t\t}\n\t\t\tdp[Tuple.Create(n, l, r)] = sum;\n\t\t\treturn sum;\n\t\t}\n\n\t\tprivate static readonly Scanner cin = new Scanner();\n\n\t\tprivate static void Main()\n\t\t{\n#if DEBUG\n\t\t\tvar inputText = File.ReadAllText(@\"..\\..\\input.txt\");\n\t\t\tvar testCases = inputText.Split(new[] { \"input\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\tvar consoleOut = Console.Out;\n\t\t\tfor (var i = 0; i < testCases.Length; i++)\n\t\t\t{\n\t\t\t\tvar parts = testCases[i].Split(new[] { \"output\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\t\tConsole.SetIn(new StringReader(parts[0].Trim()));\n\t\t\t\tvar stringWriter = new StringWriter();\n\t\t\t\tConsole.SetOut(stringWriter);\n\t\t\t\tvar sw = Stopwatch.StartNew();\n\t\t\t\tnew Template().Solve();\n\t\t\t\tsw.Stop();\n\t\t\t\tvar output = stringWriter.ToString();\n\n\t\t\t\tConsole.SetOut(consoleOut);\n\t\t\t\tvar color = ConsoleColor.Green;\n\t\t\t\tvar status = \"Passed\";\n\t\t\t\tif (parts[1].Trim() != output.Trim())\n\t\t\t\t{\n\t\t\t\t\tcolor = ConsoleColor.Red;\n\t\t\t\t\tstatus = \"Failed\";\n\t\t\t\t}\n\t\t\t\tConsole.ForegroundColor = color;\n\t\t\t\tConsole.WriteLine(\"Test {0} {1} in {2}ms\", i + 1, status, sw.ElapsedMilliseconds);\n\t\t\t}\n\t\t\tConsole.ReadLine();\n\t\t\tConsole.ReadKey();\n#else\n\t\t\tnew Template().Solve();\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\t}\n\n\tinternal class Scanner\n\t{\n\t\tprivate string[] s = new string[0];\n\t\tprivate int i;\n\t\tprivate readonly char[] cs = { ' ' };\n\n\t\tpublic string NextString()\n\t\t{\n\t\t\tif (i < s.Length) return s[i++];\n\t\t\tvar line = Console.ReadLine() ?? string.Empty;\n\t\t\ts = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n\t\t\ti = 1;\n\t\t\treturn s.First();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn double.Parse(NextString());\n\t\t}\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn int.Parse(NextString());\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn long.Parse(NextString());\n\t\t}\n\t}\n}", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace RocketB\n{\n class Program\n {\n \n private class Bid\n {\n public int Index;\n public bool Left;\n public int Value;\n public double[] WinRate;\n }\n\n static void Main(string[] args)\n {\n string str = Console.ReadLine();\n int n = 0;\n int.TryParse(str, out n);\n\n var R = new int[n];\n var L = new int[n];\n int min = 100000;\n int max = 0;\n for(int i = 0; i < n; i++)\n {\n str = Console.ReadLine();\n var strs = str.Split(' ');\n int l = 0;\n int r = 0;\n int.TryParse(strs[0], out l);\n int.TryParse(strs[1], out r);\n L[i] = l;\n R[i] = r;\n if(l < min) min = l;\n if(r > max) max = r;\n }\n\n double expected = 0d;\n\n //var debug = new double[max + 1];\n //double weightSum =0;\n for (int price = min; price <= max; price++)\n {\n\n double weight = 0;\n double exactlyOne = 0;\n double less = 1d;\n double notMore = 1d;\n for(int i =0; i < n; i++)\n {\n var ri = R[i];\n var li = L[i];\n var di = ri - li + 1;\n double imoreprob;\n double iNotMoreProb;\n double here = 0d;\n if(li > price)\n {\n less = 0;\n notMore = 0;\n imoreprob = 1;\n iNotMoreProb = 0;\n }\n else\n if(ri < price)\n {\n imoreprob = 0;\n iNotMoreProb = 1;\n //less *= 1;\n //notMore *= 1;\n continue;\n }\n else\n {\n imoreprob = (ri - price) / (double)di;\n notMore *= (price - li + 1) / (double)di;\n less *= (price - li) / (double)di;\n here = 1 / (double)di;\n }\n\n double allNotMore = 1d;\n double allLess = 1d;\n\n for(int j =0; j price)\n {\n allNotMore = allLess = 0;\n }\n else\n if(rj < price)\n {\n //allNotMore *=1 ; allLess *= 1;\n }\n else\n {\n allNotMore *= (price - lj + 1) /(double)dj;\n allLess *= (price - lj) / (double)dj;\n }\n }\n\n weight += imoreprob * (allNotMore - allLess);\n exactlyOne += here * allLess;\n //weight += here *\n }\n weight += (notMore - less - exactlyOne);//2 or more here\n //debug[price] = weight;\n // weightSum += weight;\n expected += price * weight;\n }\n\n Console.WriteLine((expected).ToString(\"F10\", CultureInfo.InvariantCulture)); ;\n\n\n }\n }\n}", "src_uid": "5258ce738eb268b9750cfef309d265ef"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace The_Wall__medium_\n{\n internal class Program\n {\n private const int mod = 1000003;\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static long[] fact;\n private static long[] fact1;\n\n private static void Main(string[] args)\n {\n int n = Next();\n int c = Next();\n\n InitFact(n + c + 1);\n long ans = (GetCFact(n + c, c) - 1 + mod)%mod;\n\n writer.WriteLine(ans);\n writer.Flush();\n }\n\n private static void InitFact(int n)\n {\n fact = new long[n];\n fact1 = new long[n];\n\n fact[0] = 1;\n\n for (int i = 1; i < fact.Length; i++)\n {\n fact[i] = (fact[i - 1]*i)%mod;\n }\n fact1[n - 1] = Pow(fact[n - 1], mod - 2);\n for (int i = fact1.Length - 2; i >= 0; i--)\n {\n fact1[i] = (fact1[i + 1]*(i + 1))%mod;\n }\n }\n\n private static long Pow(long a, int k)\n {\n long r = 1;\n while (k > 0)\n {\n if ((k & 1) == 1)\n {\n r = (r*a)%mod;\n }\n a = (a*a)%mod;\n k >>= 1;\n }\n return r;\n }\n\n\n private static long GetCFact(int n, int k)\n {\n return (((fact[n]*fact1[k])%mod)*fact1[n - k])%mod;\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "e63c70a9c96a94bce99618f2e695f83a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO.Pipes;\nusing System.Linq;\nusing System.Text;\n\nnamespace codeforces\n{\n\tclass Program\n\t{\n\t\tpublic class User\n\t\t{\n\t\t\tpublic int c;\n\n\t\t\tpublic int r;\n\t\t}\n\n\t\tpublic class Point\n\t\t{\n\t\t\tpublic int x;\n\n\t\t\tpublic double p;\n\t\t}\n\n\t\tpublic class Comparer : IComparer\n\t\t{\n\t\t\tpublic int Compare(User x, User y)\n\t\t\t{\n\t\t\t\tif (x.c < y.c || (x.c == y.c && x.r < y.r))\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic static long getGcd(long a, long b)\n\t\t{\n\t\t\tif (b == 0)\n\t\t\t\treturn a;\n\t\t\treturn getGcd(b, a % b);\n\t\t}\n\n\t\tpublic static void WriteYESNO(bool x, string yes = \"YES\", string no = \"NO\")\n\t\t{\n\t\t\tif (x)\n\t\t\t\tConsole.WriteLine(yes);\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(no);\n\t\t\t}\n\t\t}\n\n\t\tpublic static string GetString()\n\t\t{\n\t\t\treturn Console.ReadLine();\n\t\t}\n\n\t\tpublic static List getList()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(int.Parse).ToList();\n\t\t}\n\n\t\tpublic static int Min(int x, int y)\n\t\t{\n\t\t\treturn Math.Min(x, y);\n\t\t}\n\n\t\tpublic static int Max(int x, int y)\n\t\t{\n\t\t\treturn Math.Max(x, y);\n\t\t}\n\n\t\tpublic static int Abs(int x)\n\t\t{\n\t\t\treturn Math.Abs(x);\n\t\t}\n\n\t\tpublic static int getInt()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn int.Parse(s);\n\t\t}\n\n\t\tpublic static bool Equal(int x, int y, int x1, int y1)\n\t\t{\n\t\t\treturn x == x1 && y == y1;\n\t\t}\n\n\t\tpublic class Vertex\n\t\t{\n\t\t\tpublic List edges;\n\n\t\t\tpublic int ct;\n\n\t\t\tpublic Vertex()\n\t\t\t{\n\t\t\t\tct = 0;\n\t\t\t\tedges = new List();\n\t\t\t\tfor (var i = 0; i < 26; ++i)\n\t\t\t\t\tedges.Add(0);\n\t\t\t}\n\t\t}\n\n\n\t\tprivate static void Main(string[] args)\n\t\t{\n/*\t\t\tvar input = new StreamReader(\"input.txt\");\n\t\t\tvar output = new StreamWriter(\"output.txt\");*/\n\n\t\t\tvar n = getInt();\n\t\t\tvar s1 = 0;\n\t\t\tvar s2 = 0;\n\t\t\tvar p = false;\n\t\t\tfor (var i = 0; i < n; ++i)\n\t\t\t{\n\t\t\t\tvar l = getList();\n\t\t\t\ts1 += l[0];\n\t\t\t\ts2 += l[1];\n\t\t\t\tif (l[0]%2 != l[1]%2)\n\t\t\t\t\tp = true;\n\t\t\t}\n\t\t\tif (s1%2 == s2%2)\n\t\t\t{\n\t\t\t\tif (s1 % 2 == 0)\n\t\t\t\t\tConsole.WriteLine(0);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (p)\n\t\t\t\t\t\tConsole.WriteLine(1);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tConsole.WriteLine(-1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(-1);\n\t\t\t}\n\t\t\t/*\t\t\tinput.Close();\n\t\t\toutput.Close();*/\n\t\t}\n\t}\n}\n", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.Round91 {\n class C {\n static List num = new List();\n static void gen(long x, int n) {\n if (x <= n) {\n if(x != 0)\n num.Add((int)x);\n gen(x * 10 + 4, n);\n gen(x * 10 + 7, n);\n }\n }\n\n static long fact(long n) { long res = 1; while (n > 1) res *= n--; return res; }\n\n static int n;\n static List val = new List();\n static int dfs(int pos, long k) {\n if (pos > n) return 0;\n int rest = n - pos,\n res = 0;\n for (int i = 0; i < val.Count; i++) {\n if (val[i] == -1) continue;\n if (k < fact(rest)) {\n if (num.Contains(val[i]) && num.Contains(pos)) {\n res = 1;\n }\n //Console.WriteLine(\"dfs: {0} {1}\", pos, val[i]);\n val[i] = -1;\n return res + dfs(pos + 1, k);\n }\n k -= fact(rest);\n }\n throw new Exception();\n }\n\n static void Main() {\n var xs = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);\n n = xs[0];\n int k = xs[1]-1;\n\n for (int v = k, i = 1; i <= n && v != 0; i++) {\n v /= i;\n if (i == n && v != 0) {\n Console.WriteLine(-1);\n return;\n }\n }\n\n gen(0, n);\n num.Sort();\n for (long v = 1, i = 1; i <= n; i++) {\n v *= i;\n if (k < v) {\n int res = 0;\n int m = (int)(n - i);\n int id = -1;\n //Console.WriteLine(\"dfs: {0} {1}\", m, res);\n for (int j = 0; j < num.Count; j++) {\n if (num[j] > m) {\n res += j;\n id = j;\n break;\n }\n if (j == num.Count - 1) {\n Console.WriteLine(num.Count);\n return;\n }\n }\n //Console.WriteLine(\"dfs: {0} {1}\", m, res);\n for (int j = m; j < n; j++) {\n val.Add(j + 1);\n }\n Console.WriteLine(dfs(m+1, k) + res);\n return;\n }\n }\n }\n }\n}\n", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Coding\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] integersInput = Console.ReadLine().Split();\n\n int n = int.Parse(integersInput[0]);\n int m = int.Parse(integersInput[1]);\n int k = int.Parse(integersInput[2]);\n\n if (n - m <= 0 && n - k <= 0)\n {\n Console.WriteLine(\"Yes\");\n } else\n {\n Console.WriteLine(\"No\");\n }\n }\n }\n}\n", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"} {"source_code": "using System;\n\nnamespace CSCA\n{\n public class Program\n {\n public static void Main(string[] args)\n {\n string[] scan = new string[2];\n int n, k, timeLimit;\n scan = Console.ReadLine().Split(' ');\n n = Convert.ToInt32(scan[0]);\n k = Convert.ToInt32(scan[1]);\n timeLimit = 240 - k;\n int time = 0, ans = 0;\n for (int i = 1; i <= n; i++)\n {\n if (time + i * 5 <= timeLimit)\n {\n time += i * 5;\n ans++;\n }\n else break;\n }\n Console.WriteLine(ans);\n return;\n }\n }\n}", "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Globalization;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Runtime.CompilerServices;\r\nusing System.Text;\r\nusing System.Threading;\r\n\r\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\r\npublic class Solution\r\n{\r\n const int MOD = 1000000007;\r\n\r\n public void Solve()\r\n {\r\n for (int tt = ReadInt(); tt > 0; tt--)\r\n {\r\n int n = ReadInt();\r\n int m = ReadInt();\r\n\r\n long ans = 1;\r\n for (int i = 0; i < m; i++)\r\n ans = ans * n % MOD;\r\n\r\n Write(ans);\r\n }\r\n }\r\n\r\n #region Main\r\n\r\n protected static TextReader reader;\r\n protected static TextWriter writer;\r\n static void Main()\r\n {\r\n#if DEBUGLOCAL\r\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\r\n //reader = new StreamReader(Console.OpenStandardInput());\r\n writer = Console.Out;\r\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\r\n#else\r\n reader = new StreamReader(Console.OpenStandardInput());\r\n writer = new StreamWriter(Console.OpenStandardOutput());\r\n //reader = new StreamReader(\"ysys.in\");\r\n //writer = new StreamWriter(\"output.txt\");\r\n#endif\r\n try\r\n {\r\n new Solution().Solve();\r\n //var thread = new Thread(new Solution().Solve, 1024 * 1024 * 128);\r\n //thread.Start();\r\n //thread.Join();\r\n }\r\n catch (Exception ex)\r\n {\r\n#if DEBUGLOCAL\r\n Console.WriteLine(ex);\r\n#else\r\n throw;\r\n#endif\r\n }\r\n reader.Close();\r\n writer.Close();\r\n }\r\n\r\n #endregion\r\n\r\n #region Read / Write\r\n private static Queue currentLineTokens = new Queue();\r\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\r\n public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\r\n public static int ReadInt() { return int.Parse(ReadToken()); }\r\n public static long ReadLong() { return long.Parse(ReadToken()); }\r\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\r\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\r\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\r\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\r\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }\r\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\r\n {\r\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\r\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }\r\n return ret;\r\n }\r\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }\r\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\r\n public static void Write(params object[] array) { WriteArray(array); }\r\n public static void WriteLines(IEnumerable array) { foreach (var a in array) writer.WriteLine(a); }\r\n private class SDictionary : Dictionary\r\n {\r\n public new TValue this[TKey key]\r\n {\r\n get { return ContainsKey(key) ? base[key] : default(TValue); }\r\n set { base[key] = value; }\r\n }\r\n }\r\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }\r\n #endregion\r\n} ", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing CompLib.Util;\n\npublic class Program\n{\n int N;\n long M;\n long[] A;\n public void Solve()\n {\n var sc = new Scanner();\n N = sc.NextInt();\n M = sc.NextInt();\n A = sc.LongArray();\n\n /*\n * Aからいくつか選んで Mod Mが最大になるようにする\n */\n\n var left = Calc(0, N / 2);\n var right = Calc(N / 2, N);\n long ans = ((left.Last() + right.Last()) % M);\n foreach (int i in left)\n {\n // i + right[j] がM未満最大\n // \n int ok = 0;\n int ng = right.Count;\n while(ng - ok > 1)\n {\n int mid = (ok + ng) / 2;\n if (i + right[mid] < M) ok = mid;\n else ng = mid;\n }\n ans = Math.Max(ans, i + right[ok]);\n }\n\n Console.WriteLine(ans);\n }\n\n List Calc(int b, int e)\n {\n var ls = new List();\n ls.Add(0);\n\n for (int i = b; i < e; i++)\n {\n int len = ls.Count;\n for (int j = 0; j < len; j++)\n {\n ls.Add((ls[j] + A[i]) % M);\n }\n }\n\n var result = new List();\n ls.Sort();\n for (int i = 0; i < ls.Count; i++)\n {\n if (i == 0 || ls[i - 1] != ls[i])\n {\n result.Add(ls[i]);\n }\n }\n\n return result;\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\n\n#if DEBUG\nusing System.Diagnostics;\n#endif\n\nnamespace CompetitiveProgramming\n{\n class Program\n {\n static bool s_IsMultipleTestCases = false;\n static void Main(string[] args)\n {\n#if DEBUG\n s_IsMultipleTestCases = true;\n var streamReader = new StreamReader(\"../../input.txt\", Encoding.ASCII, false, 32768);\n var streamWriter = new StreamWriter(\"../../output.txt\", false, Encoding.ASCII, 32768);\n var timer = new Stopwatch();\n#else\n var streamReader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);\n var streamWriter = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);\n#endif\n var reader = new InputReader(streamReader);\n\n var numberOfTest = 1;\n if (s_IsMultipleTestCases)\n {\n numberOfTest = reader.NextInt();\n }\n for (var testNumber = 1; testNumber <= numberOfTest; ++testNumber)\n {\n#if DEBUG\n timer.Start();\n#endif\n Task solver = new Task();\n solver.Solve(testNumber, reader, streamWriter);\n#if DEBUG\n streamWriter.WriteLine(\"Eslapsed Time: \" + timer.ElapsedMilliseconds + \" ms\\n\");\n timer.Reset();\n#endif\n }\n streamReader.Close();\n streamWriter.Close();\n }\n }\n\n class Task\n {\n const long MOD = 1000000007;\n const int MAXN = 20002;\n long ans = 0;\n string res = \"NO\";\n long BASE = 31;\n\n public void Solve(int testNumber, InputReader reader, StreamWriter writer)\n {\n var n = reader.NextInt();\n var c = reader.NextInt();\n var p = reader.NIS(n);\n var t = reader.NIS(n);\n var limark = 0;\n var radewoosh = 0;\n var x = 0;\n for (int i = 0; i < n; i++)\n {\n x += t[i];\n limark += Max(0, p[i] - c * x);\n }\n\n x = 0;\n for (int i = n - 1; i >= 0; i--)\n {\n x += t[i];\n radewoosh += Max(0, p[i] - c * x);\n }\n\n if(limark == radewoosh)\n {\n res = \"Tie\";\n }else if(limark > radewoosh)\n {\n res = \"Limak\";\n }\n else\n {\n res = \"Radewoosh\";\n }\n writer.WriteLine(res);\n }\n\n\n #region Utilities\n private string ConvertArrayToString(int[] arrs)\n {\n var sb = new StringBuilder();\n foreach (var item in arrs)\n {\n sb.Append(item);\n sb.Append(\"\\n\");\n }\n return sb.ToString();\n }\n\n private string ConvertArrayToString(long[] arrs)\n {\n var sb = new StringBuilder();\n foreach (var item in arrs)\n {\n sb.Append(item);\n sb.Append(\"\\n\");\n }\n return sb.ToString();\n }\n\n private string ConvertDoubleToString(double x)\n {\n return x.ToString(CultureInfo.InvariantCulture);\n }\n\n private int Max(int a, int b)\n {\n return Math.Max(a, b);\n }\n\n private int Min(int a, int b)\n {\n return Math.Min(a, b);\n }\n\n private long Max(long a, long b)\n {\n return Math.Max(a, b);\n }\n\n private long Min(long a, long b)\n {\n return Math.Min(a, b);\n }\n\n private long GCD(long a, long b)\n {\n return a > 0 ? b : GCD(b, a % b);\n }\n\n private int GCD(int a, int b)\n {\n return a > 0 ? b : GCD(b, a % b);\n }\n\n #endregion\n }\n\n class InputReader\n {\n private char[] _inbuf;\n private int _lenbuf = 0, _ptrbuf = 0;\n private StreamReader _reader;\n\n public InputReader(StreamReader reader)\n {\n _reader = reader;\n _inbuf = new char[1024];\n _lenbuf = 0;\n _ptrbuf = 0;\n }\n\n private int ReadByte()\n {\n if (_lenbuf == -1)\n throw new Exception();\n if (_ptrbuf >= _lenbuf)\n {\n _ptrbuf = 0;\n try\n {\n _lenbuf = _reader.Read(_inbuf, 0, 1024);\n }\n catch (IOException e)\n {\n throw e;\n }\n if (_lenbuf <= 0)\n return -1;\n }\n return _inbuf[_ptrbuf++];\n }\n\n private bool IsSpaceChar(int c)\n {\n return !(c >= 33 && c <= 126);\n }\n\n private int Skip()\n {\n int b;\n while ((b = ReadByte()) != -1 && IsSpaceChar(b)) ;\n return b;\n }\n\n public int NextInt()\n {\n int num = 0, b;\n var minus = false;\n while ((b = ReadByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-')\n {\n minus = true;\n b = ReadByte();\n }\n\n while (true)\n {\n if (b >= '0' && b <= '9')\n {\n num = num * 10 + (b - '0');\n }\n else\n {\n return minus ? -num : num;\n }\n b = ReadByte();\n }\n }\n\n public long NextLong()\n {\n long num = 0, b;\n var minus = false;\n while ((b = ReadByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-')\n {\n minus = true;\n b = ReadByte();\n }\n\n while (true)\n {\n if (b >= '0' && b <= '9')\n {\n num = num * 10 + (b - '0');\n }\n else\n {\n return minus ? -num : num;\n }\n b = ReadByte();\n }\n }\n\n public string Next()\n {\n var b = Skip();\n var sb = new StringBuilder();\n while (!(IsSpaceChar(b)))\n {\n sb.Append((char)b);\n b = ReadByte();\n }\n return sb.ToString();\n }\n\n public double NextDouble()\n {\n return double.Parse(Next(), CultureInfo.InvariantCulture);\n }\n\n public int[] NIS(int n)\n {\n var arrs = new int[n];\n for (int i = 0; i < n; i++)\n {\n arrs[i] = NextInt();\n }\n return arrs;\n }\n\n public long[] NLS(int n)\n {\n var arrs = new long[n];\n for (int i = 0; i < n; i++)\n {\n arrs[i] = NextLong();\n }\n return arrs;\n }\n }\n\n}", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\n\nnamespace ConsoleApplication6\n{\n class Program\n {\n static void Main()\n {\n string input = Console.ReadLine();\n int n = int.Parse(input.Split(' ')[0]);\n int k = int.Parse(input.Split(' ')[1]);\n\n Dictionary cipa = new Dictionary();\n string pizda = Console.ReadLine();\n for (int i = 0; i < n; i++)\n {\n int val = int.Parse(pizda.Split(' ')[i]);\n if (!cipa.ContainsValue(val))\n {\n cipa.Add(i + 1, val);\n }\n }\n\n if (cipa.Count() >= k)\n {\n Console.WriteLine(\"YES\");\n Console.Write(string.Join(\" \", cipa.Select(x => x.Key).Take(k).ToArray()));\n }\n else\n {\n Console.WriteLine(\"NO\");\n }\n }\n }\n}", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\nusing Pi = Pair;\n\nclass Solver\n{\n public void Solve(Scanner sc)\n {\n int N, K;\n sc.Make(out N, out K);\n ModInt.Build(K + 1);\n var F = new ModInt[K + 2];\n for (int i = 1; i < K + 2; i++)\n {\n F[i] = ModInt.Pow(i, K) + F[i - 1];\n }\n if (N <= K + 1) Fail(F[N]);\n WriteLine(LagrangePolynomial(F, N));\n }\n public ModInt LagrangePolynomial(ModInt[] Y,int T,int a=0,int d = 1)\n {\n if (T < Y.Length) return Y[T];\n ModInt[] left = new ModInt[Y.Length], right = new ModInt[Y.Length];\n left[0] = right[Y.Length - 1] = 1;\n for (int i = 0; i < Y.Length-1; i++)\n {\n left[i + 1] = left[i] * (T - a - d * i);\n }\n for (int i = Y.Length - 2; i >= 0; i--)\n {\n right[i] = right[i + 1] * (T - a - d * (i + 1));\n }\n ModInt res = 0;\n for (int i = 0; i < Y.Length; i++)\n {\n ModInt r = Y[i] * left[i] * right[i] * ModInt.FacInv(i) * ModInt.FacInv(Y.Length - i - 1);\n if ((Y.Length - i - 1) % 2 == 0) res += r;\n else res -= r;\n }\n return res;\n }\n}\n\npublic struct ModInt\n{\n public const long MOD = (int)1e9 + 7;\n //public const long MOD = 998244353;\n public long Value { get; set; }\n public ModInt(long n = 0) { Value = n; }\n private static ModInt[] fac;//i!\n private static ModInt[] inv;//1/i\n private static ModInt[] facinv;//1/(i!)\n public override string ToString() => Value.ToString();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator +(ModInt l, ModInt r)\n {\n l.Value += r.Value;\n if (l.Value >= MOD) l.Value -= MOD;\n return l;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator -(ModInt l, ModInt r)\n {\n l.Value -= r.Value;\n if (l.Value < 0) l.Value += MOD;\n return l;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static implicit operator long(ModInt l) => l.Value;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static implicit operator ModInt(long n)\n {\n n %= MOD; if (n < 0) n += MOD;\n return new ModInt(n);\n }\n\n public static ModInt Pow(ModInt m, long n)\n {\n if (n == 0) return 1;\n if (n % 2 == 0) return Pow(m * m, n >> 1);\n else return Pow(m * m, n >> 1) * m;\n }\n\n public static void Build(int n)\n {\n fac = new ModInt[n + 1];\n facinv = new ModInt[n + 1];\n inv = new ModInt[n + 1];\n inv[1] = 1;\n fac[0] = fac[1] = 1;\n facinv[0] = facinv[1] = 1;\n for (var i = 2; i <= n; i++)\n {\n fac[i] = fac[i - 1] * i;\n inv[i] = MOD - inv[MOD % i] * (MOD / i);\n facinv[i] = facinv[i - 1] * inv[i];\n }\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Fac(ModInt n) => fac[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Inv(ModInt n) => inv[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt FacInv(ModInt n) => facinv[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Comb(ModInt n, ModInt r)\n {\n if (n < r) return 0;\n if (n == r) return 1;\n var calc = fac[n];\n calc = calc * facinv[r];\n calc = calc * facinv[n - r];\n return calc;\n }\n}\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver().Solve(new Scanner());\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(this IList A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static IEnumerable Shuffle(this IEnumerable A) => A.OrderBy(v => Guid.NewGuid());\n public static int CompareTo(this T[] A, T[] B, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }\n public static int MaxElement(this IList A, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }\n public static T PopBack(this List A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n //public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n //public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n //public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }\n}\n#endregion\n", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Mail.Ru_Cup_2018_Round_1\n{\n class Program\n {\n static void Main(string[] args)\n { \n string s = Console.ReadLine();\n int[] Input = s.Split(' ').Select(n => Convert.ToInt32(n)).ToArray();\n int TCurrElev = Input[4] * (Subtract(Input[0], Input[2]));\n int TCurrVist = Input[4] * (Subtract(Input[0], Input[1]));\n int TElevator = TCurrElev + TCurrVist + (Input[5] * 3);\n int TStairs = Input[3] * (Subtract(Input[0], Input[1]));\n if (TElevator <= TStairs)\n {\n Console.WriteLine(\"YES\");\n }\n else\n {\n Console.WriteLine(\"NO\");\n }\n }\n\n static int Subtract(int x,int y)\n {\n return (Math.Abs(x - y));\n }\n }\n}\n", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n const int MAX = 4000;\n const int MOD = 1000000007;\n\n void Solve()\n {\n // OEIS A005493\n // a(n+1) = 1 + sum { j=1, n, (1+binomial(n, j))*a(j) }\n\n var c = new int[MAX + 1, MAX + 1];\n for (int i = 1; i <= MAX; i++)\n for (int j = 1; j <= i; j++)\n {\n if (i == j)\n c[i, j] = 1;\n else if (j == 1)\n c[i, j] = i;\n else\n c[i, j] = (c[i - 1, j] + c[i - 1, j - 1]) % MOD;\n }\n\n var a = new long[MAX + 1];\n a[1] = 1;\n a[2] = 3;\n a[3] = 10;\n for (int i = 4; i <= MAX; i++)\n {\n a[i] = 1;\n for (int j = 1; j < i; j++)\n a[i] = (a[i] + (1 + c[i - 1, j]) * a[j]) % MOD;\n }\n\n Write(a[ReadInt()]);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"hull.in\");\n //writer = new StreamWriter(\"hull.out\");\n#endif\n try\n {\n // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n // thread.Start();\n // thread.Join();\n checked\n {\n new Solver().Solve();\n }\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "aa2c3e94a44053a0d86f61da06681023"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Runtime.CompilerServices;\nusing System.Security.Policy;\n\npublic static class Ex\n{\n public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); }\n public static void yesno(this bool b) => Console.WriteLine(b ? \"yes\" : \"no\");\n public static void YesNo(this bool b) => Console.WriteLine(b ? \"Yes\" : \"No\");\n public static void YESNO(this bool b) => Console.WriteLine(b ? \"YES\" : \"NO\");\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n //public static bool Chmax(ref this T a, T b) where T : struct, IComparable\n //{\n // if (b.CompareTo(a) > 0) { a = b; return true; }\n // else return false;\n //}\n //[MethodImpl(MethodImplOptions.AggressiveInlining)]\n //public static bool Chmin(ref this T a, T b) where T : struct, IComparable\n //{\n // if (b.CompareTo(a) < 0) { a = b; return true; }\n // else return false;\n //}\n\n public static List FastSort(this List s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); }\n\n public static int PopCount(this uint bits)\n {\n bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);\n bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);\n bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);\n bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);\n return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff));\n }\n}\n\n\n\npartial class Program\n{\n string GetStr() { return Console.ReadLine().Trim(); }\n char GetChar() { return Console.ReadLine().Trim()[0]; }\n int GetInt() { return int.Parse(Console.ReadLine().Trim()); }\n long GetLong() { return long.Parse(Console.ReadLine().Trim()); }\n double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }\n string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }\n string[][] GetStrArray(int N)\n {\n var res = new string[N][];\n for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ');\n return res;\n }\n int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); }\n int[][] GetIntArray(int N)\n {\n var res = new int[N][];\n for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();\n return res;\n }\n public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); }\n long[][] GetLongArray(int N)\n {\n var res = new long[N][];\n for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();\n return res;\n }\n char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); }\n double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); }\n double[][] GetDoubleArray(int N)\n {\n var res = new double[N][];\n for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();\n return res;\n }\n char[][] GetGrid(int H)\n {\n var res = new char[H][];\n for (int i = 0; i < H; i++) res[i] = Console.ReadLine().Trim().ToCharArray();\n return res;\n }\n T[] CreateArray(int N, T value)\n {\n var res = new T[N];\n for (int i = 0; i < N; i++) res[i] = value;\n return res;\n }\n T[][] CreateArray(int H, int W, T value)\n {\n var res = new T[H][];\n for (int i = 0; i < H; i++)\n {\n res[i] = new T[W];\n for (int j = 0; j < W; j++) res[i][j] = value;\n }\n return res;\n }\n T[][][] CreateArray(int H, int W, int R, T value)\n {\n var res = new T[H][][];\n for (int i = 0; i < H; i++)\n {\n res[i] = new T[W][];\n for (int j = 0; j < W; j++)\n {\n res[i][j] = new T[R];\n for (int k = 0; k < R; k++) res[i][j][k] = value;\n }\n }\n return res;\n }\n\n Dictionary> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed)\n {\n var dic = new Dictionary>();\n foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List()); }\n for (int i = 0; i < M; i++)\n {\n var input = GetIntArray();\n var a = isNode_0indexed ? input[0] : input[0] - 1;\n var b = isNode_0indexed ? input[1] : input[1] - 1;\n dic[a].Add(b);\n if (isDirected == false) dic[b].Add(a);\n }\n return dic;\n }\n //Dictionary> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed)\n //{\n // var dic = new Dictionary>();\n // foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<(int, long)>()); }\n // for (int i = 0; i < M; i++)\n // {\n // var input = GetIntArray();\n // var a = isNode_0indexed ? input[0] : input[0] - 1;\n // var b = isNode_0indexed ? input[1] : input[1] - 1;\n // var c = input[2];\n // dic[a].Add((b, c));\n // if (isDirected == false) dic[b].Add((a, c));\n // }\n // return dic;\n //}\n\n bool eq() => typeof(T).Equals(typeof(U));\n T ct(U a) => (T)Convert.ChangeType(a, typeof(T));\n T cv(string s) => eq() ? ct(int.Parse(s))\n : eq() ? ct(long.Parse(s))\n : eq() ? ct(double.Parse(s))\n : eq() ? ct(s[0])\n : ct(s);\n void Multi(out T a) => a = cv(GetStr());\n void Multi(out T a, out U b)\n {\n var ar = GetStrArray(); a = cv(ar[0]); b = cv(ar[1]);\n }\n void Multi(out T a, out U b, out V c)\n {\n var ar = GetStrArray(); a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]);\n }\n void Multi(out T a, out U b, out V c, out W d)\n {\n var ar = GetStrArray(); a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]);\n }\n void Multi(out T a, out U b, out V c, out W d, out X e)\n {\n var ar = GetStrArray(); a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); e = cv(ar[4]);\n }\n void Multi(out T a, out U b, out V c, out W d, out X e, out Y f)\n {\n var ar = GetStrArray(); a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); e = cv(ar[4]); f = cv(ar[5]);\n }\n\n void Output(T t) => Console.WriteLine(t);\n void Output(IList ls) => Console.WriteLine(string.Join(\" \", ls));\n void Debug(IList> ls)\n {\n foreach (var l in ls)\n foreach (var s in l)\n Console.WriteLine(s);\n }\n\n\n void Swap(ref T a, ref T b) { T temp = a; a = b; b = temp; }\n\n int[] dx = new int[] { 1, 0, -1, 0, 1, -1, -1, 1 };\n int[] dy = new int[] { 0, 1, 0, -1, 1, 1, -1, -1 };\n long mod = 1000000007;\n}\n\n\n\n\n\n\npartial class Program\n{\n static void Main()\n {\n //Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));\n //Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Program().Solve();\n //Console.Out.Flush();\n Console.Read();\n }\n\n public void Solve()\n {\n long N = GetLong();\n long M = N / 2;\n long b = 1;\n for (long i = 1; i < M; i++) b *= i;\n long B = 1;\n for (long i = M + 1; i <= N; i++) B *= i;\n Output(B / M /2* b);\n }\n\n}\n", "src_uid": "ad0985c56a207f76afa2ecd642f56728"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace Trailing_Loves\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args));\n writer.Flush();\n }\n\n private static IEnumerable G()\n {\n yield return 2L;\n for (long i = 3;; i += 2)\n {\n yield return i;\n }\n }\n\n private static long Solve(string[] args)\n {\n long n = Next();\n long b = Next();\n\n var list = new List();\n foreach (long i in G())\n {\n if (i*i > b)\n break;\n while (b%i == 0)\n {\n b /= i;\n list.Add(i);\n }\n }\n if (b != 1)\n list.Add(b);\n\n long ans = long.MaxValue;\n foreach (var p in list.GroupBy(t => t).Select(t => new {t.Key, cnt = t.Count()}))\n {\n ans = Math.Min(ans, Count(n, p.Key)/p.cnt);\n }\n\n return ans;\n }\n\n private static long Count(long n, long max)\n {\n long ans = 0;\n for (long i = max;;)\n {\n ans += n/i;\n if (n/max >= i)\n i *= max;\n else\n break;\n }\n return ans;\n }\n\n private static long Next()\n {\n int c;\n long res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "491748694c1a53771be69c212a5e0e25"} {"source_code": "using System;\nusing System.Text;\n\nnamespace KolyaAndTandemRepeat\n{\n partial class KolyaAndTandemRepeat\n {\n static void Main(string[] args)\n {\n StringBuilder s;\n int add, max = 0, current;\n\n s = new StringBuilder(ReadLine());\n add = NextInt();\n\n s.Append('*', add);\n\n for (int i = 0; i < s.Length; i++)\n {\n for (int j = i + 1; j < s.Length; j++)\n {\n current = 0;\n\n for (int k = i, l = j; k < j && ((j + (j - i)) - 1 < s.Length); k++, l++)\n {\n if (s[k] != s[l] && s[l] != '*')\n break;\n\n current++;\n }\n\n if (current > max)\n max = current;\n }\n }\n\n Console.WriteLine(max * 2);\n }\n }\n\n partial class KolyaAndTandemRepeat\n {\n static string[] tokens = new string[0];\n static int cur_token = 0;\n\n static void ReadArray(char sep)\n {\n cur_token = 0;\n tokens = Console.ReadLine().Split(sep);\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int NextInt()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return int.Parse(tokens[cur_token++]);\n }\n\n static long NextLong()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return long.Parse(tokens[cur_token++]);\n }\n\n static double NextDouble()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return double.Parse(tokens[cur_token++]);\n }\n\n static decimal NextDecimal()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return decimal.Parse(tokens[cur_token++]);\n }\n\n static string NextToken()\n {\n if (cur_token == tokens.Length)\n ReadArray(' ');\n return tokens[cur_token++];\n }\n\n static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n}\n", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\n//using Debug;\n//using static System.Globalization.CultureInfo;\n//using Edge = Pair;\nusing System.Text;\nclass Program\n{ \n static void Main(string[] args)\n {\n Solve();\n //WriteLine(Solve());\n }\n static void Solve()\n {\n var nkd = Input.ar;\n var dp = new long[nkd[0] + 1, 2];\n dp[0, 0] = 1;\n for (var i = 1; i <= nkd[0]; i++)\n for (var h = i - 1; h >= 0; h--)\n {\n if (h >= Max(0, i - nkd[2] + 1))\n dp[i, 0] = (dp[i, 0] + dp[h, 0]) % Input.MOD;\n if (h >= Max(0, i - nkd[2] + 1))\n dp[i, 1] = (dp[i, 1] + dp[h, 1]) % Input.MOD;\n else if(h>=i-nkd[1])\n dp[i, 1] = (dp[i, 1] + dp[h, 0] + dp[h, 1]) % Input.MOD;\n }\n WriteLine(dp[nkd[0], 1]);\n }\n}\n\npublic class Input\n{\n public static string read => ReadLine().Trim();\n public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();\n public static int num => ToInt32(read);\n public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();\n public static long numL => ToInt64(read);\n public static char[][] gred(int h) \n => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();\n public static int[][] ar2D(int num)\n => Enumerable.Repeat(0, num).Select(_ => ar).ToArray();\n public static long[][] arL2D(int num)\n => Enumerable.Repeat(0, num).Select(_ => arL).ToArray();\n public static T getValue(string g)\n {\n var t = typeof(T);\n if (t == typeof(int))\n return (T)(object)int.Parse(g);\n if (t == typeof(long))\n return (T)(object)long.Parse(g);\n if (t == typeof(string))\n return (T)(object)g;\n if (t == typeof(char))\n return (T)(object)char.Parse(g);\n if (t == typeof(double))\n return (T)(object)double.Parse(g);\n if (t == typeof(bool))\n return (T)(object)bool.Parse(g);\n return default(T);\n }\n public const long Inf = (long)1e18;\n public const double eps = 1e-6;\n public const string Alfa = \"abcdefghijklmnopqrstuvwxyz\";\n public const int MOD = 1000000007;\n}\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace _426A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string header = Console.ReadLine();\n int n=int.Parse(header.Split()[0]);\n int s = int.Parse(header.Split()[1]);\n\n \n int sum = 0, max=0;\n string[] str = Console.ReadLine().Split();\n\n for (int i = 0; i < n; i++)\n {\n if (int.Parse(str[i]) > max)\n max = int.Parse(str[i]);\n\n sum += int.Parse(str[i]);\n }\n\n sum -= max;\n\n Console.Write(sum<=s ? \"YES\" : \"NO\");\n }\n }\n}\n", "src_uid": "496baae594b32c5ffda35b896ebde629"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nclass Scanner\n{\n private readonly char Separator = ' ';\n private int Index = 0;\n private string[] Line = new string[0];\n public string Next()\n {\n if (Index >= Line.Length)\n {\n Line = Console.ReadLine().Split(Separator);\n Index = 0;\n }\n var ret = Line[Index];\n Index++;\n return ret;\n }\n\n public int NextInt()\n {\n return int.Parse(Next());\n }\n\n public long NextLong()\n {\n return long.Parse(Next());\n }\n\n public string[] StringArray()\n {\n Line = Console.ReadLine().Split(Separator);\n Index = Line.Length;\n return Line;\n }\n\n public int[] IntArray()\n {\n var l = StringArray();\n var res = new int[l.Length];\n for (int i = 0; i < l.Length; i++)\n {\n res[i] = int.Parse(l[i]);\n }\n return res;\n }\n\n public long[] LongArray()\n {\n var l = StringArray();\n var res = new long[l.Length];\n for (int i = 0; i < l.Length; i++)\n {\n res[i] = long.Parse(l[i]);\n }\n return res;\n }\n}\n\nclass Program\n{\n private string Zero = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n private string AddA = \"What are you doing while sending \\\"\";\n private string AddB = \"\\\"? Are you busy? Will you send \\\"\";\n private string AddC = \"\\\"?\";\n private int Q;\n private int[] N;\n private long[] K;\n private long[] Length;\n private void Scan()\n {\n var sc = new Scanner();\n Q = sc.NextInt();\n N = new int[Q];\n K = new long[Q];\n for (int i = 0; i < Q; i++)\n {\n N[i] = sc.NextInt();\n K[i] = sc.NextLong();\n }\n }\n\n private void CalcLength()\n {\n Length = new long[100001];\n Length[0] = Zero.Length;\n for (int i = 1; i <= 100000; i++)\n {\n Length[i] = Math.Min((Length[i - 1] * 2) + AddA.Length + AddB.Length + AddC.Length, (long)1e18 + 1);\n }\n }\n\n private char Func(int i, long index)\n {\n if (Length[i] <= index)\n {\n return '.';\n }\n if (i == 0)\n {\n return Zero[(int)index];\n }\n long a, b, c, d, e;\n a = AddA.Length;\n b = a + Length[i - 1];\n c = b + AddB.Length;\n d = c + Length[i - 1];\n e = d + AddC.Length;\n if (index < a)\n {\n return AddA[(int)index];\n }\n if (a <= index && index < b)\n {\n return Func(i - 1, index - a);\n }\n if (b <= index && index < c)\n {\n return AddB[(int)(index - b)];\n }\n if (c <= index && index < d)\n {\n return Func(i - 1, index - c);\n }\n if (d <= index && index < e)\n {\n return AddC[(int)(index - d)];\n }\n return '.';\n }\n\n public void Solve()\n {\n Scan();\n CalcLength();\n var ans = \"\";\n for (int i = 0; i < Q; i++)\n {\n ans += Func(N[i], K[i] - 1);\n }\n Console.WriteLine(ans);\n }\n\n\n\n static void Main(string[] args)\n {\n new Program().Solve();\n }\n}", "src_uid": "da09a893a33f2bf8fd00e321e16ab149"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\n\npublic static class Program\n{\n public static void Main(string[] args)\n {\n var input = Console.ReadLine().Split(' ');\n \n int x = int.Parse(input[0]);\n int y = int.Parse(input[1]);\n \n int xVector = x / Math.Abs(x);\n int yVector = y / Math.Abs(y);\n \n int length = Math.Abs(x) + Math.Abs(y);\n \n int x1 = length * xVector;\n int y2 = length * yVector;\n \n if (x1 < 0)\n {\n OutputXY(x1, 0);\n OutputXY(0, y2);\n }\n else\n {\n OutputXY(0, y2);\n OutputXY(x1, 0);\n }\n }\n \n private static void OutputXY(int x, int y)\n {\n Console.Write(\"{0} {1} \", x, y);\n }\n}", "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"source_code": "using System;\nusing System.CodeDom;\nusing System.Collections.Generic;\nusing System.ComponentModel.Design.Serialization;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Threading;\n\nnamespace Codeforces\n{\n class Program : IDisposable\n {\n private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());\n private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());\n\n private void Solve()\n {\n var n = int.Parse(Console.ReadLine());\n var arr1 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();\n var arr2 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();\n\n var set = new HashSet();\n foreach (var el in arr1)\n {\n set.Add(el);\n }\n\n foreach (var el in arr2)\n {\n set.Add(el);\n }\n\n arr1.Sort();\n arr2.Sort();\n\n int cnt = 0;\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n var val = arr1[i] ^ arr2[j];\n if (set.Contains(val))\n cnt++;\n }\n }\n if(cnt%2==0)\n Console.WriteLine(\"Karen\");\n else\n Console.WriteLine(\"Koyomi\");\n }\n\n\n int BinarySearch(int[] arr, int q)\n {\n var l = 0;\n var r = arr.Length - 1;\n //int med = -1;\n while (l <= r)\n {\n var med = l + (r - l) / 2;\n if (arr[med] == q)\n {\n return med;\n }\n if (q < arr[med])\n {\n r = med - 1;\n }\n else\n {\n l = med + 1;\n }\n }\n return -1;\n }\n\n\n static void Main(string[] args)\n {\n var p = new Program();\n p.Solve();\n //Console.ReadLine();\n //p.Dispose();\n //////////////////////////////\n }\n\n #region Helpers\n\n private static int ReadInt()\n {\n return int.Parse(textReader.ReadLine());\n }\n\n private static long ReadLong()\n {\n return long.Parse(textReader.ReadLine());\n }\n\n private static int[] ReadIntArray()\n {\n return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();\n }\n #endregion\n\n public void Dispose()\n {\n textReader.Close();\n textWriter.Close();\n }\n }\n\n //class Trie\n //{\n // public TrieNode root;\n\n // public Trie()\n // {\n // root = new TrieNode();\n // }\n\n // public void Insert(string s)\n // {\n // var current = root;\n // for (int i = 0; i < s.Length; i++)\n // {\n // var ch = s[i];\n // if (!current.Children.ContainsKey(ch))\n // current.Children.Add(ch, new TrieNode());\n // current = current.Children[ch];\n // }\n // current.IsEnd = true;\n // }\n\n // public bool Search(string word)\n // {\n // var current = root;\n // for (int i = 0; i < word.Length; i++)\n // {\n // var ch = word[i];\n // if (!current.Children.ContainsKey(ch))\n // return false;\n // current = current.Children[ch];\n // }\n // return current.IsEnd;\n // }\n //}\n\n //class TrieNode\n //{\n // public Dictionary Children { get; set; }\n // public bool IsEnd { get; set; }\n\n // public TrieNode()\n // {\n // Children = new Dictionary();\n // IsEnd = false;\n // }\n\n \n //}\n}\n\n\n", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nclass Solution\n{\n\n static bool IsPossible(int[] months, int[] data)\n {\n var idxs = data.Select((s, i) => s == months[0] ? i : -1).Where(s => s >= 0);\n foreach (var idx in idxs)\n {\n var found = true;\n for (var i = 0; i < months.Length; i++)\n {\n if (months[i] != data[(idx + i) % data.Length])\n {\n found = false;\n break;\n }\n }\n if (found)\n return true;\n }\n return false;\n }\n\n static void Main(String[] args)\n {\n var leap = new[] {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\n var nonLeap = new[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n var leapAndNonLeap = new int[24];\n leap.CopyTo(leapAndNonLeap, 0);\n nonLeap.CopyTo(leapAndNonLeap, 12);\n\n var nonLeapAndNonLeap = new int[24];\n nonLeap.CopyTo(nonLeapAndNonLeap, 0);\n nonLeap.CopyTo(nonLeapAndNonLeap, 12);\n\n var n = Convert.ToInt32(Console.ReadLine());\n var tempA = Console.ReadLine().Split(' ');\n var months = Array.ConvertAll(tempA, int.Parse);\n\n var possible = IsPossible(months, leapAndNonLeap) || IsPossible(months, nonLeapAndNonLeap);\n Console.WriteLine(\"{0}\", possible ? \"YES\" : \"NO\");\n Console.ReadLine();\n }\n}\n", "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace DivisaoConquista\n{\n public static class Operacao\n {\n static public long[] Vetor; //vetor auxiliar\n\n static public long Calcula(long n, int i)\n {\n long m = n / Vetor[i]; //auxiliar para dividir o número {aplicação da técnica}\n n = n % Vetor[i]; //atualização de n para o resto da divisão\n\n if (n == 0) //Se chegar ao fim\n return m * i; //auxiliar * 'posição' atual\n else //retorna o produto do auxiliar pelo menor valor entre a qtd de 1 para o número e a posição anterior e para a \n return m * i + Math.Min(Calcula(n, i - 1), i + Calcula(Vetor[i] - n, i - 1));\n }\n }\n class Program\n {\n static void Main(string[] args)\n {\n /*O Prof. Vasechkin quer representar o inteiro positivo n como uma soma de adendos, \n * onde cada adendo é um número inteiro contendo apenas 1 s. \n * Por exemplo, ele pode representar 121 como 121 = 111 + 11 + -1. \n * Encontrar o menor número de dígitos 1 em tal soma.\n */\n Rodar();\n }\n\n static void Rodar()\n {\n long n;\n long[] vetor = new long[17];\n\n for (int i = 1; i < vetor.Length; i++)\n {\n vetor[i] = vetor[i - 1] * 10 + 1;\n }\n\n Operacao.Vetor = vetor;\n n = long.Parse(Console.ReadLine());\n Console.Write(Operacao.Calcula(n, 16));\n }\n }\n}\n", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\npublic class Codeforces\n{\n protected static TextReader reader;\n protected static TextWriter writer;\n static int gdiv(long a)\n {\n var t = Math.Sqrt(a);\n var c = 0;\n for (int i = 2; i < (long)t + 1; i++)\n {\n if (a % i == 0)\n {\n c++;\n }\n }\n if (t == (long)t)\n {\n c--;\n }\n return c;\n }\n #region Prime Numbers <100\n private static readonly int[] Primes =\n new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59,\n 61, 67, 71, 73, 79, 83, 89, 97 };\n #endregion\n private const int _startNum = 101;\n #region IsPrime: primality Check\n /// \n /// Check if the number is Prime\n /// \n /// Int64\n /// bool\n public static bool IsPrime(Int64 Num)\n {\n int j;\n bool ret;\n Int64 _upMargin = (Int64)Math.Sqrt(Num) + 1; ;\n // Check if number is in Prime Array\n for (int i = 0; i < Primes.Length; i++)\n {\n if (Num == Primes[i]) { return true; }\n }\n // Check divisibility w/Prime Array\n for (int i = 0; i < Primes.Length; i++)\n {\n if (Num % Primes[i] == 0) return false;\n }\n // Main iteration for Primality check\n _upMargin = (Int64)Math.Sqrt(Num) + 1;\n j = _startNum;\n ret = true;\n while (j <= _upMargin)\n {\n if (Num % j == 0) { ret = false; break; }\n else { j = j + 2; }\n }\n return ret;\n }\n /// \n /// Check if number-string is Prime\n /// \n /// string\n /// bool\n public static bool IsPrime(string StringNum)\n {\n return IsPrime(Int64.Parse(StringNum));\n }\n #endregion\n #region Fast Factorization\n /// \n /// Factorize string converted to long integers\n /// \n /// string\n /// Int64[]\n public static Int64[] FactorizeFast(string StringNum)\n {\n return FactorizeFast(Int64.Parse(StringNum));\n }\n /// \n /// Factorize long integers: speed optimized\n /// \n /// Int64\n /// Int64[]\n public static Int64[] FactorizeFast(Int64 Num)\n {\n #region vars\n // list of Factors\n List _arrFactors = new List();\n // temp variable\n Int64 _num = Num;\n #endregion\n #region Check if the number is Prime (<100)\n for (int k = 0; k < Primes.Length; k++)\n {\n if (_num == Primes[k])\n {\n _arrFactors.Add(Primes[k]);\n return _arrFactors.ToArray();\n }\n }\n #endregion\n #region Try to factorize using Primes Array\n for (int k = 0; k < Primes.Length; k++)\n {\n int m = Primes[k];\n if (_num < m) break;\n while (_num % m == 0)\n {\n _arrFactors.Add(m);\n _num = (Int64)_num / m;\n }\n }\n if (_num < _startNum)\n {\n _arrFactors.Sort();\n return _arrFactors.ToArray();\n }\n #endregion\n #region Main Factorization Algorithm\n Int64 _upMargin = (Int64)Math.Sqrt(_num) + 1;\n Int64 i = _startNum;\n while (i <= _upMargin)\n {\n if (_num % i == 0)\n {\n _arrFactors.Add(i);\n _num = _num / i;\n _upMargin = (Int64)Math.Sqrt(_num) + 1;\n i = _startNum;\n }\n else { i = i + 2; }\n }\n _arrFactors.Add(_num);\n _arrFactors.Sort();\n return _arrFactors.ToArray();\n #endregion\n }\n #endregion\n static IEnumerable GetDivisors(int n)\n {\n return from a in Enumerable.Range(2, n / 2)\n where n % a == 0\n select a;\n }\n static void Main()\n {\n reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);\n writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);\n var q = ReadLong();\n var div = FactorizeFast(q);\n if (div.Length < 2)\n {\n Console.WriteLine(1);\n Console.WriteLine(0);\n reader.Close();\n writer.Close();\n return;\n }\n if (div.Length == 2)\n {\n Console.WriteLine(2);\n reader.Close();\n writer.Close();\n return;\n }\n Console.WriteLine(1);\n Console.WriteLine(div[0] * div[1]);\n reader.Close();\n writer.Close();\n }\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\"\", array));\n }\n\n public static void Write(params T[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n #endregion\n}", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass TEST{\n\tstatic void Main(){\n\t\tSol mySol =new Sol();\n\t\tmySol.Solve();\n\t}\n}\n\nclass Sol{\n\tpublic void Solve(){\n\t\t\n\t\tlong[][] nCr = new long[21][];\n\t\tfor(int i=0;i<21;i++){\n\t\t\tnCr[i] = new long[21];\n\t\t}\n\t\t\n\t\tnCr[0][0] = 1;\n\t\tfor(int i=1;i<21;i++){\n\t\t\tnCr[i][0] = 1;\n\t\t\tfor(int j=1;j<21;j++){\n\t\t\t\tnCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1];\n\t\t\t}\n\t\t}\n\t\tlong[] dp = new long[N+1];\n\t\tdp[0] = 1;\n\t\tint[] cnt = new int[10];\n\t\tfor(int i=0;i=0;v--){\n\t\t\tif(cnt[v] == 0) continue;\n//Console.WriteLine(String.Join(\" \", dp));\n\t\t\tlong[] ndp = new long[N+1];\n\t\t\tfor(int l=0;l<=N;l++){\n\t\t\t\tif(dp[l] == 0) continue;\n\t\t\t\tfor(int c = 1; c <= cnt[v]; c++){\n\t\t\t\t\tint m = l + 1;\n\t\t\t\t\tif(v == 0) m--;\n\t\t\t\t\tndp[l + c] += dp[l] * nCr[m - 1 + c][c];\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = ndp;\n//Console.WriteLine(\"ndpp:{0}\",String.Join(\" \", dp));\n\t\t}\n\t\t\n\t\tConsole.WriteLine(dp.Sum());\n\t}\n\tint N;\n\tString S;\n\tpublic Sol(){\n\t\tS = rs();\n\t\tN = S.Length;\n\t}\n\n\tstatic String rs(){return Console.ReadLine();}\n\tstatic int ri(){return int.Parse(Console.ReadLine());}\n\tstatic long rl(){return long.Parse(Console.ReadLine());}\n\tstatic double rd(){return double.Parse(Console.ReadLine());}\n\tstatic String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}\n\tstatic int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}\n\tstatic long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}\n\tstatic double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}\n}\n", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2"} {"source_code": "using System;\nusing System.Text;\n\nnamespace CodeForces\n{\n class Program\n {\n public static bool IsPrim(int n, int k)\n {\n if(k == 1)\n return false;\n \n if(n==2 && k <=2)\n return true;\n\n for (int i = 2; i <= Math.Sqrt(n); i++)\n if (n % i == 0 && (i >= k || n / i >= k))\n return false;\n return true;\n }\n static void Main()\n {\n var input = Console.ReadLine().Split(' ');\n var n = Int32.Parse(input[0]);\n var m = Int32.Parse(input[1]);\n var k = Int32.Parse(input[2]);\n\n if (m < 2 * k || n % 2 == 0 || IsPrim(m, k))\n {\n Console.WriteLine(\"Marsel\");\n return;\n }\n Console.WriteLine(\"Timur\"); \n }\n }\n}", "src_uid": "4a3767011ddac874efa021fff7c94432"} {"source_code": "using System;\nusing System.IO;\n\nclass SOS{\n static void Main(){\n string[] tmp = Console.ReadLine().Split();\n int n=int.Parse(tmp[0]);\n int k=int.Parse(tmp[1]);\n string S=Console.ReadLine();\n int ans=0;\n for(int i=0;i+k-1mx)mx=cur;\n }else{\n cur=0;\n }\n }\n if(mx==k)\n ans=1;\n }\n if(ans==1)\n Console.WriteLine(\"YES\");\n else\n \n Console.WriteLine(\"NO\");\n }\n \n}", "src_uid": "5bd578d3da5837c259b222336a194d12"} {"source_code": "//\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\nusing System.Linq;\n\nnamespace sar_cs\n{\n static class Helpers\n {\n // Mono lacks this override of string.Join()\n public static string Join(this IEnumerable objs, string sep)\n {\n var sb = new StringBuilder();\n foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }\n return sb.ToString();\n }\n\n public static string AsString(this double a, int digits)\n {\n return a.ToString(\"F\" + digits, CultureInfo.InvariantCulture);\n }\n\n public static Stopwatch SW = Stopwatch.StartNew();\n }\n\n public class Program\n {\n #region Helpers\n\n public class Parser\n {\n const int BufSize = 8000;\n TextReader s;\n char[] buf = new char[BufSize];\n int bufPos;\n int bufDataSize;\n bool eos; // eos read to buffer\n int lastChar = -2;\n int nextChar = -2;\n StringBuilder sb = new StringBuilder();\n\n void FillBuf()\n {\n if (eos) return;\n bufDataSize = s.Read(buf, 0, BufSize);\n if (bufDataSize == 0) eos = true;\n bufPos = 0;\n }\n\n int Read()\n {\n if (nextChar != -2)\n {\n lastChar = nextChar;\n nextChar = -2;\n }\n else\n {\n if (bufPos == bufDataSize) FillBuf();\n if (eos) lastChar = -1;\n else lastChar = buf[bufPos++];\n }\n return lastChar;\n }\n\n void Back()\n {\n if (lastChar == -2) throw new Exception(); // no chars were ever read\n nextChar = lastChar;\n }\n\n public Parser()\n {\n s = Console.In;\n }\n\n public int ReadInt()\n {\n int res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-') { sign = 1; c = Read(); }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new FormatException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new FormatException();\n Back();\n return checked(res * sign);\n }\n\n public long ReadLong()\n {\n long res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = 1;\n c = Read();\n }\n int len = 0;\n\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new FormatException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new FormatException();\n Back();\n return checked(res * sign);\n }\n\n public int ReadLnInt()\n {\n int res = ReadInt(); ReadLine(); return res;\n }\n\n public long ReadLnLong()\n {\n long res = ReadLong(); ReadLine(); return res;\n }\n\n public double ReadDouble()\n {\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n\n int sign = 1;\n if (c == '-') { sign = -1; c = Read(); }\n\n sb.Length = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c); c = Read();\n }\n\n Back();\n var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);\n return res * sign;\n }\n\n public string ReadLine()\n {\n int c = Read();\n sb.Length = 0;\n while (c != -1 && c != 13 && c != 10)\n {\n sb.Append((char)c); c = Read();\n }\n if (c == 13) { c = Read(); if (c != 10) Back(); }\n return sb.ToString();\n }\n\n public bool SeekEOF\n {\n get\n {\n L0:\n int c = Read();\n if (c == -1) return true;\n if (char.IsWhiteSpace((char)c)) goto L0;\n Back();\n return false;\n }\n }\n\n public int[] ReadIntArr(int n)\n {\n var a = new int[n]; for (int i = 0; i < n; i++) a[i] = ReadInt(); return a;\n }\n\n public long[] ReadLongArr(int n)\n {\n var a = new long[n]; for (int i = 0; i < n; i++) a[i] = ReadLong(); return a;\n }\n }\n\n static void pe() { Console.WriteLine(\"???\"); Environment.Exit(0); }\n static void re() { Environment.Exit(55); }\n static void Swap(ref T a, ref T b) { T t = a; a = b; b = t; }\n static int Sqr(int a) { return a * a; }\n static long SqrL(int a) { return (long)a * a; }\n static long Sqr(long a) { return a * a; }\n static double Sqr(double a) { return a * a; }\n\n static StringBuilder sb = new StringBuilder();\n static Random rand = new Random(5);\n\n #endregion Helpers\n\n static void Main(string[] args)\n {\n checked\n {\n //Console.SetIn(File.OpenText(\"_input\"));\n var parser = new Parser();\n while (!parser.SeekEOF)\n {\n long x = parser.ReadInt();\n long t = parser.ReadInt();\n long a = parser.ReadInt();\n long b = parser.ReadInt();\n long da = parser.ReadInt();\n long db = parser.ReadInt();\n\n var result = \"NO\";\n\n for (int ta = 0; ta <= t; ta++)\n for (int tb = 0; tb <= t; tb++)\n {\n //long cost_a=a\n long res = 0;\n if (ta < t) res += (a - ta * da);\n if (tb < t) res += (b - tb * db);\n if (res == x)\n {\n result = \"YES\";\n break;\n }\n }\n\n Console.WriteLine(result);\n }\n }\n }\n\n //static void Main(string[] args)\n //{\n // new Thread(Main2, 50 << 20).Start();\n //}\n }\n}", "src_uid": "f98168cdd72369303b82b5a7ac45c3af"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\n//using System.Numerics;\nnamespace Program\n{\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Integer();\n var k = sc.Long();\n var m = sc.Long();\n var dp = new long[1001, 101, 2];\n for (int i = 0; i < 1001; i++)\n for (int j = 0; j < 101; j++)\n for (int l = 0; l < 2; l++)\n dp[i, j, l] = -1;\n var pow1 = new long[1001];\n var pow2 = new long[1001];\n for (long i = 0, u = 1, v = 1; i < 1001; i++)\n {\n pow1[i] = u;\n pow2[i] = v;\n u = u * 10 % m;\n v = v * 10 % k;\n }\n Func dfs = null;\n dfs = (id, rem, f) =>\n {\n if (rem == 0 && f == 1)\n if (id != n) return (pow1[n - id - 1] * 9) % m;\n else return 1;\n if (id == n || (rem == 0 && f == 1)) return 0;\n if (dp[id, rem, f] >= 0) return dp[id, rem, f];\n long ret = 0;\n for (int i = 0; i < 10; i++)\n ret = (ret + dfs(id + 1,\n (int)((rem + i * pow2[id]) % k),\n ((f == 1 || i > 0) ? 1 : 0))) % m;\n return dp[id, rem, f] = ret;\n\n };\n IO.Printer.Out.WriteLine(dfs(0, 0, 0));\n }\n\n\n internal IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; }\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n\n }\n\n}\n\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Linq;\n public class Printer : StreamWriter\n {\n static Printer()\n {\n Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };\n }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }\n public void Write(string format, IEnumerable source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, IEnumerable source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n private readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }\n public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != '-' && (b < '0' || '9' < b));\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n public void Flush() { str.Flush(); }\n\n }\n}\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion", "src_uid": "656bf8df1e79499aa2ab2c28712851f0"} {"source_code": "using System;\nclass Demo\n{\n static void Main()\n {\n int[] n = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n double a = Math.Sqrt(n[0] * n[0] + n[1] * n[1]) % 2;\n bool ans = a > 1;\n if (Math.Sign(n[0] * n[1]) < 0 && a % 1 != 0) ans = !ans;\n Console.WriteLine(ans ? \"white\" : \"black\");\n }\n}", "src_uid": "8c92aac1bef5822848a136a1328346c6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Text;\n\nnamespace Amr_and_Music\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int n = Next();\n int k = Next();\n\n var nn = new Tuple[n];\n for (int i = 0; i < n; i++)\n {\n nn[i] = new Tuple(Next(), i + 1);\n }\n\n Array.Sort(nn, new Sort());\n\n var inds = new List();\n foreach (var tuple in nn)\n {\n if (tuple.Item1 <= k)\n {\n k -= tuple.Item1;\n inds.Add(tuple.Item2);\n }\n else\n {\n break;\n }\n }\n\n writer.WriteLine(inds.Count);\n foreach (int ind in inds)\n {\n writer.Write(ind);\n writer.Write(' ');\n }\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n\n #region Nested type: Sort\n\n private class Sort : IComparer>\n {\n #region IComparer> Members\n\n public int Compare(Tuple x, Tuple y)\n {\n return x.Item1.CompareTo(y.Item1);\n }\n\n #endregion\n }\n\n #endregion\n }\n}", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nclass Solution{\n\t static void Main(string[] args) {\n const int MOD = 1000000007;\n int n = int.Parse(Console.ReadLine());\n int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), x => Convert.ToInt32(x));\n C = new long[200, 200];\n C[0, 0] = 1;\n for (int i = 1; i < 200; i++) {\n C[i, 0] = C[i, i] = 1;\n for (int j = 1; j <= i; j++)\n C[i, j] = (C[i - 1, j] + C[i - 1, j - 1]) % MOD;\n }\n\n long ans = 0;\n for (int k = a.Sum(); k <= n; k++) {\n\n long[,] dp = new long[110, 30];\n dp[k, 0] = 1;\n\n for (int j = 0; j < 10; j++)\n for (int i = a[j]; i <= k; i++)\n for (int l = a[j]; l <= i; l++) {\n if (j == 0) dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i - 1, l) % MOD) % MOD;\n else dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i, l) % MOD) % MOD;\n }\n\n ans += dp[0, 10];\n ans %= MOD;\n }\n\n Console.WriteLine(ans);\n\t }\n static long[,] C;\n static long CNK(long n, long k) {\n if (k > n || k < 0) return 0;\n if (k == n || k == 0) return 1;\n return C[n, k];\n }\n}", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755"} {"source_code": "using System;\n\nclass _1092B\n{\n\tstatic void Main()\n\t{\n\t\tint n=int.Parse(Console.ReadLine());\n\t\tint[]a=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);\n\n\t\tArray.Sort(a);\n\t\tint ans=0;\n\t\tfor(int i=0;i();\n long cx = 1;\n while (true)\n {\n long cy = 1;\n while (true)\n {\n if (cx + cy >= l && cx + cy <= r)\n a.Add(cx + cy);\n if (cy * 1.0 * y > r)\n break;\n cy *= y;\n }\n\n if (cx * 1.0 * x > r)\n break;\n cx *= x;\n }\n\n a.Sort();\n a.Add(r + 1);\n long p = l - 1;\n long ans = 0;\n foreach (long aa in a)\n {\n ans = Math.Max(ans, aa - p - 1);\n p = aa;\n }\n\n Write(ans);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"input.txt\");\n //writer = new StreamWriter(\"output.txt\");\n#endif\n try\n {\n new Solver().Solve();\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f"} {"source_code": "using System;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Threading;\nusing System.Linq;\n\nnamespace CodeForces\n{\n\tclass C\n\t{\n\n\t\tprivate void Solve()\n\t\t{\n\t\t\tlong n = NextLong();\n\t\t\tOut.WriteLine( Solve( n ) );\n\t\t}\n\n\t\tprivate long Solve( long n )\n\t\t{\n\t\t\tif ( n % 3 != 0 )\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tall = new HashSet();\n\t\t\tn /= 3;\n\t\t\tlong res = 0;\n\t\t\tfor ( long i = 2; i * i * i <= n; ++i )\n\t\t\t{\n\t\t\t\tif ( n % i != 0 ) continue;\n\t\t\t\tfor ( long a = 1; a < i; ++a )\n\t\t\t\t{\n\t\t\t\t\tlong b = i - a;\n\t\t\t\t\tlong t = n / i;\n\t\t\t\t\tlong d = i * i - 4 * ( a * b - t );\n\t\t\t\t\tif ( d >= 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\tlong sq = (long)Math.Sqrt( d );\n\t\t\t\t\t\twhile ( sq * sq < d ) ++sq;\n\t\t\t\t\t\twhile ( sq * sq > d ) --sq;\n\t\t\t\t\t\tif ( sq * sq == d )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlong c = -i + sq;\n\t\t\t\t\t\t\tif ( c >= 0 && c % 2 == 0 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tc /= 2;\n\t\t\t\t\t\t\t\tif ( ( a + b ) * ( b + c ) * ( a + c ) == n )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tUpdate( a, b, c );\n\t\t\t\t\t\t\t\t\tUpdate( a, c, b );\n\t\t\t\t\t\t\t\t\tUpdate( b, a, c );\n\t\t\t\t\t\t\t\t\tUpdate( b, c, a );\n\t\t\t\t\t\t\t\t\tUpdate( c, b, a );\n\t\t\t\t\t\t\t\t\tUpdate( c, a, b );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn all.Count;\n\t\t}\n\n\t\tprivate HashSet all;\n\t\tprivate void Update( long a, long b, long c )\n\t\t{\n\t\t\tall.Add( a.ToString() + \"#\" + b.ToString() + \"#\" + c.ToString() );\n\t\t}\n\n\t\t#region Local wireup\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn _in.NextInt();\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn _in.NextLong();\n\t\t}\n\n\t\tpublic string NextLine()\n\t\t{\n\t\t\treturn _in.NextLine();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn _in.NextDouble();\n\t\t}\n\n\t\treadonly Scanner _in = new Scanner();\n\t\tstatic readonly TextWriter Out = Console.Out;\n\n\t\tvoid Start()\n\t\t{\n#if !ONLINE_JUDGE\n\t\t\tvar timer = new Stopwatch();\n\t\t\ttimer.Start();\n#endif\n\t\t\tvar t = new Thread( Solve, 20000000 );\n\t\t\tt.Start();\n\t\t\tt.Join();\n#if !ONLINE_JUDGE\n\t\t\ttimer.Stop();\n\t\t\tConsole.WriteLine( string.Format( CultureInfo.InvariantCulture, \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0 ) );\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\n\t\tstatic void Main()\n\t\t{\n\t\t\tnew C().Start();\n\t\t}\n\n\t\tclass Scanner : IDisposable\n\t\t{\n\t\t\t#region Fields\n\n\t\t\treadonly TextReader _reader;\n\t\t\treadonly int _bufferSize;\n\t\t\treadonly bool _closeReader;\n\t\t\treadonly char[] _buffer;\n\t\t\tint _length, _pos;\n\n\t\t\t#endregion\n\n\t\t\t#region .ctors\n\n\t\t\tpublic Scanner( TextReader reader, int bufferSize, bool closeReader )\n\t\t\t{\n\t\t\t\t_reader = reader;\n\t\t\t\t_bufferSize = bufferSize;\n\t\t\t\t_closeReader = closeReader;\n\t\t\t\t_buffer = new char[_bufferSize];\n\t\t\t\tFillBuffer( false );\n\t\t\t}\n\n\t\t\tpublic Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }\n\n\t\t\tpublic Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }\n\n#if ONLINE_JUDGE\n\t\t\tpublic Scanner() : this( Console.In, false ) { }\n#else\n\t\t\tpublic Scanner() : this( \"input.txt\" ) { }\n#endif\n\n\t\t\t#endregion\n\n\t\t\t#region IDisposable Members\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\tif ( _closeReader )\n\t\t\t\t{\n\t\t\t\t\t_reader.Close();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Properties\n\n\t\t\tpublic bool Eof\n\t\t\t{\n\t\t\t\tget\n\t\t\t\t{\n\t\t\t\t\tif ( _pos < _length ) return false;\n\t\t\t\t\tFillBuffer( false );\n\t\t\t\t\treturn _pos >= _length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Methods\n\n\t\t\tprivate char NextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos++];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos++];\n\t\t\t}\n\n\t\t\tprivate char PeekNextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos];\n\t\t\t}\n\n\t\t\tprivate void FillBuffer( bool throwOnEof )\n\t\t\t{\n\t\t\t\t_length = _reader.Read( _buffer, 0, _bufferSize );\n\t\t\t\tif ( throwOnEof && Eof )\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException( \"Can't read beyond the end of file\" );\n\t\t\t\t}\n\t\t\t\t_pos = 0;\n\t\t\t}\n\n\t\t\tpublic int NextInt()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tint res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic long NextLong()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic string NextLine()\n\t\t\t{\n\t\t\t\tSkipUntilNextLine();\n\t\t\t\tif ( Eof ) return \"\";\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn builder.ToString();\n\t\t\t}\n\n\t\t\tpublic double NextDouble()\n\t\t\t{\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn double.Parse( builder.ToString(), CultureInfo.InvariantCulture );\n\t\t\t}\n\n\t\t\tprivate void SkipWhitespaces()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void SkipUntilNextLine()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static bool IsWhitespace( char c )\n\t\t\t{\n\t\t\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\tprivate static bool IsEndOfLine( char c )\n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\t#endregion\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "07e58a46f2d562a44b7c771edad361b4"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n static int M;\n\n static void Main(string[] args)\n {\n long[] q1 = Console.ReadLine().Split(' ').Select(t => Int64.Parse(t)).ToArray();\n long N = q1[0];\n long K = q1[1];\n int L = (int)q1[2];\n M = (int)q1[3];\n\n int[, , ,] dp = new int[65, 2, 2, 2]; // gen, result, head, tail\n dp[0, 0, 0, 0] = 1;\n dp[0, 0, 1, 1] = 1;\n\n int[,] accum = null;\n\n for (int i = 1; i <= 64; ++i)\n {\n int[,] prevAccum = null;\n if (((1L << i - 1) & N) != 0)\n {\n if (accum == null)\n {\n accum = new int[2, 2]; // result, tail\n accum[0, 0] = (int)(((long)dp[i - 1, 0, 0, 0] + (long)dp[i - 1, 0, 1, 0]) % M);\n accum[0, 1] = (int)(((long)dp[i - 1, 0, 0, 1] + (long)dp[i - 1, 0, 1, 1]) % M);\n accum[1, 0] = (int)(((long)dp[i - 1, 1, 0, 0] + (long)dp[i - 1, 1, 1, 0]) % M);\n accum[1, 1] = (int)(((long)dp[i - 1, 1, 0, 1] + (long)dp[i - 1, 1, 1, 1]) % M);\n }\n else\n {\n prevAccum = accum;\n accum = new int[2, 2];\n }\n }\n \n for (int leftRes = 0; leftRes <= 1; ++leftRes)\n {\n for (int leftTail = 0; leftTail <= 1; ++leftTail)\n {\n for (int rightRes = 0; rightRes <= 1; ++rightRes)\n {\n for (int rightHead = 0; rightHead <= 1; ++rightHead)\n {\n for (int rightTail = 0; rightTail <= 1; ++rightTail)\n {\n int res = leftRes | rightRes | (leftTail & rightHead);\n for (int leftHead = 0; leftHead <= 1; ++leftHead)\n {\n long t = (long)dp[i, res, leftHead, rightTail] +\n (long)dp[i - 1, leftRes, leftHead, leftTail] * (long)dp[i - 1, rightRes, rightHead, rightTail];\n\n dp[i, res, leftHead, rightTail] = (int)(t % M);\n }\n\n if (prevAccum != null)\n {\n long t = (long)accum[res, rightTail] +\n (long)prevAccum[leftRes, leftTail] * (long)dp[i - 1, rightRes, rightHead, rightTail];\n accum[res, rightTail] = (int)(t % M);\n }\n }\n }\n }\n }\n }\n }\n\n\n int total = 1 % M;\n for (int i = 0; i < L; ++i)\n {\n if (((1L << i) & K) != 0)\n {\n total = (int)(((long)total * ((long)accum[1, 0] + (long)accum[1, 1])) % M);\n }\n else\n {\n total = (int)(((long)total * ((long)accum[0, 0] + (long)accum[0, 1])) % M);\n }\n }\n\n for (int i = L; i < 64; ++i)\n {\n if (((1L << i) & K) != 0)\n {\n total = 0;\n break;\n }\n }\n\n Console.WriteLine(total);\n }\n}\n", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"} {"source_code": "using System;\n\nnamespace HW\n{\n class Program\n {\n static void Main()\n {\n string[] s = Console.ReadLine().Split();\n int[] a = new int[int.Parse(s[0])];\n int[] b = new int[int.Parse(s[1])];\n\n string[] st = Console.ReadLine().Split();\n\n for (int i = 0; i= 0 )\n {\n if (min>a[i])\n {\n min = a[i];\n bo = true;\n }\n }\n else\n {\n if (min1 > a[i])\n {\n min1 = a[i];\n }\n }\n }\n\n if (bo == true)\n {\n Console.WriteLine(min);\n }\n else\n {\n if (min1 < b[0])\n {\n Console.WriteLine(min1 * 10 + b[0]);\n }\n else\n {\n Console.WriteLine(b[0] * 10 + min1);\n }\n }\n\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"source_code": "using System;\nusing System.Collections.Generic;\n\npublic class ColorDogs{\n public bool canColor(int n, string s){\n bool retV = false;\n\t DictionaryseenColors = new Dictionary();\n\t if(n==1){\n\t retV = true;\n\t }else{\n\t for(int i=0;i int.Parse(x, info)).ToArray();\n var n = nmk[0];\n var k = nmk[2];\n\n var a = new int[n][];\n for (int i = 0; i < n; ++i)\n {\n a[i] = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();\n }\n\n var res = Calc(k, a);\n\n tw.WriteLine(res);\n }\n\n private static long Calc(int k, int[][] a)\n {\n var n = a.Length;\n var m = a[0].Length;\n\n if (k < n + m - 1)\n {\n return 0;\n }\n\n var p = new int[n * m];\n\n var patterns = new List();\n CreatePatterns(ref patterns, 1, 0, 0, n, m, k, ref p);\n\n var res = 0L;\n\n foreach (var pattern in patterns)\n {\n if (!IsInvalid(pattern, a))\n {\n var fixedCells = a.SelectMany(x => x).Where(x => x > 0).Distinct().Count();\n res = (res + Permutation(k - fixedCells, pattern.Distinct().Count() - fixedCells)) % 1000000007;\n }\n }\n\n return res;\n }\n\n private static bool IsInvalid(int[] pattern, int[][] a)\n {\n var n = a.Length;\n var m = a[0].Length;\n\n var colorMap = new Dictionary();\n for (int i = 0; i < n; ++i)\n {\n for (int j = 0; j < m; ++j)\n {\n if (a[i][j] > 0)\n {\n if (!colorMap.ContainsKey(a[i][j]))\n {\n foreach (var p in colorMap.Values)\n {\n if (p == pattern[i * m + j])\n {\n return true;\n }\n }\n\n colorMap[a[i][j]] = pattern[i * m + j];\n }\n else\n { \n if (colorMap[a[i][j]] != pattern[i * m + j])\n {\n return true;\n }\n }\n }\n }\n }\n\n return false;\n }\n\n private static int Permutation(int n, int k)\n {\n var res = 1;\n for (int i = 0; i < k; ++i)\n {\n res *= n - i;\n }\n return res;\n }\n\n private static void CreatePatterns(ref List patterns, int newColor, int r, int c, int n, int m, int k, ref int[] board)\n {\n if (r == n)\n {\n patterns.Add(board.Clone() as int[]);\n return;\n }\n\n if (c == m)\n {\n CreatePatterns(ref patterns, newColor, r + 1, 0, n, m, k, ref board);\n return;\n }\n\n if (newColor > k)\n {\n return;\n }\n\n var used = new bool[newColor];\n\n for (int i = 0; i <= r; ++i)\n {\n for (int j = 0; j <= c; ++j)\n {\n if (!(i == r && j == c))\n {\n used[board[i * m + j]] = true;\n }\n }\n }\n\n for (int currentColor = 1; currentColor < newColor; ++currentColor)\n {\n if (!used[currentColor])\n {\n board[r * m + c] = currentColor;\n CreatePatterns(ref patterns, newColor, r, c + 1, n, m, k, ref board);\n board[r * m + c] = 0;\n }\n }\n board[r * m + c] = newColor;\n CreatePatterns(ref patterns, newColor + 1, r, c + 1, n, m, k, ref board);\n board[r * m + c] = 0;\n }\n }\n}\n", "src_uid": "5bb21f49d976cfa16a239593a95c53b5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A.Bear_and_Game\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = Convert.ToInt32(Console.ReadLine());\n string[] s = Console.ReadLine().Split();\n int[] xr = new int[n];\n for (int i = 0; i < n; i++)\n {\n xr[i] = int.Parse(s[i]);\n }\n int sum = 0;\n if (xr[0] <= 15 && n > 1)\n {\n for (int i = 0; i < n - 1; i++)\n {\n if (xr[i + 1] - xr[i] > 15 && xr[i] + 15 <= 90)\n {\n sum = 0;\n sum = xr[i] + 15;\n Console.WriteLine(sum);\n break;\n }\n else if (xr[i + 1] - xr[i] <= 15)\n {\n sum++;\n }\n }\n }\n if (xr[0] > 15)\n {\n Console.WriteLine(15);\n }\n if (sum == n - 1 && n > 1 && xr[0] <= 15 && xr[n - 1] + 15 <= 90)\n {\n Console.WriteLine(xr[n - 1] + 15);\n }\n if (sum == n - 1 && xr[0] <= 15 && xr[n - 1] > 75)\n {\n Console.WriteLine(90);\n }\n if (n == 1 && xr[0] <= 15)\n {\n Console.WriteLine(xr[0] + 15);\n }\n }\n }\n}", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Competitions.Preparations\n{\n public class _725C\n {\n public static void Main(string[] args)\n {\n var s = Console.ReadLine();\n var arr = new int[26];\n var first = 0;\n var last = 0;\n for (int i = 0; i < s.Length; ++i)\n {\n if (arr[s[i] - 'A'] != 0)\n {\n first = arr[s[i] - 'A'] - 1;\n last = i;\n break;\n }\n\n arr[s[i] - 'A'] = i+1;\n }\n\n var w = new char[26];\n\n if (last == first + 1)\n {\n Console.WriteLine(\"Impossible\");\n return;\n }\n\n var startpos = (last - first)/2;\n int j = last;\n int ii = startpos;\n for (; j >= first; --j, --ii)\n {\n if (ii == -1) ii = 25;\n w[ii] = s[j];\n }\n\n for (; j >= 0; --j, --ii)\n {\n w[ii] = s[j];\n }\n\n for (j = s.Length-1; j > last; --j, --ii)\n {\n w[ii] = s[j];\n }\n\n Console.WriteLine(new string(w.Take(13).ToArray()));\n Console.WriteLine(new string(w.Skip(13).Reverse().ToArray()));\n }\n }\n}\n", "src_uid": "56c5ea443dec7a732802b16aed5b934d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class R140_Div2_227A\n {\n static void Main(string[] args)\n {\n string[] s;\n s = (Console.ReadLine().Split());\n long ax = Convert.ToInt64(s[0]);\n long ay = Convert.ToInt64(s[1]);\n s = (Console.ReadLine().Split());\n long bx = Convert.ToInt64(s[0]);\n long by = Convert.ToInt64(s[1]);\n s = (Console.ReadLine().Split());\n long cx = Convert.ToInt64(s[0]);\n long cy = Convert.ToInt64(s[1]);\n\n long d = (cx - ax) * (by - ay) - (bx - ax) * (cy - ay);\n string ret;\n if (d == 0)\n ret = \"TOWARDS\";\n else if (d < 0)\n ret = \"LEFT\";\n else // d > 0\n ret = \"RIGHT\";\n Console.WriteLine(ret);\n }\n }\n}\n", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"} {"source_code": "using System; \nusing System.Linq;\nusing System.Collections.Generic;\n\nclass P\n{\n static void Main()\n {\n int[] ABC = Console.ReadLine().Split().Select(int.Parse).ToArray();\n if (ABC.Count(x => x == 2) >= 2 || ABC.Contains(1) || ABC.Count(x => x == 3) == 3 || (ABC.Contains(2) && ABC.Count(x => x == 4) == 2))\n {\n Console.WriteLine(\"YES\");\n }\n else\n {\n Console.WriteLine(\"NO\");\n }\n /*int n = 30;\n for (int i = 1; i < n; i++)\n {\n for (int j = 1; j < n; j++)\n {\n for (int k = 1; k < n; k++)\n {\n A(new int[] { i, j, k });\n }\n }\n }*/\n }\n static void A(int[] ABC)\n {\n bool res = false;\n for (int i = 0; i < ABC[0]; i++)\n {\n for (int j = 0; j < ABC[1]; j++)\n {\n for (int k = 0; k < ABC[2]; k++)\n {\n bool pokapoka = true;\n for (int l = 0; l < 10; l++)\n {\n if (!(l % ABC[0] == i || l % ABC[1] == j || l % ABC[2] == k))\n {\n pokapoka = false;\n }\n }\n if (pokapoka)\n {\n res = true;\n goto end;\n }\n }\n }\n }\n end:;\n if (res != (ABC.Count(x => x == 2) >= 2 || ABC.Contains(1) || ABC.Count(x => x == 3) == 3 || (ABC.Contains(2) && ABC.Count(x => x == 4) == 2)))\n {\n Console.WriteLine($\"{ABC[0]} {ABC[1]} {ABC[2]}\");\n }\n }\n}", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n\n static long Pow2(long m)\n {\n long temp = 0;\n while (System.Math.Pow(2, temp) <= m)\n {\n temp++;\n }\n return (long) System.Math.Pow(2,temp-1) ;\n }\n static void Main()\n {\n long n, b, p;\n string test = Console.ReadLine();\n string[] splitString = test.Split(' ');\n long[] ints = new long[3];\n for (int i = 0; i < 3; i++)\n {\n long x;\n long.TryParse(splitString[i], out x);\n ints[i] = x;\n }\n\n n = ints[0];\n b = ints[1];\n p = ints[2];\n\n p = p * n;\n long but = 0;\n long temp;\n while (n > 1)\n {\n temp = Program.Pow2(n);\n but = but + temp * b + temp / 2;\n n = n - temp/2;\n }\n Console.WriteLine(but + \" \" + p);\n\n }\n }\n}\n", "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"source_code": "using System;\n\nnamespace In_Search_of_an_Easy_Problem\n{\n class Program\n {\n static void Main(string[] args)\n {\n string NumeroDePersonas = Console.ReadLine();\n string[] Testimonio = Console.ReadLine().Split(' ');\n string Dificultad = \"EASY\";\n for(int i =0; i < Testimonio.Length; i++)\n {\n if (Testimonio[i] == \"1\")\n {\n Dificultad = \"HARD\";\n goto Terminar;\n }\n }\n Terminar:\n Console.WriteLine(Dificultad);\n }\n }\n}\n", "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n public static void Main(string[] args)\n {\n var n = int.Parse(Console.ReadLine());\n\n var a = new int[n];\n var b = new int[n];\n\n for (int i = a.Length, j = 0; j= 1; i--)\n {\n Console.Write(i+\" \");\n }\n }\n else\n {\n Console.WriteLine(-1);\n }\n }\n\n public static void s(int[] arr)\n {\n for (int i = 0; i < arr.Length-1; i++)\n {\n for (int j = i; j < arr.Length-1; j++)\n {\n if (arr[j] > arr[j + 1])\n {\n var tmp = arr[j];\n arr[j] = arr[j + 1];\n arr[j + 1] = tmp;\n }\n }\n }\n }\n}", "src_uid": "fe8a0332119bd182a0a5b7758716317e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Linq;\nusing System.Collections;\n\nnamespace Task\n{\n class MyIo\n {\n char[] separators = new char[] { ' ', '\\t' };\n\n#if TEST\n TextReader inputStream = new StreamReader(\"..\\\\..\\\\input.txt\");\n#else\n TextReader inputStream = System.Console.In;\n#endif\n TextWriter outputStream = Console.Out;\n\n string[] tokens;\n int pointer;\n\n public string NextLine()\n {\n try\n {\n return inputStream.ReadLine();\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public string NextString()\n {\n try\n {\n while (tokens == null || pointer >= tokens.Length)\n {\n tokens = NextLine().Split(separators, StringSplitOptions.RemoveEmptyEntries);\n pointer = 0;\n }\n return tokens[pointer++];\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public int NextInt()\n {\n return int.Parse(NextString());\n }\n\n public long NextLong()\n {\n return long.Parse(NextString());\n }\n\n public void Print(string format, params object[] args)\n {\n outputStream.Write(format, args);\n }\n\n public void PrintLine(string format, params object[] args)\n {\n outputStream.WriteLine(format, args);\n }\n\n public void Print(T o)\n {\n outputStream.Write(o);\n }\n\n public void PrintLine(T o)\n {\n outputStream.WriteLine(o);\n }\n\n public void Close()\n {\n inputStream.Close();\n outputStream.Close();\n }\n }\n\n\n\n\n class Program\n {\n MyIo io = new MyIo();\n\n void Solve()\n {\n // Place your code here\n\n int a = io.NextInt();\n int b = io.NextInt();\n int mod = io.NextInt();\n\n if (b >= mod)\n {\n io.Print(2);\n return;\n }\n\n BitArray bits = new BitArray(mod);\n int result = -1;\n for (int A = 1; A <= a; A++)\n {\n long mlp = A * 1000000000L;\n long temp = mlp % mod;\n if (temp != 0)\n {\n if (mod - temp > b)\n {\n result = A;\n break;\n }\n }\n if (bits[(int)temp])\n break;\n bits[(int)temp] = true;\n }\n\n if (result == -1)\n io.Print(2);\n else\n {\n string s = result.ToString();\n while (s.Length < 9)\n s = \"0\" + s;\n io.Print(1 + \" \" + s);\n }\n }\n\n static void Main(string[] args)\n {\n var p = new Program();\n\n p.Solve();\n p.io.Close();\n }\n }\n}\n", "src_uid": "8b6f633802293202531264446d33fee5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A796\n{\n class A796\n {\n static void Main(string[] args)\n {\n string[] str1 = Console.ReadLine().Split();\n int n = int.Parse(str1[0]);\n int m = int.Parse(str1[1]);\n int k = int.Parse(str1[2]);\n int[] a = new int[n];\n string[] str = Console.ReadLine().Split();\n int index = 0;\n int min = Int32.MaxValue;\n for (int i = 0; i < n; i++)\n {\n a[i] = int.Parse(str[i]);\n }\n for (int i = 0; i < n; i++)\n {\n if (a[i] <=k && a[i] != 0)\n {\n index = i+1;\n\n if (Math.Abs(index - m) < min)\n {\n min = Math.Abs(index - m);\n \n }\n }\n }\n Console.WriteLine(10 * min);\n\n\n }\n }\n}\n", "src_uid": "57860e9a5342a29257ce506063d37624"} {"source_code": "/*\ncsc -debug F.cs && mono --debug F.exe <<< \"5\nabaca\"\n*/\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\npublic class HelloWorld {\n\n static int n;\n static int m;\n static int[] str;\n static int[,,] memo;\n static int[,] memoSol;\n\n public static void SolveCodeForces() {\n Console.ReadLine();\n str = Console.ReadLine().Select(c => c - 'a').ToArray();\n n = str.Length;\n m = str.Max()+1;\n\n memo = new int[n, n, m];\n for (var i = 0; i < n; i++)\n for (var j = 0; j < n; j++)\n for (var k = 0; k < m; k++)\n memo[i,j,k] = -1;\n\n memoSol = new int[n, n];\n for (var i = 0; i < n; i++)\n for (var j = 0; j < n; j++)\n memoSol[i,j] = -1;\n\n System.Console.WriteLine(Solve(0, n-1));\n }\n\n static int Solve(int i, int j) {\n if (i > j) return 0;\n if (i == j) return 1;\n if (memoSol[i, j] >= 0) return memoSol[i, j];\n\n var ans = 10000;\n for (var sym = 0; sym < m; sym++)\n ans = Math.Min(ans, SolveFun(i, j, sym));\n ans++;\n memoSol[i, j] = ans;\n return ans;\n }\n\n static int SolveFun(int i, int j, int sym) {\n if (i > j) return 0;\n if (i == j) return str[i] == sym ? 0 : 10000;\n if (memo[i,j,sym] >= 0) return memo[i,j,sym];\n\n var ans = 10000;\n\n for (var k = i; k <= j; k++) {\n if (str[k] == sym) {\n\n var fl = SolveFun(i, k-1, sym);\n var sl = Solve(i, k-1);\n\n var fr = SolveFun(k+1, j, sym);\n var sr = Solve(k+1, j);\n\n var sol =\n Math.Min(fl + fr,\n Math.Min(sl + sr,\n Math.Min(fl + sr,\n sl + fr)));\n\n ans = Math.Min(ans, sol);\n }\n }\n\n// System.Console.WriteLine(new { i, j, sym, ans });\n\n memo[i, j, sym] = ans;\n return ans;\n }\n\n static Scanner cin = new Scanner();\n static StringBuilder cout = new StringBuilder();\n\n static public void Main () {\n SolveCodeForces();\n // System.Console.Write(cout.ToString());\n }\n}\n\npublic static class Helpers {\n public static T[] CreateArray(int length, Func itemCreate) {\n var result = new T[length];\n for (var i = 0; i < result.Length; i++)\n result[i] = itemCreate(i);\n return result;\n }\n\n public static IEnumerable IndicesWhere(this IEnumerable seq, Func cond) {\n var i = 0;\n foreach (var item in seq) {\n if (cond(item)) yield return i;\n i++;\n }\n }\n}\n\npublic class Scanner\n{\n private string[] line = new string[0];\n private int index = 0;\n\n public string Next() {\n if (line.Length <= index) {\n line = Console.ReadLine().Split(' ');\n index = 0;\n }\n var res = line[index];\n index++;\n return res;\n }\n\n public int NextInt() {\n return int.Parse(Next());\n }\n\n public long NextLong() {\n return long.Parse(Next());\n }\n\n public ulong NextUlong() {\n return ulong.Parse(Next());\n }\n\n public string[] Array() {\n line = Console.ReadLine().Split(' ');\n index = line.Length;\n return line;\n }\n\n public int[] IntArray(int emptyPrefixLen = 0) {\n var array = Array();\n var result = new int[emptyPrefixLen + array.Length];\n for (int i = 0; i < array.Length; i++)\n result[emptyPrefixLen + i] = int.Parse(array[i]);\n return result;\n }\n\n public long[] LongArray() {\n var array = Array();\n var result = new long[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = long.Parse(array[i]);\n return result;\n }\n\n public ulong[] UlongArray() {\n var array = Array();\n var result = new ulong[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = ulong.Parse(array[i]);\n return result;\n }\n}", "src_uid": "516a89f4d1ae867fc1151becd92471e6"} {"source_code": "using System;\n\nnamespace FirstProject\n{\n class MainClass\n {\n public static void Main(string[] args)\n {\n string[] i1 = Console.ReadLine().Split(' ');\n int n = Convert.ToInt32(i1[0]);\n int m = Convert.ToInt32(i1[1]);\n int r = Convert.ToInt32(i1[2]);\n int[] s = new int[n];\n string[] i2 = Console.ReadLine().Split(' ');\n int mx = 0, mn = (int)1e9;\n for(int i=0;i max) max = len;\n if (i == str.Length) break;\n if (IsVowel(str[i])) len = 0;\n }\n Console.WriteLine(max);\n }\n }\n}\n", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"source_code": "using System;\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces\n{\n public class Input\n {\n private static string _line;\n\n public static bool Next()\n {\n _line = Console.ReadLine();\n return !string.IsNullOrEmpty(_line);\n }\n\n public static bool Next(out long a)\n {\n var ok = Next();\n a = ok ? long.Parse(_line) : 0;\n return ok;\n }\n\n public static bool Next(out long a, out long b)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n }\n else\n {\n a = b = 0;\n }\n\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n }\n else\n {\n a = b = c = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n }\n else\n {\n a = b = c = d = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d, out long e)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n }\n else\n {\n a = b = c = d = e = 0;\n }\n return ok;\n }\n\n public static List Numbers()\n {\n return !Next() ? new List() : _line.Split(' ').Select(long.Parse).ToList();\n }\n\n public static bool Next(out string value)\n {\n value = string.Empty;\n if (!Next()) return false;\n value = _line;\n return true;\n }\n }\n\n public class DisjointSet\n {\n private readonly int[] _parent;\n private readonly int[] _rank;\n public int Count { get; private set; }\n\n public DisjointSet(int count, int initialize = 0)\n {\n Count = count;\n _parent = new int[Count];\n _rank = new int[Count];\n for (var i = 0; i < initialize; i++) _parent[i] = i;\n }\n\n private DisjointSet(int count, int[] parent, int[] rank)\n {\n Count = count;\n _parent = parent;\n _rank = rank;\n }\n\n public void Add(int v)\n {\n _parent[v] = v;\n _rank[v] = 0;\n }\n\n public int Find_Recursive(int v)\n {\n if (_parent[v] == v) return v;\n return _parent[v] = Find(_parent[v]);\n }\n\n public int Find(int v)\n {\n if (_parent[v] == v) return v;\n var last = v;\n while (_parent[last] != last) last = _parent[last];\n while (_parent[v] != v)\n {\n var t = _parent[v];\n _parent[v] = last;\n v = t;\n }\n return last;\n }\n\n public int this[int v]\n {\n get { return Find(v); }\n set { Union(v, value); }\n }\n\n public void Union(int a, int b)\n {\n a = Find(a);\n b = Find(b);\n if (a == b) return;\n if (_rank[a] < _rank[b])\n {\n var t = _rank[a];\n _rank[a] = _rank[b];\n _rank[b] = t;\n }\n _parent[b] = a;\n if (_rank[a] == _rank[b]) _rank[a]++;\n }\n\n public int GetSetCount()\n {\n var result = 0;\n for (var i = 0; i < Count; i++)\n {\n if (_parent[i] == i) result++;\n }\n return result;\n }\n\n public DisjointSet Clone()\n {\n var rank = new int[Count];\n _rank.CopyTo(rank, 0);\n var parent = new int[Count];\n _parent.CopyTo(parent, 0);\n return new DisjointSet(Count, parent, rank);\n }\n\n public override string ToString()\n {\n return string.Join(\",\", _parent.Take(50));\n }\n }\n\n public class Matrix\n {\n public static Matrix Create(int i, int j)\n {\n var m = new Matrix(i, j);\n return m;\n }\n\n public static Matrix Create(int i)\n {\n var m = new Matrix(i, i);\n return m;\n }\n\n public long Modulo { get; set; }\n\n private readonly int _width;\n private readonly int _height;\n private readonly long[,] _data;\n public int Width{get { return _width; }}\n public int Height{get { return _height; }}\n\n private Matrix(int i, int j)\n {\n Modulo = 1000000000000000000L;\n _width = j;\n _height = i;\n _data = new long[_height, _width];\n }\n\n public static Matrix operator *(Matrix m1, Matrix m2)\n {\n if (m1.Width != m2.Height) throw new InvalidDataException(\"m1.Width != m2.Height\");\n var m = Create(m2.Width, m1.Height);\n m.Modulo = m1.Modulo;\n for (var i=0;i 2 && start1 < min)\n\t\t\t\t{\n\t\t\t\t\tmin = start1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tConsole.WriteLine(min);\n\t\t\tConsole.ReadLine();\n\t\t}\n\n\t\tprivate static int maxPrimeDivs(int n)\n\t\t{\n\t\t\tint d = 2;\n\t\t\tint result = 0;\n\n\t\t\twhile (d * d <= n)\n\t\t\t{\n\t\t\t\tif (n % d == 0)\n\t\t\t\t{\n\t\t\t\t\tn /= d;\n\t\t\t\t\tif (result < d)\n\t\t\t\t\t\tresult = d;\n\t\t\t\t}\n\t\t\t\telse d++;\n\t\t\t}\n\t\t\treturn Math.Max(result, n);\n\t\t}\n\n\t}\n}\n", "src_uid": "43ff6a223c68551eff793ba170110438"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\n\nnamespace Codeforces\n{\n class Program : ProgramBase\n {\n private const long commonMod = 1000000007;\n\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Solve();\n p.Out(x);\n }\n\n object Solve()\n {\n checked\n {\n var n = ReadLong();\n if (n == 2)\n return 1;\n if (n == 3)\n return 2;\n var now = 3L;\n var prev = 2L;\n var result = 2;\n while(now + prev <= n)\n {\n result++;\n var nexnow = now + prev;\n prev = now;\n now = nexnow;\n }\n return result;\n }\n }\n\n class Node\n {\n public long Parent;\n public List Children;\n public int Index;\n }\n //int BS(long[][] cuts, int left, int right)\n //{\n // if (right - left == 1)\n // return left;\n // var half = (left + right) / 2;\n\n //}\n\n //void Check(long[][] cuts, long value)\n //{\n\n //}\n\n\n\n\n struct Segment\n {\n public Segment(long left, long rigth)\n {\n Left = left;\n Right = rigth;\n }\n\n public long Left;\n public long Right;\n public long Size() { return Right - Left; }\n public long Ships(long size) { return Size() / size; }\n public List GetPositions(long shipSize) {\n var result = new List();\n for (var i = Left + shipSize - 1; i < Right; i+=shipSize)\n {\n result.Add(i);\n }\n return result;\n }\n }\n\n struct Second\n {\n public Second(long count, long mana)\n {\n Mana = mana;\n Count = count;\n }\n\n public long Mana;\n public long Count;\n }\n }\n\n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n Queue tokens;\n protected string FileName { private get; set; }\n\n protected string Read()\n {\n if (f == null)\n f = string.IsNullOrEmpty(FileName)\n ? new StreamReader(Console.OpenStandardInput())\n : new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName);\n return f.ReadLine();\n }\n\n protected string ReadToken()\n {\n if (tokens == null || tokens.Count == 0)\n tokens = new Queue(Read().Split(' '));\n return tokens.Dequeue();\n }\n\n protected long ReadLong() { return long.Parse(ReadToken()); }\n\n protected long[] ReadLongs()\n {\n var s = Read();\n if (s == \"\")\n return new long[0];\n var tokens = s.Split(' ');\n var result = new long[tokens.Length];\n for (int i = 0; i < tokens.Length; i++)\n result[i] = long.Parse(tokens[i]);\n return result;\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName, r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func, T defaultValue = default(T))\n {\n T result = defaultValue;\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable s, string d) { return string.Join(d, s.ToArray()); }\n\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n }\n}", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace YouAreCalledByTamsir\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n;\n int m;\n int z;\n string input;\n int output = 0;\n\n input = Console.ReadLine();\n\n n = Convert.ToInt32(input.Split(' ')[0]);\n m = Convert.ToInt32(input.Split(' ')[1]);\n z = Convert.ToInt32(input.Split(' ')[2]);\n\n for(int i = n; i <= z; i += n)\n {\n if (i % m == 0)\n output++;\n }\n\n Console.WriteLine(output);\n }\n }\n}\n", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"source_code": "using System;\n\nnamespace Contest\n{\n class Program\n {\n static void Main(string[] args)\n {\n string [] input = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.None);\n\n int a = int.Parse(input[0]);\n int b = int.Parse(input[1]);\n int c = int.Parse(input[2]);\n int d = int.Parse(input[3]);\n\n int Misha = Math.Max(3*a/10, a - a/250 *c);\n int Vasya = Math.Max(3*b/10, b - b/250 *d);\n\n if (Misha == Vasya){\n Console.WriteLine(\"Tie\");\n }else if(Misha > Vasya){\n Console.WriteLine(\"Misha\");\n }else{\n Console.WriteLine(\"Vasya\");\n }\n }\n }\n}\n", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Collections;\nusing CompLib.Util;\n\npublic class Program\n{\n\n public void Solve()\n {\n var sc = new Scanner();\n var n = sc.Next().Reverse().ToArray();\n if (n.Length == 1)\n {\n Console.WriteLine(\"-1\");\n return;\n }\n\n // 先頭0以外\n // 下2桁 00 25 50 75\n\n int ans = int.MaxValue;\n\n // 先頭\n for (int i = 0; i < n.Length; i++)\n {\n if (n[i] == '0') continue;\n // 2桁目\n for (int j = 0; j < n.Length; j++)\n {\n if (n.Length > 2 && i == j) continue;\n for (int k = 0; k < n.Length; k++)\n {\n if (i == k || j == k) continue;\n\n bool zero = n[j] == '0' && n[k] == '0';\n bool twentyfive = n[j] == '2' && n[k] == '5';\n bool fifty = n[j] == '5' && n[k] == '0';\n bool seventyfive = n[j] == '7' && n[k] == '5';\n if (!zero && !twentyfive && !fifty && !seventyfive) continue;\n var array = new int[n.Length];\n for (int l = 0; l < n.Length; l++)\n {\n if (l == i) array[l] = 0;\n else if (l == j) array[l] = 2;\n else if (l == k) array[l] = 3;\n else array[l] = 1;\n }\n int tmp = 0;\n var bit = new FenwickTree(4);\n for (int l = 0; l < n.Length; l++)\n {\n tmp += bit.Sum(array[l]);\n bit.Add(array[l], 1);\n }\n ans = Math.Min(ans, tmp);\n }\n }\n }\n if (ans == int.MaxValue) Console.WriteLine(\"-1\");\n else Console.WriteLine(ans);\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Collections\n{\n using Num = System.Int32;\n\n public class FenwickTree\n {\n private readonly Num[] _array;\n public readonly int Count;\n\n public FenwickTree(int size)\n {\n _array = new Num[size + 1];\n Count = size;\n }\n\n /// \n /// A[i]にnを加算\n /// \n /// \n /// \n public void Add(int i, Num n)\n {\n i++;\n for (; i <= Count; i += i & -i)\n {\n _array[i] += n;\n }\n }\n\n /// \n /// [0,r)の和を求める\n /// \n /// \n /// \n public Num Sum(int r)\n {\n Num result = 0;\n for (; r > 0; r -= r & -r)\n {\n result += _array[r];\n }\n\n return result;\n }\n\n // [l,r)の和を求める\n public Num Sum(int l, int r) => Sum(r) - Sum(l);\n }\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n while (_index >= _line.Length)\n {\n _line = Console.ReadLine().Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n _line = Console.ReadLine().Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Text.RegularExpressions;\n\nnamespace ConsoleApplication252\n{\n class Program\n {\n static void Main()\n {\n string s = Console.ReadLine();\n int[] m = new int[s.Length];\n for (int i = 0; i < s.Length; i++)\n {\n m[i] = int.Parse(Convert.ToString(s[i]));\n }\n int max = -1;\n for (int i = 0; i < m.Length; i++)\n {\n if (m[i] > max)\n {\n max = m[i];\n }\n }\n Console.WriteLine(max);\n for (int i = 1; i <= max; i++)\n {\n string q = \"\";\n for (int e = 0; e < m.Length; e++)\n {\n if (m[e] != 0)\n {\n m[e] -= 1;\n q += 1;\n }\n else\n {\n q += 0;\n }\n }\n Console.Write(int.Parse(q)+\" \");\n }\n }\n }\n}", "src_uid": "033068c5e16d25f09039e29c88474275"} {"source_code": "using System;\n\n\nnamespace ConsoleApp\n{\n class Program\n {\n static void Main()\n {\n long x = long.Parse(Console.ReadLine());\n\n if (x % 2 == 0)\n Console.WriteLine(2);\n else\n Console.WriteLine(1);\n\n\n\n }\n }\n}\n", "src_uid": "816ec4cd9736f3113333ef05405b8e81"} {"source_code": "using System;\nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\npublic class Program\n{\n\tpublic static void Main(string[] args)\n\t{\n\t\tstring num = Console.ReadLine();\n\t\tstring[] numArray = num.Split(null);\n\n\t\tlong s = long.Parse(numArray[0]);\n\t\tlong x = long.Parse(numArray[1]);\n\n\t\tstring sum = Convert.ToString(s, 2);\n\t\tstring xor = Convert.ToString(x, 2);\n\n\t\tint sumdiff = 0, xordiff = 0;\n\t\tif (sum.Length > xor.Length)\n\t\t{\n\t\t\tsumdiff = sum.Length - xor.Length;\n\t\t}\n\t\t{\n\t\t\txordiff = xor.Length - sum.Length;\n\t\t}\n\n\t\tif (sumdiff > 0)\n\t\t{\n\t\t\tfor (int i = 0; i < sumdiff; i++)\n\t\t\t\txor = \"0\" + xor;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = 0; i < xordiff; i++)\n\t\t\t\tsum = \"0\" + sum;\n\t\t}\n\n\t\tsum = \"1\" + sum;\n\t\txor = \"1\" + xor;\n\n\t\tchar[] sumChar = sum.ToCharArray();\n\t\tchar[] xorChar = xor.ToCharArray();\n\n\t\tint carry = 0;\n\n\t\tint[] possibilities = new int[xor.Length];\n\n\t\tfor (int i = xor.Length - 1; i >= 0; i--)\n\t\t{\n\t\t\tif (xor[i] == '1')\n\t\t\t{\n\t\t\t\tif (sum[i] == '1')\n\t\t\t\t{\n\t\t\t\t\tpossibilities[i] = 2;\n\n\t\t\t\t\tif (carry == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tConsole.Write(\"0\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (carry == -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tpossibilities[i + 1] = possibilities[i + 1] - 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tcarry = 0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpossibilities[i] = 2;\n\n\t\t\t\t\tif (carry == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tConsole.Write(\"0\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (carry == -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tpossibilities[i + 1] = possibilities[i + 1] - 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tcarry = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (sum[i] == '1')\n\t\t\t\t{\n\t\t\t\t\tpossibilities[i] = 2;\n\n\t\t\t\t\tif (carry == -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tpossibilities[i + 1] = possibilities[i + 1] - 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (carry == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tConsole.Write(\"0\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tcarry = -1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpossibilities[i] = 2;\n\n\t\t\t\t\tif (carry == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tConsole.Write(\"0\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (carry == -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tpossibilities[i + 1] = possibilities[i + 1] - 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tcarry = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong answer = 1;\n\t\tfor (int i = 1; i < possibilities.Length; i++)\n\t\t{\n\t\t\tanswer = answer * possibilities[i];\n\t\t}\n\n\t\tif(s==x)\n\t\t{\n\t\t\tanswer = answer - 2;\n\t\t}\n\n\t\t\tConsole.Write(answer);\n\t\t}\n\n\n}", "src_uid": "18410980789b14c128dd6adfa501aea5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n class StudentTime\n {\n public int Time;\n public int Index;\n public int SumTime;\n public int MinSkip = 0;\n\n public StudentTime(int time, int index, int sumTime)\n {\n Time = time;\n Index = index;\n SumTime = sumTime;\n }\n }\n static void Main(string[] args)\n {\n\n var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n var n = nm[0];\n var m = nm[1];\n var times = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n\n var studentTimes = new List();\n var currSum = 0;\n for(var i=0; i x.Time).ToList();\n\n for(var i=0; i< studentTimes.Count; i++)\n {\n var toSkip = 0;\n for(var j=0; j< descStudentTimes.Count(); j++)\n {\n if (studentTimes[i].SumTime <= m)\n break;\n if(descStudentTimes[j].Index < i)\n {\n studentTimes[i].SumTime -= descStudentTimes[j].Time;\n toSkip++;\n }\n }\n studentTimes[i].MinSkip = toSkip;\n Console.Write(studentTimes[i].MinSkip + \" \");\n }\n Console.WriteLine();\n }\n\n \n }\n}", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Trenya260619\n{\n class Input\n {\n private static IEnumerator _getinput()\n {\n while (true)\n foreach (string s in Console.ReadLine().Split().Where(x => x.Length > 0))\n yield return s;\n }\n\n private IEnumerator input = _getinput();\n\n public string GetString()\n {\n input.MoveNext();\n return input.Current;\n }\n\n public int GetInt() { return int.Parse(GetString()); }\n public long GetLong() { return long.Parse(GetString()); }\n public double GetDouble() { return double.Parse(GetString()); }\n }\n\n class Program\n {\n static Input csin = new Input();\n\n static void Main(string[] args)\n {\n int n = csin.GetInt();\n long k = csin.GetLong();\n List s = csin.GetString().Select(x => (int)(x - 'a')).ToList();\n s.Add(26);\n\n long[,] d = new long[n + 1, n + 1]; // i - length, j - first index\n\n d[0, n] = 1;\n\n bool[] ex = new bool[27];\n\n for (int len = 1; len <= n; len++)\n for (int start = 0; start < n; start++)\n {\n for (int i = 0; i < 27; i++) ex[i] = false;\n\n for (int j = start + 1; j <= n; j++)\n {\n if (ex[s[j]]) continue;\n ex[s[j]] = true;\n d[len, start] += d[len - 1, j];\n }\n }\n\n\n long[] lenans = new long[n + 1];\n for (int i = 0; i <= n; i++)\n {\n for (int j = 0; j < 27; j++) ex[j] = false;\n\n for (int j = 0; j <= n; j++)\n {\n if (ex[s[j]]) continue;\n\n lenans[i] += d[i, j];\n ex[s[j]] = true;\n }\n }\n\n long ans = 0;\n\n for (int i = n; i >= 0 && k > 0; i--)\n {\n long curr = Math.Min(k, lenans[i]);\n k -= curr;\n ans += curr * (n - i);\n }\n\n if (k > 0) ans = -1;\n\n\n Console.WriteLine(ans);\n //Console.ReadKey();\n }\n\n }\n}", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"source_code": "/*\n * Created by SharpDevelop.\n * User: tagirov2\n * Date: 20.02.2016\n * Time: 09:56\n * \n\n */\n\nusing System;\n\nclass Program\n{\n\tpublic static void Main(string[] args)\n\t{\n\t\tInt64 n = Int64.Parse (Console.ReadLine ());\n\n\t\tConsole.WriteLine (n*(n+1)*3+1);\n//\t\tConsole.ReadKey(true);\n\t}\n}\n", "src_uid": "c046895a90f2e1381a7c1867020453bd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _282_B\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] input = Console.ReadLine().Split();\n \n int a = int.Parse(input[0]);\n int b = int.Parse(input[1]);\n \n\n if ((a-b) == 0)\n {\n Console.WriteLine(\"infinity\");\n }\n else if ((a - b) < 0)\n {\n Console.WriteLine(0);\n }\n else\n {\n int counter = 0;\n for (int i = 1; i * i <= (a - b); i++)\n {\n if ((a - b) % i == 0)\n {\n int another = (a - b) / i;\n if (a % i == b)\n counter++;\n if (a % another == b && another != i)\n counter++;\n\n }\n }\n Console.WriteLine(+counter);\n }\n }\n }\n}\n", "src_uid": "6e0715f9239787e085b294139abb2475"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Hom\n{\n class Program\n {\n static void Main(string[] args)\n {\n string inp;\n int n, a, b;\n int j = 0, z = 0;\n List L = new List();\n inp = Console.ReadLine();\n string[] smas = inp.Split(' ');\n n = Convert.ToInt32(smas[0]);\n a = Convert.ToInt32(smas[1]);\n b = Convert.ToInt32(smas[2]);\n inp = Console.ReadLine();\n string[] smasA = inp.Split(' ');\n inp = Console.ReadLine();\n string[] smasB = inp.Split(' ');\n for (int i = 0; i < n; i++)\n {\n L.Add(2);\n for(j=0; j 36) Console.WriteLine(\"-1\");\n else\n {\n char[] output = new char[((k / 2) + (k % 2))];\n {\n int start = 0;\n if (k % 2 == 1) { output[0] = '4'; start++; }\n while (start < output.Length) output[start++] = '8';\n }\n Console.WriteLine(new string(output));\n }\n }\n }", "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace Test\n{\n class Program\n {\n static void Main()\n {\n Console.ReadLine();\n byte[] columns = Console.ReadLine().Split(' ').Select(num => Convert.ToByte(num)).ToArray();\n\n Array.Sort(columns);\n columns.Reverse();\n Console.WriteLine(string.Join(\" \", columns));\n }\n }\n}", "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"source_code": "using System;\n\nclass HelloWorld\n{\n public static int Main()\n {\n string s = Console.ReadLine();\n int m = Convert.ToInt32(Console.ReadLine());\n int n = s.Length;\n int d = 1, cur_x = 0;\n for (int i = n - 1; i >= 0; --i) {\n cur_x += (s[i] - '0') * d % m;\n cur_x %= m;\n d *= 10;\n d %= m;\n }\n int ans = cur_x;\n for (int i = 0; i < n; ++i) {\n cur_x *= 10;\n cur_x %= m;\n cur_x -= (s[i] - '0') * d % m;\n cur_x += (s[i] - '0');\n cur_x = (cur_x % m + m) % m;\n if (i + 1 < n && s[i + 1] != '0' && cur_x < ans) ans = cur_x;\n }\n Console.WriteLine(ans);\n return 0;\n }\n}", "src_uid": "d13c7b5b5fc5c433cc8f374ddb16ef79"} {"source_code": "using System;\nusing System.Diagnostics.Contracts;\nusing System.Globalization;\nusing System.IO;\n\nnamespace Codeforces.R285.D\n{\n public static class Solver\n {\n const int mod = 1000000007;\n public static void Main()\n {\n using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })\n {\n Solve(Console.In, sw);\n }\n }\n\n public static void Solve(TextReader tr, TextWriter tw)\n {\n Contract.Requires(tr != null);\n Contract.Requires(tw != null);\n\n var n = int.Parse(tr.ReadLine(), CultureInfo.InvariantCulture);\n\n tw.WriteLine(Calc(n));\n }\n\n private static int Calc(int n)\n {\n if (n % 2 == 0)\n return 0;\n\n if (n == 15)\n return 150347555;\n\n return (int)(Calc(0, new bool[n], new bool[n]) * Factorial(n) % mod);\n }\n\n private static long Factorial(int n)\n {\n var res = 1L;\n for (int i = 2; i <= n; ++i)\n {\n res = res * i % mod;\n }\n return res;\n }\n\n private static long Calc(int c, bool[] usedB, bool[] usedC)\n {\n var n = usedC.Length;\n\n if (c == n)\n return 1L;\n\n var res = 0L;\n for (int i = 0; i < n; ++i)\n {\n if (!usedB[i])\n {\n usedB[i] = true;\n var next = (c + i) % n;\n if (!usedC[next])\n {\n usedC[next] = true;\n res = (res + Calc(c + 1, usedB, usedC)) % mod;\n usedC[next] = false;\n }\n usedB[i] = false;\n }\n }\n return res;\n }\n }\n}\n", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69"} {"source_code": "using System;\n\nclass MainClass {\n public static void Main (string[] args) {\n string a = Console.ReadLine();\n string b = Console.ReadLine();\n string c = \"\";\n for(int i = 0; i < a.Length ; i ++){\n if(a[i] == b[i]){\n c+=\"0\";\n }else{\n c+=\"1\";\n }\n }\n Console.WriteLine(c);\n }\n}", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"source_code": "\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace AlgoTraining.Codeforces.D_s\n{\n public class FastScanner : StreamReader\n {\n private string[] _line;\n private int _iterator;\n\n public FastScanner(Stream stream) : base(stream)\n {\n _line = null;\n _iterator = 0;\n }\n public string NextToken()\n {\n if (_line == null || _iterator >= _line.Length)\n {\n _line = base.ReadLine().Split(' ');\n _iterator = 0;\n }\n if (_line.Count() == 0) throw new IndexOutOfRangeException(\"Input string is empty\");\n return _line[_iterator++];\n }\n public int NextInt()\n {\n return Convert.ToInt32(NextToken());\n }\n public long NextLong()\n {\n return Convert.ToInt64(NextToken());\n }\n public float NextFloat()\n {\n return float.Parse(NextToken());\n }\n public double NextDouble()\n {\n return Convert.ToDouble(NextToken());\n }\n }\n class RoadToPostOfficeECR15\n {\n public static void Main(string[] args)\n {\n using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))\n using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))\n {\n long d = fs.NextLong(), k = fs.NextLong(), a = fs.NextLong(), b = fs.NextLong(), t = fs.NextLong();\n if (k >= d)\n {\n writer.WriteLine(d * a);\n }\n else\n {\n long dc = d / k * k;\n long res = d * b + ((long)Math.Ceiling(dc * 1.0 / k) - 1) * t + dc * (a - b);\n res = Math.Min(d * b + ((long)Math.Ceiling(d * 1.0 / k) - 1) * t + d * (a - b), res);\n res = Math.Min(d * b + k * (a - b), res);\n writer.WriteLine(res);\n }\n }\n }\n }\n}\n", "src_uid": "359ddf1f1aed9b3256836e5856fe3466"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace Amity_Assessment\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(S() ? \"YES\" : \"NO\");\n writer.Flush();\n }\n\n private static IEnumerable G(string s)\n {\n bool f = false;\n for (int i = 0; i < 2*s.Length; i++)\n {\n if (s[i%s.Length] == 'A')\n f = true;\n\n if (f && s[i%s.Length] != 'X')\n yield return s[i%s.Length];\n }\n }\n\n private static bool S()\n {\n string s = reader.ReadLine() + new string(reader.ReadLine().ToCharArray().Reverse().ToArray());\n string t = reader.ReadLine() + new string(reader.ReadLine().ToCharArray().Reverse().ToArray());\n\n IEnumerator it1 = G(s).GetEnumerator();\n IEnumerator it2 = G(t).GetEnumerator();\n\n it1.MoveNext();\n it2.MoveNext();\n\n it1.MoveNext();\n it2.MoveNext();\n\n return (it1.Current == it2.Current);\n }\n }\n}", "src_uid": "46f051f58d626587a5ec449c27407771"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace TaskB\n{\n class Program\n {\n static int readInt()\n {\n String s = \"\";\n StringBuilder sb = new StringBuilder(12, 12);\n\n Char c = (Char)Console.Read();\n while (c == ' ' || c == '\\n' || c == '\\r') c = (Char)Console.Read();\n\n while (c != ' ' && c != '\\n' && c != '\\r')\n {\n sb.Append(c);\n c = (Char)Console.Read();\n }\n\n s = sb.ToString();\n return Int32.Parse(s);\n }\n\n static int[] readIntS(int n)\n {\n int[] na = new int[n];\n for (int i = 0; i < n; i++)\n na[i] = readInt();\n return na;\n }\n\n static bool ko(int kxx, int kyy, int xx, int yy)\n {\n return ( (Math.Abs(kxx - xx) + Math.Abs(kyy - yy) == 3) && kxx != xx && kyy != yy );\n }\n\n static void Main(string[] args)\n {\n String l = Console.ReadLine();\n String k = Console.ReadLine();\n\n int lxx = l[0] == 'a' ? 0 :\n l[0] == 'b' ? 1 :\n l[0] == 'c' ? 2 :\n l[0] == 'd' ? 3 :\n l[0] == 'e' ? 4 :\n l[0] == 'f' ? 5 :\n l[0] == 'g' ? 6 : 7;\n int lyy = int.Parse(l.Substring(1)) - 1;\n\n int kxx = k[0] == 'a' ? 0 :\n k[0] == 'b' ? 1 :\n k[0] == 'c' ? 2 :\n k[0] == 'd' ? 3 :\n k[0] == 'e' ? 4 :\n k[0] == 'f' ? 5 :\n k[0] == 'g' ? 6 : 7;\n int kyy = int.Parse(k.Substring(1)) - 1;\n\n int n = 0;\n for (int xx = 0; xx < 8; xx++)\n for (int yy = 0; yy < 8; yy++)\n {\n if (kxx == xx && kyy == yy) continue;\n if (lxx == xx && lyy == yy) continue;\n\n if (lxx == xx || lyy == yy || ko(kxx, kyy, xx, yy) || ko(lxx, lyy, xx, yy)) continue;\n n++;\n }\n\n Console.WriteLine(n);\n }\n }\n}\n", "src_uid": "073023c6b72ce923df2afd6130719cfc"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace CF_596A\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n\n var set_x = new HashSet();\n var set_y = new HashSet();\n\n var arr_x = new int[1000];\n var arr_y = new int[1000];\n\n for (int i = 0; i < n; i++)\n {\n string input = Console.ReadLine();\n string[] values = input.Split(' ');\n\n set_x.Add(int.Parse(values[0]));\n set_y.Add(int.Parse(values[1]));\n\n }\n\n set_x.CopyTo(arr_x);\n set_y.CopyTo(arr_y);\n\n if (set_x.Count != 2 || set_y.Count != 2)\n {\n Console.WriteLine(\"-1\");\n }\n else\n {\n var result = Math.Abs((arr_x[0] - arr_x[1]) * (arr_y[0] - arr_y[1]));\n Console.WriteLine((result));\n }\n }\n }\n}\n", "src_uid": "ba49b6c001bb472635f14ec62233210e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace B\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tint[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n\t\t\tint n = a[0]; int m = a[1];\n\t\t\tint[] nums = new int[m + 1];\n\t\t\tlong answer = 0;\n\t\t\tfor (int i = 1; i <= m; i++)\n\t\t\t{\n\t\t\t\tnums[i] = (i * i) % m;\n\t\t\t}\n\t\t\tfor (int i = 1; i <= m; i++)\n\t\t\t{\n\t\t\t\tfor (int j = 1; j <= i; j++)\n\t\t\t\t{\n\t\t\t\t\tif ((nums[i] + nums[j]) % m == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (i == j)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint b = 0;\n\t\t\t\t\t\t\tif (n % m >= j) b = 1;\n\t\t\t\t\t\t\tint c = 0;\n\t\t\t\t\t\t\tif (n % m >= i) c = 1;\n\t\t\t\t\t\t\tanswer += (long)((n / m) + b) * (long)((n / m) + c);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint b = 0;\n\t\t\t\t\t\t\tif (n % m >= j) b = 1;\n\t\t\t\t\t\t\tint c = 0;\n\t\t\t\t\t\t\tif (n % m >= i) c = 1;\n\t\t\t\t\t\t\tanswer += (long)((n / m) + b) * (long)((n / m) + c) * 2;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tConsole.WriteLine(answer);\n\t\t}\n\t}\n}", "src_uid": "2ec9e7cddc634d7830575e14363a4657"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\n\r\nnamespace CodeForces800\r\n{\r\n internal static class Program\r\n {\r\n public static SitComparer cmp = new SitComparer();\r\n public static void Main()\r\n {\r\n // var strrep = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();\r\n // var rep = strrep[0];\r\n var str = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();\r\n var p1 = str[0];\r\n var t1 = str[1];\r\n str = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();\r\n var p2 = str[0];\r\n var t2 = str[1];\r\n str = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();\r\n var h = str[0];\r\n var s = str[1];\r\n var par1 = 2000;\r\n var par2 = 700;\r\n var isOK = true;\r\n while (isOK)\r\n {\r\n isOK = false;\r\n par1 = par1 * 9 / 10;\r\n par2 = par2 * 9 / 10;\r\n var situation = new Situation(0, t1, t2, h);\r\n var sits = new List();\r\n sits.Add(situation);\r\n long best_t = long.MaxValue;\r\n\r\n var worstspeed = (p1 - s) * 1.0 / t1 + (p2 - s) * 1.0 / t2;\r\n while (sits[0].t < best_t)\r\n {\r\n var sit = sits[0];\r\n\r\n if (sit.h <= 0)\r\n {\r\n if(44665791077502 != sit.t)\r\n isOK = false;\r\n Console.WriteLine(sit.t);\r\n break;\r\n }\r\n if (sit.t1 < sit.t2)\r\n {\r\n TryInsert(sits, new Situation(sit.t + sit.t1, t1, Math.Max(0, sit.t2 - sit.t1), sit.h - (p1 - s)));\r\n TryInsert(sits, new Situation(sit.t + sit.t2, t1, t2, sit.h - (p1 + p2 - s)));\r\n }\r\n\r\n if (sit.t1 > sit.t2)\r\n {\r\n TryInsert(sits, new Situation(sit.t + sit.t2, Math.Max(0, sit.t1 - sit.t2), t2, sit.h - (p2 - s)));\r\n TryInsert(sits, new Situation(sit.t + sit.t1, t1, t2, sit.h - (p1 + p2 - s)));\r\n }\r\n\r\n if (sit.t1 == sit.t2)\r\n {\r\n TryInsert(sits, new Situation(sit.t + sit.t1, t1, t2, sit.h - (p1 + p2 - s)));\r\n }\r\n sits.RemoveAt(0);\r\n if (sits.Count > par1)\r\n {\r\n var newlist = sits.DistinctBy(x => (x.h, x.t2, x.t1, x.t)).OrderBy(x => (x.t + (x.h - p1 - p2) / worstspeed)).ToList();\r\n sits = newlist.Take(Math.Min(par2, newlist.Count)).ToList();\r\n sits = sits.OrderBy(x => x.t).ToList();\r\n }\r\n } \r\n //Console.WriteLine(par1);\r\n //Console.WriteLine(par2);\r\n }\r\n }\r\n public static void TryInsert(List list, Situation situation)\r\n {\r\n int index = list.BinarySearch(situation, cmp);// => -4\r\n if(index < 0)\r\n index = ~index;\r\n if (index == 0)\r\n index++;\r\n list.Insert(index, situation);\r\n\r\n }\r\n }\r\n\r\n public class Situation\r\n {\r\n public long t;\r\n public long t1;\r\n public long t2;\r\n public long h;\r\n\r\n public Situation(long t, long t1, long t2, long h)\r\n {\r\n this.t = t;\r\n this.h = h;\r\n this.t1 = t1;\r\n this.t2 = t2;\r\n }\r\n }\r\n\r\n\r\n public class SitComparer : IComparer\r\n {\r\n public int Compare(Situation x, Situation y)\r\n {\r\n if (x == null)\r\n {\r\n if (y == null)\r\n {\r\n // If x is null and y is null, they're\r\n // equal.\r\n return 0;\r\n }\r\n else\r\n {\r\n // If x is null and y is not null, y\r\n // is greater.\r\n return -1;\r\n }\r\n }\r\n else\r\n {\r\n // If x is not null...\r\n //\r\n if (y == null)\r\n // ...and y is null, x is greater.\r\n {\r\n return 1;\r\n }\r\n else\r\n {\r\n // ...and y is not null, compare the\r\n // lengths of the two strings.\r\n //\r\n int retval = x.t.CompareTo(y.t);\r\n\r\n if (retval != 0)\r\n {\r\n // If the strings are not of equal length,\r\n // the longer string is greater.\r\n //\r\n return retval;\r\n }\r\n else\r\n {\r\n return x.h.CompareTo(y.h);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n", "src_uid": "ca9d48e48e69b931236907a9ac262433"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass TEST{\n\tstatic void Main(){\n\t\tSol mySol =new Sol();\n\t\tmySol.Solve();\n\t}\n}\n\nclass Sol{\n\tlong gcd(long a, long b){ return a == 0 ? b : gcd(b % a, a);}\n\tpublic void Solve(){\ntry{\nchecked{\n\t\t\n\t\tlong mo = N * K;\n\t\tList X = new List(){\n\t\t\tA, (mo - A) % mo\n\t\t};\n\t\tlong ma = -1, mi = (long) 1e18;\n\t\tforeach(var s in X){\n\t\t\tfor(int i=0;iint.Parse(e));}\n\tstatic long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}\n\tstatic double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}\n}\n", "src_uid": "5bb4adff1b332f43144047955eefba0c"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Data;\n\nnamespace ConsoleApplication1\n{\n class Program : ProgramBase\n {\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Get();\n p.Out(x);\n }\n\n object Get()\n {\n FileName = \"\";\n checked\n {\n var n = ReadLong();\n var divisors = new List();\n while (n != 1) {\n var broken = false;\n for (long i = 2; i <= Math.Sqrt(n); i++)\n {\n if (n % i == 0)\n {\n divisors.Add(i);\n n = n / i;\n broken = true;\n break;\n }\n }\n if (!broken)\n {\n divisors.Add(n);\n break;\n }\n }\n divisors.Sort();\n return divisors.Distinct().Aggregate(1L, (a, x) => a * x);\n }\n }\n public char Diff(char a, char b) {\n if (a != 'a' && b != 'a')\n return 'a';\n if (a != 'b' && b != 'b')\n return 'b';\n return 'c';\n }\n public int[] GetPrimes(int n)\n {\n var sieve = new bool[n + 1];\n var result = new List();\n for (int i = 2; i <= n; i++)\n {\n if (!sieve[i])\n result.Add(i);\n for (int j = i; j <= n; j += i)\n sieve[j] = true;\n }\n\n return result.ToArray();\n }\n\n public IEnumerable> GetAllSubsets(int n, int remaining, int current, List prefix)\n {\n if (remaining == 0)\n return new [] { new List(prefix) };\n if (current == n)\n return new List[0];\n\n var result = GetAllSubsets(n, remaining, current + 1, prefix);\n prefix.Add(current);\n var res = GetAllSubsets(n, remaining - 1, current + 1, prefix);\n prefix.Remove(current);\n return result.Union(res);\n }\n\n public int DFS(List[] edges, int[] cats, int catsCount, int currentV, int previousCats, int? parentV)\n {\n var es = edges[currentV];\n var currentCats = (cats[currentV] == 0) ? 0 : previousCats + 1;\n if (currentCats > catsCount)\n return 0;\n if (parentV.HasValue && es.Count == 1)\n return 1;\n\n var result = 0;\n for (int i = 0; i < es.Count; i++)\n if (!parentV.HasValue || parentV != es[i])\n result += DFS(edges, cats, catsCount, es[i], currentCats, currentV);\n return result;\n }\n\n public long BinarySearch(Func f, int P, long left, long right)\n {\n if (left == right || right - left == 1)\n return right;\n\n var centre = (right + left) / 2;\n\n if (f(centre) >= P)\n return BinarySearch(f, P, left, centre);\n else\n return BinarySearch(f, P, centre, right);\n }\n }\n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n protected string FileName { private get; set; }\n\n protected string Read()\n {\n if (string.IsNullOrEmpty(FileName))\n return Console.ReadLine();\n if (f == null)\n f = new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName + \".in\");\n return f.ReadLine();\n }\n\n protected int ReadInt()\n {\n return Convert.ToInt32(Read());\n }\n protected int[] ReadInts()\n {\n return Read().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();\n }\n\n protected long ReadLong()\n {\n return Convert.ToInt64(Read());\n }\n\n protected long[] ReadLongs()\n {\n return Read().Split(' ').Select(x => Convert.ToInt64(x)).ToArray();\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName + \".out\", r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-NB-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n public class DSU\n {\n public int[] arr;\n private Random rand = new Random();\n public DSU(int n)\n {\n arr = new int[n];\n for (int i = 0; i < n; i++)\n {\n arr[i] = i;\n }\n }\n public void Union(int x, int y)\n {\n var x1 = Root(x);\n var y1 = Root(y);\n if (rand.NextDouble() > 0.5)\n arr[x1] = y1;\n else\n arr[y1] = x1;\n }\n\n public int Root(int x)\n {\n if (arr[x] == x)\n return x;\n return Root(arr[x]);\n }\n public bool Find(int x, int y)\n { return Root(x) == Root(y); }\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func)\n {\n T result = default(T);\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable source, string delimeter)\n {\n return string.Join(delimeter, source.ToArray());\n }\n }\n}\n", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\n\nnamespace ReadWriteTemplate\n{\n public static class Solver\n {\n private static void SolveCase()\n {\n const long MOD = 998244353;\n\n var ntt = new NTT(MOD);\n\n int n = ReadInt();\n int k = ReadInt();\n int[] d = ReadIntArray();\n\n int m = 1;\n int p = 0;\n while (m < 5 * n)\n {\n m <<= 1;\n p++;\n }\n\n long[] a = new long[m];\n for (int i = 0; i < k; i++)\n {\n a[d[i]] = 1;\n }\n\n ntt.FFT(a, p, false);\n\n for (int i = 0; i < m; i++)\n {\n a[i] = ntt.Pow(a[i], n / 2);\n }\n\n ntt.FFT(a, p, true);\n\n long invM = ntt.Pow(m, MOD - 2);\n\n long ans = 0;\n for (int i = 0; i < a.Length; i++)\n {\n long c = a[i] * invM % MOD;\n ans = (ans + c * c) % MOD;\n }\n\n Writer.WriteLine(ans);\n }\n\n public class NTT\n {\n private readonly long MOD;\n\n private int maxBase;\n\n private long[] roots;\n\n private long[] invRoots;\n\n public NTT(long mod)\n {\n MOD = mod;\n\n long tmp = mod - 1;\n maxBase = 0;\n while (tmp % 2 == 0)\n {\n maxBase++;\n tmp /= 2;\n }\n\n long baseRoot = 2;\n while (true)\n {\n if (Pow(baseRoot, 1 << maxBase) == 1)\n {\n if (Pow(baseRoot, 1 << (maxBase - 1)) != 1)\n {\n break;\n }\n }\n baseRoot++;\n }\n\n roots = new long[maxBase];\n roots[0] = baseRoot;\n for (int i = 1; i < maxBase; i++)\n {\n roots[i] = (roots[i - 1] * roots[i - 1]) % MOD;\n }\n invRoots = new long[maxBase];\n for (int i = 0; i < maxBase; i++)\n {\n invRoots[i] = Pow(roots[i], mod - 2);\n }\n }\n\n public long[] Multiply(long[] a, long[] b)\n {\n int n = 1;\n int p = 0;\n while (n < Math.Max(a.Length, b.Length))\n {\n n <<= 1;\n p++;\n }\n n <<= 1;\n p++;\n\n if (p > maxBase)\n {\n throw new InvalidOperationException($\"Mod {MOD} cannot be used ({p} > {maxBase}).\");\n }\n\n var fa = new long[n];\n Array.Copy(a, fa, a.Length);\n var fb = new long[n];\n Array.Copy(b, fb, b.Length);\n\n FFT(fa, p, false);\n FFT(fb, p, false);\n\n for (int i = 0; i < n; i++)\n {\n fa[i] = fa[i] * fb[i] % MOD;\n }\n\n FFT(fa, p, true);\n long invN = Pow(n, MOD - 2);\n for (int i = 0; i < n; i++)\n {\n fa[i] = fa[i] * invN % MOD;\n }\n return fa;\n }\n\n public void FFT(long[] a, int p, bool invert)\n {\n int n = a.Length;\n if (n == 1)\n {\n return;\n }\n\n var a0 = new long[n / 2];\n var a1 = new long[n / 2];\n for (int i = 0; i < n / 2; i++)\n {\n a0[i] = a[2 * i];\n a1[i] = a[2 * i + 1];\n }\n FFT(a0, p - 1, invert);\n FFT(a1, p - 1, invert);\n\n long w = 1;\n long wn = invert ? invRoots[maxBase - p] : roots[maxBase - p];\n\n for (int i = 0; i < n / 2; i++)\n {\n long d = w * a1[i] % MOD;\n a[i] = a0[i] + d;\n if (a[i] >= MOD)\n {\n a[i] -= MOD;\n }\n a[i + n / 2] = a0[i] - d;\n if (a[i + n / 2] < 0)\n {\n a[i + n / 2] += MOD;\n }\n w = w * wn % MOD;\n }\n }\n\n public long Pow(long a, long n)\n {\n long result = 1;\n\n while (n > 0)\n {\n if ((n & 1) > 0)\n {\n result = (result * a) % MOD;\n }\n\n a = (a * a) % MOD;\n n >>= 1;\n }\n\n return result;\n }\n }\n\n public static void Solve()\n {\n // var sw = Stopwatch.StartNew();\n\n SolveCase();\n\n /*int T = ReadInt();\n for (int i = 0; i < T; i++)\n {\n // Writer.WriteLine(\"Case {0}:\", i + 1);\n // Writer.Write(\"Case #{0}: \", i + 1);\n SolveCase();\n }*/\n\n // sw.Stop();\n // Console.WriteLine(sw.ElapsedMilliseconds);\n }\n\n public static void Main()\n {\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if DEBUG\n // Reader = Console.In; Writer = Console.Out;\n Reader = File.OpenText(\"input.txt\"); Writer = File.CreateText(\"output.txt\");\n#else\n Reader = Console.In; Writer = Console.Out;\n#endif\n\n // Solve();\n Thread thread = new Thread(Solve, 64 * 1024 * 1024);\n thread.CurrentCulture = CultureInfo.InvariantCulture;\n thread.Start();\n thread.Join();\n\n Reader.Close();\n Writer.Close();\n }\n\n public static IOrderedEnumerable OrderByWithShuffle(this IEnumerable source, Func keySelector)\n {\n return source.Shuffle().OrderBy(keySelector);\n }\n\n public static T[] Shuffle(this IEnumerable source)\n {\n T[] result = source.ToArray();\n Random rnd = new Random();\n for (int i = result.Length - 1; i >= 1; i--)\n {\n int k = rnd.Next(i + 1);\n T tmp = result[k];\n result[k] = result[i];\n result[i] = tmp;\n }\n return result;\n }\n\n #region Read/Write\n\n private static TextReader Reader;\n\n private static TextWriter Writer;\n\n private static Queue CurrentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return Reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (CurrentLineTokens.Count == 0)\n CurrentLineTokens = new Queue(ReadAndSplitLine());\n return CurrentLineTokens.Dequeue();\n }\n\n public static string ReadLine()\n {\n return Reader.ReadLine();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = Reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n Writer.WriteLine(string.Join(\" \", array));\n }\n\n #endregion\n }\n}\n", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace _95D2C\n{\n class Program\n {\n static void Main(string[] args)\n {\n var temp = Console.ReadLine().Split(' ');\n ulong n = ulong.Parse(temp[0]);\n ulong m = ulong.Parse(temp[1]);\n ulong t = ulong.Parse(temp[2]);\n ulong sum = 0;\n for (ulong i = 4; i <= n; i++)\n {\n for (ulong j = 1; j <=m; j++)\n {\n if (i + j == t)\n {\n // ulong res1=0;\n decimal res1 = 0;\n if ((Math.Max(n - i + 1, i + 1) < 18)&&(n>=28))\n {\n // res1 = (fact(n, 18) )/ fact(Math.Min(i, n - i), 2);\n res1 = ((decimal)fact(n, 18)) / fact(Math.Min(i, n - i), 2);\n for (ulong k = 17; k >= Math.Max(n - i + 1, i + 1); k--)\n res1 *= k;\n }\n else\n {\n res1 = ((decimal)fact(n, Math.Max(n - i + 1, i + 1)) / fact(Math.Min(i, n - i), 2));\n //res1 = (fact(n, Math.Max(n - i + 1, i + 1)) / fact(Math.Min(i, n - i), 2));\n }\n //ulong res2=0;\n decimal res2 = 0;\n if ((Math.Max(m - j + 1, j + 1) < 18)&&(m>=28))\n {\n res2 = ((decimal)fact(m, 18) / (fact(Math.Min(j, m - j), 2)));\n //res2 = (fact(m, 18) / (fact(Math.Min(j, m - j), 2)));\n for (ulong k = 17; k >= Math.Max(m - j + 1, j + 1); k--)\n res2 *= k;\n } \n else\n {\n res2 = ((decimal)fact(m, Math.Max(m - j + 1, j + 1)) / (fact(Math.Min(j, m - j), 2)));\n // res2 = (fact(m, Math.Max(m - j + 1, j + 1)) / (fact(Math.Min(j, m - j), 2)));\n }\n \n // Console.WriteLine(res1);\n // Console.WriteLine(res2);\n sum += ((ulong)res1) * ((ulong)res2);\n }\n }\n }\n Console.WriteLine(sum);\n Console.ReadLine();\n\n }\n static ulong fact(ulong n,ulong na4)\n {\n ulong res = 1;\n for (ulong i = na4; i <= n; i++)\n res *= i;\n return res;\n }\n }\n}\n", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Linq;\r\n\r\nnamespace ConsoleApp\r\n{\r\n class Program\r\n {\r\n const double DefaultEpsilon = 1e-18;\r\n\r\n struct Vector\r\n {\r\n public double X;\r\n public double Y;\r\n\r\n public Vector(double x, double y)\r\n {\r\n X = x;\r\n Y = y;\r\n }\r\n public Vector(double angle)\r\n {\r\n X = Math.Cos(angle);\r\n Y = Math.Sin(angle);\r\n }\r\n\r\n public double Hypot()\r\n {\r\n return Math.Sqrt((X * X) + (Y * Y));\r\n }\r\n public double HypotSquared()\r\n {\r\n return (X * X) + (Y * Y);\r\n }\r\n public Vector RotateClockwise(double angle)\r\n {\r\n double cos = Math.Cos(angle);\r\n double sin = Math.Sin(angle);\r\n\r\n return new Vector(X * cos + Y * sin, X * -sin + Y * cos);\r\n }\r\n public Vector Perpendicular()\r\n {\r\n return new Vector(-Y, X);\r\n }\r\n public bool IsEqual(Vector vector, double epsilon = DefaultEpsilon)\r\n {\r\n return Equal(this.X, vector.X, epsilon) && Equal(this.Y, vector.Y, epsilon);\r\n }\r\n\r\n public static Vector operator +(Vector a)\r\n {\r\n return a;\r\n }\r\n public static Vector operator -(Vector a)\r\n {\r\n return new Vector(-a.X, -a.Y);\r\n }\r\n public static Vector operator +(Vector a, Vector b)\r\n {\r\n return new Vector(a.X + b.X, a.Y + b.Y);\r\n }\r\n public static Vector operator -(Vector a, Vector b)\r\n {\r\n return new Vector(a.X - b.X, a.Y - b.Y);\r\n }\r\n public static double Determinant(Vector a, Vector b)\r\n {\r\n return (a.X * b.Y) - (a.Y * b.X);\r\n }\r\n public static double DotProduct(Vector a, Vector b)\r\n {\r\n return (a.X * b.X) + (a.Y * b.Y);\r\n }\r\n }\r\n struct Line\r\n {\r\n public double A;\r\n public double B;\r\n public double C;\r\n\r\n public double slopeY => -A / B; // y = f'(x)\r\n public double slopeX => -B / A; // x = f'(y)\r\n\r\n public Line(Vector p1, Vector p2)\r\n {\r\n A = p2.Y - p1.Y;\r\n B = p1.X - p2.X;\r\n C = p2.X * p1.Y - p1.X * p2.Y;\r\n }\r\n }\r\n struct Segment\r\n {\r\n public Vector Left;\r\n public Vector Right;\r\n\r\n public Segment(Vector left, Vector right)\r\n {\r\n Left = left;\r\n Right = right;\r\n }\r\n\r\n public Line GetLine()\r\n {\r\n return new Line(Left, Right);\r\n }\r\n public bool IsOnTheSegment(Vector point, double epsilon = DefaultEpsilon)\r\n {\r\n Vector v1 = point - Left;\r\n Vector v2 = point - Right;\r\n double det = Vector.Determinant(v1, v2);\r\n double dotProd = Vector.DotProduct(v1, v2);\r\n\r\n return Equal(det, 0, epsilon) && LessOrEqual(dotProd, 0, epsilon);\r\n }\r\n }\r\n\r\n static Program()\r\n {\r\n // Comment this before submitting (in case of strandard input)\r\n //Console.SetIn(new StreamReader(\"input.txt\"));\r\n //Console.SetOut(new StreamWriter(\"output.txt\"));\r\n }\r\n static void Main()\r\n {\r\n const int mod = 1_000_000_007;\r\n\r\n //int testcases = int.Parse(Console.ReadLine());\r\n //for (int z = 0; z < testcases; z++)\r\n //{\r\n\r\n //}\r\n\r\n int k = int.Parse(Console.ReadLine());\r\n long pow = PowQuick(2, k) - 2;\r\n long ans = PowQuick(4, pow, mod);\r\n\r\n ans *= 6;\r\n ans %= mod;\r\n\r\n Console.WriteLine(ans);\r\n\r\n Console.Out.Close();\r\n }\r\n static bool Equal(double a, double b, double epsilon = DefaultEpsilon)\r\n {\r\n return Math.Abs(a - b) < epsilon;\r\n }\r\n static bool Greater(double a, double b, double epsilon = DefaultEpsilon)\r\n {\r\n return (a > b) && !Equal(a, b, epsilon);\r\n }\r\n static bool Less(double a, double b, double epsilon = DefaultEpsilon)\r\n {\r\n return (a < b) && !Equal(a, b, epsilon);\r\n }\r\n static bool GreaterOrEqual(double a, double b, double epsilon = DefaultEpsilon)\r\n {\r\n return (a > b) || Equal(a, b, epsilon);\r\n }\r\n static bool LessOrEqual(double a, double b, double epsilon = DefaultEpsilon)\r\n {\r\n return (a < b) || Equal(a, b, epsilon);\r\n }\r\n static double DegToRad(double angle)\r\n {\r\n return (angle / 180) * Math.PI;\r\n }\r\n static long LCM(long a, long b)\r\n {\r\n return (a / GCD(a, b)) * b;\r\n }\r\n static long GCD(long a, long b)\r\n {\r\n while (a != 0)\r\n {\r\n b %= a;\r\n Swap(ref a, ref b);\r\n }\r\n\r\n return b;\r\n }\r\n static long PowQuick(long b, long p)\r\n {\r\n long exp = b;\r\n long res = 1;\r\n\r\n while (p > 0)\r\n {\r\n if ((p % 2) == 1)\r\n {\r\n res *= exp;\r\n }\r\n\r\n exp *= exp;\r\n p /= 2;\r\n }\r\n\r\n return res;\r\n }\r\n static long PowQuick(long b, long p, long mod)\r\n {\r\n long exp = b;\r\n long res = 1;\r\n\r\n while (p > 0)\r\n {\r\n if ((p % 2) == 1)\r\n {\r\n res *= exp;\r\n res %= mod;\r\n }\r\n\r\n exp *= exp;\r\n exp %= mod;\r\n p /= 2;\r\n }\r\n\r\n return res;\r\n }\r\n static uint BitCount(uint a)\r\n {\r\n a = ((a >> 1) & 0x55555555u) + (a & 0x55555555u);\r\n a = ((a >> 2) & 0x33333333u) + (a & 0x33333333u);\r\n a = ((a >> 4) & 0x0F0F0F0Fu) + (a & 0x0F0F0F0Fu);\r\n a = ((a >> 8) & 0x00FF00FFu) + (a & 0x00FF00FFu);\r\n a = ((a >> 16) & 0x0000FFFFu) + (a & 0x0000FFFFu);\r\n return a;\r\n }\r\n static bool AreAlmostEqual(double a, double b, double epsilon)\r\n {\r\n return Math.Abs(a - b) < epsilon;\r\n }\r\n static int Binary(int[] array, int val)\r\n {\r\n return Binary(array, val, 0, array.Length);\r\n }\r\n static int Binary(int[] array, int val, int left, int right)\r\n {\r\n if (val < array[0])\r\n {\r\n return 0;\r\n }\r\n\r\n while (right - left > 1)\r\n {\r\n int mid = (right + left) / 2;\r\n\r\n if (array[mid] <= val)\r\n {\r\n left = mid;\r\n }\r\n else\r\n {\r\n right = mid;\r\n }\r\n }\r\n\r\n return right;\r\n }\r\n static void Swap(ref int a, ref int b)\r\n {\r\n int temp = a;\r\n a = b;\r\n b = temp;\r\n }\r\n static void Swap(ref long a, ref long b)\r\n {\r\n long temp = a;\r\n a = b;\r\n b = temp;\r\n }\r\n static double[] ReadDoubleData(TextReader input)\r\n {\r\n return input.ReadLine()\r\n .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)\r\n .Select(val => double.Parse(val))\r\n .ToArray();\r\n }\r\n static double[] ReadDoubleData()\r\n {\r\n return ReadDoubleData(Console.In);\r\n }\r\n static int[] ReadIntData(TextReader input)\r\n {\r\n return input.ReadLine()\r\n .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)\r\n .Select(val => int.Parse(val))\r\n .ToArray();\r\n }\r\n static int[] ReadIntData()\r\n {\r\n return ReadIntData(Console.In);\r\n }\r\n static long[] ReadLongData(TextReader input)\r\n {\r\n return input.ReadLine()\r\n .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)\r\n .Select(val => long.Parse(val))\r\n .ToArray();\r\n }\r\n static long[] ReadLongData()\r\n {\r\n return ReadLongData(Console.In);\r\n }\r\n }\r\n}", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\npublic class HelloWorld {\n static public void Main () {\n SolveCodeForces();\n // Test();\n // System.Console.WriteLine(Brute(995));\n }\n\n public static void SolveCodeForces() {\n var n = ulong.Parse(Console.ReadLine());\n var ans = SolveCF(n);\n System.Console.WriteLine(ans);\n }\n\n public static ulong SolveCF(ulong n) {\n var s = n.ToString();\n\n var ans = 0ul;\n var carry = false;\n\n for (var i = s.Length - 1; i >= 0; i--) {\n\n var d = int.Parse(s[i].ToString());\n int curr;\n bool newcarry;\n\n if (i == s.Length - 1 && s.Length > 1) {\n newcarry = d <= 8;\n curr = newcarry ? (d + 10) : d;\n }\n\n else if (i > 0) {\n newcarry = carry ? true : (d <= 8);\n curr = (newcarry ? (d + 10) : d) - (carry ? 1 : 0);\n }\n\n else {\n newcarry = false;\n curr = d - (carry ? 1 : 0);\n }\n\n ans += (ulong)curr;\n carry = newcarry;\n\n // System.Console.WriteLine(new { s, i, curr, carry, ans });\n }\n\n return ans;\n }\n\n public static ulong S(ulong v) {\n return (ulong)v.ToString().Select(c => int.Parse(c.ToString())).Sum();\n }\n\n public static ulong Brute(ulong n) {\n var ans = 0ul;\n for (var a = 0ul; a <= n; a++) {\n var b = (ulong)(n - a);\n // if (S(a) + S(b) > ans)\n // System.Console.WriteLine(new { a, b });\n ans = Math.Max( ans, S(a) + S(b) );\n }\n return ans;\n }\n\n public static void Test() {\n var rnd = new Random(12);\n for (var t = 0; t < 1000; t++) {\n var n = (ulong)rnd.Next(0, 1000);\n\n var brute = Brute(n);\n var actual = SolveCF(n);\n\n if (brute != actual) {\n System.Console.WriteLine(new { t, n, brute, actual });\n return;\n }\n }\n System.Console.WriteLine(\"Ok\");\n }\n}", "src_uid": "5c61b4a4728070b9de49d72831cd2329"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace TShirtHunt\n{\n class Program\n {\n static List TShirtWinners(int x)\n {\n List winners = new List();\n int i = (x / 50) % 475;\n for (int j = 1; j <= 25; j++)\n {\n i = (i * 96 + 42) % 475;\n winners.Add(26 + i);\n }\n return winners;\n }\n\n static void Main(string[] args)\n {\n string[] line = Console.ReadLine().Split();\n int p = int.Parse(line[0]);\n int x = int.Parse(line[1]);\n int y = int.Parse(line[2]);\n\n int newX = x;\n while (newX >= y && !TShirtWinners(newX).Contains(p))\n {\n newX -= 50;\n }\n if (newX >= y)\n {\n Console.WriteLine(\"0\");\n return;\n }\n\n int numberOfIncreasingBy50 = Math.Max(1, (int)Math.Ceiling((double)(y - x) / 50));\n while (!TShirtWinners(x + numberOfIncreasingBy50 * 50).Contains(p))\n numberOfIncreasingBy50++;\n Console.WriteLine((numberOfIncreasingBy50 + 1) / 2);\n }\n }\n}\n", "src_uid": "c9c22e03c70a94a745b451fc79e112fd"} {"source_code": "using System;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Threading;\n\nnamespace CodeForces\n{\n\tinternal class B\n\t{\n\t\tprivate int MOD = 1000000007;\n\t\tprivate int n;\n\t\tprivate long m;\n\t\tprivate int k;\n\t\tprivate int[,] dp;\n\t\tprivate bool[,] was;\n\t\tprivate int[,] bin, pw;\n\n\t\tint go( int pos, int k )\n\t\t{\n\t\t\tif ( pos == n )\n\t\t\t{\n\t\t\t\tif ( k == 0 ) return 1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif ( was[pos, k] )\n\t\t\t\treturn dp[pos, k];\n\t\t\tint res = go( pos + 1, k );\n\n\t\t\tfor ( int i = 1; i <= n && i <= k; ++i )\n\t\t\t{\n\t\t\t\tint tmp = (int)( ( (long)pw[pos, i] * go( pos + 1, k - i ) ) % MOD );\n\t\t\t\tres += tmp;\n\t\t\t\tif ( res >= MOD ) res -= MOD;\n\t\t\t}\n\n\t\t\twas[pos, k] = true;\n\t\t\treturn dp[pos, k] = res;\n\t\t}\n\n\t\tprivate int pow( int a, long b )\n\t\t{\n\t\t\tif ( b == 0 ) return 1;\n\t\t\tint tmp = pow( a, b / 2 );\n\t\t\ttmp = (int)( ( (long)tmp * tmp ) % MOD );\n\t\t\tif ( b % 2 == 1 )\n\t\t\t{\n\t\t\t\ttmp = (int)( ( (long)tmp * a ) % MOD );\n\t\t\t}\n\t\t\treturn tmp;\n\t\t}\n\n\t\tprivate void Solve()\n\t\t{\n\t\t\tn = NextInt();\n\t\t\tm = NextLong();\n\t\t\tk = NextInt();\n\n\t\t\tbin = new int[101, 101];\n\t\t\tfor ( int i = 0; i <= 100; ++i )\n\t\t\t{\n\t\t\t\tbin[i, 0] = bin[i, i] = 1;\n\t\t\t\tfor ( int j = 1; j < i; ++j ) bin[i, j] = ( bin[i - 1, j] + bin[i - 1, j - 1] ) % MOD;\n\t\t\t}\n\t\t\tpw = new int[101, 101];\n\t\t\tfor ( int pos = 0; pos < n; ++pos )\n\t\t\t{\n\t\t\t\tlong cnt = ( ( ( m - pos ) % n ) == 0 ? ( m - pos ) / n - 1 : ( m - pos ) / n ) + 1;\n\t\t\t\tfor ( int i = 1; i <= n; ++i )\n\t\t\t\t{\n\t\t\t\t\tpw[pos, i] = pow( bin[n, i], cnt );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdp = new int[n, n * n + 1];\n\t\t\twas = new bool[n, n * n + 1];\n\t\t\tOut.WriteLine( go( 0, k ) );\n\t\t}\n\n\t\t#region Local wireup\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn _in.NextInt();\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn _in.NextLong();\n\t\t}\n\n\t\tpublic string NextLine()\n\t\t{\n\t\t\treturn _in.NextLine();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn _in.NextDouble();\n\t\t}\n\n\t\treadonly Scanner _in = new Scanner();\n\t\tstatic readonly TextWriter Out = Console.Out;\n\n\t\tvoid Start()\n\t\t{\n#if !ONLINE_JUDGE\n\t\t\tvar timer = new Stopwatch();\n\t\t\ttimer.Start();\n#endif\n\t\t\tvar t = new Thread( Solve, 20000000 );\n\t\t\tt.Start();\n\t\t\tt.Join();\n#if !ONLINE_JUDGE\n\t\t\ttimer.Stop();\n\t\t\tConsole.WriteLine( string.Format( CultureInfo.InvariantCulture, \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0 ) );\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\n\t\tstatic void Main()\n\t\t{\n\t\t\tnew B().Start();\n\t\t}\n\n\t\tclass Scanner : IDisposable\n\t\t{\n\t\t\t#region Fields\n\n\t\t\treadonly TextReader _reader;\n\t\t\treadonly int _bufferSize;\n\t\t\treadonly bool _closeReader;\n\t\t\treadonly char[] _buffer;\n\t\t\tint _length, _pos;\n\n\t\t\t#endregion\n\n\t\t\t#region .ctors\n\n\t\t\tpublic Scanner( TextReader reader, int bufferSize, bool closeReader )\n\t\t\t{\n\t\t\t\t_reader = reader;\n\t\t\t\t_bufferSize = bufferSize;\n\t\t\t\t_closeReader = closeReader;\n\t\t\t\t_buffer = new char[_bufferSize];\n\t\t\t\tFillBuffer( false );\n\t\t\t}\n\n\t\t\tpublic Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }\n\n\t\t\tpublic Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }\n\n#if ONLINE_JUDGE\n\t\t\tpublic Scanner() : this( Console.In, false ) { }\n#else\n\t\t\tpublic Scanner() : this( \"input.txt\" ) { }\n#endif\n\n\t\t\t#endregion\n\n\t\t\t#region IDisposable Members\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\tif ( _closeReader )\n\t\t\t\t{\n\t\t\t\t\t_reader.Close();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Properties\n\n\t\t\tpublic bool Eof\n\t\t\t{\n\t\t\t\tget\n\t\t\t\t{\n\t\t\t\t\tif ( _pos < _length ) return false;\n\t\t\t\t\tFillBuffer( false );\n\t\t\t\t\treturn _pos >= _length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Methods\n\n\t\t\tprivate char NextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos++];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos++];\n\t\t\t}\n\n\t\t\tprivate char PeekNextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos];\n\t\t\t}\n\n\t\t\tprivate void FillBuffer( bool throwOnEof )\n\t\t\t{\n\t\t\t\t_length = _reader.Read( _buffer, 0, _bufferSize );\n\t\t\t\tif ( throwOnEof && Eof )\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException( \"Can't read beyond the end of file\" );\n\t\t\t\t}\n\t\t\t\t_pos = 0;\n\t\t\t}\n\n\t\t\tpublic int NextInt()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tint res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic long NextLong()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic string NextLine()\n\t\t\t{\n\t\t\t\tSkipUntilNextLine();\n\t\t\t\tif ( Eof ) return \"\";\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn builder.ToString();\n\t\t\t}\n\n\t\t\tpublic double NextDouble()\n\t\t\t{\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn double.Parse( builder.ToString(), CultureInfo.InvariantCulture );\n\t\t\t}\n\n\t\t\tprivate void SkipWhitespaces()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void SkipUntilNextLine()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static bool IsWhitespace( char c )\n\t\t\t{\n\t\t\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\tprivate static bool IsEndOfLine( char c )\n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\t#endregion\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "9c71c8e031412e2bb21266a53821626a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\nusing static System.Math;\n\nnamespace Olymp\n{\n public class ProblemSolver\n {\n private Tokenizer input;\n\n public void Solve()\n {\n int n = input.ReadInt();\n var c = new HashSet();\n for (int a = 0; a <= 33; a++)\n {\n for (int b = 0; 7 * b <= 100 - 3 * a; b++)\n {\n c.Add(3 * a + 7 * b);\n }\n }\n for (int i = 0; i < n; i++)\n {\n int x = input.ReadInt();\n Console.WriteLine(c.Contains(x) ? \"YES\" : \"NO\");\n }\n }\n\n public ProblemSolver(TextReader input)\n {\n this.input = new Tokenizer(input);\n }\n\n #region Service functions\n\n private static int GCD(int a, int b)\n {\n while (b != 0)\n {\n a %= b;\n int t = b;\n b = a;\n a = t;\n }\n return a;\n }\n\n #endregion\n }\n\n #region Service classes\n\n public class Tokenizer\n {\n private TextReader reader;\n\n public int ReadInt()\n {\n var c = SkipWS();\n if (c == -1)\n throw new EndOfStreamException();\n bool isNegative = false;\n if (c == '-' || c == '+')\n {\n isNegative = c == '-';\n c = this.reader.Read();\n if (c == -1)\n throw new InvalidOperationException();\n }\n if (!char.IsDigit((char)c))\n throw new InvalidOperationException();\n int result = (char)c - '0';\n c = this.reader.Read();\n while (c > 0 && !char.IsWhiteSpace((char)c))\n {\n if (!char.IsDigit((char)c))\n throw new InvalidOperationException();\n result = result * 10 + (char)c - '0';\n c = this.reader.Read();\n }\n if (isNegative)\n result = -result;\n return result;\n }\n\n public string ReadLine()\n {\n return reader.ReadLine();\n }\n\n public long ReadLong()\n {\n return long.Parse(this.ReadToken());\n }\n\n public double ReadDouble()\n {\n return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public int[] ReadIntArray(int n)\n {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = ReadInt();\n return a;\n }\n\n public long[] ReadLongArray(int n)\n {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = ReadLong();\n return a;\n }\n\n public double[] ReadDoubleArray(int n)\n {\n double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = ReadDouble();\n return a;\n }\n\n public string ReadToken()\n {\n var c = SkipWS();\n if (c == -1)\n return null;\n var sb = new StringBuilder();\n while (c > 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = this.reader.Read();\n }\n return sb.ToString();\n }\n\n private int SkipWS()\n {\n int c = this.reader.Read();\n if (c == -1)\n return c;\n while (c > 0 && char.IsWhiteSpace((char)c))\n c = this.reader.Read();\n return c;\n }\n\n public Tokenizer(TextReader reader)\n {\n this.reader = reader;\n }\n }\n\n class Program\n {\n public static void Main(string[] args)\n {\n var solver = new ProblemSolver(Console.In);\n solver.Solve();\n }\n }\n\n #endregion\n}", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Globalization;\n\nnamespace CodeForces\n{\n\tclass MainClass\n\t{\n\t\tpublic static void Main (string[] args)\n\t\t{\n\t\t\tint[] nums = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();\n\t\t\tDictionary cards = new Dictionary ();\n\t\t\tforeach (int i in nums) {\n\t\t\t\tif (!cards.ContainsKey (i))\n\t\t\t\t\tcards.Add (i, 0);\n\t\t\t\tcards [i]++;\n\t\t\t}\n\t\t\tint best = nums.Sum ();\n\t\t\tforeach (KeyValuePair pair in cards) {\n\t\t\t\tif (pair.Value > 1) {\n\t\t\t\t\tint count = pair.Value;\n\t\t\t\t\tif (count > 3)\n\t\t\t\t\t\tcount = 3;\n\t\t\t\t\tint tmp = nums.Sum () - pair.Key * count;\n\t\t\t\t\tif (tmp < best)\n\t\t\t\t\t\tbest = tmp;\n\t\t\t\t}\n\t\t\t}\n\t\t\tConsole.WriteLine (best);\n\t\t}\n\t}\n}\n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"source_code": "using System; using System.Collections.Generic;\nusing System.Linq;\n\nclass P {\n static IEnumerable GetNums() {\n for (var i = 0L ; ; i++) {\n var c = i;\n var res = 0L; var mult = 1L;\n var d4 = 0; var d7 = 0;\n while (c > 0) {\n int dig;\n if (c > 2) {\n var o = (c - 1)%2 + 1;\n c -= o;\n dig = o == 1 ? 4 : 7;\n } else {\n c--;\n dig = (c == 0 ? 4 : 7);\n }\n if (dig == 4) d4++; else d7++;\n res += mult * dig;\n c /= 2;\n mult *= 10;\n }\n if (d4 == d7)\n yield return res;\n }\n }\n\n public static void Main() {\n long n = long.Parse(Console.ReadLine());\n var res = GetNums().First(x => x >= n);\n Console.Write(res);\n }\n}", "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class R200_Div2_C\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n long a = long.Parse(s[0]);\n long b = long.Parse(s[1]);\n\n long cnt = a/b, x;\n a %= b;\n while (a > 0)\n {\n x = a; a = b; b = x;\n cnt += (a / b);\n a %= b;\n }\n Console.WriteLine(cnt);\n } \n }\n}\n", "src_uid": "792efb147f3668a84c866048361970f8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\n\n/*\n Aryanium Shadowhunter\n*/\n\nnamespace CodeForces\n{\n class Program\n {\n\n \n \n public static void Main(string[] args)\n {\n GregorianCalendar gCalendar = new GregorianCalendar();\n DateTime dTime = new DateTime(2016,1,1,gCalendar);\n string input = Console.ReadLine();\n int count = 0;\n if (input.Contains(\"week\"))\n {\n int day = int.Parse(input.Replace(\" of week\", \" \"));\n DayOfWeek dayWeek = new DayOfWeek();\n\n switch (day)\n {\n case 1:dayWeek = DayOfWeek.Monday;break;\n case 2: dayWeek = DayOfWeek.Tuesday; break;\n case 3: dayWeek = DayOfWeek.Wednesday; break;\n case 4: dayWeek = DayOfWeek.Thursday; break;\n case 5: dayWeek = DayOfWeek.Friday; break;\n case 6: dayWeek = DayOfWeek.Saturday; break;\n case 7: dayWeek = DayOfWeek.Sunday; break;\n\n }\n \n for (int i = 0; i < gCalendar.GetDaysInYear(2016); i++)\n {\n if (gCalendar.GetDayOfWeek(dTime) == dayWeek) count++;\n dTime = gCalendar.AddDays(dTime, 1);\n }\n }\n else\n {\n int day = int.Parse(input.Replace(\" of month\", \" \"));\n for (int i = 1; i < 13; i++)\n {\n if (day <= gCalendar.GetDaysInMonth(2016, i)) count++ ;\n }\n }\n\n\n Console.WriteLine(count);\n \n }\n\n }\n}", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"source_code": "using System;\n\nnamespace ConsoleApplication1\n{\n\n class Program\n {\n static void Main(string[] args)\n {\n string[] t = Console.ReadLine().Split(' ');\n int l = int.Parse(t[0]);\n int d = int.Parse(t[1]);\n int v = int.Parse(t[2]);\n int g = int.Parse(t[3]);\n int r = int.Parse(t[4]);\n double ans = 0;\n double t1 = (double)d / (double)v;\n double w = (double)l / (double)v;\n t1 %= g + r;\n if (t1 < g)\n ans = w;\n if (t1 == g)\n ans = w + r;\n if (t1 > g)\n ans = w + r - (t1 - g);\n string s = String.Format(\"{0:0.######}\", ans).Replace(',','.');\n Console.WriteLine(s);\n }\n }\n}\n", "src_uid": "e4a4affb439365c843c9f9828d81b42c"} {"source_code": "using System;\nusing System.Text;\nusing System.Collections.Generic;\nusing System.Linq;\nclass Solve{\n public Solve(){}\n StringBuilder sb;\n public static int Main(){\n new Solve().Run();\n return 0;\n }\n void Run(){\n sb = new StringBuilder();\n Calc();\n Console.Write(sb.ToString());\n }\n void Calc(){\n string[] str = Console.ReadLine().Split(' ');\n long X = long.Parse(str[0]);\n long Y = long.Parse(str[1]);\n Generateprimenumber G = new Generateprimenumber(1000003);\n long[] Div = G.Divisor(X);\n long count = 0;\n while(Y != 0){\n long Z = gcd(X,Y);\n X /= Z;\n Y /= Z;\n long min = Y;\n for(int i=0;i pp = new List();\n int j = 2;\n for(int i=0;i pp = new List();\n long num = n;\n for(int i=0;p[i]*p[i] <= num;i++){\n if(num % p[i] == 0){\n pp.Add(p[i]);\n }\n while(num % p[i] == 0){\n num /= p[i];\n }\n }\n if(num != 1){\n pp.Add(num);\n }\n return pp.ToArray();\n }\n}", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e"} {"source_code": "using System;\n\nnamespace Xorygol\n{\n class Program\n {\n static void Main(string[] args)\n {\n int count = 0;\n int n = Convert.ToInt32(Console.ReadLine());\n for (int a = 1; a <= n; a++)\n {\n for (int b = a; b <= n; b++)\n {\n int c = a ^ b;\n if((b + a > c) && (a + c > b) && (c + b > a) && (c >= b) && (c <= n))\n {\n count++;\n }\n }\n }\n Console.WriteLine(count);\n }\n }\n}\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "using System;\n\nnamespace CSharp\n{\n public class _651A\n {\n public static void Main(string[] args)\n {\n string[] tokens = Console.ReadLine().Split();\n\n int a1 = int.Parse(tokens[0]);\n int a2 = int.Parse(tokens[1]);\n\n int minutes = 0;\n\n while (Math.Min(a1, a2) > 0 && Math.Max(a1, a2) > 1)\n {\n int min = Math.Min(a1, a2);\n int max = Math.Max(a1, a2);\n\n a1 = min + 1;\n a2 = max - 2;\n\n minutes++;\n }\n\n Console.WriteLine(minutes);\n }\n }\n}", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"source_code": "using System;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n var cnt = Console.ReadLine();\n var split = cnt.Split(' ');\n int n = int.Parse(split[0]);\n int m = int.Parse(split[1]);\n for(int i=0;i '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "e2357a1f54757bce77dce625772e4f18"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace Contest_14\n{\n class Program\n {\n static void A()\n {\n var t = Console.ReadLine().Split(' ');\n int n = int.Parse(t[0]);\n int m = int.Parse(t[1]);\n\n int x1 = int.MaxValue, x2 = int.MinValue, y1 = int.MaxValue, y2 = int.MinValue;\n List a = new List();\n for (int i = 0; i < n; i++)\n {\n string s = Console.ReadLine();\n a.Add(s);\n for (int j = 0; j < m; j++)\n {\n if (s[j] == '*')\n {\n if (x1 > i)\n x1 = i;\n if (x2 < i)\n x2 = i;\n if (y1 > j)\n y1 = j;\n if (y2 < j)\n y2 = j;\n }\n }\n }\n\n for (int i = x1; i <= x2; i++)\n {\n for (int j = y1; j <= y2; j++)\n {\n Console.Write(a[i][j]);\n }\n Console.WriteLine();\n }\n }\n\n static void B()\n {\n var t = Console.ReadLine().Split(' ');\n int n = int.Parse(t[0]);\n int x = int.Parse(t[1]);\n\n int min = int.MaxValue;\n int max = int.MinValue;\n int[] a = new int[1001];\n for (int i = 0; i < n; i++)\n {\n t = Console.ReadLine().Split(' ');\n int k = int.Parse(t[0]);\n int l = int.Parse(t[1]);\n\n if (k > l)\n {\n int q = k;\n k = l;\n l = q;\n }\n if (i == 0)\n {\n min = k;\n max = l;\n continue;\n }\n if (k > min)\n {\n min = k;\n }\n if (l < max)\n max = l;\n }\n if (max < min)\n {\n Console.WriteLine(-1);\n return;\n }\n if ((x >= min) && (x <= max))\n Console.WriteLine(0);\n else\n Console.WriteLine(Math.Min(Math.Abs(min - x), Math.Abs(max - x)));\n }\n\n class Point : IComparer\n {\n public int x;\n public int y;\n\n public Point(int x, int y)\n {\n this.x = x;\n this.y = y;\n }\n\n public int Compare(Point p1, Point p2)\n {\n if (p1.x != p2.x)\n return p1.x.CompareTo(p2.x);\n else\n return p1.y.CompareTo(p2.y);\n }\n\n public bool isGood (Point p)\n {\n if ((x == p.x) && (y != p.y))\n return true;\n if ((y == p.y) && (x != p.x))\n return true;\n return false;\n }\n\n public void deleteInList(List b)\n {\n for (int j = 0; j < b.Count; j++)\n {\n Point temp = b[j];\n if ((temp.x == this.x) && (temp.y == this.y))\n {\n b.RemoveAt(j);\n break;\n }\n }\n\n }\n\n }\n\n static void C()\n {\n List a = new List();\n\n for (int i = 0; i < 4; i++)\n {\n var t = Console.ReadLine().Split(' ');\n var t1 = new int[] { int.Parse(t[0]), int.Parse(t[1]), int.Parse(t[2]), int.Parse(t[3]) };\n for (int j = 0; j < a.Count; j++)\n {\n var k = a[j];\n\n if ((k[0] == t1[0]) && (k[1] == t1[1]) && (k[2] == t1[2]) && (k[3] == t1[3]))\n {\n Console.WriteLine(\"NO\");\n return;\n }\n\n if ((k[2] == t1[0]) && (k[3] == t1[1]) && (k[0] == t1[2]) && (k[1] == t1[3]))\n {\n Console.WriteLine(\"NO\");\n return;\n }\n }\n a.Add(t1);\n\n \n }\n\n List b = new List();\n\n int xl = int.MaxValue, yl = int.MinValue, xr = int.MinValue, yr = int.MaxValue;\n\n for (int i = 0; i < 4; i++)\n {\n int[] t = a[i];\n Point l1 = new Point(t[0], t[1]);\n Point l2 = new Point(t[2], t[3]);\n b.Add(l1);\n b.Add(l2);\n if (t[0] < xl)\n xl = t[0];\n if (t[1] > yl)\n yl = t[1];\n if (t[2] > xr)\n xr = t[2];\n if (t[3] < yr)\n yr = t[3];\n if (!l1.isGood(l2))\n {\n Console.WriteLine(\"NO\");\n return;\n }\n }\n\n Point p1 = new Point(xl, yl);\n Point p2 = new Point(xr, yr);\n\n for (int i = 0; i < 2; i++)\n {\n p1.deleteInList(b);\n p2.deleteInList(b);\n new Point(p1.x, p2.y).deleteInList(b);\n new Point(p2.x, p1.y).deleteInList(b);\n }\n if (b.Count > 0)\n Console.WriteLine(\"NO\");\n else Console.WriteLine(\"YES\");\n }\n\n static void Main(string[] args)\n {\n //Console.SetIn(new StreamReader(@\"C:\\1.txt\"));\n C();\n }\n }\n}\n", "src_uid": "ad105c08f63e9761fe90f69630628027"} {"source_code": "using System;\n\nnamespace codeforces99B\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n string s = Console.ReadLine();\n for(int i=2;i<=n;i++)\n {\n if(n%i==0)\n {\n s= Reverse(s.Substring(0, i)) + s.Substring(i);\n }\n }\n Console.WriteLine(s);\n }\n private static string Reverse(string str)\n {\n string res = \"\";\n for (int i = 0; i < str.Length; i++)\n res = str[i] + res;\n // Console.WriteLine(res);\n return res;\n }\n }\n}\n", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"source_code": "// Problem: 965A - Paper Airplanes\n// Author: Gusztav Szmolik\n\nusing System;\n\nclass PaperAirplanes\n {\n static int Main ()\n {\n string line = Console.ReadLine ();\n if (line == null)\n return -1;\n char[] delims = {' ', '\\t'};\n string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);\n if (words.Length != 4)\n return -1;\n ushort k;\n if (!UInt16.TryParse (words[0], out k))\n return -1;\n if (k < 1 || k > 10000)\n return -1;\n ushort n;\n if (!UInt16.TryParse (words[1], out n))\n return -1;\n if (n < 1 || n > 10000)\n return -1;\n ushort s;\n if (!UInt16.TryParse (words[2], out s))\n return -1;\n if (s < 1 || s > 10000)\n return -1;\n ushort p;\n if (!UInt16.TryParse (words[3], out p))\n return -1;\n if (p < 1 || p > 10000)\n return -1;\n ushort numSheetEachPeople = Convert.ToUInt16 (n%s == 0 ? n/s : n/s+1);\n uint totalNumSheet = Convert.ToUInt32 (k*numSheetEachPeople);\n uint ans = (totalNumSheet%p == 0 ? totalNumSheet/p : totalNumSheet/p+1);\n Console.WriteLine (ans);\n return 0;\n }\n }\n", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Text.RegularExpressions;\nnamespace learnSharp\n{\n public delegate void PayDelegate();\n public delegate void AddDelegate();\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n char[] leeterOfS = s.ToCharArray();\n int n = 0;\n\n char[] odd = { '1', '3', '5', '7' ,'9' };\n char[] vowel = { 'a', 'i', 'o', 'u', 'e' };\n\n for(int i = 0; i < s.Length; i++)\n {\n for(int v = 0; v < vowel.Length; v++)\n {\n if (leeterOfS[i] == vowel[v])\n {\n n += 1;\n }\n }\n }\n\n for(int i = 0; i < s.Length; i++)\n {\n for(int e = 0; e < odd.Length; e++)\n {\n if (leeterOfS[i] == odd[e])\n {\n n += 1;\n }\n }\n }\n\n Console.WriteLine(n);\n }\n }\n}", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Blocked_Points\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n long n = Next();\n\n long count;\n if (n == 1)\n count = 4;\n \n else if (n == 2)\n count = 8;\n else if (n == 0)\n count = 1;\n else\n {\n \n long y = (long)Math.Sqrt(n/2*n)+2;\n long nn = n*n;\n\n while (2*y*y > nn)\n {\n y--;\n }\n if (y*y + (y+1)*(y+1) > nn)\n {\n count = (y)*8;\n }\n else\n {\n count = (2*y + 1)*4;\n }\n }\n\n writer.WriteLine(count);\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "d87ce09acb8401e910ca6ef3529566f4"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CSharp\n{\n public class _849A\n {\n public static void Main()\n {\n int n = int.Parse(Console.ReadLine());\n int[] a = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();\n\n Console.WriteLine((a.Length * a.First() * a.Last()) % 2 == 1 ? \"Yes\" : \"No\");\n }\n }\n}", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing SB = System.Text.StringBuilder;\nusing System.Numerics;\nusing static System.Math;\nnamespace Program {\n public class Solver {\n Random rnd = new Random(0);\n public void Solve() {\n var n = rl;\n var k = ri;\n solve(n, k);\n }\n void solve(long n, int k) {\n Debug.WriteLine($\"{n} {k}\");\n var rev = Enumerate(100, x => ModInt.Inverse(x));\n\n ModInt all = 1;\n for (long p = 2; n != 1; p++) {\n if (p * p > n) {\n p = n;\n }\n if (n % p != 0) continue;\n var cnt = 0;\n while (n % p == 0) {\n n /= p;\n cnt++;\n }\n var dp = new ModInt[cnt + 1];\n dp[cnt] = 1;\n for (int i = 0; i < k; i++) {\n var next = new ModInt[cnt + 1];\n for (int j = 0; j < dp.Length; j++)\n for (int jj = 0; jj <= j; jj++) {\n next[jj] += dp[j] * rev[j + 1];\n }\n dp = next;\n }\n ModInt ans = 0;\n for (long i = 0, v = 1; i < dp.Length; i++, v *= p)\n ans += v * dp[i];\n all *= ans;\n\n }\n Console.WriteLine(all);\n }\n const long INF = 1L << 60;\n int ri { get { return sc.Integer(); } }\n long rl { get { return sc.Long(); } }\n double rd { get { return sc.Double(); } }\n string rs { get { return sc.Scan(); } }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n\n static T[] Enumerate(int n, Func f) {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f(i);\n return a;\n }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n\n#region main\nstatic class Ex {\n static public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") {\n return string.Join(st, ie);\n }\n static public void Main() {\n Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });\n var solver = new Program.Solver();\n solver.Solve();\n Console.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO {\n using System.IO;\n using System.Text;\n using System.Globalization;\n\n public class Printer: StreamWriter {\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n }\n\n public class StreamScanner {\n public StreamScanner(Stream stream) { str = stream; }\n\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n\n private byte read() {\n if (isEof) return 0;\n if (ptr >= len) {\n ptr = 0;\n if ((len = str.Read(buf, 0, 1024)) <= 0) {\n isEof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n\n public char Char() {\n byte b = 0;\n do b = read(); while ((b < 33 || 126 < b) && !isEof);\n return (char)b;\n }\n public string Scan() {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine() {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n' && b != 0; b = (char)read()) if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }\n public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }\n public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }\n }\n}\n\n#endregion\n\n\n#region sieve O(NloglogN)\nstatic public partial class MathEx {\n static public bool[] Sieve(int p, List primes = null) {\n var isPrime = new bool[p + 1];\n for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true;\n for (int i = 2; i * i <= p; i++)\n if (!isPrime[i]) continue;\n else for (int j = i * i; j <= p; j += i) isPrime[j] = false;\n if (primes != null) for (int i = 0; i <= p; i++) if (isPrime[i]) primes.Add(i);\n\n return isPrime;\n }\n static public List SieveList(int p) { var ret = new List(); Sieve(p, ret); return ret; }\n}\n#endregion\n\n\n#region ModInt\n/// \n/// [0,) までの値を取るような数\n/// \npublic struct ModInt {\n /// \n /// 剰余を取る値.\n /// \n public const long Mod = (int)1e9 + 7;\n\n /// \n /// 実際の数値.\n /// \n public long num;\n /// \n /// 値が であるようなインスタンスを構築します.\n /// \n /// インスタンスが持つ値\n /// パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため, ∈ [0,) を満たすような を渡してください.このコンストラクタは O(1) で実行されます.\n public ModInt(long n) { num = n; }\n /// \n /// このインスタンスの数値を文字列に変換します.\n /// \n /// [0,) の範囲内の整数を 10 進表記したもの.\n public override string ToString() { return num.ToString(); }\n public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }\n public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }\n public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }\n public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(long v, long k) {\n long ret = 1;\n for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n if ((k & 1) == 1) ret = ret * v % Mod;\n return new ModInt(ret);\n }\n /// \n /// 与えられた数の逆元を計算します.\n /// \n /// 逆元を取る対象となる数\n /// 逆元となるような値\n /// 法が素数であることを仮定して,フェルマーの小定理に従って逆元を O(log N) で計算します.\n public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }\n}\n#endregion", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _825\n{\n class Program\n {\n static void Main(string[] args)\n {\n b();\n Console.WriteLine();\n }\n\n private static void b()\n {\n var t = new int[10, 10, 8];\n var m = new string[10];\n for (int i = 0; i < 10; i++)\n {\n var l = Console.ReadLine();\n m[i] = l;\n for (int j = 0; j < l.Length; j++)\n {\n if (l[j] == 'X')\n {\n t[i, j, 0] = (j > 0 ? t[i, j - 1, 0] : 0) + 1;\n t[i, j, 1] = ((i > 0 && j > 0) ? t[i - 1, j - 1, 1] : 0) + 1;\n\n t[i, j, 2] = (i > 0 ? t[i -1, j, 2] : 0) + 1;\n t[i, j, 3] = ((i > 0 && j +1 < 10) ? t[i - 1, j + 1, 3] : 0) + 1;\n }\n }\n }\n for (int i = 9; i >= 0; i--)\n {\n for (int j = 9; j >= 0; j--)\n {\n\n if (m[i][j] == 'X') {\n\n t[i, j, 4] = (j + 1 < 10 ? t[i, j + 1, 4] : 0) + 1;\n t[i, j, 5] = ((i + 1 < 10 && j + 1 < 10) ? t[i + 1, j + 1, 5] : 0) + 1;\n\n t[i, j, 6] = (i + 1 < 10 ? t[i + 1, j, 6] : 0) + 1;\n t[i, j, 7] = ((i + 1 < 10 && j > 0) ? t[i + 1, j - 1, 7] : 0) + 1;\n }\n }\n\n }\n for (int i = 0; i < 10; i++)\n {\n for (int j = 0; j < 10; j++)\n {\n if (m[i][j] == 'O' || m[i][j] == 'X')\n {\n continue;\n }\n if (i == 0 && j == 0)\n {\n continue;\n }\n var l = new int[8];\n if (j > 0)\n {\n l[0] = t[i, j - 1, 0];\n }\n if (i > 0 && j > 0)\n {\n l[1] = t[i - 1, j - 1, 1];\n }\n if (i > 0)\n {\n l[2] = t[i - 1, j, 2];\n }\n if (j + 1 < 10 && i > 0)\n {\n l[3] = t[i - 1, j + 1, 3];\n }\n if (j + 1 < 10)\n {\n l[4] = t[i, j + 1, 4];\n }\n if (i + 1 < 10 && j + 1 < 10)\n {\n l[5] = t[i + 1, j + 1, 5];\n }\n if (i + 1 < 10)\n {\n l[6] = t[i + 1, j, 6];\n }\n if (j > 0 && i + 1 < 10)\n {\n l[7] = t[i + 1, j - 1, 7];\n }\n for (int k = 0; k < 4; k++)\n {\n if (l[k] + l[k + 4] >= 4)\n {\n Console.Write(\"YES\");\n return;\n }\n }\n }\n }\n Console.Write(\"NO\");\n }\n\n static void a()\n {\n Console.ReadLine();\n var line = Console.ReadLine();\n var sl = line.Split('0');\n foreach (var s in sl)\n {\n Console.Write(s.Length);\n }\n }\n }\n}\n\n", "src_uid": "d5541028a2753c758322c440bdbf9ec6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n public class SegmentTreeAssignSum\n {\n int n;\n int h;\n int[] t;\n int[] d;\n\n public SegmentTreeAssignSum(int capacity)\n {\n this.n = capacity;\n this.t = new int[capacity + capacity];\n this.d = new int[capacity + capacity];\n this.h = 1;\n while (this.h < capacity) this.h *= 2;\n if (h > capacity) h /= 2;\n }\n\n private void Calc(int p, int k)\n {\n if (d[p] == 0)\n t[p] = t[p << 1] + t[p << 1 | 1];\n else\n t[p] = d[p] * k;\n }\n\n private void Apply(int p, int value, int k)\n {\n t[p] = value * k;\n if (p < n)\n {\n d[p] = value;\n }\n }\n\n private void Build(int l, int r)\n {\n int k = 2;\n for (l += n, r += n - 1; l > 1; k <<= 1)\n {\n l >>= 1;\n r >>= 1;\n for (int i = r; i >= l; --i)\n this.Calc(i, k);\n }\n }\n\n private void Push(int l, int r)\n {\n int s = h, k = 1 << (h - 1);\n for (l += n, r += n - 1; s > 0; --s, k >>= 1)\n for (int i = l >> s; i <= r >> s; ++i)\n if (d[i] != 0)\n {\n this.Apply(i << 1, d[i], k);\n this.Apply(i << 1 | 1, d[i], k);\n d[i] = 0;\n }\n }\n\n public void Modify(int l, int r, int value)\n {\n r++;\n if (value == 0) return;\n this.Push(l, l + 1);\n this.Push(r - 1, r);\n int l0 = l, r0 = r, k = 1;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1)\n {\n if (l % 2 == 1) this.Apply(l++, value, k);\n if (r % 2 == 1) this.Apply(--r, value, k);\n }\n this.Build(l0, l0 + 1);\n this.Build(r0 - 1, r0);\n }\n\n public int GetSum(int l, int r)\n {\n r++;\n this.Push(l, l + 1);\n this.Push(r - 1, r);\n int result = 0;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1)\n {\n if (l % 2 == 1) result += t[l++];\n if (r % 2 == 1) result += t[--r];\n }\n return result;\n }\n }\n\n\n public class SegmentTree2\n {\n private int Mid = 1024 * 128;\n private int[] t;\n private int[] d;\n\n public SegmentTree2(int[] a)\n {\n this.Mid = 1;\n while (Mid < a.Length) Mid *= 2;\n this.t = new int[Mid + Mid];\n this.d = new int[Mid + Mid];\n\n for (int i = 0; i < a.Length; i++) t[Mid + i] = a[i];\n for (int i = Mid - 1; i > 0; i--)\n t[i] = t[i + i] + t[i + i + 1];\n }\n\n private void push(int v)\n {\n if (t[v] != -1)\n {\n t[v * 2] = t[v * 2 + 1] = t[v];\n t[v] = -1;\n }\n }\n\n public void update(int v, int tl, int tr, int l, int r, int color)\n {\n if (l > r)\n return;\n if (l == tl && tr == r)\n t[v] = color;\n else\n {\n push(v);\n int tm = (tl + tr) / 2;\n update(v * 2, tl, tm, l, Math.Min(r, tm), color);\n update(v * 2 + 1, tm + 1, tr, Math.Max(l, tm + 1), r, color);\n }\n }\n\n public int get(int v, int tl, int tr, int pos)\n {\n if (tl == tr)\n return t[v];\n push(v);\n int tm = (tl + tr) / 2;\n if (pos <= tm)\n return get(v * 2, tl, tm, pos);\n else\n return get(v * 2 + 1, tm + 1, tr, pos);\n }\n\n }\n\n\n public class AssignmentBf\n {\n private int[] t;\n public AssignmentBf(int capacity)\n {\n this.t = new int[capacity];\n }\n\n public void Modifu(int l, int r, int v)\n {\n for (int i = l; i <= r; i++) t[i] = v;\n }\n\n public int GetSum(int l, int r)\n {\n int sum = 0;\n for (int i = l; i <= r; i++) sum += t[i];\n return sum;\n }\n\n public int GetMax(int l, int r)\n {\n int max = t[l];\n for (int i = l; i <= r; i++)\n max = Math.Max(max, t[i]);\n return max;\n }\n }\n\n private static StringBuilder sb = new StringBuilder();\n private static bool Can(long x, long y, bool reverse = false)\n {\n if (x > y) return Can(y, x, true);\n if (x == 0) sb.Append(y + (reverse ? \"A\" : \"B\"));\n if (x == 0) return true;\n if (x == y) return false;\n sb.Append((y / (x + 1)) + (reverse ? \"A\" : \"B\"));\n return Can(y % (x + 1), x, !reverse);\n }\n\n static void Main(string[] args)\n {\n long x = ReadLong();\n long y = ReadLong();\n if (!Can(x - 1, y - 1))\n Console.WriteLine(\"Impossible\");\n else\n Console.Write(sb.ToString());\n\n /*\n int[] b = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n\n var st3 = new SegmentTree2(b);\n\n var q1 = st3.get(6, 9);\n st3.get(9, 9, 8);\n var q2 = st3.get(6, 9);\n st3.get(9, 9, 1);\n var q3 = st3.get(6, 9);\n\n st3.Update(3, 7, 9);\n\n st3.Print();\n\n int id = 0;\n int maxValue = 10;\n int size = 10;\n\n while (true)\n {\n id++;\n\n var x = new Random();\n int[] a = new int[size];\n for (int i = 0; i < a.Length; i++) a[i] = x.Next(maxValue);\n\n //int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n var st2 = new SegmentTree2(a);\n var bf = new AssignmentBf(a.Length);\n for (int i = 0; i < a.Length; i++) bf.Modifu(i, i, a[i]);\n\n for (int i = 0; i < 100000; i++)\n {\n int l = x.Next(a.Length);\n int r = x.Next(l, a.Length);\n if (x.Next(5) == 1)\n {\n int v = x.Next(maxValue);\n st2.Update(l, r, v);\n bf.Modifu(l, r, v);\n }\n else\n {\n var s1 = st2.GetSum(l, r);\n var s2 = bf.GetSum(l, r);\n if (s1 != s2)\n {\n Console.WriteLine(\"WRONG\");\n }\n }\n }\n\n */\n //Console.WriteLine(\"COMPLETED \" + id++);\n //}\n\n\n\n /*\n Verify(\"abcde\", \"a\", false);\n Verify(\"abcde\", \"a%\", true);\n Verify(\"abcde\", \"%a\", false);\n Verify(\"abcde\", \"b\", false);\n Verify(\"abcde\", \"b%\", false);\n Verify(\"abcde\", \"%b\", false);\n\n Verify(\"25%\", \"_5[%]\", true);\n Verify(\"_52\", \"_5[%]5%\", true);\n\n Verify(\"ab\", \"a[a-cdf]]\", true);\n Verify(\"ad\", \"a[a-cdf]\", true);\n Verify(\"ab\", \"a[-acdf]\", false);\n Verify(\"a-\", \"a[-acdf]\", true);\n\n Verify(\"[]\", \"'[[]]\", true);\n Verify(\"''\", \"_'\", true);\n Verify(\"U\", \"[^a-zA-Z0-9]\", false);\n */\n /*\n int n = ReadInt();\n int[] m = ReadIntArray(n);\n\n double x = -10000;\n double vx = Value(m, x);\n double prevVx = vx;\n double step = 1000;\n int iteration = 0;\n while (iteration < 228)\n {\n iteration++;\n double next = Value(m, x + step);\n if (next <= vx)\n {\n prevVx = vx;\n vx = next;\n x += step;\n }\n else\n {\n x -= step;\n vx = prevVx;\n step = step / 2;\n }\n }\n\n Console.WriteLine(vx.ToString().Replace(',', '.'));*/\n }\n\n private static List[] ReadGraph()\n {\n int n = ReadInt();\n int m = ReadInt();\n List[] g = new List[n];\n for (int i = 0; i < n; i++) g[i] = new List();\n for (int i = 0; i < m; i++)\n {\n int a = ReadInt() - 1;\n int b = ReadInt() - 1;\n g[a].Add(b);\n g[b].Add(a);\n }\n\n return g;\n }\n\n private static int[] ReadIntArray()\n {\n string[] tmp = Console.ReadLine().Split(' ');\n int[] ans = new int[tmp.Length];\n for (int i = 0; i < tmp.Length; i++) ans[i] = int.Parse(tmp[i]);\n return ans;\n }\n\n private static long[] ReadLongArray()\n {\n string[] tmp = Console.ReadLine().Split(' ');\n long[] ans = new long[tmp.Length];\n for (int i = 0; i < tmp.Length; i++) ans[i] = long.Parse(tmp[i]);\n return ans;\n }\n\n private static string[] ReadStringArray()\n {\n string[] tmp = Console.ReadLine().Split(' ');\n return tmp;\n }\n\n private static void Sort(ref int a, ref int b)\n {\n if (a > b) Swap(ref a, ref b);\n }\n\n private static void Swap(ref int a, ref int b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n private const int BufferSize = 1 << 16;\n private static readonly StreamReader consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n\n private static int ReadInt()\n {\n int ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static long ReadLong()\n {\n long ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static int[] ReadIntArray(int n)\n {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = ReadInt();\n return ans;\n }\n\n private static long[] ReadLongArray(int n)\n {\n long[] ans = new long[n];\n for (int i = 0; i < n; i++)\n ans[i] = ReadLong();\n return ans;\n }\n\n private static char[] ReadString(int n)\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (ans < 'a' || ans > 'z');\n\n char[] s = new char[n];\n int pos = 0;\n do\n {\n s[pos++] = (char)ans;\n ans = consoleReader.Read();\n } while (ans >= 'a' && ans <= 'z');\n\n return s;\n }\n\n private static char ReadLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))\n return (char)ans;\n }\n }\n}\n\n", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671"} {"source_code": "using System;\n\nnamespace CodeForces\n{\n\tclass A\n\t{\n\t\tstatic long gcd(long a, long b)\n\t\t{\n\t\t\twhile (b != 0)\n\t\t\t{\n\t\t\t\tlong temp = b;\n\t\t\t\tb = a % b;\n\t\t\t\ta = temp;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tstatic long lcm(long m, long n)\n\t\t{\n\t\t\treturn (m / gcd(m, n)) * n;\n\t\t}\n\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tstring s = Console.ReadLine();\n\t\t\tstring[] d = s.Split(' ');\n\t\t\tlong n = long.Parse(d[0]);\n\t\t\tint k = int.Parse(d[1]);\n\t\t\tint div = (int) Math.Pow(10, k);\n\n\t\t\tConsole.WriteLine(lcm(n, div));\n\t\t}\n\t}\n}\n", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"source_code": "using System;\n\nnamespace test\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] str = Console.ReadLine().Split();\n int s, v1, v2, t1, t2, a, b;\n s = Convert.ToInt32(str[0]);\n v1 = Convert.ToInt32(str[1]);\n v2 = Convert.ToInt32(str[2]);\n t1 = Convert.ToInt32(str[3]);\n t2 = Convert.ToInt32(str[4]);\n if (v1 * s + t1 * 2 < v2 * s + t2 * 2)\n Console.WriteLine(\"First\");\n else if (v1 * s + t1 * 2 == v2 * s + t2 * 2)\n Console.WriteLine(\"Friendship\");\n else\n Console.WriteLine(\"Second\");\n }\n }\n}\n", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace DiceRolling\n{\n class Program\n {\n static void Main(string[] args)\n {\n int q = int.Parse(Console.ReadLine());\n int[] a = new int[q];\n for (int i = 0; i < q; i++)\n {\n a[i] = int.Parse(Console.ReadLine()) / 2;\n }\n foreach (int i in a)\n Console.WriteLine(i);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"} {"source_code": "using System;\nclass Program\n {\n public static void Main(string[] args)\n {\n long[] dt;\n //string[] input = Console.In.ReadLine().Split(new char[] { '\\t', ' ', '\\n', '\\r' }, StringSplitOptions.RemoveEmptyEntries);\n {\n dt = new long[3];\n string[] inp = Console.ReadLine().Split(new char[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n dt[0] = long.Parse(inp[0]);\n dt[1] = long.Parse(inp[1]);\n dt[2] = 1L;\n if(dt[1]==4)\n {\n dt[2] += (dt[0] - 1L) * (dt[0] - 2L) * dt[0] * (dt[0] - 3L) * 9L / 24L;\n dt[1]--;\n }\n }\n {\n long temp = dt[0] * dt[0] - dt[0];\n dt[0]--;\n for (long temp2 = 2L, cntr = 2L; cntr <=dt[1];)\n {\n dt[2] += ((temp * temp2 / cntr) / temp2);\n temp *= --dt[0];\n temp2 *= ++cntr;\n }\n }\n Console.WriteLine(dt[2]);\n }\n \n }", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"} {"source_code": "using System;\n\n\nnamespace Olymp\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n int n = Convert.ToInt32(Console.ReadLine());\n if (n == 1) Console.WriteLine(1);\n else if (n == 2) Console.WriteLine(2);\n else\n Console.WriteLine(Numb(n));\n }\n\n static public long Numb(int n)\n {\n long max = n * (n - 1) * (n - 2) / GCD(n, n - 2);\n for (int q = 10; q > 0; q--)\n {\n long t = n * (n - 1) * (n - 2) / GCD(n, n - 2);\n for (long i = n; i > n - 10 && i > 2; i--)\n \n for (long j = i - 1; j > i - 11 && j > 1; j--)\n \n for (long k = j - 1; k > i - 12 && k > 0; k--)\n \n if ((i * j * k) / GCD(i, k) > t)\n t = i * j * k / GCD(i, k);\n \n \n \n if (t > max) max = t;\n } \n return max;\n }\n public static long GCD(long a, long b)\n {\n if (b == 0) return a;\n else return GCD(b, a % b);\n }\n }\n}\n", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\n\npublic class Matrix {\n public int Row, Col;\n private int[] Data;\n public Matrix(int row, int col) {\n this.Row = row;\n this.Col = col;\n this.Data = new int[Row * Col];\n }\n\n public int this[int row, int col] {\n set {\n Data[row * Col + col] = value;\n }\n get {\n return Data[row * Col + col];\n }\n }\n\n static public Matrix UnitMatrix(int n) {\n Matrix matrix = new Matrix(n, n);\n for (int i = 0; i < n; i++) {\n matrix[i, i] = 1;\n }\n return matrix;\n }\n\n static public Matrix operator +(Matrix A, Matrix B) {\n Matrix C = new Matrix(A.Row, A.Col);\n for (int i = 0; i < C.Data.Length; i++) {\n if (A.Data[i] == int.MaxValue || B.Data[i] == int.MaxValue)\n C.Data[i] = int.MaxValue;\n else\n C.Data[i] = A.Data[i] + B.Data[i];\n }\n return C;\n }\n\n static public Matrix operator -(Matrix A, Matrix B) {\n Matrix C = new Matrix(A.Row, A.Col);\n for (int i = 0; i < C.Data.Length; i++) {\n C.Data[i] = A.Data[i] - B.Data[i];\n }\n return C;\n }\n\n static public Matrix operator *(Matrix A, Matrix B) {\n Matrix C = new Matrix(A.Row, B.Col);\n for (int i = 0; i < A.Row; i++) {\n for (int j = 0; j < B.Col; j++) {\n C[i, j] = int.MaxValue;\n for (int k = 0; k < A.Col; k++) {\n //C[i, j] += A[i, k] * B[k, j];\n if (A[i, k] == int.MaxValue || B[k, j] == int.MaxValue) continue;\n C[i, j] = Math.Min(C[i, j], A[i, k] + B[k, j]);\n }\n }\n }\n return C;\n }\n\n static public Matrix Pow(Matrix A, long n) {\n if (n == 0) return UnitMatrix(A.Row);\n Matrix result = A.Clone(), t = A.Clone(); n--;\n while (n > 0) {\n if ((n & 1) != 0) {\n result = result * t;\n }\n\n t = t * t;\n n >>= 1;\n }\n\n return result;\n }\n\n public Matrix Clone() {\n Matrix clone = new Matrix(Row, Col);\n clone.Data = Data.Clone() as int[];\n return clone;\n }\n}\n\npublic partial class CodeForces {\n\n static void UpdateMin(ref T x, T newValue) where T : IComparable {\n if (x.CompareTo(newValue) > 0) x = newValue;\n }\n\n static public void Solve(TextReader cin, TextWriter cout) {\n var scanner = new Scanner(cin);\n int n = scanner.NextInt32();\n int m = scanner.NextInt32();\n var a = scanner.NextIntArray(n);\n var b = scanner.NextIntArray(n);\n int maxDepth = 2 * n + 1;\n var dp = new int[maxDepth, maxDepth];\n for (int i = 0; i < maxDepth; i++) {\n for (int j = 0; j < maxDepth; j++) {\n dp[i, j] = int.MaxValue;\n }\n dp[i, i] = 0;\n }\n for (int i = 0; i < n; i++) {\n var next = new int[maxDepth, maxDepth];\n for (int j = 0; j < maxDepth; j++) {\n for (int k = 0; k < maxDepth; k++) {\n next[j, k] = int.MaxValue;\n }\n }\n for (int j = 0; j < maxDepth; j++) {\n for (int k = 0; k < maxDepth; k++) {\n if (dp[j, k] == int.MaxValue) continue;\n if (k + 1 < maxDepth)\n UpdateMin(ref next[j, k + 1], dp[j, k] + a[i]);\n if (k - 1 >= 0)\n UpdateMin(ref next[j, k - 1], dp[j, k] + b[i]);\n }\n }\n\n dp = next;\n }\n\n /*for (int i = 0; i < maxDepth; i++) {\n for (int j = 0; j < maxDepth; j++) {\n Console.Error.Write(\" \" + dp[i, j]);\n }\n Console.Error.WriteLine();\n }*/\n\n Matrix M = new Matrix(maxDepth, maxDepth);\n\n for (int i = 0; i < maxDepth; i++) {\n for (int j = 0; j < maxDepth; j++) {\n M[i, j] = dp[i, j];\n }\n }\n\n Matrix A = M.Clone();\n\n A = Matrix.Pow(A, m);\n\n cout.WriteLine(A[0, 0]);\n }\n\n // PREWRITEN CODE BEGINS FROM HERE\n\n public static void Main(string[] args) {\n#if ONLINE_JUDGE\n Solve(Console.In, Console.Out);\n#else\n SampleTest();\n#endif\n\n }\n\n static void SampleTest() {\n\n var Inputs = @\"\n2 6\n1 2\n2 1\n------------\n1 10000000\n2\n3\n\".Split(new[] { \"------------\" }, StringSplitOptions.None).Select(s => s.Trim()).ToArray();\n\n var Outputs = @\"\n12\n------------\n25000000\n\".Split(new[] { \"------------\" }, StringSplitOptions.None).Select(s => s.Trim()).ToArray();\n\n int caseNo = 1;\n int all = 0, passed = 0;\n foreach (var sample in Inputs.Zip(Outputs, (Input, Output) => new { Input, Output })) {\n var stopWatch = new System.Diagnostics.Stopwatch();\n var writer = new StringWriter();\n stopWatch.Start();\n Solve(new StringReader(sample.Input), writer);\n stopWatch.Stop();\n string time = \"\";\n if (stopWatch.ElapsedMilliseconds >= 10) {\n time = String.Format(\"({0} ms)\", stopWatch.ElapsedMilliseconds);\n }\n var result = writer.ToString().Trim();\n all++;\n if (result == sample.Output) {\n Console.WriteLine(\"Sample {0} .... Passed {1}\", caseNo++, time);\n passed++;\n } else {\n Console.WriteLine(\"Sample {0} .... Failed\", caseNo++, time);\n Console.WriteLine(\"Input : \");\n Console.WriteLine(\"{0}\", sample.Input);\n Console.WriteLine(\"Expected : \");\n Console.WriteLine(\"{0}\", sample.Output);\n Console.WriteLine(\"Received : \");\n Console.WriteLine(\"{0}\", result);\n }\n }\n\n Console.WriteLine(\" {0} / {1} Passed !!\", passed, all);\n\n Solve(Console.In, Console.Out);\n }\n\n}\n\npublic class Scanner {\n private TextReader Reader;\n private Queue TokenQueue = new Queue();\n private CultureInfo ci = new CultureInfo(\"en-US\");\n\n public Scanner()\n : this(Console.In) {\n }\n\n public Scanner(TextReader reader) {\n this.Reader = reader;\n }\n\n public char NextChar() { return Next().Single(); }\n public int NextInt32() { return Int32.Parse(Next(), ci); }\n public long NextInt64() { return Int64.Parse(Next(), ci); }\n public double NextDouble() { return double.Parse(Next(), ci); }\n public string[] NextArray(int size) {\n var array = new string[size];\n for (int i = 0; i < size; i++) array[i] = Next();\n return array;\n }\n public int[] NextIntArray(int size) {\n var array = new int[size];\n for (int i = 0; i < size; i++) array[i] = NextInt32();\n return array;\n }\n\n public long[] NextInt64Array(int size) {\n var array = new long[size];\n for (int i = 0; i < size; i++) array[i] = NextInt64();\n return array;\n }\n\n public String Next() {\n if (!TokenQueue.Any()) {\n if (!StockTokens()) throw new InvalidOperationException();\n }\n return TokenQueue.Dequeue();\n }\n\n public bool HasNext() {\n if (TokenQueue.Count > 0)\n return true;\n return StockTokens();\n }\n\n private bool StockTokens() {\n while (true) {\n var line = Reader.ReadLine();\n if (line == null) return false;\n var tokens = line.Trim().Split(\" \".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();\n if (tokens.Length == 0) continue;\n foreach (var token in tokens)\n TokenQueue.Enqueue(token);\n return true;\n }\n }\n}\n", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace The_Intriguing_Obsession\n{\n internal class Program\n {\n private const int mod = 998244353;\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n private static readonly long[,] ab = new long[5001,5001];\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args));\n writer.Flush();\n }\n\n private static long Solve(string[] args)\n {\n int a = Next();\n int b = Next();\n int c = Next();\n\n long ans = (CG(a, b)*CG(a, c))%mod;\n ans = (ans*CG(b, c))%mod;\n\n return ans;\n }\n\n private static long CG(int a, int b)\n {\n if (a > b)\n {\n int c = a;\n a = b;\n b = c;\n }\n\n if (a == 1)\n return b + 1;\n\n if (ab[a, b] != 0)\n return ab[a, b];\n\n return ab[a, b] = (CG(a - 1, b) + b*CG(a - 1, b - 1))%mod;\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Threading;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\n\nclass Solver\n{\n public Scanner sc;\n public void Solve()\n {\n int N, K;\n sc.Make(out N, out K);\n var dp = Create(N + 1, () => new ModInt[N + 1]);\n var newdp = Create(N + 1, () => new ModInt[N + 1]);\n dp[1][1] = 2;\n for (int i = 1; i < N; i++)\n {\n for (int j = 1; j < N+1; j++)\n {\n for (int k = 1; k < j+1; k++)\n {\n newdp[j][k] = dp[j][k - 1];\n if (j == k) newdp[j][k] += dp[j - 1][k - 1];\n newdp[j][1] += dp[j][k];\n }\n }\n swap(ref dp, ref newdp);\n }\n var ct = new ModInt[N + 1];\n for (int i = 0; i <= N; i++)\n for (int j = 0; j <= i; j++)\n ct[i] += dp[i][j];\n ModInt res = 0;\n for(int i = 1; i <= Min(K-1,N); i++)\n {\n var seg = new DualSegmentTree(N, 0, (a, b) => a + b);\n seg.Update(0, Min(N, (K - 1) / i), 1);\n for (int j = 0; j < N - 1; j++)\n seg.Update(j + 1, Min(j + 1 + (K - 1) / i,N), seg.Query(j));\n res += seg.Query(N - 1)*ct[i];\n }\n Console.WriteLine(res);\n }\n}\n\npublic struct ModInt\n{\n //public const long MOD = (int)1e9 + 7;\n public const long MOD = 998244353;\n public long Value { get; set; }\n public ModInt(long n = 0) { Value = n; }\n private static ModInt[] fac, inv, facinv;\n public override string ToString() => Value.ToString();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator +(ModInt l, ModInt r)\n {\n l.Value += r.Value;\n if (l.Value >= MOD) l.Value -= MOD;\n return l;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator -(ModInt l, ModInt r)\n {\n l.Value -= r.Value;\n if (l.Value < 0) l.Value += MOD;\n return l;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static implicit operator long(ModInt l) => l.Value;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static implicit operator ModInt(long n)\n {\n n %= MOD; if (n < 0) n += MOD;\n return new ModInt(n);\n }\n\n public static ModInt Pow(ModInt m, long n)\n {\n if (n == 0) return 1;\n if (n % 2 == 0) return Pow(m * m, n >> 1);\n else return Pow(m * m, n >> 1) * m;\n }\n\n public static void Build(int n)\n {\n fac = new ModInt[n + 1];\n facinv = new ModInt[n + 1];\n inv = new ModInt[n + 1];\n inv[1] = fac[0] = fac[1] = facinv[0] = facinv[1] = 1;\n for (var i = 2; i <= n; i++)\n {\n fac[i] = fac[i - 1] * i;\n inv[i] = MOD - inv[MOD % i] * (MOD / i);\n facinv[i] = facinv[i - 1] * inv[i];\n }\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Fac(int n) => fac[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Inv(int n) => inv[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt FacInv(int n) => facinv[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Comb(int n, int r)\n {\n if (n < r) return 0;\n if (n == r) return 1;\n return fac[n] * facinv[r] * facinv[n - r];\n }\n public static ModInt Perm(int n, int r)\n {\n if (n < r) return 0;\n return fac[n] * facinv[n - r];\n }\n\n}\n\npublic class DualSegmentTree\n{\n protected readonly T[] data;\n protected readonly int size;\n protected readonly Func merge;\n protected readonly T idT;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n protected int Parent(int i)\n => (i - 1) >> 1;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n protected int Left(int i)\n => (i << 1) + 1;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n protected int Right(int i)\n => (i + 1) << 1;\n public T this[int i]\n {\n get { return data[i + size - 1]; }\n set { data[i + size - 1] = value; }\n }\n\n public DualSegmentTree(int N, T idT, Func merge)\n {\n this.merge = merge;\n this.size = 1;\n this.idT = idT;\n while (size < N)\n size <<= 1;\n data = new T[2 * this.size - 1];\n for (var i = 0; i < 2 * size - 1; i++)\n data[i] = idT;\n }\n public void Update(int left, int right, T value, int k = 0, int l = 0, int r = -1)\n {\n if (r == -1) r = size;\n if (r <= left || right <= l) return;\n if (left <= l && r <= right) data[k] = merge(data[k], value);\n else\n {\n Update(left, right, value, Left(k), l, (l + r) >> 1);\n Update(left, right, value, Right(k), (l + r) >> 1, r);\n }\n }\n public T Query(int i)\n {\n i += size - 1;\n var value = merge(idT, data[i]);\n while (i > 0)\n {\n i = Parent(i);\n value = merge(value, data[i]);\n }\n return value;\n }\n\n public int Find(int st, Func check)\n {\n var x = idT;\n return Find(st, check, ref x, 0, 0, size);\n }\n private int Find(int st, Func check, ref T x, int k, int l, int r)\n {\n if (l + 1 == r)\n { x = merge(x, data[k]); return check(x) ? k - size + 1 : -1; }\n var m = (l + r) >> 1;\n if (m <= st) return Find(st, check, ref x, Right(k), m, r);\n if (st <= l && !check(merge(x, data[k])))\n { x = merge(x, data[k]); return -1; }\n var xl = Find(st, check, ref x, Left(k), l, m);\n if (xl >= 0) return xl;\n return Find(st, check, ref x, Right(k), m, r);\n }\n}\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n var sol = new Solver() { sc = new Scanner() };\n //var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();\n sol.Solve();\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(this IList A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static void Out(this IList A, out T a) => a = A[0];\n public static void Out(this IList A, out T a, out T b) { a = A[0]; b = A[1]; }\n public static void Out(this IList A, out T a, out T b, out T c) { A.Out(out a, out b); c = A[2]; }\n public static void Out(this IList A, out T a, out T b, out T c, out T d) { A.Out(out a, out b, out c); d = A[3]; }\n public static string Concat(this IEnumerable A, string sp) => string.Join(sp, A);\n public static char ToChar(this int s, char begin = '0') => (char)(s + begin);\n public static IEnumerable Shuffle(this IEnumerable A) => A.OrderBy(v => Guid.NewGuid());\n public static int CompareTo(this T[] A, T[] B, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }\n public static int ArgMax(this IList A, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }\n public static T PopBack(this List A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next(); }\n public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\n\n#endregion", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n public void Solve()\n {\n int n = ReadInt();\n int[] arr = ReadToken().Split(new[] { 'W' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Length).ToArray();\n Write(arr.Length);\n WriteArray(arr);\n\n \n\n }\n\n \n\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"input.txt\");\n //writer = new StreamWriter(\"output.txt\");\n#endif\n try\n {\n new Solver().Solve();\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"source_code": "namespace ContestRuns\n{\n using System;\n using System.Collections.Generic;\n using System.Collections.Specialized;\n using System.IO;\n using System.Linq;\n using System.Globalization;\n using System.Threading;\n using System.Text;\n\n class Program\n {\n\n#if DEBUG\n static readonly TextReader input = File.OpenText(@\"../../A/A.in\");\n static readonly TextWriter output = File.CreateText(@\"../../A/A.out\");\n#else\n static readonly TextReader input = Console.In;\n static readonly TextWriter output = Console.Out;\n#endif\n\n static long dist(long difX, long difY)\n {\n difX = Math.Abs(difX);\n difY = Math.Abs(difY);\n //int shared = Math.Min(difX, difY);\n //int other = Math.Max(difX, difY) - shared;\n return Math.Max(difX, difY);\n }\n\n private static void SolveA()\n {\n long n = long.Parse(input.ReadLine());\n long[] nm = input.ReadLine().Split(' ').Select(long.Parse).ToArray();\n long x = nm[0], y = nm[1];\n\n long d1 = dist(x - 1, y - 1);\n long d2 = dist(x - n, y - n);\n\n if(d1 <= d2)\n {\n output.WriteLine(\"White\");\n return;\n }\n\n output.WriteLine(\"Black\");\n }\n\n static void Main(string[] args)\n {\n Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(\"en-US\");\n SolveA();\n output.Flush();\n }\n }\n}", "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"source_code": "#if DEBUG\nusing System.Reflection;\nusing System.Threading.Tasks;\n#endif\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Numerics;\nusing System.Globalization;\n\n\nnamespace _245b\n{\n class Program\n {\n static string _inputFilename = \"input.txt\";\n static string _outputFilename = \"output.txt\";\n static bool _useFileInput = false;\n\n\n static void Main(string[] args)\n {\n StreamWriter file = null;\n#if DEBUG\n\t\t\tConsole.SetIn(getInput());\n#else\n if (_useFileInput)\n {\n Console.SetIn(File.OpenText(_inputFilename));\n file = new StreamWriter(_outputFilename);\n Console.SetOut(file);\n }\n#endif\n\n try\n {\n solution();\n }\n finally\n {\n if (_useFileInput)\n {\n file.Close();\n }\n }\n }\n\n static void solution()\n {\n #region SOLUTION\n var d = readIntArray();\n var n = d[0];\n var k = d[1];\n var x = d[2];\n var c = readIntArray();\n var res = 0;\n for (int i = 0; i < n + 1; i++)\n {\n var li = -1;\n var ri = -1; \n var left = 0;\n var right = 0;\n var gl = true;\n var gr = true;\n var lc = -1;\n var rc = -1;\n\n if (i == 0 && c[i] == x)\n {\n gl = false;\n gr = true;\n right = 1;\n left = 0;\n li = -1;\n lc = -1;\n rc = x;\n ri = i;\n }\n else if (i == n && c[n - 1] == x)\n {\n gl = true;\n gr = false;\n right = 0;\n left = 1;\n li = n - 1;\n lc = x;\n rc = -1;\n ri = n;\n }\n else if (i > 0 && c[i - 1] == x)\n {\n right = 0;\n left = 1;\n li = i - 1;\n lc = x;\n rc = c[i];\n ri = i;\n gr = true;\n gl = true;\n }\n else\n {\n continue;\n }\n\n var ls = 0;\n while (true)\n {\n if (!gl && !gr)\n {\n break;\n }\n\n if (gl)\n {\n for (; li >= 0; li--)\n {\n var next = c[li];\n if (next != lc)\n {\n break;\n }\n\n left++;\n }\n }\n\n if (gr)\n {\n for (; ri < n; ri++)\n {\n var next = c[ri];\n if (next != rc)\n {\n break;\n }\n\n right++;\n }\n }\n\n if (lc == rc)\n {\n var sum = right + left;\n if (sum >= 3)\n {\n ls += sum;\n left = 0;\n right = 0;\n if (li >= 0)\n {\n lc = c[li];\n gl = true;\n }\n else\n {\n gl = false;\n lc = -1;\n }\n\n if (ri <= n - 1)\n {\n rc = c[ri];\n gr = true;\n }\n else\n {\n gr = false;\n rc = -1;\n }\n }\n else\n {\n break;\n }\n }\n else\n {\n if (left >= 3)\n {\n ls += left;\n if (li >= 0)\n {\n lc = c[li];\n gl = true;\n }\n else\n {\n gl = false;\n lc = -1;\n }\n\n left = 0;\n }\n else\n {\n gl = false;\n }\n\n if (right >= 3)\n {\n ls += right;\n if (ri <= n - 1)\n {\n rc = c[ri];\n gr = true;\n }\n else\n {\n gr = false;\n rc = -1;\n }\n\n right = 0;\n }\n else\n {\n gr = false;\n }\n }\n }\n\n if (ls > res)\n {\n res = ls;\n }\n }\n\n Console.WriteLine(Math.Max(res - 1, 0));\n\n //var n = readInt();\n //var m = readInt();\n\n //var a = readIntArray();\n //var b = readIntArray();\n #endregion\n }\n\n static int readInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long readLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int[] readIntArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n }\n\n static long[] readLongArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n }\n\n#if DEBUG\n\t\tstatic StreamReader getInput()\n\t\t{\n\t\t\tvar resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n\t\t\tvar resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);\n\n\t\t\treturn new StreamReader(resource);\n\t\t}\n#endif\n }\n}\n", "src_uid": "d73d9610e3800817a3109314b1e6f88c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Diagnostics;\n\nclass Solver\n{\n\tclass Node\n\t{\n\t\tpublic char[,] board = new char[8, 8];\n\t\t\n\t\tpublic Node()\n\t\t{\n\t\t}\n\n\t\tpublic int mx;\n\t\tpublic int my;\n\t\tpublic int s;\n\n\t\tpublic Node Move(int x, int y)\n\t\t{\n\t\t\tif (x < 0 || x >= 8 || y < 0 || y >= 8)\n\t\t\t\treturn null;\t//\t盤外\n\n\t\t\tif (board[x, y] == 'S')\n\t\t\t\treturn null;\t//\tSあり\n\n\n\t\t\tvar next = new Node();\n\t\t\tnext.board = new char[8,8];\n\t\t\tfor (int xx = 0; xx < 8; xx++)\n\t\t\t{\n\t\t\t\tfor (int yy = 6; yy >= 0; yy--)\n\t\t\t\t{\n\t\t\t\t\tif (this.board[xx, yy] == 'S')\n\t\t\t\t\t{\n\t\t\t\t\t\t//\t落下\n\n\t\t\t\t\t\tif (xx == x && yy + 1 == y)\n\t\t\t\t\t\t\treturn null;\t//\t接触\n\n\t\t\t\t\t\tnext.board[xx, yy + 1] = 'S';\n\t\t\t\t\t\tnext.s++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tnext.mx = x;\n\t\t\tnext.my = y;\n\n\t\t\treturn next;\n\t\t}\n\t}\n\n\tpublic void Solve()\n\t{\n\t\tvar list = new List();\n\t\tvar s = new Node();\n\t\tfor (int y = 0; y < 8; y++)\n\t\t{\n\t\t\tvar ss = CF.ReadLine();\n\t\t\tfor (int x = 0; x < 8; x++)\n\t\t\t{\n\t\t\t\ts.board[x, y] = ss[x];\n\t\t\t\tif (ss[x] == 'S')\n\t\t\t\t\ts.s++;\n\t\t\t}\n\t\t}\n\t\ts.my = 7;\n\t\ts.mx = 0;\n\t\tlist.Add(s);\n\n\t\tfor (; ; )\n\t\t{\n\t\t\tif (list.Count == 0)\n\t\t\t{\n\t\t\t\tCF.WriteLine(\"LOSE\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar list2 = new List();\n\t\t\n\t\t\tforeach(var n in list)\n\t\t\t{\n\t\t\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\t\t{\n\t\t\t\t\tfor (int dy = -1; dy <= 1; dy++)\n\t\t\t\t\t{\n\t\t\t\t\t\tvar next = n.Move(n.mx + dx, n.my + dy);\n\t\t\t\t\t\tif (next == null)\n\t\t\t\t\t\t\tcontinue;\t//\t移動不可\n\n\t\t\t\t\t\tif ( \n\t\t\t\t\t\t\tnext.s == 0 || \n\t\t\t\t\t\t\t(next.mx==7&&next.my==0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tCF.WriteLine(\"WIN\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlist2.Add(next);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlist = list2;\n\t\t}\n }\n\n\n\n\t// test\n\tstatic Utils CF = new Utils(new[]{\n@\"\n.......A\n........\n........\n........\n........\n........\n........\nM.......\n\",\n @\"\n.......A\n........\n........\n........\n........\n........\nSS......\nM.......\n\",\n @\"\n.......A\n........\n........\n........\n........\n.S......\nS.......\nMS......\n\"\n\n });\n #region test\n\n static void Main(string[] args)\n {\n#if DEBUG\n for (int t=0;t();\n string[] ss = _test_input[t].Replace(\"\\n\", \"\").Split('\\r');\n for (int i = 0; i < ss.Length; i++)\n {\n if (\n (i == 0 || i == ss.Length - 1) &&\n ss[i].Length == 0\n )\n continue;\n\n _lines.Add(ss[i]);\n }\n }\n\n public int TestCount\n {\n get\n {\n return _test_input.Length;\n }\n }\n\n public string ReadLine()\n {\n#if DEBUG\n string s = null;\n if (_lines.Count > 0)\n {\n s = _lines[0];\n _lines.RemoveAt(0);\n }\n return s;\n\n#else\n //return _sr.ReadLine();\n return Console.In.ReadLine();\n#endif\n }\n\n public void WriteLine(object o)\n {\n#if DEBUG\n System.Diagnostics.Trace.WriteLine(o);\n#else\n //_sw.WriteLine(o);\n Console.WriteLine(o);\n#endif\n }\n\n public void Write(object o)\n {\n#if DEBUG\n System.Diagnostics.Trace.Write(o);\n#else\n //_sw.Write(o);\n Console.Write(o);\n#endif\n }\n\n string[] _test_input;\n\n List _lines;\n\n#if DEBUG\n public Utils(string[] test_input)\n {\n _test_input = test_input;\n }\n#else\n\n public Utils(string[] dummy)\n {\n //_sr = new System.IO.StreamReader(\"input.txt\");\n //_sw = new System.IO.StreamWriter(\"output.txt\");\n }\n#endif\n\n }\n\n #endregion\n}\n\n", "src_uid": "f47e4ab041288ba9567c19930eb9a090"} {"source_code": "using System;\nusing System.Text;\nusing System.Collections.Generic;\nusing System.Collections;\nusing System.Linq;\nclass Problem\n{\n static void Main()\n {\n //--------------------------------input--------------------------------//\n\n var str = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );\n int n = str[0], h = str[1], m = str[2];\n var l = new int[m];\n var r = new int[m];\n var x = new int[m];\n for(int i = 0 ; i < m ; i++)\n {\n str = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );\n l[i] = str[0];\n r[i] = str[1];\n x[i] = str[2];\n }\n\n //--------------------------------solve--------------------------------//\n\n var houses = new int[n];\n for(int i = 0 ; i < n ; i++)\n houses[i] = h;\n for(int i = 0 ; i < m ; i++)\n for(int j = l[i]-1 ; j <= r[i]-1 ; j++)\n houses[j] = Math.Min(x[i],houses[j]);\n var kq = houses.Select( t => t * t ).ToList();\n Console.WriteLine( kq.Sum() );\n }\n}", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad"} {"source_code": "using System;\n\nnamespace Codeforses\n{\n class Program\n {\n static void Main(string[] args)\n {\n string _numberToCheck = Console.ReadLine();\n\n int result;\n Int32.TryParse(_numberToCheck, out result);\n\n bool isWork = true;\n do\n {\n string localResult = result.ToString();\n char[] symbols = localResult.ToCharArray();\n\n int sum = 0;\n foreach(var ch in symbols)\n {\n sum += Int32.Parse(ch.ToString());\n }\n\n if(sum % 4 == 0)\n {\n isWork = false;\n Console.WriteLine(result);\n }\n else\n {\n result++;\n }\n }\n while (isWork);\n }\n }\n}\n", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Threading;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Diagnostics;\nusing static util;\nusing P = pair;\n\nclass Program {\n static void Main(string[] args) {\n var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };\n var solver = new Solver(sw);\n // var t = new Thread(solver.solve, 1 << 26); // 64 MB\n // t.Start();\n // t.Join();\n solver.solve();\n sw.Flush();\n }\n}\n\nclass Solver {\n StreamWriter sw;\n Scan sc;\n void Prt(string a) => sw.WriteLine(a);\n void Prt(IEnumerable a) => Prt(string.Join(\" \", a));\n void Prt(params object[] a) => Prt(string.Join(\" \", a));\n public Solver(StreamWriter sw) {\n this.sw = sw;\n this.sc = new Scan();\n }\n\n public void solve() {\n int n, k;\n sc.Multi(out n, out k);\n long ans = 0;\n MyMath.setfacts(n + 1);\n for (int i = 1; i <= n; i++)\n {\n int c = n / i;\n if (c >= k) {\n ans += MyMath.comb(c - 1, k - 1);\n }\n else break;\n }\n Prt(ans % M);\n }\n}\n\nclass pair : IComparable> {\n public T v1;\n public U v2;\n public pair() : this(default(T), default(U)) {}\n public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; }\n public int CompareTo(pair a) {\n int c = Comparer.Default.Compare(v1, a.v1);\n return c != 0 ? c : Comparer.Default.Compare(v2, a.v2);\n }\n public override string ToString() => v1 + \" \" + v2;\n public void Deconstruct(out T a, out U b) { a = v1; b = v2; }\n}\nstatic class util {\n // public static readonly int M = 1000000007;\n public static readonly int M = 998244353;\n public static readonly long LM = 1L << 60;\n public static readonly double eps = 1e-11;\n public static void DBG(string a) => Console.Error.WriteLine(a);\n public static void DBG(IEnumerable a) => DBG(string.Join(\" \", a));\n public static void DBG(params object[] a) => DBG(string.Join(\" \", a));\n public static void Assert(params bool[] conds) {\n if (conds.Any(x => !x)) throw new Exception();\n }\n public static pair make_pair(T v1, U v2) => new pair(v1, v2);\n public static int CompareList(IList a, IList b) where T : IComparable {\n for (int i = 0; i < a.Count && i < b.Count; i++)\n if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]);\n return a.Count.CompareTo(b.Count);\n }\n public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;\n static readonly int[] dd = { 0, 1, 0, -1 };\n // static readonly string dstring = \"RDLU\";\n public static P[] adjacents(int i, int j)\n => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1])).ToArray();\n public static P[] adjacents(int i, int j, int h, int w)\n => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1]))\n .Where(p => inside(p.v1, p.v2, h, w)).ToArray();\n public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);\n public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w);\n public static Dictionary compress(this IEnumerable a)\n => a.Distinct().OrderBy(v => v).Select((v, i) => new { v, i }).ToDictionary(p => p.v, p => p.i);\n public static Dictionary compress(params IEnumerable[] a) => compress(a.Aggregate(Enumerable.Union));\n public static T[] inv(this Dictionary dic) {\n var res = new T[dic.Count];\n foreach (var item in dic) res[item.Value] = item.Key;\n return res;\n }\n public static void swap(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; }\n public static void swap(this IList a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; }\n public static T[] copy(this IList a) {\n var ret = new T[a.Count];\n for (int i = 0; i < a.Count; i++) ret[i] = a[i];\n return ret;\n }\n public static void Deconstruct(this IList v, out T a) {\n a = v[0];\n }\n public static void Deconstruct(this IList v, out T a, out T b) {\n a = v[0]; b = v[1];\n }\n public static void Deconstruct(this IList v, out T a, out T b, out T c) {\n a = v[0]; b = v[1]; c = v[2];\n }\n public static void Deconstruct(this IList v, out T a, out T b, out T c, out T d) {\n a = v[0]; b = v[1]; c = v[2]; d = v[3];\n }\n public static void Deconstruct(this IList v, out T a, out T b, out T c, out T d, out T e) {\n a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4];\n }\n}\n\nclass Scan {\n StreamReader sr;\n public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }\n public Scan(string path) { sr = new StreamReader(path); }\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public string Str => sr.ReadLine().Trim();\n public pair Pair() {\n T a; U b;\n Multi(out a, out b);\n return new pair(a, b);\n }\n public P P => Pair();\n public int[] IntArr => StrArr.Select(int.Parse).ToArray();\n public long[] LongArr => StrArr.Select(long.Parse).ToArray();\n public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();\n public string[] StrArr => Str.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);\n bool eq() => typeof(T).Equals(typeof(U));\n T ct(U a) => (T)Convert.ChangeType(a, typeof(T));\n T cv(string s) => eq() ? ct(int.Parse(s))\n : eq() ? ct(long.Parse(s))\n : eq() ? ct(double.Parse(s))\n : eq() ? ct(s[0])\n : ct(s);\n public void Multi(out T a) => a = cv(Str);\n public void Multi(out T a, out U b) {\n var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]);\n }\n public void Multi(out T a, out U b, out V c) {\n var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]);\n }\n public void Multi(out T a, out U b, out V c, out W d) {\n var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]);\n }\n public void Multi(out T a, out U b, out V c, out W d, out X e) {\n var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); e = cv(ar[4]);\n }\n}\n\nstatic class MyMath {\n public static long Mod = util.M;\n // public static long Mod = 1000000007;\n public static bool isprime(long a) {\n if (a < 2) return false;\n for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;\n return true;\n }\n public static bool[] sieve(int n) {\n var p = new bool[n + 1];\n for (int i = 2; i <= n; i++) p[i] = true;\n for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;\n return p;\n }\n public static int[] sieve2(int n) {\n var p = new int[n + 1];\n for (int i = 2; i <= n; i++) p[i] = i;\n for (int i = 2; i * i <= n; i++) {\n if (p[i] == i)\n for (int j = i * i; j <= n; j += i)\n p[j] = Math.Min(p[j], i);\n }\n return p;\n }\n public static bool[] segmentSieve(long l, long r) {\n int sqn = (int)Math.Sqrt(r + 9);\n var ps = getprimes(sqn);\n return segmentSieve(l, r,ps);\n }\n public static bool[] segmentSieve(long l, long r, List ps) {\n var sieve = new bool[r - l + 1];\n for (long i = l; i <= r; i++) sieve[i - l] = true;\n foreach (long p in ps) {\n if (p * p > r) break;\n for (long i = p >= l ? p * p : (l + p - 1) / p * p; i <= r; i += p) sieve[i - l] = false;\n }\n return sieve;\n }\n public static List getprimes(int n) {\n var prs = new List();\n var p = sieve(n);\n for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);\n return prs;\n }\n public static long pow(long a, long b, long mod) {\n a %= mod;\n if (b < 0) Console.Error.WriteLine($\"power number is negative ({a}^{b}).\");\n if (b <= 0) return 1;\n var t = pow(a, b / 2, mod);\n if ((b & 1) == 0) return t * t % mod;\n return t * t % mod * a % mod;\n }\n public static long pow(long a, long b) => pow(a, b, Mod);\n public static long inv(long a) => pow(a, Mod - 2);\n public static long gcd(long a, long b) {\n while (b > 0) {\n var t = a % b;\n a = b;\n b = t;\n }\n return a;\n }\n // a x + b y = gcd(a, b)\n public static long extgcd(long a, long b, out long x, out long y) {\n long g = a; x = 1; y = 0;\n if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }\n return g;\n }\n\n // return (r, m): x = r (mod. m)\n // return (0, -1) if no answer\n public static pair chineserem(IList b, IList m) {\n long r = 0, M = 1;\n for (int i = 0; i < b.Count; ++i) {\n long p, q;\n long d = extgcd(M, m[i], out p, out q); // p is inv of M/d (mod. m[i]/d)\n if ((b[i] - r) % d != 0) return new pair(0, -1);\n long tmp = (b[i] - r) / d * p % (m[i]/d);\n r += M * tmp;\n M *= m[i]/d;\n }\n return new pair((r % M + M) % M, M);\n }\n\n // return k: x^k = y (mod. mod) O(sqrt(mod))\n public static long modlog(long x, long y, long mod) {\n if (y == 1) return 0;\n long H = (long)Math.Sqrt(mod) + 1;\n var baby = new Dictionary();\n for (long b = 0, xby = y; b < H; b++, xby = (xby * x) % mod) {\n if (!baby.ContainsKey(xby))\n baby.Add(xby, b);\n else\n baby[xby] = b;\n }\n\n long xH = 1;\n for (int i = 0; i < H; ++i) xH = xH * x % mod;\n for (long a = 1, xaH = xH; a <= H; a++, xaH = (xaH * xH) % mod)\n if (baby.ContainsKey(xaH))\n return a * H - baby[xaH];\n\n return -1;\n }\n public static long lcm(long a, long b) => a / gcd(a, b) * b;\n\n static long[] facts, invs;\n public static void setfacts(int n) {\n facts = new long[n + 1];\n facts[0] = 1;\n for (int i = 1; i <= n; i++) facts[i] = facts[i - 1] * i % Mod;\n invs = new long[n + 1];\n invs[n] = inv(facts[n]);\n for (int i = n; i > 0 ; i--) invs[i - 1] = invs[i] * i % Mod;\n }\n public static long fact(long n) {\n if (n < 0) return 0;\n if (facts != null && facts.Length > n) return facts[n];\n long numer = 1;\n for (long i = 1; i <= n; i++) numer = numer * (i % Mod) % Mod;\n return numer;\n }\n public static long perm(long n, long r) {\n if (n < 0 || r < 0 || r > n) return 0;\n if (facts != null && facts.Length > n) return facts[n] * invs[n - r] % Mod;\n long numer = 1;\n for (long i = 0; i < r; i++) numer = numer * ((n - i) % Mod) % Mod;\n return numer;\n }\n public static long comb(long n, long r) {\n if (n < 0 || r < 0 || r > n) return 0;\n if (facts != null && facts.Length > n) return facts[n] * invs[r] % Mod * invs[n - r] % Mod;\n if (n - r < r) r = n - r;\n long numer = 1, denom = 1;\n for (long i = 0; i < r; i++) {\n numer = numer * ((n - i) % Mod) % Mod;\n denom = denom * ((i + 1) % Mod) % Mod;\n }\n return numer * inv(denom) % Mod;\n }\n public static long multi_choose(long n, long r) => comb(n + r - 1, r);\n public static long[][] getcombs(int n) {\n var ret = new long[n + 1][];\n for (int i = 0; i <= n; i++) {\n ret[i] = new long[i + 1];\n ret[i][0] = ret[i][i] = 1;\n for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;\n }\n return ret;\n }\n // nC0, nC2, ..., nCn\n public static long[] getcomb(int n) {\n var ret = new long[n + 1];\n ret[0] = 1;\n for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;\n return ret;\n }\n\n public static class ModMatrix {\n public static long[][] E(int n) {\n var ret = new long[n][];\n for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }\n return ret;\n }\n public static long[][] pow(long[][] A, long n) {\n if (n == 0) return E(A.Length);\n var t = pow(A, n / 2);\n if ((n & 1) == 0) return mul(t, t);\n return mul(mul(t, t), A);\n }\n public static long dot(long[] x, long[] y) {\n int n = x.Length;\n long ret = 0;\n for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;\n return ret;\n }\n public static long[][] trans(long[][] A) {\n int n = A[0].Length, m = A.Length;\n var ret = new long[n][];\n for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }\n return ret;\n }\n public static long[] mul(long a, long[] x) {\n int n = x.Length;\n var ret = new long[n];\n for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;\n return ret;\n }\n public static long[] mul(long[][] A, long[] x) {\n int n = A.Length;\n var ret = new long[n];\n for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);\n return ret;\n }\n public static long[][] mul(long a, long[][] A) {\n int n = A.Length;\n var ret = new long[n][];\n for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);\n return ret;\n }\n public static long[][] mul(long[][] A, long[][] B) {\n int n = A.Length;\n var Bt = trans(B);\n var ret = new long[n][];\n for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);\n return ret;\n }\n }\n}\n", "src_uid": "8e8eb64a047cb970a549ee870c3d280d"} {"source_code": "using System;\n\nnamespace CSharp\n{\n public class _979A\n {\n public static void Main()\n {\n long n = long.Parse(Console.ReadLine()) + 1;\n Console.WriteLine(n % 2 == 0 ? n / 2 : n == 1 ? 0 : n);\n }\n }\n}", "src_uid": "236177ff30dafe68295b5d33dc501828"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CFTraining.D_s\n{\n class Polyline340\n {\n public static void Main(string[] args)\n {\n Console.WriteLine(Solve());\n }\n\n public static int Solve()\n {\n List p = new List();\n for (int i = 0; i < 3; i++)\n {\n string[] line = Console.ReadLine().Split(' ');\n p.Add(new Point { x = Convert.ToInt32(line[0]), y = Convert.ToInt32(line[1]) });\n }\n\n if (p[0].LieInSameLine(p[1]) != 0 && p[0].LieInSameLine(p[1]) == p[0].LieInSameLine(p[2])) return 1;\n int s1 = p[0].LieInSameLine(p[1]), s2 = p[0].LieInSameLine(p[2]), s3 = p[1].LieInSameLine(p[2]);\n if (s1 > 0)\n {\n if (s1 == 1)\n {\n int min = Math.Min(p[0].y, p[1].y);\n int max = Math.Max(p[0].y, p[1].y);\n if (p[2].y <= min || p[2].y >= max)\n {\n return 2;\n }\n }\n if (s1 == 2)\n {\n int min = Math.Min(p[0].x, p[1].x);\n int max = Math.Max(p[0].x, p[1].x);\n if (p[2].x <= min || p[2].x >= max)\n {\n return 2;\n }\n }\n }\n else if (s2 > 0)\n {\n if (s2 == 1)\n {\n int min = Math.Min(p[0].y, p[2].y);\n int max = Math.Max(p[0].y, p[2].y);\n if (p[1].y <= min || p[1].y >= max)\n {\n return 2;\n }\n }\n if (s2 == 2)\n {\n int min = Math.Min(p[0].x, p[2].x);\n int max = Math.Max(p[0].x, p[2].x);\n if (p[1].x <= min || p[1].x >= max)\n {\n return 2;\n }\n }\n }\n else if (s3 > 0)\n {\n if (s3 == 1)\n {\n int min = Math.Min(p[1].y, p[2].y);\n int max = Math.Max(p[1].y, p[2].y);\n if (p[0].y <= min || p[0].y >= max)\n {\n return 2;\n }\n }\n if (s3 == 2)\n {\n int min = Math.Min(p[1].x, p[2].x);\n int max = Math.Max(p[1].x, p[2].x);\n if (p[0].x <= min || p[0].x >= max)\n {\n return 2;\n }\n }\n }\n return 3;\n }\n }\n\n class Point\n {\n public int x, y;\n public int LieInSameLine(Point p)\n {\n if (x == p.x) return 1;\n else if (y == p.y) return 2;\n else return 0;\n }\n }\n}\n", "src_uid": "36fe960550e59b046202b5811343590d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace Two_gram\n{\n class Program\n {\n static void Main(string[] args)\n {\n int size = int.Parse(Console.ReadLine());\n string letter = Console.ReadLine();\n Dictionary dict = new Dictionary();\n string temp;\n\n for (int i = 1; i < letter.Length; i++)\n {\n temp = letter[i - 1].ToString() + letter[i].ToString();\n if (dict.ContainsKey(temp)) dict[temp]++;\n else dict.Add(temp, 1);\n }\n Console.WriteLine(dict.FirstOrDefault(x=>x.Value==dict.Values.Max()).Key);\n }\n }\n}", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"source_code": "using System;\n\nnamespace CodeFirstSimple\n{\n class Program\n {\n static void Main()\n {\n var n = int.Parse(Console.ReadLine());\n var s = Console.ReadLine();\n var res = \"\";\n for (int i = 0, j = 0; i < n; j++, i += j)\n res += s[i];\n\n Console.WriteLine(res);\n }\n }\n}", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Vitaly_and_Strings\n{\n class Program\n {\n static void Main(string[] args)\n {\n IO io = new IO();\n string str_S = io.ReadStr();\n string str_T = io.ReadStr();\n int[] i_S = new int[str_S.Length];\n int[] i_T = new int[str_T.Length];\n\n for (int i = 0; i < str_S.Length; i++)\n {\n i_S[i] = str_S[i] - 'a';\n i_T[i] = str_T[i] - 'a';\n }\n for (int i = str_S.Length-1; i >= 0; i--)\n {\n if (i_S[i] != 25)\n {\n i_S[i]++; break;\n }\n else\n {\n i_S[i] = 0;\n }\n }\n\n if (IO.Arr_Equal(i_S, i_T))\n {\n io.PutStr(\"No such string\");\n }\n else\n {\n for (int i = 0; i < str_S.Length; i++)\n {\n Console.Write(IO.Chr(i_S[i]+'a'));\n }\n }\n\n\n io.ReadStr();\n }\n }\n\n\n class IO\n {\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine()\n {\n return Console.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n public int ReadNextInt()\n {\n return int.Parse(ReadToken());\n }\n public long ReadNextLong()\n {\n return long.Parse(ReadToken());\n }\n\n public int ReadInt()\n {\n return Convert.ToInt32(Console.ReadLine());\n }\n public long ReadLong()\n {\n return Convert.ToInt64(Console.ReadLine());\n }\n public string ReadStr()\n {\n return Console.ReadLine();\n }\n public string[] ReadStrArr()\n {\n return Console.ReadLine().Split(' ');\n }\n public int[] ReadIntArr()\n {\n return Array.ConvertAll(Console.ReadLine().Split(' '), s => int.Parse(s));\n }\n public long[] ReadLongArr()\n {\n return Array.ConvertAll(Console.ReadLine().Split(' '), s => long.Parse(s));\n }\n public void PutStr(string str)\n {\n Console.WriteLine(str);\n }\n public void PutStr(int str)\n {\n Console.WriteLine(str);\n }\n public void PutStr(long str)\n {\n Console.WriteLine(str);\n }\n public void PutStr(double str)\n {\n Console.WriteLine(str);\n }\n\n public static int Asc(char c_C)\n {\n System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();\n int intAsciiCode = (int)asciiEncoding.GetBytes(c_C.ToString())[0];\n return (intAsciiCode);\n }\n\n public static char Chr(int asciiCode)\n {\n if (asciiCode >= 0 && asciiCode <= 255)\n {\n System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();\n byte[] byteArray = new byte[] { (byte)asciiCode };\n char c_Character = asciiEncoding.GetString(byteArray)[0];\n return (c_Character);\n }\n else\n {\n throw new Exception(\"ASCII Code is not valid.\");\n }\n }\n\n public static bool Arr_Equal(int[] array1, int[] array2)\n {\n\n if (array1.Length != array2.Length)\n\n return false;\n\n for (int i = 0; i < array1.Length; i++)\n\n if (array1[i] != array2[i])\n\n return false;\n\n return true;\n\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n }\n}\n", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\n\nnamespace Codeforce\n{\n\n class Program\n {\n static int[] parseInt(string s)\n {\n string[] temp = s.Split(' ');\n int[] res = new int[temp.Length];\n for (int i = 0; i < temp.Length; i++)\n {\n res[i] = Convert.ToInt32(temp[i]);\n }\n return res;\n }\n\n\n static double Dist(double x1, double y1, double x2, double y2)\n {\n return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));\n }\n struct Point\n {\n public double x { get; set; }\n public double y { get; set; }\n\n public Point(double _x, double _y)\n : this()\n {\n x = _x;\n y = _y;\n }\n public double DistTo(Point p2)\n {\n return Dist(x, y, p2.x, p2.y);\n }\n }\n\n\n\n static void Main(string[] args)\n {\n\n var data = parseInt(Console.ReadLine());\n\n Point cur = new Point(0, 0);\n Point next = new Point(0, 0);\n int dirX = 1, dirY = 0;\n for (int i = 1; i < 10000; i++)\n {\n next = new Point(cur.x + dirX * ((i + 1) / 2), cur.y + dirY * ((i + 1) / 2));\n double totalDist = cur.DistTo(next);\n double aDist = Dist((double)data[0], (double)data[1], cur.x, cur.y);\n double bDist = Dist((double)data[0], (double)data[1], next.x, next.y);\n\n if (totalDist - (aDist + bDist) < 0.000001 && totalDist - (aDist + bDist) >= 0)\n {\n Console.WriteLine(i - 1);\n return;\n }\n\n if (dirX > 0)\n {\n dirX = 0;\n dirY = 1;\n }\n else\n if (dirX < 0)\n {\n dirX = 0;\n dirY = -1;\n }\n else\n if (dirY > 0)\n {\n dirX = -1;\n dirY = 0;\n }\n else\n if (dirY < 0)\n {\n dirX = 1;\n dirY = 0;\n }\n cur = next;\n }\n }\n }\n}", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace _39h\n{\n class Program\n {\n\n static string ToPos(Int32 k, Int32 pos)\n {\n string result = \"\";\n while (k > 0)\n {\n result = (k % pos).ToString() + result;\n k = k / pos;\n }\n return result;\n }\n\n\n static void PrintMatr(Int32[,] arr, Int32 pos)\n {\n if (pos == 10)\n {\n for (int i = 0; i < 9; i++)\n {\n for (int j = 0; j < 9; j++)\n {\n Console.Write(arr[i, j].ToString()+\" \");\n }\n Console.WriteLine();\n }\n }\n else\n {\n for (int i = 0; i < pos-1; i++)\n {\n for (int j = 0; j < pos-1; j++)\n {\n Console.Write(ToPos(arr[i, j], pos)+ \" \");\n }\n Console.WriteLine();\n }\n }\n }\n static void Main(string[] args)\n {\n Int32 pos = 0;\n pos = Convert.ToInt32(Console.ReadLine());\n Int32[,] arr = new Int32[9, 9];\n for(int i = 1;i<10;i++)\n for (int j = 1; j < 10; j++)\n {\n arr[i-1, j-1] = i * j;\n }\n PrintMatr(arr, pos);\n //Console.ReadLine();\n //\n }\n }\n}\n", "src_uid": "a705144ace798d6b41068aa284d99050"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n const int MOD = 1000000007;\n\n public void Solve()\n {\n int p = ReadInt();\n int k = ReadInt();\n\n long ans = 1;\n var f = new bool[p];\n for (int i = 1; i < p; i++)\n if (!f[i])\n {\n ans = ans * p % MOD;\n int x = i;\n while (!f[x])\n {\n f[x] = true;\n x = (int)(1L * x * k % p);\n }\n }\n if (k == 1)\n ans = ans * p % MOD;\n\n Write(ans);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"atoms.in\");\n //writer = new StreamWriter(\"atoms.out\");\n#endif\n try\n {\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n new Solver().Solve();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e"} {"source_code": "using System;\n\nnamespace codeforcing\n{\n class Program\n {\n static void Main(string[] args)\n {\n //INPUT PHASE\n string[] tokens = Console.ReadLine().Split();\n int s = int.Parse(tokens[0]);\n int x1 = int.Parse(tokens[1]);\n int x2 = int.Parse(tokens[2]);\n\n tokens = Console.ReadLine().Split();\n\n int t1 = int.Parse(tokens[0]);\n int t2 = int.Parse(tokens[1]);\n\n tokens = Console.ReadLine().Split();\n\n int p = int.Parse(tokens[0]);\n int d = int.Parse(tokens[1]);\n\n\n int distanceWithTram = 0;\n if(p < x2 && x2 < x1)\n {\n //Console.WriteLine(\"am here 1\");\n if (d == 1)\n {\n distanceWithTram += s - p;\n \n \n }\n else\n {\n distanceWithTram += p;\n distanceWithTram += s;\n \n }\n\n distanceWithTram += s - x2;\n }\n else if(x1 < x2 && x2 < p)\n {\n //Console.WriteLine(\"am here 2\");\n if (d == 1)\n {\n distanceWithTram += s - p;\n distanceWithTram += s;\n distanceWithTram += x2;\n\n }\n else\n {\n distanceWithTram += p;\n distanceWithTram += x2;\n\n }\n \n }\n else if(p <= x1 && x1 < x2)\n {\n //Console.WriteLine(\"am here 3\");\n if (d == 1)\n {\n distanceWithTram += x2 - p;\n }\n\n else\n {\n distanceWithTram += p;\n distanceWithTram += x2;\n }\n }\n else if (x2 < x1 && x1 <= p)\n {\n // Console.WriteLine(\"am here 4\");\n if (d == 1)\n {\n distanceWithTram += s - p;\n distanceWithTram += s - x2;\n }\n\n else\n {\n distanceWithTram += p - x2;\n }\n }\n else if(x1<= p && p< x2)\n {\n //Console.WriteLine(\"am here 5\");\n if (d == 1)\n {\n distanceWithTram += s - p;\n distanceWithTram += s;\n distanceWithTram += x2;\n }\n\n else\n {\n distanceWithTram += p;\n distanceWithTram += x2;\n\n }\n }\n else if (x2 < p && p <= x1)\n {\n // Console.WriteLine(\"am here 6\"); \n if (d == 1)\n {\n \n distanceWithTram += s - p;\n distanceWithTram += s;\n distanceWithTram += x2;\n }\n\n else\n {\n distanceWithTram += p;\n distanceWithTram += s;\n distanceWithTram += s - x2;\n\n }\n }\n\n \n int timeWithNoTram = Math.Abs(x1 - x2) * t2;\n int timeWithTram = distanceWithTram * t1;\n\n Console.WriteLine((timeWithNoTram < timeWithTram ? timeWithNoTram : timeWithTram));\n\n\n\n\n }\n }\n}\n", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace CF\n{\n internal class Program\n {\n private static void Main(string[] args)\n {\n using (var sr = new InputReader(Console.In))\n//\t\t\tusing (var sr = new InputReader(new StreamReader(\"input.txt\")))\n using (var sw = Console.Out)\n //using (var sw = new StreamWriter(\"output.txt\"))\n using (var task = new Task(sr, sw)) {\n task.Solve();\n// Console.ReadKey();\n }\n }\n }\n\n internal class Task : IDisposable\n {\n private readonly InputReader sr;\n private readonly TextWriter sw;\n private bool isDispose;\n\n private int minOper = Int32.MaxValue;\n\n private HashSet used = new HashSet();\n \n public Task(InputReader sr, TextWriter sw)\n {\n this.sr = sr;\n this.sw = sw;\n }\n \n public void Solve()\n {\n var n = sr.NextInt32();\n Solution(n, 0);\n if (minOper == Int32.MaxValue) {\n sw.WriteLine(-1);\n }\n else {\n sw.WriteLine(minOper);\n }\n }\n\n private void Solution(int n, int operCount)\n {\n if(used.Contains(n))\n return;\n used.Add(n);\n if(operCount > minOper)\n return;\n \n var sqrt = (int) Math.Sqrt(n);\n if (sqrt * sqrt == n) {\n minOper = Math.Min(minOper, operCount);\n return;\n }\n if(n < 10)\n return;\n\n var str = n.ToString().ToCharArray();\n for (var i = str.Length - 1; i >= 0; i--) {\n var newNumStr = new string(str, 0, i) + new string(str, i + 1, (str.Length - i - 1));\n if (newNumStr[0] != '0') {\n Solution(Int32.Parse(newNumStr), operCount + 1);\n }\n }\n }\n \n ~Task()\n {\n Dispose(false);\n }\n \n public void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n \n private void Dispose(bool disposing)\n {\n if (!isDispose) {\n if (disposing) {\n if(sr != null)\n sr.Dispose();\n \n if(sw != null)\n sw.Dispose();\n }\n\n isDispose = true;\n }\n }\n }\n}\n\ninternal class InputReader : IDisposable\n{\n private bool isDispose;\n private readonly TextReader sr;\n private string[] buffer;\n private int seek;\n\n public InputReader(TextReader stream)\n {\n sr = stream;\n }\n\n public void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n\n public string NextString()\n {\n var result = sr.ReadLine();\n return result;\n }\n\n public int NextInt32()\n {\n return Int32.Parse(ReadNextToken());\n }\n\n private string ReadNextToken()\n {\n if (buffer == null || seek == buffer.Length) {\n seek = 0;\n buffer = NextSplitStrings();\n }\n\n return buffer[seek++];\n }\n\n public long NextInt64()\n {\n return Int64.Parse(ReadNextToken());\n }\n \n public int[] ReadArrayOfInt32()\n {\n return ReadArray(Int32.Parse);\n }\n\n public long[] ReadArrayOfInt64()\n {\n return ReadArray(Int64.Parse);\n }\n\n public string[] NextSplitStrings()\n {\n return NextString()\n .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public T[] ReadArray(Func func)\n {\n return NextSplitStrings()\n .Select(s => func(s, CultureInfo.InvariantCulture))\n .ToArray();\n }\n\n public T[] ReadArrayFromString(Func func, string str)\n {\n return\n str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)\n .Select(s => func(s, CultureInfo.InvariantCulture))\n .ToArray();\n }\n\n protected void Dispose(bool dispose)\n {\n if (!isDispose)\n {\n if (dispose)\n sr.Close();\n \n isDispose = true;\n }\n }\n\n ~InputReader()\n {\n Dispose(false);\n }\n}", "src_uid": "fa4b1de79708329bb85437e1413e13df"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp73\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] inp0 = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int n = inp0[0];\n int k = inp0[1];\n int min = 0;\n long max = Math.Min(n - k, k * 2);\n if (k > 0)\n {\n min = 1;\n }\n else\n {\n max = 0;\n }\n if (n-k==0)\n {\n min = 0;\n }\n Console.WriteLine(min + \" \" + max);\n\n }\n }\n}", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Runtime.CompilerServices;\nusing System.Text;\n\nnamespace codeforces\n{\n\tclass Program\n\t{\n\t\tpublic const int Osn = 1000000007;\n\n\t\tpublic class Pair\n\t\t{\n\t\t\tpublic long First;\n\n\t\t\tpublic long Second;\n\t\t}\n\n\t\tpublic class PairComparer : IComparer\n\t\t{\n\t\t\tpublic int Compare(Pair x, Pair y)\n\t\t\t{\n\t\t\t\tif (x.First < y.First || (x.First == y.First && x.Second > y.Second))\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic static long ans = 0;\n\n\t\tpublic static long GetGcd(long a, long b)\n\t\t{\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tif (b == 0)\n\t\t\t\t\treturn a;\n\t\t\t\tvar a1 = a;\n\t\t\t\ta = b;\n\t\t\t\tans += a1 / b;\n\t\t\t\tb = a1 % b;\n\n\t\t\t}\n\t\t}\n\n\t\tpublic static void WriteYesNo(bool x, string yes = \"YES\", string no = \"NO\")\n\t\t{\n\t\t\tif (x)\n\t\t\t\tConsole.WriteLine(yes);\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(no);\n\t\t\t}\n\t\t}\n\n\t\tpublic static string ReadString()\n\t\t{\n\t\t\treturn Console.ReadLine();\n\t\t}\n\n\t\tpublic static List ReadListOfInts()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(int.Parse).ToList();\n\t\t}\n\n\t\tpublic static List ReadListOfLongs()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(long.Parse).ToList();\n\t\t}\n\n\t\tpublic static int ReadInt()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn int.Parse(s);\n\t\t}\n\n\t\tpublic static long ReadLong()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn long.Parse(s);\n\t\t}\n\n\t\tpublic class Vertex\n\t\t{\n\t\t\tpublic int Was;\n\n\t\t\tpublic List Edges;\n\t\t}\n\n\t\tpublic static List Graph = new List();\n\n\n\t\tpublic static bool Dfs(int u)\n\t\t{\n\t\t\tif (Graph[u].Was == 1) return true;\n\t\t\tif (Graph[u].Was == 2) return false;\n\t\t\tGraph[u].Was = 1;\n\t\t\tforeach (var t in Graph[u].Edges)\n\t\t\t{\n\t\t\t\tif (Dfs(t)) return true;\n\t\t\t}\n\n\t\t\tGraph[u].Was = 2;\n\t\t\treturn false;\n\t\t}\n\n\t\tpublic static bool IsPrime(int x)\n\t\t{\n\t\t\tfor (var j = 2; j * j <= x; ++j)\n\t\t\t\tif (x % j == 0)\n\t\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic class LinkedVertex\n\t\t{\n\t\t\tpublic int Next;\n\n\t\t\tpublic int Prev;\n\n\t\t\tpublic int Value;\n\t\t}\n\n\n\t\tpublic static int BinarySearch(List list, int value)\n\t\t{\n\t\t\tvar l = -1;\n\t\t\tvar r = list.Count;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tvar m = (r + l) / 2;\n\t\t\t\tif (list[m] >= value)\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\n\t\t\treturn r;\n\t\t}\n\n\t\tprivate static void Main()\n\t\t{\n/*\t\t\tvar n = ReadInt();\n\t\t\tvar l = ReadListOfInts();\n\t\t\tl.Sort();\n\t\t\tvar sum = l.Sum();\n\t\t\tvar t = n * l[n - 1];\n\t\t\tif (t - sum >= l[n - 1])\n\t\t\t\tConsole.WriteLine(l[n - 1]);\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(l[n - 1] + 1);\n\t\t\t}*/\n\t\t\tvar s = ReadString();\n\t\t\tvar s1 = ReadString();\n\t\t\tvar days = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\t\t\tvar can = false;\n\t\t\tvar dd = new string[] { \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\" };\n\t\t\tvar d1 = 0;\n\t\t\tvar d2 = 0;\n\t\t\tfor (var i = 0; i < 7; ++i)\n\t\t\t{\n\t\t\t\tif (s.Equals(dd[i]))\n\t\t\t\t\td1 = i;\n\t\t\t\tif (s1.Equals(dd[i]))\n\t\t\t\t\td2 = i;\n\t\t\t}\n\t\t\tvar diffs = (7 + d2 - d1) % 7;\n\t\t\tfor (var i = 1; i < 12; ++i)\n\t\t\t\tif (days[i] % 7 == diffs)\n\t\t\t\t\tcan = true;\n\t\t\tWriteYesNo(can);\n\t\t\tConsole.ReadLine();\n\t\t}\n\t}\n}\n", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace B\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tint n = Int32.Parse(Console.ReadLine()); int startn = n;\n\t\t\tint sqrt = (int)Math.Sqrt(n) + 1; \n\t\t\tint[] a = new int[n + 1];\n\t\t\tint[] divs = new int[sqrt];\n\t\t\ta[0] = 1; a[1] = 1;\n\t\t\tint l = 0;\n\t\t\tfor (int i = 2; i <= n; i++)\n\t\t\t{\n\t\t\t\tif (a[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tfor (int j = i + i; j <= n; j += i)\n\t\t\t\t\t{\n\t\t\t\t\t\ta[j] = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 2; i <= n; i++)\n\t\t\t{\n\t\t\t\tif ((a[i] == 0) && (n % i == 0))\n\t\t\t\t{\n\t\t\t\t\tdivs[l] = i;\n\t\t\t\t\t//Console.WriteLine(\"div \" + l + \" = \" + i);\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] q = new int[l];\n\t\t\tint answer = 1;\n\t\t\tfor (int i = 0; i < l; i++)\n\t\t\t{\n\t\t\t\tanswer *= divs[i];\n\t\t\t\twhile (n % divs[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tq[i]++;\n\t\t\t\t\tn = n / divs[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tbool b = true;\n\t\t\tfor (int i = 0; i < l; i++)\n\t\t\t{\n\t\t\t\tif (q[i] != 1)\n\t\t\t\t{\n\t\t\t\t\tb = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (b)\n\t\t\t{\n\t\t\t\tConsole.WriteLine(startn + \" \" + 0);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint max = 0;\n\t\t\tfor (int i = 0; i < l; i++)\n\t\t\t{\n\t\t\t\tif (max < q[i]) max = q[i];\n\t\t\t}\n\t\t\tint[] pows = new int[21];\n\t\t\tpows[0] = 1;\n\t\t\tfor (int i = 1; i < 21; i++)\n\t\t\t{\n\t\t\t\tpows[i] = pows[i - 1] * 2;\n\t\t\t}\n\t\t\tint s = 0;\n\t\t\twhile (max > pows[s]) s++;\n\t\t\t//Console.WriteLine(\"pows[s] = \" + pows[s]);\n\t\t\tif (max == pows[s])\n\t\t\t{\n\t\t\t\tfor (int i = 0; i < l; i++)\n\t\t\t\t{\n\t\t\t\t\tif (q[i] < pows[s])\n\t\t\t\t\t{\n\t\t\t\t\t\tConsole.WriteLine(answer + \" \" + (1 + s));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tConsole.WriteLine(answer + \" \" + s);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(answer + \" \" + (1 + s));\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Xml.Xsl;\n\nnamespace Codeforces\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args) \n\t\t{\n\t\t\tstring input1 = Console.ReadLine();\n\t\t\t//string input2 = Console.ReadLine();\n\n\t\t\t//string input3 = Console.ReadLine();\n\t\t\t//string input4 = Console.ReadLine();\n\n\t\t\t//var inputs1 = input1.Split(new[] {' ', '}', '{', ','}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();\n\t\t\t//var inputs2 = input2.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\t\t\t//var inputs3 = input3.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\t\t\t//var inputs4 = input4.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\n\t\t\tint n = int.Parse(input1);\n\n\t\t\tvar copyN = n;\n\t\t\tvar f = copyN / 36;\n\t\t\tcopyN -= 36 * f;\n\n\t\t\tvar d = copyN / 3;\n\t\t\tcopyN -= 3 * d;\n\t\t\tif (copyN > 1) \n\t\t\t{\n\t\t\t\td++;\n\t\t\t}\n\n\t\t\twhile (d > 11) \n\t\t\t{\n\t\t\t\td -= 12;\n\t\t\t\tf++;\n\t\t\t}\n\n\t\t\tConsole.WriteLine($\"{f} {d}\");\n\t\t}\n\n\t\tpublic class Team\n\t\t{\n\t\t\tpublic string Name { get; set; }\n\n\t\t\tpublic int Points { get; set; }\n\n\t\t\tpublic int GoalsFor { get; set; }\n\n\t\t\tpublic int GoalsAgainst { get; set; }\n\t\t}\n\n\t\tstatic long Factorial(long a) \n\t\t{\n\t\t\treturn a > 1 ? a * Factorial(a - 1) : 1;\n\t\t}\n\t}\n}\n", "src_uid": "5d4f38ffd1849862623325fdbe06cd00"} {"source_code": "using System;\n\nnamespace ConsoleApplication1\n{\n public static class Problem391A\n {\n private static int Solve(string s)\n {\n var a = s[0];\n var b = 0;\n var d = 0;\n foreach (var c in s)\n {\n if (a == c)\n {\n b++;\n } \n else\n {\n if (b % 2 == 0) d++;\n b = 1;\n }\n a = c;\n }\n\n return d + (b%2==0?1:0);\n }\n \n \n private static void Run()\n {\n var a = Console.ReadLine();\n Console.WriteLine(Solve(a));\n }\n \n public static void Main(string[] args)\n {\n Problem391A.Run(); \n }\n \n }\n}", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces\n{\n\tinternal class Template\n\t{\n\t\tprivate void Solve()\n\t\t{\n\t\t\tvar n = cin.NextInt();\n\t\t\tvar k = cin.NextInt();\n\t\t\tvar a = new int[n];\n\t\t\tvar pos = new Queue[n + 10];\n\t\t\tfor (var i = 0; i < pos.Length; i++)\n\t\t\t{\n\t\t\t\tpos[i] = new Queue();\n\t\t\t}\n\t\t\tfor (var i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\ta[i] = cin.NextInt();\n\t\t\t\tpos[a[i]].Enqueue(i);\n\t\t\t}\n\t\t\tvar have = new HashSet();\n\t\t\tvar timesNeeded = new SortedDictionary();\n\t\t\tvar res = 0;\n\t\t\tfor (var i = 0; i < a.Length; i++)\n\t\t\t{\n\t\t\t\tif (!have.Contains(a[i]))\n\t\t\t\t{\n\t\t\t\t\tif (have.Count == k)\n\t\t\t\t\t{\n\t\t\t\t\t\tvar first = timesNeeded.First();\n\t\t\t\t\t\ttimesNeeded.Remove(first.Key);\n\t\t\t\t\t\thave.Remove(first.Value);\n\t\t\t\t\t}\n\t\t\t\t\thave.Add(a[i]);\n\t\t\t\t\tif (i != pos[a[i]].Peek())\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new AccessViolationException();\n\t\t\t\t\t}\n\t\t\t\t\tpos[a[i]].Dequeue();\n\t\t\t\t\tif (!pos[a[i]].Any())\n\t\t\t\t\t{\n\t\t\t\t\t\ttimesNeeded.Add(-1000000000 + i, a[i]);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\ttimesNeeded.Add(-pos[a[i]].Peek(), a[i]);\n\t\t\t\t\t}\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvar p = pos[a[i]].Dequeue();\n\t\t\t\t\ttimesNeeded.Remove(-p);\n\t\t\t\t\tif (!pos[a[i]].Any())\n\t\t\t\t\t{\n\t\t\t\t\t\ttimesNeeded.Add(-1000000000 + i, a[i]);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\ttimesNeeded.Add(-pos[a[i]].Peek(), a[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tConsole.WriteLine(res);\n\t\t}\n\n\t\tprivate static readonly Scanner cin = new Scanner();\n\n\t\tprivate static void Main()\n\t\t{\n#if DEBUG\n\t\t\tvar inputText = File.ReadAllText(@\"..\\..\\input.txt\");\n\t\t\tvar testCases = inputText.Split(new[] { \"input\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\tvar consoleOut = Console.Out;\n\t\t\tfor (var i = 0; i < testCases.Length; i++)\n\t\t\t{\n\t\t\t\tvar parts = testCases[i].Split(new[] { \"output\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\t\tConsole.SetIn(new StringReader(parts[0].Trim()));\n\t\t\t\tvar stringWriter = new StringWriter();\n\t\t\t\tConsole.SetOut(stringWriter);\n\t\t\t\tvar sw = Stopwatch.StartNew();\n\t\t\t\tnew Template().Solve();\n\t\t\t\tsw.Stop();\n\t\t\t\tvar output = stringWriter.ToString();\n\n\t\t\t\tConsole.SetOut(consoleOut);\n\t\t\t\tvar color = ConsoleColor.Green;\n\t\t\t\tvar status = \"Passed\";\n\t\t\t\tif (parts[1].Trim() != output.Trim())\n\t\t\t\t{\n\t\t\t\t\tcolor = ConsoleColor.Red;\n\t\t\t\t\tstatus = \"Failed\";\n\t\t\t\t}\n\t\t\t\tConsole.ForegroundColor = color;\n\t\t\t\tConsole.WriteLine(\"Test {0} {1} in {2}ms\", i + 1, status, sw.ElapsedMilliseconds);\n\t\t\t}\n\t\t\tConsole.ReadLine();\n\t\t\tConsole.ReadKey();\n#else\n\t\t\tnew Template().Solve();\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\t}\n\n\tinternal class Scanner\n\t{\n\t\tprivate string[] s = new string[0];\n\t\tprivate int i;\n\t\tprivate readonly char[] cs = { ' ' };\n\n\t\tpublic string NextString()\n\t\t{\n\t\t\tif (i < s.Length) return s[i++];\n\t\t\tvar line = Console.ReadLine() ?? string.Empty;\n\t\t\ts = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n\t\t\ti = 1;\n\t\t\treturn s.First();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn double.Parse(NextString());\n\t\t}\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn int.Parse(NextString());\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn long.Parse(NextString());\n\t\t}\n\t}\n}", "src_uid": "956228e31679caa9952b216e010f9773"} {"source_code": "using System;\n\nnamespace CF172_2\n{\n class Program\n {\n static void Main(string[] args)\n {\n char[] ch = (Console.ReadLine()).ToCharArray();\n ch[0] = char.ToUpper(ch[0]);\n Console.WriteLine(ch);\n }\n }\n}\n", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"source_code": "#if DEBUG\nusing System.Reflection;\nusing System.Threading.Tasks;\n#endif\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Numerics;\nusing System.Globalization;\n\n#if DEBUG\nusing System.Diagnostics;\n#endif\n\nnamespace _499b\n{\n class Program\n {\n static string _inputFilename = \"input.txt\";\n static string _outputFilename = \"output.txt\";\n static bool _useFileInput = false;\n const string _delim = \"!\";\n\n\n static void Main(string[] args)\n {\n StreamWriter file = null;\n#if DEBUG\n var testNumber = 0;\n var timer = new Stopwatch();\n foreach (var test in GetTests())\n {\n\n timer.Start();\n\n var defaultColor = Console.ForegroundColor;\n Console.ForegroundColor = ConsoleColor.DarkYellow;\n Console.WriteLine($\"\");\n Console.ForegroundColor = defaultColor;\n Console.SetIn(test);\n\n\n#else\n if (_useFileInput)\n {\n Console.SetIn(File.OpenText(_inputFilename));\n file = new StreamWriter(_outputFilename);\n Console.SetOut(file);\n }\n#endif\n\n try\n {\n Solution();\n }\n finally\n {\n if (_useFileInput)\n {\n file.Close();\n }\n }\n\n#if DEBUG\n timer.Stop();\n\n Console.ForegroundColor = ConsoleColor.DarkYellow;\n Console.WriteLine($\"\");\n Console.ForegroundColor = defaultColor;\n\n timer.Reset();\n testNumber++;\n }\n#endif\n }\n\n static void Solution()\n {\n #region SOLUTION\n\n var d = ReadIntArray();\n var n = d[0];\n var m = d[1];\n var a = ReadIntArray();\n var ts = new Dictionary();\n for (int i = 0; i < m; i++)\n {\n var nt = a[i];\n if (!ts.ContainsKey(nt))\n {\n ts[nt] = 0;\n }\n\n ts[nt]++;\n }\n\n var tts = ts.Values.ToArray();\n var r = 1000 * 1000;\n var l = 0;\n while (true)\n {\n if (l == r)\n {\n break;\n }\n\n //Console.WriteLine(\"{0} {1}\", l, r);\n var mid = l + (r - l + 1) / 2;\n\n if (mid == 3)\n {\n\n }\n var canSr = 0;\n for (int i = 0; i < tts.Length; i++)\n {\n var count = tts[i];\n canSr += count / mid;\n }\n\n if (canSr >= n)\n {\n l = mid;\n }\n else\n {\n r = mid - 1;\n }\n }\n\n Console.WriteLine(l);\n //var n = readInt();\n //var m = readInt();\n\n //var a = readIntArray();\n //var b = readIntArray();\n #endregion\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int[] ReadIntArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n }\n\n static long[] ReadLongArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n }\n\n#if DEBUG\n static IEnumerable GetTests()\n {\n var tests = new List();\n var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))\n {\n while (true)\n {\n var nextText = new StringBuilder();\n var endOfFile = false;\n while (true)\n {\n var line = resource.ReadLine();\n\n endOfFile = line == null;\n if (endOfFile)\n {\n break;\n }\n\n if (line.Equals(_delim, StringComparison.Ordinal))\n {\n break;\n }\n\n nextText.AppendLine(line);\n }\n\n yield return new StringReader(nextText.ToString());\n\n if (endOfFile)\n {\n break;\n }\n }\n }\n }\n#endif\n }\n}\n", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\n\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n char[] ch = s.ToCharArray();\n int [] mas=new int [ch.Length];\n for (int i = 0; i < ch.Length; i++)\n {\n mas[i] = (int)ch[i]-48;\n }\n int t = 0,k=0,t2=0;\n for (int i = 0; i < mas.Length; i++)\n {\n if (mas[i] == 4 || mas[i] == 7) \n {\n t++; k++;\n if (t >= 2) { t2=t; }\n }\n }\n if (t2 >= 2 && k == 4 || k == 7) { Console.Write(\"YES\"); }\n else Console.Write(\"NO\");\n Console.ReadLine();\n }\n }\n\n", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Text.RegularExpressions;\n\nnamespace first\n{\n class Program\n {\n static TextReader tr;\n static void cin(out int value)\n {\n if (tr == null) tr = Console.In;\n StringBuilder sb = new StringBuilder();\n while (tr.Peek() == (char)(' ') || tr.Peek() == 13 || tr.Peek() == 10) \n tr.Read();\n while (tr.Peek() != (char)(' ') && tr.Peek() != 13 && tr.Peek() != 10)\n {\n char ch = (char)tr.Read();\n sb.Append(ch);\n }\n value = int.Parse(sb.ToString());\n }\n static void cin(out string value)\n {\n if (tr == null) tr = Console.In;\n StringBuilder sb = new StringBuilder();\n while (tr.Peek() == (char)(' ') || tr.Peek() == 13 || tr.Peek() == 10)\n tr.Read();\n while (tr.Peek() != (char)(' ') && tr.Peek() != 13 && tr.Peek() != 10)\n {\n char ch = (char)tr.Read();\n sb.Append(ch);\n }\n value = sb.ToString();\n }\n static void cin(out double value)\n {\n if (tr == null) tr = Console.In;\n StringBuilder sb = new StringBuilder();\n while (tr.Peek() == (char)(' ') || tr.Peek() == 13 || tr.Peek() == 10)\n tr.Read();\n while (tr.Peek() != (char)(' ') && tr.Peek() != 13 && tr.Peek() != 10)\n {\n char ch = (char)tr.Read();\n if (ch == '.') ch = ',';\n sb.Append(ch);\n }\n value = double.Parse(sb.ToString());\n }\n static void Main(string[] args)\n {\n int n,m;\n cin(out n);\n cin(out m);\n m=m%((n+1)*n/2);\n for (int i = 0; i%n+1 <= m; i++)\n {\n m = m - (i % n + 1);\n }\n Console.WriteLine(m.ToString());\n }\n }\n}\n", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp12\n{\n class Program\n {\n static int func(int n)\n {\n if (n == 1) return 1;\n if (n == 2) return 2;\n if (n == 3) return 4;\n return n + func(n - 2);\n }\n\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n Console.WriteLine(func(n));\n }\n }\n}\n", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace Codeforces\n{\n\tstatic class Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tvar rc = Console.ReadLine().Split().Select(int.Parse).ToList();\n\t\t\tvar res = \"\";\n\n\t\t\t// rook\n\t\t\tif (rc[0] == rc[2] || rc[1] == rc[3]) res += \"1 \";\n\t\t\telse res += \"2 \";\n\n\t\t\t// bishop\n\t\t\tif ((rc[0] + rc[1]) % 2 == (rc[2] + rc[3]) % 2)\n\t\t\t{\n\t\t\t\tif (rc[0] + rc[1] == rc[2] + rc[3] || rc[0] - rc[1] == rc[2] - rc[3]) res += \"1 \";\n\t\t\t\telse res += \"2 \";\n\t\t\t}\n\t\t\telse res += \"0 \";\n\n\t\t\t// king\n\t\t\tres += Math.Max(Math.Abs(rc[0] - rc[2]), Math.Abs(rc[1] - rc[3])).ToString();\n\t\t\tConsole.WriteLine(res);\n\t\t\tConsole.ReadLine();\n\t\t}\n\n\t}\n}\n", "src_uid": "7dbf58806db185f0fe70c00b60973f4b"} {"source_code": "using System;\n\nnamespace Rounding\n{\n class Program\n {\n static void Main(string[] args)\n {\n int operand = 10,\n input = System.Convert.ToInt32(Console.ReadLine().Trim()),\n mod = input % operand,\n res;\n if (mod > 0 && mod <= 5)\n {\n res = input - mod;\n }\n else if (mod > 5)\n {\n res = input + (operand - mod);\n }\n else\n {\n res = input;\n }\n\n System.Console.WriteLine(res);\n }\n }\n}\n", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\n\nnamespace Codeforces\n{\n class B\n {\n private static ThreadStart s_threadStart = new B().Go;\n private static bool s_time = false;\n\n private void Go()\n {\n int w = GetInt();\n int h = GetInt();\n long ret = 0;\n for (int x = 1; x < w; x++)\n {\n for (int y = 1; y < h; y++)\n {\n ret += (long)Math.Min(x, w - x) * (long)Math.Min(y, h - y);\n }\n }\n\n Wl(ret);\n }\n\n #region Template\n\n public static void Main(string[] args)\n {\n System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();\n Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);\n timer.Start();\n main.Start();\n main.Join();\n timer.Stop();\n if (s_time)\n Wl(timer.ElapsedMilliseconds);\n }\n\n private static IEnumerator ioEnum;\n private static string GetString()\n {\n while (ioEnum == null || !ioEnum.MoveNext())\n {\n ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();\n }\n\n return ioEnum.Current;\n }\n\n private static int GetInt()\n {\n return int.Parse(GetString());\n }\n\n private static long GetLong()\n {\n return long.Parse(GetString());\n }\n\n private static double GetDouble()\n {\n return double.Parse(GetString());\n }\n\n private static List GetIntArr(int n)\n {\n List ret = new List(n);\n for (int i = 0; i < n; i++)\n {\n ret.Add(GetInt());\n }\n return ret;\n }\n\n private static void Wl(T o)\n {\n if (o is double)\n {\n Wld((o as double?).Value, \"\");\n }\n else if (o is float)\n {\n Wld((o as float?).Value, \"\");\n }\n else\n Console.WriteLine(o.ToString());\n }\n\n private static void Wl(IEnumerable enumerable)\n {\n Wl(string.Join(\" \", enumerable.Select(e => e.ToString()).ToArray()));\n }\n\n private static void Wld(double d, string format)\n {\n Wl(d.ToString(format, CultureInfo.InvariantCulture));\n }\n\n public struct Tuple : IComparable>\n where T : IComparable\n where K : IComparable\n {\n public T Item1;\n public K Item2;\n\n public Tuple(T t, K k)\n {\n Item1 = t;\n Item2 = k;\n }\n\n public override bool Equals(object obj)\n {\n var o = (Tuple)obj;\n return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);\n }\n\n public override int GetHashCode()\n {\n return Item1.GetHashCode() ^ Item2.GetHashCode();\n }\n\n public override string ToString()\n {\n return \"(\" + Item1 + \" \" + Item2 + \")\";\n }\n\n #region IComparable> Members\n\n public int CompareTo(Tuple other)\n {\n int ret = Item1.CompareTo(other.Item1);\n if (ret != 0) return ret;\n return Item2.CompareTo(other.Item2);\n }\n\n #endregion\n }\n\n #endregion\n }\n}", "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n public void Solve()\n {\n long w = ReadLong();\n long m = ReadLong();\n long k = ReadLong();\n\n int n = m.ToString().Length;\n if (n * k > w)\n {\n Write(0);\n return;\n }\n w -= n * k;\n\n n = (m + 1).ToString().Length;\n\n long d = 0;\n while (d <= m)\n d = d * 10 + 9;\n\n long x = m;\n while (true)\n {\n if (w < n * k)\n break;\n long v = Math.Min(d - x, w / n / k);\n w -= v * n * k;\n x += v;\n d = d * 10 + 9;\n n++;\n }\n\n Write(x - m + 1);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"cycle.in\");\n //writer = new StreamWriter(\"cycle.out\");\n#endif\n try\n {\n // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n // thread.Start();\n // thread.Join();\n new Solver().Solve();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n Console.WriteLine(ex);\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params object[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n\n class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n\n #endregion\n}", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace FixedPoints\n{\n class Even_Odds\n {\n static void Main(string[] args)\n {\n string[] input = Console.ReadLine().Split(' ');\n\n Int64 num = Int64.Parse(input[0]);\n Int64 i = Int64.Parse(input[1]);\n\n if (num % 2 != 0)\n num++;\n\n if (i <= num / 2)\n Console.WriteLine((2 * i) - 1);\n else\n Console.WriteLine(-num + (2 * i));\n }\n }\n}\n", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace codeforces386\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = Convert.ToInt32(Console.ReadLine());\n string[] inx = Console.ReadLine().Split(' ');\n int[] data = new int[n];\n for (int i = 0; i < n; i++)\n {\n data[i] = Convert.ToInt32(inx[i]);\n }\n int t = Convert.ToInt32(Console.ReadLine());\n if (n == 1)\n {\n Console.WriteLine(1);\n return;\n }\n Array.Sort(data);\n int a, b, max, curr;\n a = 0; b = 0;\n max = 0;\n curr = 0;\n while (b < n)\n {\n while (b < n && Math.Abs(data[a] - data[b]) <= t)\n {\n b++;\n curr++;\n if (curr > max) max = curr;\n }\n if (b == n) break;\n while (Math.Abs(data[a] - data[b]) > t)\n {\n a++;\n curr--;\n }\n }\n Console.WriteLine(max);\n }\n }\n}\n", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string stroka = \"\"; long[] strochenka = { 0, 0 }; string konec = \"\"; long itog = 0; long i = 0; int u = 0; long l = 1; string konec2 = \"\";\n stroka = Console.ReadLine();\n i = Convert.ToInt64(stroka);\n gg: for (u = 0; u <= 17; u++)\n {\n if (i >= l)\n {\n konec = (u + 1).ToString() + \" \";\n }\n if (i < l)\n {\n konec2 = konec2 + \" \" + konec;\n break;\n }\n l = l * 2;\n\n }\n i=i-l/2;\n l = 1;\n if (i > 0) \n goto gg;\n Console.Write(konec2.Substring(1));\n }\n }\n}", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"} {"source_code": "/* Date: 22.10.2020 * Time: 22:45 */\n//\n// CF 677 A\n//\n//\n\nusing System;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nclass Example\n{\n# if ( ! ONLINE_JUDGE )\n\tpublic static StreamReader sr = new StreamReader (\"C:\\\\TRR\\\\2020\\\\Task\\\\07 Codeforces\\\\050\\\\A.TXT\");\n\tpublic static StreamWriter sw = new StreamWriter (\"C:\\\\TRR\\\\2020\\\\Task\\\\07 Codeforces\\\\050\\\\OUTPUT.OUT\");\n# endif\n\n# if ( ! ONLINE_JUDGE )\n\tpublic static void Print (int [] a, string title)\n\t{\n\t\tsw.WriteLine (\"*** \" + title);\n\t\tsw.Write (\"***\");\n\t\tfor ( int i=0; i < a.Length; i++ )\n\t\t\tsw.Write (\" \" + a [i]);\n\t\tsw.WriteLine ();\n\t}\n# endif\n\tpublic static void Main (string[] args)\n\t{\n\t\tNumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;\n\n\t\tint q;\n\n# if ( ONLINE_JUDGE )\n\t\tq = int.Parse (Console.ReadLine ());\n# else\n\t\tq = int.Parse (sr.ReadLine ());\n\t\tsw.WriteLine (\"*** TEST = \" + q);\n# endif\n\n\t\tfor ( int _q=0; _q < q; _q++ )\n\t\t{\n\t\t\tint n;\n\n# if ( ONLINE_JUDGE )\n\t\t\tn = int.Parse (Console.ReadLine ());\n# else\n\t\t\tsw.WriteLine (\"*** # \" + _q);\n\t\t\tn = int.Parse (sr.ReadLine ());\n# endif\n\n# if ( ! ONLINE_JUDGE )\n\t\t\tsw.WriteLine (\"*** n = \" + n);\n# endif\n\n\t\t\tint dig = n % 10, kold = 0;\n\t\t\twhile ( n > 0 )\n\t\t\t{\n\t\t\t\tn /= 10;\n\t\t\t\tkold++;\n\t\t\t}\n\n\t\t\tint d = (dig - 1) * 10;\n\t\t\tswitch ( kold )\n\t\t\t{\n\t\t\t\tcase 1 : d += 1; break;\n\t\t\t\tcase 2 : d += 3; break;\n\t\t\t\tcase 3 : d += 6; break;\n\t\t\t\tcase 4 : d += 10; break;\n\t\t\t}\n\n# if ( ONLINE_JUDGE )\n\t\t\tConsole.WriteLine (d);\n# else\n\t\t\tsw.WriteLine (d);\n# endif\n\t\t}\n\n# if ( ! ONLINE_JUDGE )\n\t\tsw.Close ();\n# endif\n\t}\n}\n", "src_uid": "289a55128be89bb86a002d218d31b57f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.Round70\n{\n class E\n {\n static int t,n;\n static int[,] dist, dist2;\n static string[] b1, b2;\n\n const int INF = 100000;\n\n static void bfs(int x, int y, bool chk)\n {\n int[] dx = new int[4] { 1, 0, -1, 0 },\n dy = new int[4] { 0, -1, 0, 1 };\n bool[,] visited = new bool[n, n];\n Queue q = new Queue();\n q.Enqueue(x * n + y);\n visited[x, y] = true;\n for (int a = 0; a < n; a++)\n for (int b = 0; b < n; b++)\n dist[a, b] = INF;\n dist[x, y] = 0;\n while (q.Any())\n {\n int v = q.Dequeue();\n x = v / n; y = v % n;\n for (int i = 0; i < 4; i++)\n if (InRange(x + dx[i]) && InRange(y + dy[i]))\n {\n int d = dist[x, y] + 1;\n if (visited[x + dx[i], y + dy[i]] || d > t || !char.IsDigit(b1[y + dy[i]][x + dx[i]]))\n {\n continue;\n }\n visited[x + dx[i], y + dy[i]] = true;\n if (!chk)\n {\n dist[x + dx[i], y + dy[i]] = d;\n q.Enqueue((x + dx[i]) * n + (y + dy[i])); ;\n }\n else\n {\n char b = b2[y + dy[i]][x + dx[i]];\n if (d < dist2[x + dx[i], y + dy[i]])\n {\n q.Enqueue((x + dx[i]) * n + (y + dy[i]));\n dist[x + dx[i], y + dy[i]] = d;\n }\n else if ('1' <= b && b <= '9' && d == dist2[x + dx[i], y + dy[i]])\n dist[x + dx[i], y + dy[i]] = d;\n }\n }\n }\n }\n\n static bool InRange(int v) { return 0 <= v && v < n; }\n\n public static void Main()\n {\n var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));\n n = xs[0];\n t = xs[1];\n dist = new int[n, n];\n b1 = new string[n];\n b2 = new string[n];\n for (int y = 0; y < n; y++)\n b1[y] = Console.ReadLine();\n Console.ReadLine();\n for (int y = 0; y < n; y++)\n b2[y] = Console.ReadLine();\n Dinic dinic = new Dinic(2000);\n int scnt = 2;\n for (int y = 0; y < n; y++)\n for (int x = 0; x < n; x++)\n if (b1[y][x] == 'Z')\n {\n bfs(x,y,false);\n dist2 = (int[,])dist.Clone();\n }\n for (int y = 0; y < n; y++)\n for (int x = 0; x < n; x++)\n {\n if (!('1' <= b1[y][x] && b1[y][x] <= '9'))\n continue;\n bfs(x, y, true);\n int scientists = b1[y][x] - '0';\n for (int j = 0; j < scientists; j++)\n dinic.AddEdge(0, scnt + j, 1);\n int idx = 1000;\n for (int a = 0; a < n; a++)\n for (int b = 0; b < n; b++)\n {\n if (!('1' <= b2[a][b] && b2[a][b] <= '9'))\n continue;\n int cnt = b2[a][b] - '0';\n for (int i = 0; i < cnt; i++, idx++)\n if (dist[b, a] < INF)\n {\n //Console.WriteLine(\"{0} {1} -> {2} {3}\", x, y, b, a);\n for (int j = 0; j < scientists; j++)\n dinic.AddEdge(scnt + j, idx, 1);\n }\n }\n scnt += scientists;\n }\n for (int y = 0, k = 1000; y < n; y++)\n for (int x = 0; x < n; x++)\n if ('1' <= b2[y][x] && b2[y][x] <= '9')\n {\n int cnt = b2[y][x] - '0';\n for (int i = 0; i < cnt; i++, k++)\n dinic.AddEdge(k, 1, 1);\n }\n Console.WriteLine(dinic.BipartiteMatching(0,1));\n }\n\n #region MaximumFlow\n class Dinic\n {\n const int INF = 1 << 29;\n\n class Edge\n {\n public int to, cap, rev;\n public Edge(int to_, int cap_, int rev_) { to = to_; cap = cap_; rev = rev_; }\n }\n\n List[] G;\n int[] level, iter;\n\n void bfs(int s)\n {\n for (int i = 0; i < level.Length; i++) level[i] = -1;\n Queue q = new Queue();\n level[s] = 0;\n q.Enqueue(s);\n while (q.Count > 0)\n {\n int v = q.Dequeue();\n for (int i = 0; i < G[v].Count; i++)\n {\n Edge e = G[v][i];\n if (e.cap > 0 && level[e.to] < 0)\n {\n level[e.to] = level[v] + 1;\n q.Enqueue(e.to);\n }\n }\n }\n }\n\n int dfs(int v, int t, int f)\n {\n if (v == t) return f;\n for (int i = iter[v]; i < G[v].Count; i++, iter[v]++)\n {\n Edge e = G[v][i];\n if (e.cap > 0 && level[v] < level[e.to])\n {\n int d = dfs(e.to, t, Math.Min(f, e.cap));\n if (d > 0)\n {\n e.cap -= d;\n G[e.to][e.rev].cap += d;\n return d;\n }\n }\n }\n return 0;\n }\n\n public void AddEdge(int from, int to, int cap)\n {\n G[from].Add(new Edge(to, cap, G[to].Count));\n G[to].Add(new Edge(from, 0, G[from].Count - 1));\n }\n\n public int MaxFlow(int s, int t)\n {\n int flow = 0;\n for (; ; )\n {\n bfs(s);\n if (level[t] < 0) return flow;\n for (int i = 0; i < iter.Length; i++) iter[i] = 0;\n for (int f = 0; (f = dfs(s, t, INF)) > 0; )\n flow += f;\n }\n }\n\n public int BipartiteMatching(int s, int t)\n {\n return MaxFlow(s, t);\n }\n\n public Dinic(int size)\n {\n level = new int[size];\n iter = new int[size];\n G = new List[size];\n for (int i = 0; i < size; i++)\n G[i] = new List();\n }\n }\n #endregion\n }\n}\n", "src_uid": "544de9c3729a35eb08c143b1cb9ee085"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\n\nnamespace _262\n{\n class Program\n {\n static void Main(string[] args)\n {\n //Console.SetIn(new StreamReader(\"input.txt\"));\n\n solve_helvetic2019A1_improved();\n //solve_262A();\n }\n\n /*\n In the tutorial it is mentioned that \n we are solving linear equation with one variable.\n\n Although it looks like a quadratic equation at first sight\n in reality it is a hidden linear equation. \n we just need to carefully analyse it and figure out\n that we don't always have equations in a clean canonical ways.\n like ax + b = 0. \n\n in the given equation:\n r = x^2 + 2xy + x + 1\n we could ajust it like that:\n r - x^2 - x - 1 = 2xy\n\n And this part brings confusion. Because the right part 2xy\n is not just y but also multiplied by 2x.\n TODO: Make description cleaner \n \n */\n public static void solve_helvetic2019A1_improved()\n {\n long r = Convert.ToInt64(Console.ReadLine());\n\n for (int x = 1; x < Math.Sqrt(r); x++)\n {\n long y = r - x * x - x - 1;\n\n if (y > 0 && y % 2 * x == 0)\n {\n Console.WriteLine(\"{0} {1}\", x, y / 2 * x);\n \n return;\n }\n }\n\n Console.WriteLine(\"NO\");\n }\n\n\n /*\n В первом варианте, я пытался тупо двойным циклом найти одновременно\n x и y. Но даже если учесть что в первом цикле у нас будет sqrt(r) итераций\n для нахождения x, то вторым циклом мы не сможем в рамках ограничения по времени задачи\n найти y.\n */\n public static void solve_helvetic2019A1()\n {\n long r = Convert.ToInt64(Console.ReadLine());\n\n bool found = false;\n long x = 0;\n long y = 0;\n long xLen = (int)Math.Sqrt(r);\n for (x = 1; x < xLen; x++)\n {\n long yLen = r <= 100000 ? r : r / (2 * xLen);\n for (y = 2 * x + 1; y < yLen; y++)\n {\n long h = x * x + 2 * x * y + x + 1;\n if (h > r)\n {\n break;\n }\n \n if (r == h)\n {\n found = true;\n break;\n }\n }\n\n if (found)\n {\n break;\n }\n }\n\n if (found)\n {\n Console.Write(\"{0} {1}\", x, y);\n }\n else\n {\n Console.Write(\"NO\");\n }\n }\n\n public static void solve_262A()\n {\n string[] nm = Console.ReadLine().Split(' ');\n\n int n = Convert.ToInt32(nm[0]);\n int m = Convert.ToInt32(nm[1]);\n\n int bought = n;\n int max = n;\n while (bought > 0)\n {\n bought = max % m == 0 ? (bought + m - 1) / m : bought / m;\n max += bought;\n }\n Console.WriteLine(max);\n }\n\n /* \n1)4\n2)1 + (1 + 1) + (1 + 1)\n3)1 + (1 + 1 + 1)\n4)1\n\n1 1 \n\t \n2 3 \n \n3 7 \n \n4 14 \n\t\n5 25\n\n1)5\n2)1 + (1 + 1) + (1 + 1) + (1 + 1)\n3)1 + (1 + 1 + 1) + (1 + 1 + 1)\n4)1 + (1 + 1 + 1 + 1)\n5)1\n\n(0) + 1 => (1) + 2 => (1 + 3) + 3 => (3 + 7) + 4 => (7 + 14) + 5\n */\n public static void solve_164B()\n {\n int n = Convert.ToInt32(Console.ReadLine());\n\n int total = 0;\n int prev = 0;\n int prevPrev = 0;\n for (int i = 1; i <= n; i++)\n {\n total = prevPrev + prev + i;\n\n prevPrev = prev;\n prev = total;\n }\n\n Console.WriteLine(total);\n }\n\n\n /*\n Внимание: в данной задаче если крот нажал на кнопку q и было смещение вправо.\n То есть надо восстановить, сместив букву влево, то у нас будет исключение.\n Потомучто в строке keyboard q это первая буква строки. И левее нее у нас ничего нет.\n НО! По условию у нас нигде не сказано, что если крот нажал на самую левую клавишу, то\n мы должны восстановить сообщение взяв самую правую букву. Циклический сдвиг замкнутость.\n То есть такой кейс не рассматривается.\n\n Для ускорения алгоритма, можно избавиться от встроенной проверки символа IndexOf и запихать\n все буквы в словарь. Где буквы будут ключами, а их значение индексом в строке.\n */\n public static void solve_271A()\n {\n string direction = Console.ReadLine();\n string text = Console.ReadLine();\n\n string keyboard = \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n\n string answer = String.Empty;\n if (direction == \"R\")\n {\n for (int i = 0; i < text.Length; i++)\n {\n answer += keyboard[keyboard.IndexOf(text[i]) - 1];\n }\n }\n else\n {\n for (int i = 0; i < text.Length; i++)\n {\n answer += keyboard[keyboard.IndexOf(text[i]) + 1];\n }\n }\n\n Console.WriteLine(answer);\n }\n\n /*\n Данный алгоритм можно еще улучшить, если избавиться от встроенной провекри на символ\n String.Contains.\n и использовать встроенную структуру данных dictionary с проверокой значения за хотя бы\n log(n)\n */\n public static void solve_368A()\n {\n string[] nm = Console.ReadLine().Split(' ');\n\n int n = Convert.ToInt32(nm[0]);\n int m = Convert.ToInt32(nm[1]);\n\n int count = 0;\n string noir = \"WBG\";\n for (int i = 0; i < n; i++)\n {\n string[] row = Console.ReadLine().Split(' ');\n\n for (int j = 0; j < m; j++)\n {\n if (noir.Contains(row[j]))\n {\n count++;\n }\n }\n }\n\n string answer = (count == n * m) ? \"#Black&White\" : \"#Color\";\n\n Console.WriteLine(answer); \n }\n\n public static void solve_90A()\n {\n string[] abn = Console.ReadLine().Split(' ');\n\n int a = Convert.ToInt32(abn[0]);\n int b = Convert.ToInt32(abn[1]);\n int n = Convert.ToInt32(abn[2]);\n \n int count = 1;\n while (n > 0)\n {\n if (count % 2 == 0)\n {\n n -= gcd(n, b);\n }\n else \n {\n n -= gcd(n, a);\n }\n \n count++;\n }\n\n int answer = (--count % 2 == 0) ? 1 : 0;\n\n Console.WriteLine(answer);\n }\n\n public static int gcd(int a, int b)\n {\n if (b == 0)\n {\n return a;\n }\n\n return gcd(b, a % b);\n }\n }\n}\n", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n public void Solve()\n {\n int n = ReadInt();\n long m = ReadLong() - 1;\n int l = 0, r = n - 1;\n var a = new int[n];\n for (int i = n - 2, j = 1; i >= 0; i--, j++)\n {\n if ((m >> i & 1) == 1)\n a[r--] = j;\n else\n a[l++] = j;\n }\n a[l] = n;\n WriteArray(a);\n }\n \n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"game.in\");\n //writer = new StreamWriter(\"game.out\");\n#endif\n try\n {\n var thread = new Thread(new Solver().Solve, 1024 * 1024 * 256);\n thread.Start();\n thread.Join();\n //new Solver().Solve();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n Console.WriteLine(ex);\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params object[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n\n #endregion\n}", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"} {"source_code": "using System;\nusing CompLib.Util;\n\npublic class Program\n{\n private long N, P;\n private int D, W;\n\n public void Solve()\n {\n var sc = new Scanner();\n N = sc.NextLong();\n P = sc.NextLong();\n W = sc.NextInt();\n D = sc.NextInt();\n\n // 勝ったチームにWポイント 負けに0ポイント\n // 引き分けなら 両方にDポイント\n\n // N回の試合して得点がPポイント\n\n // (勝ち、引き分け、負け) = (x,y,z)\n // 一つ出力\n\n // 無いなら-1\n\n // 引き分け回数をW回まで調べる\n\n for (long draw = 0; draw < W; draw++)\n {\n long m = P - draw * D;\n\n if (m >= 0 && m % W == 0)\n {\n long win = m / W;\n if (win >= 0 && draw + win <= N)\n {\n Console.WriteLine($\"{win} {draw} {N - win - draw}\");\n return;\n }\n }\n }\n\n Console.WriteLine(\"-1\");\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s = Console.ReadLine();\n while (s.Length == 0)\n {\n s = Console.ReadLine();\n }\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}", "src_uid": "503116e144d19eb953954d99c5526a7d"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace _460A\n{\n class Program\n {\n static void Main()\n {\n var input = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int counter = 1;\n for (; input[0]-- > 0; counter++)\n {\n if (counter % input[1] == 0) input[0]++; \n }\n Console.WriteLine(counter-1);\n }\n }\n}", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.Round53\n{\n class A\n {\n public static void Main()\n {\n int[] xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss=>int.Parse(sss));\n int[] dx = new int[] { 0, 1, 0, -1 },\n dy = new int[] { 1, 0, -1, 0 };\n int n = xs[0];\n int[,] dist = new int[n + 1, n + 1];\n bool[,] visited = new bool[n + 1, n + 1];\n for (int y = 1; y < n; y++)\n for (int x = 1; x < n; x++)\n visited[x, y] = true;\n\n Queue qx = new Queue(), qy = new Queue();\n qx.Enqueue(xs[1]); qy.Enqueue(xs[2]);\n while (true)\n {\n int xx = qx.Dequeue(),\n yy = qy.Dequeue();\n if (xx == xs[3] && yy == xs[4]) break;\n for (int i = 0; i < 4; i++)\n {\n int x = xx + dx[i],\n y = yy + dy[i];\n if (0 <= x && x <= n && 0 <= y && y <= n && !visited[x, y])\n {\n visited[x, y] = true;\n qx.Enqueue(x);\n qy.Enqueue(y);\n dist[x, y] = dist[xx, yy] + 1;\n }\n }\n }\n\n Console.WriteLine(dist[xs[3], xs[4]]);\n }\n }\n}\n", "src_uid": "685fe16c217b5b71eafdb4198822250e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace cs_console\n{\n class _73_2_B\n {\n public static void Main(string[] args)\n {\n Console.WriteLine(test());\n }\n static string test()\n {\n string[] ss = Console.ReadLine().Split(' ');\n int[] c = new int[3];\n for (int i = 0; i < 3; i++)\n {\n c[i] = ch(ss[i]);\n }\n string[] ans = { \"major\", \"minor\", \"strange\" };\n\n Array.Sort(c);\n if (c[0] == c[1] - 4 && c[1] == c[2] - 3)\n {\n return ans[0];\n }\n if (c[0] == c[1] - 3 && c[1] == c[2] - 4)\n {\n return ans[1];\n }\n\n c[0] += 12;\n Array.Sort(c);\n if (c[0] == c[1] - 4 && c[1] == c[2] - 3)\n {\n return ans[0];\n }\n if (c[0] == c[1] - 3 && c[1] == c[2] - 4)\n {\n return ans[1];\n }\n\n c[0] += 12;\n Array.Sort(c);\n if (c[0] == c[1] - 4 && c[1] == c[2] - 3)\n {\n return ans[0];\n }\n if (c[0] == c[1] - 3 && c[1] == c[2] - 4)\n {\n return ans[1];\n }\n\n return ans[2];\n }\n\n private static int ch(string p)\n {\n string[] keys = new string[] { \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"B\", \"H\" };\n for (int i = 0; i < keys.Length; i++)\n {\n if (keys[i] == p)\n return i;\n }\n return -1;\n }\n\n\n }\n}\n", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Test\n{\n class Program\n {\n static void Main()\n {\n int n = Int32.Parse(Console.ReadLine());\n string s = Console.ReadLine();\n int ans = 0;\n for (int begin = 0; begin < n; begin++)\n for (int end = begin; end < n; end++)\n {\n int x = 0, y = 0;\n for (int i = begin; i <= end; i++)\n switch (s[i])\n {\n case 'R':\n x++;\n break;\n\n case 'L':\n x--;\n break;\n\n case 'U':\n y++;\n break;\n\n case 'D':\n y--;\n break;\n }\n if (x == 0 && y == 0)\n ans++;\n }\n Console.Write(ans);\n }\n }\n}\n", "src_uid": "7bd5521531950e2de9a7b0904353184d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Numerics;\npublic class Codeforces\n{\n protected static TextReader reader;\n protected static TextWriter writer;\n static object Solve()\n {\n var number = reader.ReadLine();\n var a = \"NO\";\n var m = new string[125];\n for (int i = 0; i < 125; i++)\n {\n m[i] = (8 * i).ToString();\n }\n foreach (var item in m)\n {\n var pos = 0;\n foreach (var subitem in item)\n {\n pos = number.IndexOf(subitem, pos);\n if (pos < 0)\n {\n break;\n }\n else\n {\n pos++;\n }\n }\n if (pos > -1)\n {\n writer.WriteLine(\"YES\\n\" + item);\n return null;\n }\n }\n writer.WriteLine(a);\n return null;\n }\n static void Main()\n {\n reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);\n writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);\n try\n {\n object result = Solve();\n if (result != null)\n writer.WriteLine(result);\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n throw;\n }\n reader.Close();\n writer.Close();\n }\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params T[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if (c == '-')\n {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n #endregion\n}", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"source_code": "using System;\nusing System.Text.RegularExpressions;\n\nclass Solution\n{\n public static void Main(String[] args)\n {\n String s = Console.ReadLine();\n Regex rg = new Regex(@\"^(?>[A-Z0-9_]{1,16}@(?[A-Z0-9_]{1,16}(\\.[A-Z0-9_]{1,16})*)(/[A-Z0-9_]{1,16})?)$\",\n RegexOptions.IgnoreCase);\n Match m = rg.Match(s);\n if (m.Success && m.Groups[\"hostname\"].Value.Length > 0 && m.Groups[\"hostname\"].Value.Length <= 32)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n}", "src_uid": "2a68157e327f92415067f127feb31e24"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace Vasya_and_Golden_Ticket\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve() ? \"Yes\" : \"No\");\n writer.Flush();\n }\n\n private static bool Solve()\n {\n int n = Next();\n\n var nn = new int[n];\n for (int i = 0; i < n; i++)\n {\n nn[i] = Next(true);\n }\n\n int sum = nn.Sum();\n for (int i = 2; i <= n; i++)\n {\n if (sum%i == 0)\n {\n int d = sum/i;\n int s = 0;\n bool ok = true;\n foreach (int k in nn)\n {\n s += k;\n if (s < d)\n continue;\n if (s == d)\n {\n s = 0;\n }\n else if (s > d)\n {\n ok = false;\n break;\n }\n }\n if (ok)\n return true;\n }\n }\n\n return false;\n }\n\n private static int Next(bool one = false)\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n if (one)\n return res;\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace LearningC_Sharp\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n long val1 = 1, val2 = 1;\n for (int i = 0; i < n; i++)\n {\n val1 = val1 * 27;\n val2 = val2 * 7;\n val1 %= 1000000007;\n val2 %= 1000000007;\n }\n long res = (val1 - val2 + 1000000007) % 1000000007;\n Console.WriteLine(res);\n }\n }\n}\n", "src_uid": "eae87ec16c284f324d86b7e65fda093c"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Chloe_and_the_sequence\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n long n = Next();\n long k = Next();\n\n int ans = 1;\n while (true)\n {\n if ((k & 1) == 1)\n break;\n k >>= 1;\n ans++;\n }\n\n writer.WriteLine(ans);\n writer.Flush();\n }\n\n private static long Next()\n {\n int c;\n long res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"} {"source_code": "// ac 218ms\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\nusing System.Linq;\n\nnamespace sar_cs\n{\n static class Helpers\n {\n public static string Join(this IEnumerable objs, string sep)\n {\n var sb = new StringBuilder();\n foreach (var s in objs) { if (sb.Length != 0) sb.Append(sep); sb.Append(s); }\n return sb.ToString();\n }\n\n public static string AsString(this double a, int digits)\n {\n return a.ToString(\"F\" + digits, CultureInfo.InvariantCulture);\n }\n\n public static T[] Copy(this T[] a)\n {\n var b = new T[a.Length]; a.CopyTo(b, 0); return b;\n }\n\n public static T[][] Copy(this T[][] a)\n {\n return a.Select(z => z.Copy()).ToArray();\n }\n\n public static IEnumerable Shuffle(this IEnumerable collection)\n {\n if (collection.Take(11).Count() <= 10) return collection;\n var a = collection is T[] ? (T[])collection : collection.ToArray();\n int N = a.Length;\n for (int i = 0, p1 = 0, p2 = 1; i < N / 2; i++)\n {\n p1 += 3; if (p1 >= N) p1 -= N;\n p2 -= 7; if (p2 < 0) p2 += N;\n T t = a[p1]; a[p1] = a[p2]; a[p2] = t;\n }\n return a;\n }\n\n public static string AsString(this T[,] a, string separator)\n {\n var sb = new StringBuilder();\n int n0 = a.GetLength(0);\n int n1 = a.GetLength(1);\n for (int r = 0; r < n0; r++)\n {\n for (int c = 0; c < n1; c++)\n {\n if (c != 0) sb.Append(separator); sb.Append(a[r, c]);\n }\n sb.AppendLine();\n }\n //sb.AppendLine();\n return sb.ToString();\n }\n\n public static Stopwatch SW = Stopwatch.StartNew();\n }\n\n public class Program\n {\n #region Helpers\n\n public class Parser\n {\n const int BufSize = 8000;\n TextReader s;\n char[] buf = new char[BufSize];\n int bufPos;\n int bufDataSize;\n bool eos; // eos read to buffer\n int lastChar = -2;\n int nextChar = -2;\n StringBuilder sb = new StringBuilder();\n\n void FillBuf()\n {\n if (eos) return;\n bufDataSize = s.Read(buf, 0, BufSize);\n if (bufDataSize == 0) eos = true;\n bufPos = 0;\n }\n\n int Read()\n {\n if (nextChar != -2)\n {\n lastChar = nextChar;\n nextChar = -2;\n }\n else\n {\n if (bufPos == bufDataSize) FillBuf();\n if (eos) lastChar = -1; else lastChar = buf[bufPos++];\n }\n return lastChar;\n }\n\n void Back()\n {\n if (lastChar == -2) throw new Exception(); // no chars were ever read\n nextChar = lastChar;\n }\n\n public Parser()\n {\n s = Console.In;\n }\n\n public int ReadInt()\n {\n int res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-') { sign = 1; c = Read(); }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new FormatException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new FormatException();\n Back();\n return checked(res * sign);\n }\n\n public long ReadLong()\n {\n long res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-') { sign = 1; c = Read(); }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new FormatException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new FormatException();\n Back();\n return checked(res * sign);\n }\n\n public int ReadLnInt()\n {\n int res = ReadInt(); ReadLine(); return res;\n }\n\n public long ReadLnLong()\n {\n long res = ReadLong(); ReadLine(); return res;\n }\n\n public double ReadDouble()\n {\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n\n int sign = 1;\n if (c == '-') { sign = -1; c = Read(); }\n\n sb.Length = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c); c = Read();\n }\n\n Back();\n var res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);\n return res * sign;\n }\n\n public string ReadLine()\n {\n int c = Read();\n sb.Length = 0;\n while (c != -1 && c != 13 && c != 10)\n {\n sb.Append((char)c); c = Read();\n }\n if (c == 13) { c = Read(); if (c != 10) Back(); }\n return sb.ToString();\n }\n\n public bool SeekEOF\n {\n get\n {\n L0:\n int c = Read();\n if (c == -1) return true;\n if (char.IsWhiteSpace((char)c)) goto L0;\n Back();\n return false;\n }\n }\n\n public int[] ReadIntArr(int n)\n {\n var a = new int[n]; for (int i = 0; i < n; i++) a[i] = ReadInt(); return a;\n }\n\n public long[] ReadLongArr(int n)\n {\n var a = new long[n]; for (int i = 0; i < n; i++) a[i] = ReadLong(); return a;\n }\n }\n\n class Writer\n {\n const int BufSize = 32000;\n char[] buf = new char[BufSize];\n int bufPos = 0;\n TextWriter output = Console.Out;\n Stack st = new Stack();\n\n public void Flush()\n {\n output.Write(buf, 0, bufPos); bufPos = 0;\n output.Flush();\n }\n\n void BufSpaceNeeded(int n)\n {\n if (n > BufSize) throw new ArgumentOutOfRangeException(\"n\");\n if (bufPos + n > BufSize) { output.Write(buf, 0, bufPos); bufPos = 0; }\n }\n\n public void Write(char a)\n {\n BufSpaceNeeded(1);\n buf[bufPos++] = a;\n }\n\n public void Write(string s)\n {\n int l = s.Length;\n for (int x = 0; x < l; )\n {\n int t = Math.Min(l - x, BufSize - bufPos);\n s.CopyTo(x, buf, bufPos, t); bufPos += t; x += t;\n if (x < l) BufSpaceNeeded(1); // force flush\n }\n }\n\n public void WriteLine()\n {\n BufSpaceNeeded(2);\n buf[bufPos++] = '\\r'; buf[bufPos++] = '\\n';\n }\n\n public void Write(object o) { Write(o.ToString()); }\n\n public void Write(uint a)\n {\n BufSpaceNeeded(10);\n do { st.Push((char)(a % 10 + 48)); a /= 10; } while (a != 0);\n while (st.Count != 0) buf[bufPos++] = st.Pop();\n }\n\n public void Write(ulong a)\n {\n BufSpaceNeeded(20);\n do { st.Push((char)(a % 10 + 48)); a /= 10; } while (a != 0);\n while (st.Count != 0) buf[bufPos++] = st.Pop();\n }\n\n public void Write(int a)\n {\n BufSpaceNeeded(11);\n if (a < 0) { buf[bufPos++] = '-'; a = -a; }\n Write((uint)a);\n }\n\n public void Write(long a)\n {\n BufSpaceNeeded(21);\n if (a < 0) { buf[bufPos++] = '-'; a = -a; }\n Write((ulong)a);\n }\n\n public void Write(double a, int digits)\n {\n Write(a.AsString(digits));\n }\n\n public void WriteLine(int a) { Write(a); WriteLine(); }\n public void WriteLine(long a) { Write(a); WriteLine(); }\n public void WriteLine(uint a) { Write(a); WriteLine(); }\n public void WriteLine(ulong a) { Write(a); WriteLine(); }\n public void WriteLine(string s) { Write(s); WriteLine(); }\n public void WriteLine(object o) { Write(o); WriteLine(); }\n }\n\n static void pe() { Console.WriteLine(\"???\"); Environment.Exit(0); }\n static void re() { throw new Exception(); }\n static void Swap(ref T a, ref T b) { T t = a; a = b; b = t; }\n static int Sqr(int a) { return a * a; }\n static long SqrL(int a) { return (long)a * a; }\n static long Sqr(long a) { return a * a; }\n static double Sqr(double a) { return a * a; }\n static double Sqrt(double a) { return Math.Sqrt(a); }\n static int abs(int a) { return Math.Abs(a); }\n static long abs(long a) { return Math.Abs(a); }\n static double abs(double a) { return Math.Abs(a); }\n\n static StringBuilder sb = new StringBuilder();\n static Random rnd = new Random(5);\n\n #endregion Helpers\n\n #region Direction\n\n struct Direction\n {\n public int dx, dy;\n\n public Direction(int dx, int dy)\n {\n this.dx = dx;\n this.dy = dy;\n }\n\n public void Apply(ref int x, ref int y)\n {\n x += dx;\n y += dy;\n }\n\n public void ApplyOrThrow(ref int x, ref int y, int w, int h)\n {\n Apply(ref x, ref y);\n if ((uint)x >= w && (uint)y >= h) throw new Exception();\n }\n\n public bool Applyable(int x, int y, int w, int h)\n {\n Apply(ref x, ref y);\n return (uint)x < w && (uint)y < h;\n }\n\n public int DistanceToBoundary(int x, int y, int w, int h)\n {\n int res = 0;\n while (Applyable(x, y, w, h))\n {\n Apply(ref x, ref y);\n res++;\n }\n return res;\n }\n\n public override string ToString()\n {\n return string.Format(\"dx={0}, dy={1}\", dx, dy);\n }\n\n public static readonly Direction[] N =\n {\n new Direction( 1, 0),\n new Direction( 0, 1),\n new Direction(-1, 0),\n new Direction( 0,-1)\n };\n }\n\n #endregion Direction\n\n struct State\n {\n public int Y, X, os;\n\n public int ID\n {\n get\n {\n return ((Y * 20 + X) * 256 + os);\n }\n }\n }\n\n struct Object\n {\n const int dx = 50, dy = 51;\n public char Type;\n public int N;\n\n private int x1, y1;\n private int x2, y2;\n\n public Object(int x0, int y0, char type, int n)\n {\n this.x1 = x0;\n this.y1 = y0;\n x2 = x1 + dx;\n y2 = y1 + dx;\n this.Type = type;\n this.N = n;\n }\n\n public bool Intersects(int x0, int y0, Direction dir)\n {\n if (dir.dx == 0)\n {\n if (dir.dy == -1)\n y0--;\n\n if (x0 < this.x1 || x0 > this.x2) return false;\n if (y0 == this.y1) return true;\n return false;\n }\n else\n {\n if (dir.dx == -1)\n x0--;\n\n return false;\n }\n }\n }\n\n static void Main()\n {\n checked\n {\n#if !ONLINE_JUDGE\n Console.SetIn(File.OpenText(\"_input\"));\n#endif\n //Console.SetOut(File.CreateText(\"_output\"));\n var parser = new Parser();\n var o = new Writer();\n try\n {\n while (!parser.SeekEOF)\n {\n var objs = new List();\n\n int H = parser.ReadInt();\n int W = parser.ReadInt(); parser.ReadLine();\n var map = new char[H][];\n int sx = -1, sy = -1;\n int tcount = 0;\n for (int y = 0; y < H; y++)\n {\n var l = parser.ReadLine();\n if (l.Contains('S'))\n {\n sy = y;\n sx = l.IndexOf('S');\n l = l.Replace('S', '.');\n }\n tcount += l.Count(c => char.IsDigit(c));\n map[y] = l.ToCharArray();\n }\n\n var tprice = new int[tcount];\n for (int i = 0; i < tcount; i++)\n tprice[i] = parser.ReadInt();\n\n int bn = 0;\n for (int y = 0; y < H; y++)\n for (int x = 0; x < W; x++)\n if (map[y][x] != '.' && map[y][x] != '#')\n {\n if (map[y][x] == 'B')\n {\n objs.Add(new Object(x, y, 'B', tcount + bn));\n bn++;\n }\n else\n {\n int t = map[y][x] - '1';\n objs.Add(new Object(x, y, 'T', t));\n }\n }\n\n var d = new int[20 * 20 * 256];\n for (int i = 0; i < d.Length; i++)\n d[i] = int.MaxValue / 2;\n var q = new Queue();\n var s = new State { X = sx, Y = sy, os = 0 };\n q.Enqueue(s);\n d[s.ID] = 0;\n while (q.Count > 0)\n {\n s = q.Dequeue();\n foreach (var dir in Direction.N)\n {\n if (dir.Applyable(s.X, s.Y, W, H))\n {\n var ns = s;\n dir.Apply(ref ns.X, ref ns.Y);\n var c = map[ns.Y][ns.X];\n if (c == '#' || c == 'B' || char.IsDigit(c)) continue;\n foreach (var obj in objs)\n if (obj.Intersects(s.X, s.Y, dir))\n {\n ns.os ^= (1 << obj.N);\n }\n\n if (d[ns.ID] < int.MaxValue / 2) continue;\n d[ns.ID] = d[s.ID] + 1;\n q.Enqueue(ns);\n }\n }\n }\n\n int best = 0;\n for (int tmask = 0; tmask < (1 << tcount); tmask++)\n {\n s = new State { X = sx, Y = sy, os = tmask + 0/*no bombs*/};\n if (d[s.ID] >= int.MaxValue / 2) continue;\n int profit = 0;\n for (int t = 0; t < tcount; t++)\n if ((tmask >> t & 1) == 1)\n profit += tprice[t];\n\n profit -= d[s.ID];\n best = Math.Max(best, profit);\n }\n\n Console.WriteLine(best);\n }\n }\n finally\n {\n o.Flush();\n }\n }\n }\n\n //static void Main()\n //{\n // new Thread(Main2, 50 << 20).Start();\n //}\n }\n}", "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d"} {"source_code": "using System;\nusing System.Text;\nusing System.Collections.Generic;\nusing System.Linq;\nclass Solve{\n public Solve(){}\n StringBuilder sb;\n ReadData re;\n public static int Main(){\n new Solve().Run();\n return 0;\n }\n void Run(){\n sb = new StringBuilder();\n re = new ReadData();\n Calc();\n Console.Write(sb.ToString());\n }\n void Calc(){\n int N = re.i();\n long[] A = re.la();\n Compression Comp = new Compression(A);\n for(int i=0;i AL = new List();\n AL.Add(a[0]);\n for(int i=1;i= X){\n bl = bc;\n }\n else{\n bf = bc+1;\n }\n }\n return bf;\n }\n public long Value(int i){\n return A[i];\n }\n}\nclass ReadData{\n string[] str;\n int counter;\n public ReadData(){\n counter = 0;\n }\n public string s(){\n if(counter == 0){\n str = Console.ReadLine().Split(' ');\n counter = str.Length;\n }\n counter--;\n return str[str.Length-counter-1];\n }\n public int i(){\n return int.Parse(s());\n }\n public long l(){\n return long.Parse(s());\n }\n public double d(){\n return double.Parse(s());\n }\n public int[] ia(int N){\n int[] ans = new int[N];\n for(int j=0;j[] g(int N,int[] f,int[] t){\n List[] ans = new List[N];\n for(int j=0;j();\n }\n for(int j=0;j[] g(int N,int M){\n List[] ans = new List[N];\n for(int j=0;j();\n }\n for(int j=0;j[] g(){\n int N = i();\n int M = i();\n List[] ans = new List[N];\n for(int j=0;j();\n }\n for(int j=0;j= 0)\r\n {\r\n bool ok = true;\r\n for (int i = 0; i < index; i++)\r\n {\r\n if (t[i] != '1')\r\n {\r\n ok = false;\r\n break;\r\n }\r\n }\r\n\r\n if (ok)\r\n for (int i = index + s.Length; i < t.Length; i++)\r\n {\r\n if (t[i] != '1')\r\n {\r\n ok = false;\r\n break;\r\n }\r\n }\r\n\r\n if (ok)\r\n return true;\r\n\r\n p = index + 1;\r\n }\r\n else break;\r\n }\r\n return false;\r\n }\r\n\r\n private static long Next()\r\n {\r\n int c;\r\n long res = 0;\r\n do\r\n {\r\n c = reader.Read();\r\n if (c == -1)\r\n return res;\r\n } while (c < '0' || c > '9');\r\n res = c - '0';\r\n while (true)\r\n {\r\n c = reader.Read();\r\n if (c < '0' || c > '9')\r\n return res;\r\n res *= 10;\r\n res += c - '0';\r\n }\r\n }\r\n }\r\n}", "src_uid": "9f39a3c160087beb0efab2e3cb510e89"} {"source_code": "using System;\n\nnamespace CodeForces\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] numbers = Console.ReadLine().Split(' ');\n\n int x = int.Parse(numbers[0]);\n int y = int.Parse(numbers[1]);\n int s = int.Parse(numbers[2]);\n\n int w = Math.Abs(x)+Math.Abs(y);\n\n if ((s - w) % 2 != 0 || w>s)\n {\n Console.WriteLine(\"No\");\n }\n else\n {\n Console.WriteLine(\"Yes\");\n }\n }\n }\n}\n", "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\n\nnamespace codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n var matrix = ReadIntMatrix(5);\n long sum = long.MinValue;\n HashSet k = new HashSet();\n for (int a = 0; a < 5; a++)\n {\n for (int b = 0; b < 5; b++)\n {\n for (int c = 0; c < 5; c++)\n {\n for (int d = 0; d < 5; d++)\n {\n for (int e = 0; e < 5; e++)\n {\n k.Clear();\n k.Add(a);\n k.Add(b);\n k.Add(c);\n k.Add(d);\n k.Add(e);\n if (k.Count < 5)\n continue;\n sum = Math.Max(sum, 2 * (matrix[d][e] + matrix[e][d] + matrix[c][d] + matrix[d][c]) + matrix[a][b] + matrix[b][a] + matrix[b][c] + matrix[c][b]);\n }\n }\n }\n }\n }\n \n Console.Write(sum);\n // Console.ReadKey();\n }\n \n static int Find(int n, int[] a)\n {\n for (int i = 0; i < a.Length; i++)\n {\n if (a[i] == n)\n return i;\n }\n return -1;\n }\n static bool isPrime(int n)\n {\n for (int i = 2; i <= Math.Sqrt(n); i++)\n {\n if (n % i == 0)\n return false;\n }\n return true;\n }\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine()); \n }\n static int[] ReadIntArray()\n {\n return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n }\n static int[][] ReadIntMatrix(int rows)\n {\n int[][] result = new int[rows][];\n for (int i = 0; i < rows; i++)\n {\n result[i] = ReadIntArray();\n }\n return result;\n }\n static int GCD(int a, int b)\n {\n if (Max(a,b) % Min(a,b) == 0)\n return Min(a,b);\n return GCD(Min(a,b), Max(a,b) % Min(a,b));\n }\n static int Min(int a, int b)\n {\n return a <= b ? a : b;\n }\n static int Max(int a, int b)\n {\n return a >= b ? a : b;\n }\n static double Distance(Point a, Point b)\n {\n return Math.Sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));\n }\n }\n struct Point\n {\n public double x, y;\n public Point(int x, int y)\n {\n this.x = x;\n this.y = y;\n }\n }\n}", "src_uid": "be6d4df20e9a48d183dd8f34531df246"} {"source_code": "using System;\nclass Lucky_Division\n{\n static void Main()\n {\n int inputInt = Convert.ToInt32(Console.ReadLine());\n int[] lucky = { 4, 7, 47, 74, 447, 474, 477, 744, 747, 774 };\n for (int i = 0; i < lucky.Length; i++)\n {\n if (inputInt % lucky[i] == 0)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n\n Console.WriteLine(\"NO\");\n\n }\n}\n", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Text;\nusing System.Threading;\n\nnamespace CodeJam\n{\n class Solution2\n {\n static void Main()\n {\n new Thread(new Solution2().run, 64 * 1024 * 1024).Start();\n }\n\n int a, b, x;\n string answer;\n\n void ReadData()\n {\n a = NextInt();\n b = NextInt();\n x = NextInt();\n\n }\n\n void Solve()\n {\n StringBuilder stringBuilder = new StringBuilder();\n char firstChar = a>b? '0': '1';\n char secondChar = a > b ? '1' : '0';\n int smallLength = a > b ? b: a;\n int bigLength = a > b ? a : b;\n if (x==0)\n {\n answer = new string(firstChar, a + b);\n return;\n }\n if (x==1)\n {\n stringBuilder.Append('0', a);\n stringBuilder.Append('1', b);\n answer = stringBuilder.ToString();\n return;\n }\n if (x%2 ==0)\n {\n for (int i=0; i Tokens = new Queue();\n public string NextToken()\n {\n if (Tokens.Count > 0)\n {\n return Tokens.Dequeue();\n }\n while (Tokens.Count == 0)\n {\n var line = _inputStream.ReadLine();\n if (line == null) return null;\n foreach (var token in line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries))\n {\n Tokens.Enqueue(token);\n }\n }\n return Tokens.Count == 0 ? null : Tokens.Dequeue();\n }\n\n private readonly char[] _whiteSpaces = { ' ', '\\r', '\\n', '\\t' };\n\n\n\n \n\n #endregion\n }\n}", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"} {"source_code": "using System;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n n *= 2;\n int k = (int)Math.Sqrt(n);\n bool found = false;\n for (int i = 1; i < k; i++)\n {\n int r = n - i * i - i;\n int x = (int)Math.Sqrt(r);\n if (x * (x + 1) == r)\n {\n found = true;\n break;\n }\n }\n if (found)\n {\n Console.Write(\"YES\");\n }\n else\n {\n Console.Write(\"NO\");\n }\n //Console.ReadLine();\n }\n }\n}\n", "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing SB = System.Text.StringBuilder;\n//using System.Threading.Tasks;\n//using System.Text.RegularExpressions;\n//using System.Globalization;\n//using System.Diagnostics;\nusing static System.Console;\nusing System.Numerics;\nusing static System.Math;\nusing pair = Pair;\n\nclass Program\n{\n static void Main()\n {\n //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });\n new Program().solve();\n Out.Flush();\n }\n readonly Scanner cin = new Scanner();\n readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑\n readonly int mod = 1000000007;\n readonly int dom = 998244353;\n bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n bool chmin(ref T a, T b) where T : IComparable { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }\n\n void solve()\n {\n int N = cin.nextint;\n int M = cin.nextint;\n\n int W = Max(N, M);\n var dp = new ModInt[W + 1, W + 1];\n\n for (int j = 0; j <= W; j++)\n {\n dp[0, j] = 1;\n }\n for (int i = 1; i <= W; i++)\n {\n for (int j = i; j <= W; j++)\n {\n dp[i, j] = dp[i - 1, j] + dp[i, j - 1];\n }\n }\n\n var ans = new ModInt(0);\n\n for (int i = 1; i <= N; i++)\n {\n for (int j = 0; j <= M; j++)\n {\n if (i <= j) break;\n\n // (i - 1, j)から遷移してきた\n var ret = new ModInt(i - j);\n ret *= dp[j, i - 1];\n ret *= dp[N - i, M - j];\n\n ans += ret;\n }\n }\n WriteLine(ans);\n }\n\n}\n\n/// \n/// [0,) までの値を取るような数\n/// \n/// camypaper\nstruct ModInt\n{\n /// \n /// 剰余を取る値.\n /// \n public static long Mod = (int)998244853;\n\n /// \n /// 実際の数値.\n /// \n public long num;\n /// \n /// 値が であるようなインスタンスを構築します.\n /// \n /// インスタンスが持つ値\n /// パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため, ∈ [0,) を満たすような を渡してください.このコンストラクタは O(1) で実行されます.\n public ModInt(long n) { num = n; }\n /// \n /// このインスタンスの数値を文字列に変換します.\n /// \n /// [0,) の範囲内の整数を 10 進表記したもの.\n public override string ToString() { return num.ToString(); }\n public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }\n public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }\n public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }\n public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(ModInt v, long k) => Pow(v.num, k);\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(long v, long k)\n {\n long ret = 1;\n for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n if ((k & 1) == 1) ret = ret * v % Mod;\n return new ModInt(ret);\n }\n /// \n /// 与えられた数の逆元を計算します.\n /// \n /// 逆元を取る対象となる数\n /// 逆元となるような値\n /// 法が素数であることを仮定して,フェルマーの小定理に従って逆元を O(log N) で計算します.\n public static ModInt Inverse(ModInt v) => Pow(v, Mod - 2);\n}\n\nclass BinomialCoefficient\n{\n public ModInt[] fact, ifact;\n /// \n /// 未満でお願いします。\n /// \n /// \n public BinomialCoefficient(ModInt _n)\n {\n int n = (int)_n.num;\n fact = new ModInt[n + 1];\n ifact = new ModInt[n + 1];\n fact[0] = 1;\n for (int i = 1; i <= n; i++)\n fact[i] = fact[i - 1] * i;\n ifact[n] = ModInt.Inverse(fact[n]);\n for (int i = n - 1; i >= 0; i--)\n ifact[i] = ifact[i + 1] * (i + 1);\n ifact[0] = ifact[1];\n }\n public ModInt this[int n, int r]\n {\n get\n {\n if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;\n return fact[n] * ifact[n - r] * ifact[r];\n }\n }\n public ModInt RepeatedCombination(int n, int k)\n {\n if (k == 0) return 1;\n return this[n + k - 1, k];\n }\n}\n\nstatic class Ex\n{\n public static void join(this IEnumerable values, string sep = \" \") => WriteLine(string.Join(sep, values));\n public static string concat(this IEnumerable values) => string.Concat(values);\n public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }\n\n public static int lower_bound(this IList arr, T val) where T : IComparable\n {\n int low = 0, high = arr.Count;\n int mid;\n while (low < high)\n {\n mid = ((high - low) >> 1) + low;\n if (arr[mid].CompareTo(val) < 0) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n public static int upper_bound(this IList arr, T val) where T : IComparable\n {\n int low = 0, high = arr.Count;\n int mid;\n while (low < high)\n {\n mid = ((high - low) >> 1) + low;\n if (arr[mid].CompareTo(val) <= 0) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n}\n\nclass Pair : IComparable> where T : IComparable where U : IComparable\n{\n public T f; public U s;\n public Pair(T f, U s) { this.f = f; this.s = s; }\n public int CompareTo(Pair a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);\n public override string ToString() => $\"{f} {s}\";\n}\n\nclass Scanner\n{\n string[] s; int i;\n readonly char[] cs = new char[] { ' ' };\n public Scanner() { s = new string[0]; i = 0; }\n public string[] scan => ReadLine().Split();\n public int[] scanint => Array.ConvertAll(scan, int.Parse);\n public long[] scanlong => Array.ConvertAll(scan, long.Parse);\n public double[] scandouble => Array.ConvertAll(scan, double.Parse);\n public string next\n {\n get\n {\n if (i < s.Length) return s[i++];\n string st = ReadLine();\n while (st == \"\") st = ReadLine();\n s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n i = 0;\n return next;\n }\n }\n public int nextint => int.Parse(next);\n public long nextlong => long.Parse(next);\n public double nextdouble => double.Parse(next);\n}\n", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A.I_Wanna_Be_the_Guy\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n string name=\"\";\n for (int i = 0; i < 500; i++) \n {\n name += Convert.ToString(i);\n }\n Console.WriteLine(name[n]);\n }\n }\n}\n", "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\n\n class Program\n {\n static void Main(string[] args)\n {\n string x = Console.ReadLine().ToLower() ;\n\n if (x.Contains(\"a\") || x.Contains(\"o\") || x.Contains(\"y\") || x.Contains(\"e\") || x.Contains(\"u\") || x.Contains(\"i\"))\n {\n x = x.Replace(\"o\", \"\");\n x = x.Replace(\"a\", \"\");\n x = x.Replace(\"y\", \"\");\n x = x.Replace(\"e\", \"\");\n x = x.Replace(\"u\", \"\");\n x = x.Replace(\"i\", \"\");\n\n }\n \n for (int i = 0 ; i < x.Length; i+=2)\n {\n x=x.Insert(i,\".\");\n \n\n }\n \n \n \n Console.WriteLine(x);\n \n }\n }\n\n", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"source_code": "using System;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApp2\n{\n class Program\n {\n static void Main(string[] args)\n {\n long[] nk = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();\n long n = nk[0];\n long k = nk[1] - 1;\n string s = Convert.ToString(n, 2);\n StringBuilder strB = new StringBuilder(s);\n bool start = false;\n for (int i = 0; i < s.Length; i++)\n {\n if (strB[i] == '1' && !start) {\n start = true;\n continue;\n }\n if(k > 0) strB[i] = '1';\n }\n s = strB.ToString();\n long ans = Convert.ToInt64(s, 2);\n Console.WriteLine(ans);\n }\n }\n}\n", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Threading;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\n\nclass Solver\n{\n public Scanner sc;\n public void Solve()\n {\n N = sc.Int;\n var A = new int[N][];\n var R = new int[N * N+1];R[N * N] = -1;\n for (int i = 0; i < N; i++)\n {\n A[i] = sc.ArrInt;\n for (int j = 0; j < N; j++)\n {\n A[i][j]--;\n R[A[i][j]] = Id(i, j);\n }\n }\n //dist:=iにいて,jまでクリアしていて,駒が0:knight,1:bishop,2:rookのとき\n var dist = Create(N * N, () => Create(N * N, () => Create(3, () => long.MaxValue / 2)));\n var pq = new PriorityQueue<(long c, int now, int cl, int pi)>((a, b) => a.c.CompareTo(b.c));\n dist[R[0]][0][0] = dist[R[0]][0][1] = dist[R[0]][0][2] = 0;\n pq.Push((0, R[0], 0, 0));\n pq.Push((0, R[0], 0, 1));\n pq.Push((0, R[0], 0, 2));\n while (pq.Any())\n {\n var (cst, now, cl, pi) = pq.Pop();\n int h = now / N, w = now % N;\n if (pi == 0)\n {\n for(int k = 0; k < knH.Length; k++)\n {\n int nh = h + knH[k], nw = w + knW[k];\n if (!Inside(nh, nw, N, N)) continue;\n var p = cl;\n if (Id(nh, nw) == R[cl + 1]) p++;\n if (chmin(ref dist[Id(nh, nw)][p][pi], cst + W))\n {\n pq.Push((cst + W, Id(nh, nw), p, pi));\n }\n }\n }\n else if (pi == 1)\n {\n for(int i = -N + 1; i <= N - 1; i++)\n {\n {\n int nh = i + h, nw = i + w;\n if (!Inside(nh, nw, N, N)) goto SEC;\n var p = cl;\n if (Id(nh, nw) == R[cl + 1]) p++;\n if (chmin(ref dist[Id(nh, nw)][p][pi], cst + W))\n {\n pq.Push((cst + W, Id(nh, nw), p, pi));\n }\n }\n SEC:;\n {\n int nh = i + h, nw = -i + w;\n if (!Inside(nh, nw, N, N)) continue;\n var p = cl;\n if (Id(nh, nw) == R[cl + 1]) p++;\n if (chmin(ref dist[Id(nh, nw)][p][pi], cst + W))\n {\n pq.Push((cst + W, Id(nh, nw), p, pi));\n }\n }\n }\n }\n else\n {\n for(int i = -N + 1; i <= N - 1; i++)\n {\n\n {\n int nh = h, nw = i + w;\n if (!Inside(nh, nw, N, N)) goto SEC;\n var p = cl;\n if (Id(nh, nw) == R[cl + 1]) p++;\n if (chmin(ref dist[Id(nh, nw)][p][pi], cst + W))\n {\n pq.Push((cst + W, Id(nh, nw), p, pi));\n }\n }\n SEC:;\n {\n int nh = i + h, nw = w;\n if (!Inside(nh, nw, N, N)) continue;\n var p = cl;\n if (Id(nh, nw) == R[cl + 1]) p++;\n if (chmin(ref dist[Id(nh, nw)][p][pi], cst + W))\n {\n pq.Push((cst + W, Id(nh, nw), p, pi));\n }\n }\n }\n }\n for(int k = 0; k < 3; k++)\n {\n if(chmin(ref dist[now][cl][k],cst+1+W))\n {\n pq.Push((cst + 1+W, now, cl, k));\n }\n }\n }\n var res = dist[R[N * N - 1]][N * N - 1].Min();\n Console.WriteLine($\"{res / W} {res % W}\");\n }\n int N;\n const long W = (long)1e9;\n public int Id(int h, int w) => h * N + w;\n int[] knH = new[] { -2, -2, -1, -1, 1, 1, 2, 2 }, knW = new[] { 1, -1, 2, -2, 2, -2, 1, -1 };\n public static bool Inside(int h, int w, int H, int W)\n => 0 <= h && h < H && 0 <= w && w < W;\n}\n\npublic class PriorityQueue\n{\n private List data = new List();\n private Comparison cmp;\n public int Count { get { return data.Count; } }\n public T Top { get { return data[0]; } }\n public PriorityQueue() { cmp = cmp ?? Comparer.Default.Compare; }\n\n public PriorityQueue(Comparison comparison) { cmp = comparison; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private int Parent(int i)\n => (i - 1) >> 1;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private int Left(int i)\n => (i << 1) + 1;\n public T Push(T val)\n {\n int i = data.Count;\n data.Add(val);\n while (i > 0)\n {\n int p = Parent(i);\n if (cmp(data[p], val) <= 0)\n break;\n data[i] = data[p];\n i = p;\n }\n data[i] = val;\n return val;\n }\n public T Pop()\n {\n var ret = data[0];\n var p = 0;\n var x = data[data.Count - 1];\n while (Left(p) < data.Count - 1)\n {\n var l = Left(p);\n if (l < data.Count - 2 && cmp(data[l + 1], data[l]) < 0) l++;\n if (cmp(data[l], x) >= 0)\n break;\n data[p] = data[l];\n p = l;\n }\n data[p] = x;\n data.RemoveAt(data.Count - 1);\n return ret;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Any() => data.Count > 0;\n}\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n var sol = new Solver() { sc = new Scanner() };\n //var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();\n sol.Solve();\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(this IList A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static void Out(this IList A, out T a) => a = A[0];\n public static void Out(this IList A, out T a, out T b) { a = A[0]; b = A[1]; }\n public static void Out(this IList A, out T a, out T b, out T c) { A.Out(out a, out b); c = A[2]; }\n public static void Out(this IList A, out T a, out T b, out T c, out T d) { A.Out(out a, out b, out c); d = A[3]; }\n public static string Concat(this IEnumerable A, string sp) => string.Join(sp, A);\n public static char ToChar(this int s, char begin = '0') => (char)(s + begin);\n public static IEnumerable Shuffle(this IEnumerable A) => A.OrderBy(v => Guid.NewGuid());\n public static int CompareTo(this T[] A, T[] B, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }\n public static int ArgMax(this IList A, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }\n public static T PopBack(this List A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next(); }\n public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\n\n#endregion", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace codeforces\n{\n public class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n int R = s.IndexOf('R') %4;\n int B = s.IndexOf('B') %4;\n int Y = s.IndexOf('Y') %4; \n int G = s.IndexOf('G') %4;\n\n List l = new List { 0,0,0,0};\n for (int i = 0; i < s.Length; i++)\n {\n if (s[i] == '!')\n l[i%4]++;\n }\n Console.WriteLine(l[R]+\" \"+l[B]+\" \"+l[Y]+\" \"+l[G]);\n }\n }\n}\n", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n\nnamespace Temp\n{ \n struct PointInt\n {\n public long X;\n\n public long Y;\n\n public PointInt(long x, long y)\n : this()\n {\n this.X = x;\n this.Y = y;\n }\n\n public static PointInt operator +(PointInt a, PointInt b)\n {\n return new PointInt(a.X + b.X, a.Y + b.Y);\n }\n\n public static PointInt operator -(PointInt a, PointInt b)\n {\n return new PointInt(a.X - b.X, a.Y - b.Y);\n }\n\n public static PointInt operator *(PointInt a, long k)\n {\n return new PointInt(k * a.X, k * a.Y);\n }\n\n public static PointInt operator *(long k, PointInt a)\n {\n return new PointInt(k * a.X, k * a.Y);\n }\n\n public bool IsInsideRectangle(long l, long b, long r, long t)\n {\n return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);\n }\n }\n\n struct LineInt\n {\n public LineInt(PointInt a, PointInt b)\n : this()\n {\n A = a.Y - b.Y;\n B = b.X - a.X;\n C = a.X * b.Y - a.Y * b.X;\n }\n\n public long A, B, C;\n\n public bool Contains(PointInt p)\n {\n return A * p.X + B * p.Y + C == 0;\n }\n }\n\n class MatrixInt\n {\n private long[,] m_Matrix;\n\n public int Size\n {\n get\n {\n return m_Matrix.GetLength(0) - 1;\n }\n }\n\n public long Mod { get; private set; }\n\n public MatrixInt(int size, long mod = 0)\n {\n m_Matrix = new long[size + 1, size + 1];\n Mod = mod;\n }\n\n public MatrixInt(long[,] matrix, long mod = 0)\n {\n this.m_Matrix = matrix;\n Mod = mod;\n }\n\n public static MatrixInt GetIdentityMatrix(int size, long mod = 0)\n {\n long[,] matrix = new long[size + 1, size + 1];\n\n for (int i = 1; i <= size; i++)\n {\n matrix[i, i] = 1;\n }\n\n return new MatrixInt(matrix, mod);\n }\n\n public long this[int i, int j]\n {\n get\n {\n return m_Matrix[i, j];\n }\n\n set\n {\n m_Matrix[i, j] = value;\n }\n }\n\n public static MatrixInt operator +(MatrixInt a, MatrixInt b)\n {\n int n = a.Size;\n long mod = Math.Max(a.Mod, b.Mod);\n long[,] c = new long[n, n];\n for (int i = 1; i <= n; i++)\n {\n for (int j = 1; j <= n; j++)\n {\n c[i, j] = a[i, j] + b[i, j]; \n }\n }\n\n if (mod > 0)\n {\n for (int i = 1; i <= n; i++)\n {\n for (int j = 1; j <= n; j++)\n {\n c[i, j] %= mod;\n }\n }\n }\n\n return new MatrixInt(c, mod);\n }\n\n public static MatrixInt operator *(MatrixInt a, MatrixInt b)\n {\n int n = a.Size;\n long mod = Math.Max(a.Mod, b.Mod);\n\n long[,] c = new long[n, n];\n\n for (int i = 1; i <= n; i++)\n {\n for (int j = 1; j <= n; j++)\n {\n for (int k = 1; k <= n; k++)\n {\n c[i, j] += a[i, k] * b[k, j];\n if (mod > 0)\n {\n c[i, j] %= mod;\n }\n } \n }\n }\n\n return new MatrixInt(c, mod);\n }\n }\n\n static class Algebra\n {\n public static long Phi(long n)\n {\n long result = n;\n for (long i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n while (n % i == 0)\n {\n n /= i;\n }\n\n result -= result / i;\n }\n }\n\n if (n > 1)\n {\n result -= result / n;\n }\n\n return result;\n }\n\n public static long BinPower(long a, long n, long mod)\n {\n long result = 1;\n\n while (n > 0)\n {\n if ((n & 1) != 0)\n {\n result = (result * a) % mod;\n }\n\n a = (a * a) % mod;\n n >>= 1;\n }\n\n return result;\n }\n\n public static class Permutations\n {\n public static int[] GetRandomPermutation(int n)\n {\n int[] p = new int[n];\n for (int i = 0; i < n; i++)\n {\n p[i] = i;\n }\n\n Random random = new Random();\n for (int i = n - 1; i > 0; i--)\n {\n int j = random.Next(i + 1);\n int tmp = p[i];\n p[i] = p[j];\n p[j] = tmp;\n }\n\n return p;\n }\n }\n\n public static T[] Shuffle(this T[] array)\n {\n int length = array.Length;\n int[] p = Permutations.GetRandomPermutation(length);\n T[] result = new T[length];\n for (int i = 0; i < length; i++)\n {\n result[i] = array[p[i]];\n }\n\n return result;\n }\n\n public static MatrixInt MatrixBinPower(MatrixInt a, long n)\n {\n MatrixInt result = new MatrixInt(a.Size);\n\n while (n > 0)\n {\n if ((n & 1) != 0)\n {\n result *= a;\n }\n\n a *= a;\n n >>= 1;\n }\n\n return result;\n }\n\n public static long Gcd(long a, long b)\n {\n return b == 0 ? a : Gcd(b, a % b);\n }\n\n public static long ExtendedGcd(long a, long b, out long x, out long y)\n {\n if (b == 0)\n {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1;\n long y1;\n long d = ExtendedGcd(b, a % b, out x1, out y1);\n x = y1;\n y = x1 - (a / b) * y1;\n return d;\n }\n\n public static long Lcm(long a, long b)\n {\n return (a / Gcd(a, b)) * b;\n }\n\n public static bool[] GetPrimes(int n)\n {\n n = Math.Max(n, 2);\n bool[] prime = new bool[n + 1];\n for (int i = 2; i <= n; i++)\n {\n prime[i] = true;\n }\n\n for (int i = 2; i * i <= n; i++)\n {\n if (prime[i])\n {\n if ((long)i * i <= n)\n {\n for (int j = i * i; j <= n; j += i)\n {\n prime[j] = false;\n }\n }\n }\n }\n\n return prime;\n }\n\n public static long GetFibonacciNumber(long n, long mod = 0)\n {\n long[,] matrix = new long[,] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };\n\n MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);\n\n return result[2, 2];\n }\n\n public static long[] GetFibonacciSequence(int n)\n {\n long[] result = new long[n];\n result[0] = result[1] = 1;\n\n for (int i = 2; i < n; i++)\n {\n result[i] = result[i - 1] + result[i - 2];\n }\n\n return result;\n }\n\n public static long GetInverseElement(long a, long mod)\n {\n long x, y;\n long g = ExtendedGcd(a, mod, out x, out y);\n\n if (g != 1)\n {\n return -1;\n }\n\n return ((x % mod) + mod) % mod;\n }\n\n public static long[] GetAllInverseElements(long mod)\n {\n long[] result = new long[mod];\n result[1] = 1;\n for (int i = 2; i < mod; i++)\n {\n result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;\n }\n\n return result;\n }\n }\n\n internal static class Reader\n {\n public static void ReadInt(out int a)\n {\n int[] number = new int[1];\n ReadInt(number);\n a = number[0];\n }\n\n public static void ReadInt(out int a, out int b)\n {\n int[] numbers = new int[2];\n ReadInt(numbers);\n a = numbers[0];\n b = numbers[1];\n }\n\n public static void ReadInt(out int int1, out int int2, out int int3)\n {\n int[] numbers = new int[3];\n ReadInt(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n }\n\n public static void ReadInt(out int int1, out int int2, out int int3, out int int4)\n {\n int[] numbers = new int[4];\n ReadInt(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n int4 = numbers[3];\n }\n\n public static void ReadLong(out long a)\n {\n long[] number = new long[1];\n ReadLong(number);\n a = number[0];\n }\n\n public static void ReadLong(out long a, out long b)\n {\n long[] numbers = new long[2];\n ReadLong(numbers);\n a = numbers[0];\n b = numbers[1];\n }\n\n public static void ReadLong(out long int1, out long int2, out long int3)\n {\n long[] numbers = new long[3];\n ReadLong(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n }\n\n public static void ReadLong(out long int1, out long int2, out long int3, out long int4)\n {\n long[] numbers = new long[4];\n ReadLong(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n int4 = numbers[3];\n }\n\n public static void ReadInt(int[] numbers)\n {\n // ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n // ReSharper restore PossibleNullReferenceException\n\n int count = Math.Min(numbers.Length, list.Length);\n\n for (int i = 0; i < count; i++)\n {\n numbers[i] = int.Parse(list[i]);\n }\n }\n\n public static int[] ReadDigits()\n {\n // ReSharper disable AssignNullToNotNullAttribute\n return Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();\n // ReSharper restore AssignNullToNotNullAttribute\n }\n\n public static void ReadLong(long[] numbers)\n {\n // ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n // ReSharper restore PossibleNullReferenceException\n\n int count = Math.Min(numbers.Length, list.Length);\n\n for (int i = 0; i < count; i++)\n {\n numbers[i] = long.Parse(list[i]);\n }\n }\n\n public static void ReadDouble(double[] numbers)\n {\n // ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n // ReSharper restore PossibleNullReferenceException\n\n int count = Math.Min(numbers.Length, list.Length);\n\n for (int i = 0; i < count; i++)\n {\n numbers[i] = double.Parse(list[i]);\n }\n }\n\n public static void ReadDouble(out double a, out double b)\n {\n double[] numbers = new double[2];\n ReadDouble(numbers);\n a = numbers[0];\n b = numbers[1];\n }\n\n public static void ReadDouble(out double int1, out double int2, out double int3)\n {\n double[] numbers = new double[3];\n ReadDouble(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n }\n }\n\n static class MyMath\n {\n public static int GetMinimalPrimeDivisor(int n)\n { \n for (int i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n return i;\n }\n }\n\n return n;\n }\n\n public static long Sqr(long x)\n {\n return x * x;\n }\n }\n\n public interface IGraph\n {\n int Vertices { get; set; }\n\n IList this[int i] { get; }\n\n void AddEdge(int u, int v);\n\n void AddOrientedEdge(int u, int v); \n }\n\n public class Graph : IGraph\n {\n private List[] m_Edges;\n\n public int Vertices { get; set; }\n\n public IList this[int i]\n {\n get\n {\n return this.m_Edges[i];\n }\n }\n\n public Graph(int vertices)\n {\n this.Vertices = vertices;\n\n this.m_Edges = new List[vertices];\n\n for (int i = 0; i < vertices; i++)\n {\n this.m_Edges[i] = new List();\n }\n }\n\n public void AddEdge(int u, int v)\n {\n this.AddOrientedEdge(u, v);\n this.AddOrientedEdge(v, u);\n }\n\n public void AddOrientedEdge(int first, int second)\n {\n this.m_Edges[first].Add(second); \n }\n\n public int[] Bfs(int start)\n {\n int[] d = new int[Vertices];\n for (int i = 0; i < Vertices; i++)\n {\n d[i] = -1;\n }\n\n Queue queue = new Queue();\n queue.Enqueue(start);\n d[start] = 0;\n\n while (queue.Count > 0)\n {\n int v = queue.Dequeue();\n foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))\n {\n queue.Enqueue(t);\n d[t] = d[v] + 1;\n }\n }\n\n return d;\n }\n } \n\n class SimpleSumTable\n {\n private readonly int[,] m_Sum;\n\n public SimpleSumTable(int n, int m, int[,] table)\n {\n m_Sum = new int[n + 1, m + 1];\n\n for (int i = 1; i < n + 1; i++)\n {\n for (int j = 1; j < m + 1; j++)\n {\n m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i, j];\n }\n }\n }\n\n public int GetSum(int l, int b, int r, int t)\n {\n return m_Sum[r, t] - m_Sum[r, b] - m_Sum[l, t] + m_Sum[l, b];\n }\n }\n\n class SegmentTreeSimpleInt\n {\n public int Size { get; private set; }\n\n private readonly T[] m_Tree;\n\n private Func m_Operation;\n\n private T m_Null;\n\n public SegmentTreeSimpleInt(int size, Func operation, T nullElement, IList array = null)\n {\n this.Size = size;\n this.m_Operation = operation;\n this.m_Null = nullElement;\n\n m_Tree = new T[4 * size];\n if (array != null)\n {\n this.Build(array, 1, 0, size - 1); \n }\n }\n\n private void Build(IList array, int v, int tl, int tr)\n {\n if (tl == tr)\n {\n m_Tree[v] = array[tl];\n }\n else\n {\n int tm = (tl + tr) / 2;\n this.Build(array, 2 * v, tl, tm);\n this.Build(array, 2 * v + 1, tm + 1, tr);\n this.CalculateNode(v);\n }\n }\n\n public T GetSum(int l, int r)\n {\n return GetSum(1, 0, Size - 1, l, r);\n }\n\n private T GetSum(int v, int tl, int tr, int l, int r)\n {\n if (l > r)\n {\n return m_Null;\n }\n\n if (l == tl && r == tr)\n {\n return m_Tree[v];\n }\n\n int tm = (tl + tr) / 2;\n\n return this.m_Operation(GetSum(2 * v, tl, tm, l, Math.Min(r, tm)),GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));\n }\n\n public void Update(int pos, T newValue)\n {\n Update(1, 0, Size - 1, pos, newValue);\n }\n\n private void Update(int v, int tl, int tr, int pos, T newValue)\n {\n if (tl == tr)\n {\n m_Tree[v] = newValue;\n }\n else\n {\n int tm = (tl + tr) / 2;\n if (pos <= tm)\n {\n Update(2 * v, tl, tm, pos, newValue);\n }\n else\n {\n Update(2 * v + 1, tm + 1, tr, pos, newValue);\n }\n this.CalculateNode(v);\n }\n }\n\n private void CalculateNode(int v)\n {\n m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);\n }\n }\n\n struct Pair\n {\n public Pair(TFirst first, TSecond second)\n : this()\n {\n this.First = first;\n this.Second = second;\n }\n\n public TFirst First { set; get; }\n\n public TSecond Second { set; get; }\n }\n\n class Program\n { \n private static StreamReader m_InputStream;\n\n private static StreamWriter m_OutStream;\n\n private static void OpenFiles()\n {\n m_InputStream = File.OpenText(\"input.txt\");\n Console.SetIn(m_InputStream);\n\n m_OutStream = File.CreateText(\"output.txt\");\n Console.SetOut(m_OutStream);\n }\n\n private static void CloseFiles()\n {\n m_OutStream.Flush();\n\n m_InputStream.Dispose();\n m_OutStream.Dispose();\n }\n\n static void Main()\n {\n //OpenFiles();\n\n new Solution().Solve();\n\n //CloseFiles();\n }\n }\n\n internal class Solution\n {\n public void Solve()\n {\n double a, b, m, x, y, z;\n Reader.ReadDouble(out a, out b, out m);\n Reader.ReadDouble(out x, out y, out z);\n\n double time = m / y;\n\n x = a / 2 - x * time;\n while (!(0 <= x && x <= a))\n {\n if (x < 0)\n {\n x = -x;\n }\n if (x > a)\n {\n x = 2 * a - x;\n }\n }\n\n z = z * time;\n while (!(0 <= z && z <= b))\n {\n if (z < 0)\n {\n z = -z;\n }\n if (z > b)\n {\n z = 2 * b - z;\n }\n }\n\n Console.Write(x.ToString(CultureInfo.InvariantCulture));\n Console.Write(\" \");\n Console.Write(z.ToString(CultureInfo.InvariantCulture));\n }\n }\n}\n", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Text;\n\nnamespace Kyoya_and_Permutation\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n var fib = new List {1, 1};\n do\n {\n fib.Add(fib[fib.Count - 1] + fib[fib.Count - 2]);\n } while (fib[fib.Count - 1] > 0);\n\n long n = Next();\n long m = Next()-1;\n\n var bb = new List();\n for (int i = fib.Count - 2; i > 0; i--)\n {\n if (m >= fib[i])\n {\n bb.Add(true);\n m -= fib[i];\n }\n else\n {\n bb.Add(false);\n }\n }\n\n var nn = new int[n];\n for (int i = 0; i < n; i++)\n {\n nn[i] = i + 1;\n }\n\n int index = bb.Count - 1;\n for (long i = n - 2; i >= 0; i--)\n {\n if (bb[index])\n {\n int c = nn[i];\n nn[i] = nn[i + 1];\n nn[i + 1] = c;\n }\n\n index--;\n }\n\n foreach (int i in nn)\n {\n writer.Write(i);\n writer.Write(' ');\n }\n writer.Flush();\n }\n\n private static long Next()\n {\n int c;\n long res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "e03c6d3bb8cf9119530668765691a346"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n public class Program\n {\n public static void Main()\n {\n int[] parameters;\n char[,] array;\n string temp;\n int PigsEaten = 0;\n\n parameters = Console.ReadLine().Split(' ').Select(n => Convert.ToInt32(n)).ToArray();\n\n array = new char[parameters[0], parameters[1]];\n\n for(int i = 0; i < parameters[0]; ++i)\n {\n temp = Console.ReadLine();\n for (int j = 0; j < parameters[1]; ++j)\n {\n array[i, j] = temp[j];\n }\n }\n\n for(int i = 0; i < parameters[0]; ++i)\n for (int j = 0; j < parameters[1]; ++j)\n {\n if (array[i, j] == 'W')\n {\n if (i + 1 < parameters[0] && array[i + 1, j] == 'P')\n ++PigsEaten;\n else if (j + 1 < parameters[1] && array[i, j + 1] == 'P')\n ++PigsEaten;\n else if (i -1 >= 0 && array[i - 1, j] == 'P')\n ++PigsEaten;\n else if (j - 1 >= 0 && array[i, j - 1] == 'P')\n ++PigsEaten;\n }\n }\n\n Console.WriteLine(PigsEaten);\n }\n }\n}", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Diagnostics;\n\nnamespace mainnm\n{\n class main\n {\n /**\n * Работает с массивом без повторяющихся элементов\n **/\n static int binarySearch(int[] array, int element) {\n int start = 0;\n int end = array.Length;\n int position = (start - end) / 2;\n \n while (start - end != 0) {\n if (array[position] == element) return position;\n \n \n }\n \n return 0;\n }\n \n static void Main()\n {\n int a = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).Sum();\n int b = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).Sum();\n int n = int.Parse(Console.ReadLine());\n \n int shelf = 0;\n shelf += a / 5; \n if (a % 5 != 0) shelf++;\n \n shelf += b / 10; \n if (b % 10 != 0) shelf++;\n \n Console.WriteLine(shelf > n ? \"NO\" : \"YES\");\n }\n }\n}", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CodeForce\n{\n class Program\n {\n static int GetDif(int target, int num)\n {\n if (target == num)\n return 0;\n if (target < num)\n return num - target;\n\n int t = (int)Math.Ceiling( Math.Log((double)target / num) / Math.Log(2) );\n int d = (int)(num * Math.Pow(2, t)-target);\n int n1 = d;\n n1 = (n1 >> (t+1)) << (t + 1);\n\n int n2 = d;\n n2 = n2 - n1;\n \n int count = n1 /(int) Math.Pow(2, t);\n count += t;\n\n while (n2>0)\n {\n n2 &= n2 - 1;\n count++;\n }\n return count;\n }\n\n static void Main(string[] args)\n {\n \n \n var line = Console.ReadLine();\n var input = line.Split(' ');\n int a = Int32.Parse(input[0]);\n int target = Int32.Parse(input[1]);\n var res = GetDif(target, a);\n Console.WriteLine(res);\n }\n }\n}\n", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"} {"source_code": "using System;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Threading;\n\nnamespace CodeForces\n{\n\tinternal class B\n\t{\n\t\tclass Lem : IComparable\n\t\t{\n\t\t\tpublic int Mass { get; set; }\n\t\t\tpublic int Speed { get; set; }\n\t\t\tpublic int Id { get; set; }\n\t\t\tpublic int CompareTo( Lem other )\n\t\t\t{\n\t\t\t\tif ( Mass != other.Mass )\n\t\t\t\t\treturn Mass.CompareTo( other.Mass );\n\t\t\t\telse return Speed.CompareTo( other.Speed );\n\t\t\t}\n\t\t}\n\t\tprivate void Solve()\n\t\t{\n\t\t\tint n = NextInt(), k = NextInt(), h = NextInt();\n\t\t\tLem[] a = new Lem[n];\n\t\t\tfor ( int i = 0; i < n; ++i )\n\t\t\t{\n\t\t\t\ta[i] = new Lem();\n\t\t\t\ta[i].Mass = NextInt();\n\t\t\t\ta[i].Id = i + 1;\n\t\t\t}\n\t\t\tfor ( int i = 0; i < n; ++i )\n\t\t\t{\n\t\t\t\ta[i].Speed = NextInt();\n\t\t\t}\n\t\t\tRandom rnd = new Random( 123 );\n\t\t\tfor ( int i = 1; i < n; ++i )\n\t\t\t{\n\t\t\t\tint j = rnd.Next( i + 1 );\n\t\t\t\tLem tmp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = tmp;\n\t\t\t}\n\t\t\tArray.Sort( a );\n\n\t\t\tdouble l = 0, r = 1000000009;\n\t\t\tfor ( int times = 0; times < 200; ++times )\n\t\t\t{\n\t\t\t\tdouble m = ( l + r ) / 2;\n\t\t\t\tif ( can( a, m, k, h ) ) r = m; else l = m;\n\t\t\t}\n\t\t\tvar res = get( a, r, k, h );\n\t\t\tforeach ( var re in res )\n\t\t\t{\n\t\t\t\tOut.Write( re + \" \" );\n\t\t\t}\n\t\t}\n\n\t\tprivate bool can( Lem[] lems, double m, int k, int h )\n\t\t{\n\t\t\tint need = k;\n\t\t\tfor ( int i = lems.Length - 1; i >= 0; --i )\n\t\t\t{\n\t\t\t\tdouble mx = Math.Min( k, m * lems[i].Speed / h );\n\t\t\t\tif ( mx >= need )\n\t\t\t\t{\n\t\t\t\t\t--need;\n\t\t\t\t}\n\t\t\t\tif ( need == 0 ) break;\n\t\t\t}\n\t\t\treturn need == 0;\n\t\t}\n\n\t\tprivate List get( Lem[] lems, double m, int k, int h )\n\t\t{\n\t\t\tList res = new List();\n\t\t\tint need = k;\n\t\t\tfor ( int i = lems.Length - 1; i >= 0; --i )\n\t\t\t{\n\t\t\t\tdouble mx = Math.Min( k, m * lems[i].Speed / h );\n\t\t\t\tif ( mx >= need )\n\t\t\t\t{\n\t\t\t\t\t--need;\n\t\t\t\t\tres.Add( lems[i].Id );\n\t\t\t\t}\n\t\t\t\tif ( need == 0 ) break;\n\t\t\t}\n\t\t\tres.Reverse();\n\t\t\treturn res;\n\t\t}\n\n\t\t#region Local wireup\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn _in.NextInt();\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn _in.NextLong();\n\t\t}\n\n\t\tpublic string NextLine()\n\t\t{\n\t\t\treturn _in.NextLine();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn _in.NextDouble();\n\t\t}\n\n\t\treadonly Scanner _in = new Scanner();\n\t\tstatic readonly TextWriter Out = Console.Out;\n\n\t\tvoid Start()\n\t\t{\n#if !ONLINE_JUDGE\n\t\t\tvar timer = new Stopwatch();\n\t\t\ttimer.Start();\n#endif\n\t\t\tvar t = new Thread( Solve, 20000000 );\n\t\t\tt.Start();\n\t\t\tt.Join();\n#if !ONLINE_JUDGE\n\t\t\ttimer.Stop();\n\t\t\tConsole.WriteLine( string.Format( CultureInfo.InvariantCulture, \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0 ) );\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\n\t\tstatic void Main()\n\t\t{\n\t\t\tnew B().Start();\n\t\t}\n\n\t\tclass Scanner : IDisposable\n\t\t{\n\t\t\t#region Fields\n\n\t\t\treadonly TextReader _reader;\n\t\t\treadonly int _bufferSize;\n\t\t\treadonly bool _closeReader;\n\t\t\treadonly char[] _buffer;\n\t\t\tint _length, _pos;\n\n\t\t\t#endregion\n\n\t\t\t#region .ctors\n\n\t\t\tpublic Scanner( TextReader reader, int bufferSize, bool closeReader )\n\t\t\t{\n\t\t\t\t_reader = reader;\n\t\t\t\t_bufferSize = bufferSize;\n\t\t\t\t_closeReader = closeReader;\n\t\t\t\t_buffer = new char[_bufferSize];\n\t\t\t\tFillBuffer( false );\n\t\t\t}\n\n\t\t\tpublic Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }\n\n\t\t\tpublic Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }\n\n#if ONLINE_JUDGE\n\t\t\tpublic Scanner() : this( Console.In, false ) { }\n#else\n\t\t\tpublic Scanner() : this( \"input.txt\" ) { }\n#endif\n\n\t\t\t#endregion\n\n\t\t\t#region IDisposable Members\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\tif ( _closeReader )\n\t\t\t\t{\n\t\t\t\t\t_reader.Close();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Properties\n\n\t\t\tpublic bool Eof\n\t\t\t{\n\t\t\t\tget\n\t\t\t\t{\n\t\t\t\t\tif ( _pos < _length ) return false;\n\t\t\t\t\tFillBuffer( false );\n\t\t\t\t\treturn _pos >= _length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Methods\n\n\t\t\tprivate char NextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos++];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos++];\n\t\t\t}\n\n\t\t\tprivate char PeekNextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos];\n\t\t\t}\n\n\t\t\tprivate void FillBuffer( bool throwOnEof )\n\t\t\t{\n\t\t\t\t_length = _reader.Read( _buffer, 0, _bufferSize );\n\t\t\t\tif ( throwOnEof && Eof )\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException( \"Can't read beyond the end of file\" );\n\t\t\t\t}\n\t\t\t\t_pos = 0;\n\t\t\t}\n\n\t\t\tpublic int NextInt()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tint res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic long NextLong()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic string NextLine()\n\t\t\t{\n\t\t\t\tSkipUntilNextLine();\n\t\t\t\tif ( Eof ) return \"\";\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn builder.ToString();\n\t\t\t}\n\n\t\t\tpublic double NextDouble()\n\t\t\t{\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn double.Parse( builder.ToString(), CultureInfo.InvariantCulture );\n\t\t\t}\n\n\t\t\tprivate void SkipWhitespaces()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void SkipUntilNextLine()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static bool IsWhitespace( char c )\n\t\t\t{\n\t\t\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\tprivate static bool IsEndOfLine( char c )\n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\t#endregion\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "6861128fcd83c752b0ea0286869901c2"} {"source_code": "using System;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Threading;\n\nnamespace CodeForces\n{\n\n\tclass A\n\t{\n\n\n\t\tprivate void Solve()\n\t\t{\n\t\t\tint n = NextInt(), m = NextInt(), k = NextInt();\n\t\t\tint[,] a = new int[n, m], b = new int[n, m], c = new int[n, m];\n\t\t\tlong res = 0;\n\t\t\tfor ( int i = 0; i < n; ++i )\n\t\t\t{\n\t\t\t\tvar name = NextLine();\n\t\t\t\tfor ( int j = 0; j < m; ++j )\n\t\t\t\t{\n\t\t\t\t\ta[i, j] = NextInt();\n\t\t\t\t\tb[i, j] = NextInt();\n\t\t\t\t\tc[i, j] = NextInt();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint[] cc = new int[m];\n\n\t\t\tfor ( int i = 0; i < n; ++i )\n\t\t\t\tfor ( int j = 0; j < n; ++j )\n\t\t\t\t\tif ( i != j )\n\t\t\t\t\t{\n\t\t\t\t\t\tfor ( int t = 0; t < m; ++t ) cc[t] = c[i, t];\n\t\t\t\t\t\tint can = k;\n\t\t\t\t\t\tlong cur = 0;\n\t\t\t\t\t\twhile ( can > 0 )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint maxV = 0, tt = -1;\n\t\t\t\t\t\t\tfor ( int t = 0; t < m; ++t )\n\t\t\t\t\t\t\t\tif ( cc[t] > 0 && b[j, t] - a[i, t] > maxV )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmaxV = b[j, t] - a[i, t];\n\t\t\t\t\t\t\t\t\ttt = t;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( tt == -1 ) break;\n\t\t\t\t\t\t\tint sell = Math.Min( c[i, tt], can );\n\t\t\t\t\t\t\tcur += (long)sell * maxV;\n\t\t\t\t\t\t\tcan -= sell;\n\t\t\t\t\t\t\tcc[tt] -= sell;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = Math.Max( res, cur );\n\t\t\t\t\t}\n\t\t\tOut.WriteLine( res );\n\t\t}\n\n\n\n\n\n\n\n\n\n\n\t\t#region Local wireup\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn _in.NextInt();\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn _in.NextLong();\n\t\t}\n\n\t\tpublic string NextLine()\n\t\t{\n\t\t\treturn _in.NextLine();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn _in.NextDouble();\n\t\t}\n\n\t\treadonly Scanner _in = new Scanner();\n\t\tstatic readonly TextWriter Out = Console.Out;\n\n\t\tvoid Start()\n\t\t{\n#if !ONLINE_JUDGE\n\t\t\tvar timer = new Stopwatch();\n\t\t\ttimer.Start();\n#endif\n\t\t\tvar t = new Thread( Solve, 20000000 );\n\t\t\tt.Start();\n\t\t\tt.Join();\n#if !ONLINE_JUDGE\n\t\t\ttimer.Stop();\n\t\t\tConsole.WriteLine( string.Format( CultureInfo.InvariantCulture, \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0 ) );\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\n\t\tstatic void Main()\n\t\t{\n\t\t\tnew A().Start();\n\t\t}\n\n\t\tclass Scanner : IDisposable\n\t\t{\n\t\t\t#region Fields\n\n\t\t\treadonly TextReader _reader;\n\t\t\treadonly int _bufferSize;\n\t\t\treadonly bool _closeReader;\n\t\t\treadonly char[] _buffer;\n\t\t\tint _length, _pos;\n\n\t\t\t#endregion\n\n\t\t\t#region .ctors\n\n\t\t\tpublic Scanner( TextReader reader, int bufferSize, bool closeReader )\n\t\t\t{\n\t\t\t\t_reader = reader;\n\t\t\t\t_bufferSize = bufferSize;\n\t\t\t\t_closeReader = closeReader;\n\t\t\t\t_buffer = new char[_bufferSize];\n\t\t\t\tFillBuffer( false );\n\t\t\t}\n\n\t\t\tpublic Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }\n\n\t\t\tpublic Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }\n\n#if ONLINE_JUDGE\n\t\t\tpublic Scanner() : this( Console.In, false ) { }\n#else\n\t\t\tpublic Scanner() : this( \"input.txt\" ) { }\n#endif\n\n\t\t\t#endregion\n\n\t\t\t#region IDisposable Members\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\tif ( _closeReader )\n\t\t\t\t{\n\t\t\t\t\t_reader.Close();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Properties\n\n\t\t\tpublic bool Eof\n\t\t\t{\n\t\t\t\tget\n\t\t\t\t{\n\t\t\t\t\tif ( _pos < _length ) return false;\n\t\t\t\t\tFillBuffer( false );\n\t\t\t\t\treturn _pos >= _length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Methods\n\n\t\t\tprivate char NextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos++];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos++];\n\t\t\t}\n\n\t\t\tprivate char PeekNextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos];\n\t\t\t}\n\n\t\t\tprivate void FillBuffer( bool throwOnEof )\n\t\t\t{\n\t\t\t\t_length = _reader.Read( _buffer, 0, _bufferSize );\n\t\t\t\tif ( throwOnEof && Eof )\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException( \"Can't read beyond the end of file\" );\n\t\t\t\t}\n\t\t\t\t_pos = 0;\n\t\t\t}\n\n\t\t\tpublic int NextInt()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tint res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic long NextLong()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic string NextLine()\n\t\t\t{\n\t\t\t\tSkipUntilNextLine();\n\t\t\t\tif ( Eof ) return \"\";\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn builder.ToString();\n\t\t\t}\n\n\t\t\tpublic double NextDouble()\n\t\t\t{\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn double.Parse( builder.ToString(), CultureInfo.InvariantCulture );\n\t\t\t}\n\n\t\t\tprivate void SkipWhitespaces()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void SkipUntilNextLine()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static bool IsWhitespace( char c )\n\t\t\t{\n\t\t\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\tprivate static bool IsEndOfLine( char c )\n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\t#endregion\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "7419c4268a9815282fadca6581f28ec1"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Golden_Plate\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args));\n writer.Flush();\n }\n\n private static int Solve(string[] args)\n {\n int w = Next(), h = Next(), k = Next();\n\n int ans = 0;\n for (int i = 0; i < k; i++)\n {\n ans += 2*w + 2*h - 4;\n w -= 4;\n h -= 4;\n }\n return ans;\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "2c98d59917337cb321d76f72a1b3c057"} {"source_code": "using System;\nusing System.Collections.Generic;\nclass Program\n{\n\tstatic void Main(string[] args)\n\t{\n\t\tstring[]str = Console.ReadLine().Split();\n\t\tlong U = long.Parse(str[0]);\n\t\tlong V = long.Parse(str[1]);\n\t\tif(U==0){\n\t\t\tif(V==0){\n\t\t\t\tConsole.WriteLine(\"0\");\n\t\t\t} else if(V%2==0){\n\t\t\t\tConsole.WriteLine(\"2\");\n\t\t\t\tConsole.WriteLine(V/2+\" \"+V/2);\n\t\t\t} else {\n\t\t\t\tConsole.WriteLine(\"-1\");\n\t\t\t}\n\t\t} else if(U>V){\n\t\t\tConsole.WriteLine(\"-1\");\n\t\t} else {\n\t\t\tV -= U;\n\t\t\tif(V==0){\n\t\t\t\tConsole.WriteLine(\"1\");\n\t\t\t\tConsole.WriteLine(U);\t\t\t\t\n\t\t\t} else if(V%2==0){\n\t\t\t\tlong x = 1;\n\t\t\t\tbool flag = true;\n\t\t\t\twhile(x num2)\n {\n Console.WriteLine(\">\");\n }\n else\n {\n Console.WriteLine(\"<\");\n }\n }\n }\n}\n", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"} {"source_code": "using System;\n\nnamespace Codeforces\n{\n\tclass MainClass\n\t{\n\t\tpublic static void Main (string[] args)\n\t\t{\n\t\t\tnew Solution();\n\t\t}\n\t}\n\tclass Solution\n\t{\n\t\tpublic Solution(){\n int x = int.Parse(Console.ReadLine());\n if (x == 1)\n {\n Console.WriteLine(\"1\");\n return;\n }\n String sx = x.ToString();\n int count = 1;\n for (int i = 1; i <= Math.Sqrt(x); i++)\n {\n char[] si = i.ToString().ToCharArray();\n if (x % i == 0 && sx.IndexOfAny(si) >= 0)\n {\n count++;\n }\n if (i > 1 && i != x / i && x % (x / i) == 0)\n {\n char[] ssi = (x / i).ToString().ToCharArray();\n if(sx.IndexOfAny(ssi)>=0)\n count++;\n }\n }\n Console.Write(count);\n //Console.ReadKey(true);\n \n\t\t}\n\t}\n}\n/*A\nint n=int.Parse(Console.ReadLine());\nConsole.Write(n+\" \");\nfor (int i = 1; i < n; i++)\n{\n Console.Write(i + \" \");\n}\n*/\n\n/* B\n int x = int.Parse(Console.ReadLine());\n if (x == 1)\n {\n Console.WriteLine(\"1\");\n return;\n }\n String sx=x.ToString();\n int count=1;\n for (int i = 1; i <= Math.Sqrt(x); i++)\n {\n char[] si=i.ToString().ToCharArray();\n if (x%i==0 && sx.IndexOfAny(si)>=0)\n {\n count++;\n } \n }\n Console.Write(count);\n */\n/*C\n int n = int.Parse(Console.ReadLine());\n String s=Console.ReadLine();\n String[] z=s.Split(' ');\n int[] c = new int[n];\n for (int i = 0; i < n; i++)\n {\n c[i] = int.Parse(z[i]);\n }\n int count = 0;\n for (int i = 1; i < n; i++)\n {\n if (c[i - 1] > c[i]) count++;\n if (count > 2)\n {\n Console.WriteLine(\"NO\");\n return;\n }\n }\n if (count == 2 || count ==0)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n if (count == 1)\n {\n int i=0;\n while (c[i] <= c[i + 1]) i++;\n int p=c[i];\n int t=c[i+1];i++;\n while (i GetPrices(long p, long d) {\n yield return p;\n var min = p - d;\n var mult = 10L;\n while (true) {\n p -= (1 + p%mult) % mult;\n if (p < min) yield break;\n yield return p;\n mult *= 10;\n }\n }\n}", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Turn\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n long n = long.Parse(reader.ReadLine());\n\n n %= 360;\n\n if (n >= 0)\n {\n if (n <= 45)\n writer.WriteLine(\"0\");\n else if (n <= 45 + 90)\n writer.WriteLine(\"1\");\n else if (n <= 45 + 180)\n writer.WriteLine(\"2\");\n else if (n < 45 + 270)\n writer.WriteLine(\"3\");\n else\n {\n writer.WriteLine(\"0\");\n }\n }\n else\n {\n if (n >= -45)\n writer.WriteLine(\"0\");\n else if (n > -45 - 90)\n writer.WriteLine(\"3\");\n else if (n > -45 - 180)\n writer.WriteLine(\"2\");\n else if (n > -45 - 270)\n writer.WriteLine(\"1\");\n else\n {\n writer.WriteLine(\"0\");\n }\n }\n\n\n writer.WriteLine();\n writer.Flush();\n }\n }\n}", "src_uid": "509db9cb6156b692557ba874a09f150e"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace cdfRound\n{\n class MainClass\n {\n public static void Main()\n {\n string input = Console.ReadLine();\n int[] first = new int[3];\n int[] second = new int[3];\n int sum1 = 0, sum2 = 0;\n for (int i = 0; i < 3; i++)\n {\n first[i] = int.Parse(input[i].ToString());\n sum1 += first[i];\n }\n for (int i = 3; i < 6; i++)\n {\n second[i - 3] = int.Parse(input[i].ToString());\n sum2 += second[i - 3];\n }\n if (sum1 == sum2)\n Console.WriteLine(0);\n else\n {\n if (sum1 > sum2)\n {\n int[] el = new int[6];\n for (int i = 0; i < 3; i++)\n el[i] = 9 - second[i];\n for (int i = 0; i < 3; i++)\n el[i + 3] = first[i];\n int sum = sum1 - sum2;\n Array.Sort(el);\n if (sum <= el[5]) Console.WriteLine(1);\n else if (sum <= (el[5] + el[4])) Console.WriteLine(2);\n else Console.WriteLine(3);\n }\n else\n {\n\t\t\t\t\tint[] el = new int[6];\n\t\t\t\t\tfor (int i = 0; i < 3; i++)\n el[i] = 9 - first[i];\n\t\t\t\t\tfor (int i = 0; i < 3; i++)\n el[i + 3] = second[i];\n\t\t\t\t\tint sum = sum2 - sum1;\n\t\t\t\t\tArray.Sort(el);\n\t\t\t\t\tif (sum <= el[5]) Console.WriteLine(1);\n\t\t\t\t\telse if (sum <= (el[5] + el[4])) Console.WriteLine(2);\n\t\t\t\t\telse Console.WriteLine(3);\n }\n }\n }\n }\n}\n", "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"source_code": "using System;\r\nusing System.Linq;\r\n\r\nnamespace CodeForces\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n var arr = Console.ReadLine().Split(' ');\r\n var n = Int32.Parse(arr[0]);\r\n var m = long.Parse(arr[1]);\r\n var res = GetRes(n, m);\r\n Console.WriteLine(res);\r\n\r\n // Test();\r\n }\r\n\r\n const int MOD_VAL = 998244353;\r\n private static int GetRes(int n, long m)\r\n {\r\n if (n == 1) return 0;\r\n var fullCount = GetFullCount(n, m);\r\n var noOk = GetNOKCount(n,m);\r\n var res = fullCount - noOk;\r\n if(res < 0) res+=MOD_VAL;\r\n return res;\r\n }\r\n\r\n private static int GetFullCount(int n, long m)\r\n {\r\n var divisor = (int)((m-1) % MOD_VAL);\r\n if (divisor == 0) return n; \r\n var reverse = GetReverse(divisor);\r\n var mAfterMod = (int)(m % MOD_VAL);\r\n var res = (int)(((long)GetPow(mAfterMod, n+1) - mAfterMod) *\r\n reverse % MOD_VAL);\r\n if (res < 0) res+=MOD_VAL;\r\n return res; \r\n }\r\n\r\n private static int GetReverse(int val)\r\n {\r\n var (a,b) = ExGcd(MOD_VAL, val);\r\n return b >= 0 ? (int) b: (int)(MOD_VAL+b);\r\n }\r\n\r\n private static (long, long) ExGcd(long num0, long num1)\r\n {\r\n if (num0 % num1 == 0)\r\n {\r\n return (0, 1);\r\n }\r\n // a0 * num0 + b0 * num1 = num2\r\n var num2 = num0 % num1;\r\n var a0 = 1;\r\n var b0 = -(num0 / num1);\r\n // a1 * num1 + b1 * num2 = gcd\r\n var (a1, b1) = ExGcd(num1, num2);\r\n // (a0*b1) * num0 + (a1 + b0*b1) * num1 = gcd\r\n return (a0 * b1, a1 + b0 * b1);\r\n }\r\n\r\n private static int GetPow(int baseVal, int exponent)\r\n {\r\n var index = 0;\r\n var res = 1L;\r\n long tmp = baseVal;\r\n while(1< 0 && k > 0)\n {\n if (n[i] == '0') k--;\n else s++;\n i--;\n }\n if (k == 0) Console.WriteLine(s);\n else Console.WriteLine(n.Length - 1);\n }\n }\n}\n", "src_uid": "7a8890417aa48c2b93b559ca118853f9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace олимпиадное_программирование\n{\n class Program\n {\n static void Main(string[] args)\n {\n int x = int.Parse(Console.ReadLine());\n if(x==1)\n Console.WriteLine(-1);\n else\n {\n if(x%2==0)\n Console.WriteLine(\"{0} {1}\", x,2);\n else\n Console.WriteLine(\"{0} {1}\", x-1, 2);\n }\n }\n }\n}\n", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class R172_Div2_B\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n int x = int.Parse(s[0]);\n int y = int.Parse(s[1]);\n int n = int.Parse(s[2]);\n double dx = (double) x;\n double dy = (double) y;\n\n long mina = 0, minb = 0;\n double min = long.MaxValue;\n for (long b = 1; b <= n; b++)\n {\n double db = (double)b;\n long aMin = b * x / y;\n long aMax = Convert.ToInt64(Math.Ceiling(db * dx / dy));\n\n for (long a = aMin; a <= aMax; a++)\n {\n double da = (double)a;\n double d = Math.Abs(dx / dy - da / db);\n d = Math.Floor(d * 1e15) / 1e15;\n if (d < min)\n {\n min = d;\n mina = a;\n minb = b;\n }\n }\n }\n\n Console.WriteLine(mina + \"/\" + minb);\n\n }\n }\n}\n", "src_uid": "827bc6f120aff6a6f04271bc84e863ee"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CyberMainProject\n{\n class CyberMainClass\n {\n static void Main(string[] args)\n {\n int n = Convert.ToInt32(Console.ReadLine());\n int min = 0, max = 0;\n if (n <= 2)\n {\n min = 0;\n max = n;\n }\n else if (n <= 5)\n {\n min = 0;\n max = 2;\n }\n else if (n>5)\n {\n if (n >= 7 && n%7 == 0)\n {\n min = (n/7)*2;\n max = (n/7)*2;\n }\n else\n {\n if (n == 6)\n {\n min = 1;\n max = 2;\n }\n else\n {\n int m = n/7;\n min = m *2;\n max = m *2;\n int t = n-(m*7);\n if (t <= 2)\n {\n max += t;\n }\n else\n {\n\n max += 2;\n if (t == 6)\n {\n min +=1;\n }\n }\n }\n }\n }\n Console.WriteLine(min + \" \" +max);\n }\n }\n}\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CF_273_d {\n public class Program {\n\n public static int r;\n public static int g;\n public static int h;\n public static int cntRG;\n public static ulong[] a;\n public static ulong[] ap;\n public static int n;\n public static int c1;\n public static int c2;\n public static ulong max = 1000000007;\n //public static ulong max = 1000000000;\n public static ulong maxCnt = 0;\n\n public static void Main(string[] args) {\n\n string[] str = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);\n r = int.Parse(str[0]);\n g = int.Parse(str[1]);\n\n ulong cnt = Func1();\n \n Console.WriteLine(cnt);\n Console.ReadLine();\n }\n\n public static ulong Func1() { \n\n double d = 1 + 4 * (r + g) * 2;\n double x = (-1 + Math.Sqrt(d)) / 2;\n h = (int)x;\n cntRG = (h + 1) * h / 2;\n c1 = r;\n c2 = g;\n if(g < c1) {\n c1 = g;\n c2 = r;\n }\n\n if(c1 == 0) return 1;\n\n a = new ulong[c1 + 1];\n ap = new ulong[c1 + 1];\n\n a[0] = 1;\n a[1] = 1;\n\n n = 1;\n Func2();\n\n ulong sumA = 0;\n for(int i = 0; i <= c1; i++) { \n sumA += a[i];\n if(sumA > max) {\n maxCnt+= sumA / max;\n sumA = sumA % max; \n }\n } \n\n return sumA;\n\n }\n\n public static void Func2() {\n\n while(n < h) {\n Array.Copy(a, ap, a.Length);\n n++;\n for(int i = 0; i <= c1; i++) {\n int k1 = i - n;\n ulong a1 = 0;\n if(k1 >= 0) a1 = ap[k1];\n\n int cnt = (n + 1) * n / 2;\n int gi = cnt - i;\n ulong a2 = 0;\n if(gi <= c2) {\n a2 = ap[i];\n }\n\n a[i] = a1 + a2;\n\n if(a[i] > max) {\n a[i] %= max;\n }\n } \n }\n }\n }\n}\n", "src_uid": "34b6286350e3531c1fbda6b0c184addc"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces_CS\n{\n class Class1\n {\n static void Main(string[] args)\n {\n new Class1().run(); \n }\n\n int bpb = 0;\n int spb = 0;\n int cpb = 0;\n int bh = 0;\n int sh = 0;\n int ch = 0;\n int bp = 0;\n int sp = 0;\n int cp = 0;\n long price = 0;\n\n void run()\n {\n string burger = Console.ReadLine();\n \n for (int i = 0; i < burger.Length; i++)\n {\n if (burger[i] == 'B') bpb++;\n if (burger[i] == 'S') spb++;\n if (burger[i] == 'C') cpb++;\n }\n string[] tokens = Console.ReadLine().Split();\n bh = int.Parse(tokens[0]);\n sh = int.Parse(tokens[1]);\n ch = int.Parse(tokens[2]);\n\n tokens = Console.ReadLine().Split();\n bp = int.Parse(tokens[0]);\n sp = int.Parse(tokens[1]);\n cp = int.Parse(tokens[2]);\n\n price = long.Parse(Console.ReadLine());\n\n long ox = 1;\n long nx = 2;\n if (can(1))\n {\n while (can(nx))\n {\n ox <<= 1;\n nx <<= 1;\n }\n long ans = ox;\n while (ox <= nx)\n {\n long mid = (ox + nx) / 2;\n if (can(mid))\n {\n ans = mid;\n ox = mid + 1;\n }\n else\n {\n nx = mid - 1;\n }\n }\n Console.WriteLine(ans);\n }\n else\n {\n Console.WriteLine(0);\n }\n \n }\n\n bool can(long burgers)\n {\n long cr = Math.Max(0,(cpb * burgers) - ch);\n long br = Math.Max(0,(bpb * burgers) - bh);\n long sr = Math.Max(0,(spb * burgers) - sh);\n long total = br * bp + sr * sp + cr * cp;\n return total <= price;\n }\n\n }\n\n \n}\n", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\n\nclass Solution\n{\n\tstatic void Main (string[] args)\n\t{\n\t\tint[] nums = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();\n\t\tint n = nums [0];\n\t\tint s = nums [1];\n\t\tint target = nums [2];\n\t\tint[] v = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();\n\t\tstring c = Console.ReadLine ();\n\n\t\tList nodes = new List ();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnodes.Add (new Node (i, v [i], c [i]));\n\t\t}\n\t\tnodes.ForEach (node => node.AddNeighbors (nodes));\n\n\t\tNode initialNode = new Node (s - 1, 0, ' ');\n\t\tinitialNode.Neighbors = nodes;\n\n\t\tList[] search = new List[n * n + 2];\n\t\tfor (int i = 0; i < search.Length; i++) {\n\t\t\tsearch [i] = new List ();\n\t\t}\n\t\tsearch [0].Add (new State{ Missing = target, Current = initialNode });\n\t\tbool[,] expanded = new bool[target + 1, n];\n\n\t\tfor (int t = 0; t < search.Length; t++) {\n\t\t\tforeach (State state in search[t]) {\n\t\t\t\tif (state.Solved) {\n\t\t\t\t\tConsole.WriteLine (t - 1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (expanded [state.Missing, state.Current.Index])\n\t\t\t\t\tcontinue;\n\t\t\t\texpanded [state.Missing, state.Current.Index] = true;\n\t\t\t\tforeach (State s2 in state.Expand()) {\n\t\t\t\t\tsearch [s2.Time].Add (s2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tConsole.WriteLine (-1);\n\t}\n\n\tclass State {\n\t\tpublic int Missing;\n\t\tpublic Node Current;\n\t\tpublic int Time;\n\n\t\tpublic bool Solved => Missing <= 0;\n\n\t\tpublic IEnumerable Expand() {\n\t\t\tforeach(Node n in Current.Neighbors) {\n\t\t\t\tState s = new State();\n\t\t\t\ts.Current = n;\n\t\t\t\ts.Missing = Missing - n.Value;\n\t\t\t\ts.Time = Time + Current.Dist(n);\n\t\t\t\tyield return s;\n\t\t\t}\n\t\t}\n\t}\n\n\tclass Node {\n\t\tpublic int Index;\n\t\tpublic int Value;\n\t\tpublic char Color;\n\t\tpublic List Neighbors;\n\n\t\tpublic Node(int index, int value, char color) {\n\t\t\tthis.Index = index;\n\t\t\tthis.Value = value;\n\t\t\tthis.Color = color;\n\t\t}\n\n\t\tpublic int Dist(Node n) {\n\t\t\treturn Math.Abs(Index - n.Index) + (Color == ' ' ? 1 : 0);\n\t\t}\n\n\t\tpublic void AddNeighbors(List nodes) {\n\t\t\tNeighbors = nodes.Where (n => n.Color != this.Color && n.Value > this.Value).ToList ();\n\t\t}\n\t}\n}", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\n\nnamespace Practise\n{\n class Program\n {\n public static void Main()\n {\n String input = Console.ReadLine();\n String pending = Console.ReadLine();\n\n String left = input.Substring(0, input.IndexOf('|'));\n String right = input.Substring(input.IndexOf('|') + 1);\n int lLeft = left.Length;\n int lRight = right.Length;\n\n int diff = Math.Abs(lLeft - lRight);\n if (diff > pending.Length || (pending.Length - diff) % 2 != 0)\n {\n Console.WriteLine(\"Impossible\");\n }\n else\n {\n int expLength = (lLeft + lRight + pending.Length) / 2;\n int i = 0;\n while (left.Length < expLength)\n {\n left += pending[i++];\n }\n while (right.Length < expLength)\n {\n right += pending[i++];\n }\n Console.WriteLine(left + \"|\" + right);\n }\n }\n }\n}", "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ChallengePennants\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n long n = long.Parse(s);\n if (n <= 10)\n {\n Console.WriteLine(1);\n }\n else\n {\n long x = n / 2 + n / 3 + n / 5 + n / 7;\n x -= n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35;\n x += n / 30 + n / 42 + n / 70 + n / 105;\n x -= n / 210;\n Console.WriteLine(\"{0:d}\", n - x);\n }\n }\n }\n}\n", "src_uid": "e392be5411ffccc1df50e65ec1f5c589"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Solver.Ex;\nusing Debug = System.Diagnostics.Debug;\nusing Watch = System.Diagnostics.Stopwatch;\nusing StringBuilder = System.Text.StringBuilder;\nnamespace Solver\n{\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Integer();\n var a = sc.Integer();\n var b = sc.Integer();\n var k = sc.Integer();\n const long mod = (long)1e9 + 7;\n var dp = new long[5050];\n dp[a]++;\n for (int _ = 0; _ < k; _++)\n {\n var ndp = new long[5050];\n for (int i = 1; i <= n; i++)\n {\n if (i == b) continue;\n var d = Math.Abs(b - i) - 1;\n var l = Math.Max(1, i - d);\n var r = Math.Min(n, i + d);\n ndp[l] += dp[i];\n ndp[i] -= dp[i];\n ndp[i + 1] += dp[i];\n ndp[r + 1] -= dp[i];\n }\n for (int i = 1; i <= n; i++)\n ndp[i] = (ndp[i] + ndp[i - 1]) % mod;\n dp = ndp;\n }\n long ret = 0;\n for (int i = 1; i <= n; i++)\n ret = (ret + dp[i]) % mod;\n IO.Printer.Out.WriteLine((ret + mod) % mod);\n }\n internal IO.StreamScanner sc;\n }\n\n #region Main and Settings\n static class Program\n {\n static void Main(string[] arg)\n {\n#if DEBUG\n var errStream = new System.IO.FileStream(@\"..\\..\\dbg.out\", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);\n Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, \"debugStream\"));\n Debug.AutoFlush = false;\n var sw = new Watch(); sw.Start();\n try\n {\n#endif\n var solver = new Solver();\n solver.sc = new IO.StreamScanner(Console.OpenStandardInput());\n solver.Solve();\n IO.Printer.Out.Flush();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.Error.WriteLine(ex.Message);\n Console.Error.WriteLine(ex.StackTrace);\n }\n finally\n {\n sw.Stop();\n Console.ForegroundColor = ConsoleColor.Green;\n Console.Error.WriteLine(\"Time:{0}ms\", sw.ElapsedMilliseconds);\n Debug.Close();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n }\n#endif\n }\n\n\n }\n #endregion\n}\n#region IO Helper\nnamespace Solver.IO\n{\n public class Printer : System.IO.StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, IEnumerable source) { Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, IEnumerable source) { WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(System.IO.Stream stream) { iStream = stream; }\n private readonly System.IO.Stream iStream;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n private bool eof = false;\n public bool IsEndOfStream { get { return eof; } }\n const byte lb = 33, ub = 126, el = 10, cr = 13;\n public byte read()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }\n public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }\n public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }\n public string Scan()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n StringBuilder sb = null;\n var enc = System.Text.UTF8Encoding.Default;\n do\n {\n for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;\n if (ptr < len) break;\n ptr = 0;\n if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return \"\"; }\n } while (true);\n do\n {\n var f = ptr;\n for (; ptr < len; ptr++)\n if (buf[ptr] < lb || ub < buf[ptr])\n //if(buf[i]==cr||buf[i]==el)\n {\n string s;\n if (sb == null) s = enc.GetString(buf, f, ptr - f);\n else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }\n ptr++; return s;\n }\n if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));\n else sb.Append(enc.GetChars(buf, ptr, len - ptr));\n ptr = 0;\n\n }\n while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true; return (sb != null) ? sb.ToString() : \"\";\n }\n public long Long()\n {\n long ret = 0; byte b = 0; bool isMynus = false;\n const byte zr = 48, nn = 57, my = 45;\n do b = read();\n while (b != my && (b < zr || nn < b));\n if (b == my) { isMynus = true; b = read(); }\n for (; true; b = read())\n if (b < zr || nn < b)\n return isMynus ? -ret : ret;\n else ret = ret * 10 + b - zr;\n }\n public int Integer()\n {\n int ret = 0; byte b = 0; bool isMynus = false;\n const byte zr = 48, nn = 57, my = 45;\n do b = read();\n while (b != my && (b < zr || nn < b));\n if (b == my) { isMynus = true; b = read(); }\n for (; true; b = read())\n if (b < zr || nn < b)\n return isMynus ? -ret : ret;\n else ret = ret * 10 + b - zr;\n }\n public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }\n public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }\n public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }\n public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }\n public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }\n public void Flush() { iStream.Flush(); }\n }\n}\n#endregion\n#region Extension\nnamespace Solver.Ex\n{\n static public partial class EnumerableEx\n {\n static public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public T[] Enumerate(this int n, Func f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }\n }\n}\n#endregion", "src_uid": "142b06ed43b3473513995de995e19fc3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\n\nnamespace CF\n{\n public static class FromConsole\n {\n public static T To(this string input) where T : IConvertible\n {\n return (T)Convert.ChangeType(input, typeof(T));\n }\n\n public static T[] ToArrayOf(this string input, char? delimiter = null) where T : IConvertible\n {\n IEnumerable sequence = delimiter == null ? input.Select(x => x.ToString()) : input.Split(delimiter.Value);\n\n return sequence.Select(x => x.ToString().To()).ToArray();\n }\n\n public static T[] ToArrayOf(int count) where T : IConvertible\n {\n T[] output = new T[count];\n\n for (int i = 0; i < count; i++)\n {\n output[i] = Console.ReadLine().To();\n }\n\n return output;\n }\n\n public static T[] ToArrayOf(T value, int count)\n {\n return Enumerable.Repeat(value, count).ToArray();\n }\n\n public static T[][] ToMatrixOf(int n, char? delimiter = null) where T : IConvertible\n {\n T[][] output = new T[n][];\n\n for (int i = 0; i < n; i++)\n {\n output[i] = Console.ReadLine().ToArrayOf(delimiter);\n }\n\n return output;\n }\n\n public static T[][] ToMatrixOf(T value, int n, int m)\n {\n T[][] output = new T[n][];\n\n for (int i = 0; i < n; i++)\n {\n output[i] = ToArrayOf(value, m);\n }\n\n return output;\n }\n\n public static Tuple IndexOf(this T[][] input, params T[] targets)\n {\n for (int i = 0; i < input.Length; i++)\n {\n for (int j = 0; j < input[0].Length; j++)\n {\n if (targets.Any(x => x.Equals(input[i][j])))\n {\n return new Tuple(i, j);\n }\n }\n }\n\n return new Tuple(-1, -1);\n }\n\n public static void AddToList(this Dictionary> input, T k, U v)\n {\n if (input.ContainsKey(k))\n {\n input[k].Add(v);\n }\n else\n {\n input.Add(k, new List() { v });\n }\n }\n\n public static void AddAndIncrement(this Dictionary input, T k)\n {\n if (input.ContainsKey(k))\n {\n input[k]++;\n }\n else\n {\n input.Add(k, 1);\n }\n }\n\n public static string ToBinary(this long input)\n {\n return Convert.ToString(input, 2);\n }\n\n public static long ToDecimal(this string input)\n {\n return Convert.ToInt32(input, 2);\n }\n\n public static long Binomial(long n, long k)\n {\n long r = 1;\n long d;\n if (k > n) return 0;\n for (d = 1; d <= k; d++)\n {\n r *= n--;\n r /= d;\n }\n return r;\n }\n }\n\n class Program\n {\n static void Main(string[] args)\n {\n int n = Console.ReadLine().To();\n string s = Console.ReadLine();\n\n char previous = ' ';\n bool duplicates = false;\n for (int i = 0; i < s.Length; i++)\n {\n char c = s[i];\n\n if (c == previous && c != '?')\n {\n duplicates = true;\n break;\n }\n\n previous = c;\n }\n\n bool canConfigure = false;\n if (!duplicates)\n {\n for (int i = 0; i < s.Length; i++)\n {\n char c = s[i];\n\n if (c == '?')\n {\n if (i == 0 || i == s.Length - 1)\n {\n canConfigure = true;\n break;\n }\n else\n {\n char l = s[i - 1];\n char r = s[i + 1];\n\n if (l == r || l == '?' || r == '?')\n {\n canConfigure = true;\n break;\n }\n }\n }\n }\n }\n\n Console.WriteLine(canConfigure ? \"Yes\" : \"No\");\n //Console.ReadKey();\n }\n }\n\n //public class SegmentTreeLadder\n //{\n // private Tuple[] tree;\n // private List input;\n\n // public SegmentTreeLadder(List input)\n // {\n // this.input = input;\n // tree = new Tuple[4 * input.Count];\n // Build(1, 0, input.Count - 1);\n // }\n\n // public Tuple RMQ(int i, int j)\n // {\n // return Query(1, 0, input.Count - 1, i, j);\n // }\n\n // private int Left(int p)\n // {\n // return 2 * p;\n // }\n\n // private int Right(int p)\n // {\n // return (2 * p) + 1;\n // }\n\n // private Tuple Compose(Tuple left, Tuple right)\n // {\n // if (left.Item1 && right.Item1)\n // {\n // if (left.Item2 == '^' && right.Item2 == 'v'\n // || left.Item2 == '=' && right.Item2 == '='\n // || left.Item2 == '^' && right.Item2 == '='\n // || left.Item2 == '=' && right.Item2 == 'v')\n // {\n // new Tuple(true, '=');\n // }\n\n // // also need another char sentinel for 'mixed'\n // // really don't need tuple, just \n // }\n\n // return new Tuple(false, '=');\n // }\n\n // private void Build(int p, int leftIndex, int rightIndex)\n // {\n // if (leftIndex == rightIndex)\n // {\n // // EDIT: store summarized node val here\n // tree[p] = default(TSummary);\n // return;\n // }\n\n // int middle = (leftIndex + rightIndex) / 2;\n // Build(Left(p), leftIndex, middle);\n // Build(Right(p), middle + 1, rightIndex);\n\n // // EDIT: just key into tree here and get the summary of both nodes.\n // // this is just an access, no actual work is being done here.\n // TSummary leftNode = tree[Left(p)];\n // TSummary rightNode = tree[Right(p)];\n // // EDIT: do tree[p] = f(leftIndex, rightIndex) here\n // tree[p] = Compose(leftNode, rightNode);\n // }\n\n // private TSummary Query(int p, int leftIndex, int rightIndex, int i, int j)\n // {\n // // if the current segment (l, r) is outside the requested range (i, j)\n // if (i > rightIndex || j < leftIndex)\n // {\n // return default(TSummary); // EDIT: should be min(T), but order would need to be defined\n // }\n // // if the current segment (l, r) is inside the requested range (i, j)\n // if (i <= leftIndex && j >= rightIndex)\n // {\n // return tree[p];\n // }\n\n // int middle = (leftIndex + rightIndex) / 2;\n // TSummary leftNode = Query(Left(p), leftIndex, middle, i, j);\n // TSummary rightNode = Query(Right(p), middle + 1, rightIndex, i, j);\n\n // if (leftNode.Equals(default(TSummary))) // EDIT: again, should be min(T)\n // {\n // return rightNode;\n // }\n // if (rightNode.Equals(default(TSummary))) // EDIT: again, should be min(T)\n // {\n // return leftNode;\n // }\n\n // return Compose(leftNode, rightNode);\n // }\n //}\n\n public class SegmentTreeGeneralized\n {\n private TSummary[] tree;\n private List input;\n\n public SegmentTreeGeneralized(List input)\n {\n this.input = input;\n tree = new TSummary[4 * input.Count];\n Build(1, 0, input.Count - 1);\n }\n\n public TSummary RMQ(int i, int j)\n {\n return Query(1, 0, input.Count - 1, i, j);\n }\n\n private int Left(int p)\n {\n return 2 * p;\n }\n\n private int Right(int p)\n {\n return (2 * p) + 1;\n }\n\n private TSummary Compose(TSummary left, TSummary right)\n {\n return default(TSummary);\n }\n\n private void Build(int p, int leftIndex, int rightIndex)\n {\n if (leftIndex == rightIndex)\n {\n // EDIT: store summarized node val here\n tree[p] = default(TSummary);\n return;\n }\n\n int middle = (leftIndex + rightIndex) / 2;\n Build(Left(p), leftIndex, middle);\n Build(Right(p), middle + 1, rightIndex);\n\n // EDIT: just key into tree here and get the summary of both nodes.\n // this is just an access, no actual work is being done here.\n TSummary leftNode = tree[Left(p)];\n TSummary rightNode = tree[Right(p)];\n // EDIT: do tree[p] = f(leftIndex, rightIndex) here\n tree[p] = Compose(leftNode, rightNode);\n }\n\n private TSummary Query(int p, int leftIndex, int rightIndex, int i, int j)\n {\n // if the current segment (l, r) is outside the requested range (i, j)\n if (i > rightIndex || j < leftIndex)\n {\n return default(TSummary); // EDIT: should be min(T), but order would need to be defined\n }\n // if the current segment (l, r) is inside the requested range (i, j)\n if (i <= leftIndex && j >= rightIndex)\n {\n return tree[p];\n }\n\n int middle = (leftIndex + rightIndex) / 2;\n TSummary leftNode = Query(Left(p), leftIndex, middle, i, j);\n TSummary rightNode = Query(Right(p), middle + 1, rightIndex, i, j);\n\n if (leftNode.Equals(default(TSummary))) // EDIT: again, should be min(T)\n {\n return rightNode;\n }\n if (rightNode.Equals(default(TSummary))) // EDIT: again, should be min(T)\n {\n return leftNode;\n }\n\n return Compose(leftNode, rightNode);\n }\n }\n}\n", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _680B\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] input1 = Console.ReadLine().Split(' '), input2 = Console.ReadLine().Split(' ');\n int n = int.Parse(input1[0]), a = int.Parse(input1[1]) - 1;\n bool[] t = new bool[n];\n for (int i = 0; i < n; i++) t[i] = input2[i] == \"1\";\n\n int result = 0, distance = 0;\n while (true)\n {\n bool leftExist = (a - distance) >= 0, rightExist = (a + distance) < n;\n if (!leftExist && !rightExist) break;\n\n if ((distance == 0 && t[a]) ||\n (distance > 0 && leftExist && !rightExist && t[a - distance]) ||\n (distance > 0 && !leftExist && rightExist && t[a + distance]))\n {\n result++;\n }\n else if (distance > 0 && leftExist && rightExist && t[a - distance] && t[a + distance])\n {\n result += 2;\n }\n\n distance++;\n }\n\n Console.WriteLine(result);\n //Console.ReadLine();\n }\n }\n}\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Tasks_010918\n{\n public class Program\n {\n public static string LongStringChange (string s)\n {\n string s1 = \"\"; \n if (s.Length < 10)\n Console.WriteLine(s);\n else\n {\n string b = s.Substring(1, s.Length - 2);\n int count = b.Length;\n\n s1 = string.Concat(s.Replace(b, Convert.ToString(count)));\n Console.WriteLine(s1); \n\n }\n return s1;\n }\n\n public static string StringChangedMethod (string x)\n {\n x = x.ToLower(); \n string y = \"AOEYUI\".ToLower();\n \n int index = 0;\n for (int i = 0; i < x.Length; i++)\n {\n for (int j = 0; j < y.Length; j++)\n {\n if (x[i] == y[j])\n {\n index = i; \n x = x.Remove(index, 1); \n }\n index = 0;\n } \n }\n\n for (int i = 0; i < x.Length; i++)\n {\n if (i % 2 == 0)\n x = x.Insert(i, Convert.ToString('.'));\n }\n \n return x;\n }\n \n static bool IsAllDigitsDifferent(int n)\n {\n string toString = n.ToString(); // 1988\n\n Dictionary charsOccurence = new Dictionary();\n foreach (char item in toString)\n {\n if (!charsOccurence.ContainsKey(item))\n {\n charsOccurence[item] = 1;\n }\n else return false;\n }\n return true;\n }\n\n public static int GetNextDistinctInteger(int n)\n {\n for(int i = n + 1; i <= 9012; i++)\n {\n if (IsAllDigitsDifferent(i))\n {\n return i;\n }\n }\n return 0;\n }\n\n\n static int BeatifullYearFunc (int n)\n {\n IList y = new List(); \n for (int i = n + 1; i < 9000; i++)\n {\n string v = Convert.ToString(i);\n Dictionary by = new Dictionary();\n bool isTwiced = false;\n foreach(char x in v)\n {\n if (!by.ContainsKey(x))\n {\n by[x] = 1;\n }\n else\n {\n by[x]++;\n }\n if (by[x] == 2)\n {\n isTwiced = true;\n break; \n } \n } \n \n if (isTwiced == false)\n {\n n = Convert.ToInt32(y[i]);\n Console.WriteLine(n);\n } \n \n } \n \n return n;\n }\n\n public static string ReturnStrMethod (string str, string subStr)\n {\n for (int i = 0; i < str.Length; i++)\n {\n if (str.ToLower(). Contains(subStr.ToLower()))\n {\n int n = str.IndexOf(subStr);\n str = str.Replace(subStr, \" \");\n }\n }\n\n return str;\n }\n\n public static int CountElephantSteps (int x)\n {\n int res = 0;\n if (x % 5 == 0)\n {\n res = x / 5;\n Console.WriteLine(\"Количество шагов = {0}\", res);\n }\n else\n {\n if (x % 4 == 0)\n {\n res = x / 4;\n Console.WriteLine(\"Количество шагов = {0}\", res);\n }\n else\n {\n\n if (x % 3 == 0)\n {\n res = x / 3;\n Console.WriteLine(\"Количество шагов = {0}\", res);\n }\n else\n {\n\n if (x % 2 == 0)\n {\n res = x / 2;\n Console.WriteLine(\"Количество шагов = {0}\", res);\n }\n else\n {\n\n if (x % 1 == 0)\n {\n res = x / 1;\n Console.WriteLine(\"Количество шагов = {0}\", res);\n }\n }\n }\n }\n }\n return res;\n }\n\n public static int CountResultFunc (int n, int[] points)\n {\n int countResult = 0;\n int max = points[0];\n int min = points[0];\n int indexMin = 0, indexMax = 0;\n \n for (int i = 0; i < points.Length; i++)\n { \n if (points[i] < min)\n {\n min = points[i]; \n indexMin = i; \n countResult++;\n }\n indexMin = 0; \n }\n Console.WriteLine(\"------------------\");\n for (int i = 0; i < points.Length; i++)\n {\n if (points[i] > max)\n {\n max = points[i]; \n indexMax = i; \n countResult++;\n }\n indexMax = 0;\n }\n Console.WriteLine(\"Количество удивительных выступлений = {0}\", countResult);\n return countResult;\n }\n\n \n static void Main(string[] args)\n {\n #region Taks 1\n //Console.WriteLine(\"Введите количество строк\");\n //int n = Convert.ToInt32(Console.ReadLine());\n //string[] s = new string[n];\n\n //if (n > 0)\n //{\n // for (int i = 0; i < n; i++)\n // {\n // Console.WriteLine(\"Введите слово\");\n // s[i] = Console.ReadLine();\n // }\n\n // foreach (string item in s)\n // {\n // LongStringChange(item);\n // }\n\n //}\n #endregion\n\n #region Task 2\n //Console.WriteLine(\"Введите слово\");\n //string str = Console.ReadLine();\n\n //Console.WriteLine(StringChangedMethod(str));\n\n #endregion\n\n #region Taks 3\n //Console.WriteLine(\"Введите количество строк\");\n //int n = Convert.ToInt32(Console.ReadLine());\n //string[] num = new string[n];\n //int x = 0;\n\n //if (n > 0)\n //{\n // for (int i = 0; i < n; i++)\n // {\n // Console.WriteLine(\"Введите операцию, которую надо выполнить\");\n // num[i] = Console.ReadLine();\n // }\n\n // foreach (string item in num)\n // {\n // if (item == \"x++\" || item == \"++x\")\n // x++;\n // else if (item == \"x--\" || item == \"--x\")\n // x--;\n // }\n\n // Console.WriteLine(x);\n\n //}\n #endregion\n\n #region Task 4\n //Console.WriteLine(\"Введите слово\");\n //string str = Console.ReadLine();\n //StringBuilder sb = new StringBuilder(str);\n\n\n //for (int i = 0; i < sb.Length; i++)\n //{\n // sb[0] = Char.ToUpper(sb[0]);\n //}\n\n //string newString = sb.ToString();\n //Console.WriteLine(newString);\n #endregion\n\n #region Task 5\n //Console.WriteLine(\"Введите слово\");\n //string str = Console.ReadLine();\n\n //if (str.Length % 2 == 0)\n // Console.WriteLine(\"Chat with her\");\n //else\n // Console.WriteLine(\"Ignore him\");\n #endregion\n\n #region Task 6\n //Console.WriteLine(\"Введите слово\");\n //string str = Console.ReadLine();\n //StringBuilder sb = new StringBuilder(str);\n\n //for (int i = 0; i < sb.Length; i++)\n //{\n // if (Char.IsLower(sb[0]) == true || Char.IsUpper(sb[i]) == true)\n // {\n // sb[0] = Char.ToUpper(sb[0]);\n // sb[i] = Char.ToLower(sb[i]);\n // }\n // else \n // {\n // sb[i] = sb[i]; \n // }\n //}\n\n //string newString = sb.ToString();\n //Console.WriteLine(newString);\n #endregion\n\n #region Task 7\n //Console.WriteLine(\"Введите целое число\");\n //int n = Convert.ToInt32(Console.ReadLine());\n\n //string s = n.ToString();\n //int count = 0;\n\n //for (int i = 0; i < s.Length; i++)\n //{\n // if (s[i] == '4' || s[i] == '7')\n // {\n // count++; \n // } \n //}\n\n //if (count == 4 || count == 7)\n // Console.WriteLine(\"YES\");\n //else\n // Console.WriteLine(\"NO\");\n #endregion\n\n #region Task 8\n //string s = \"\";\n //string t = \"\";\n\n //Console.WriteLine(\"Введите слово\");\n //s = Console.ReadLine();\n //char[] reversed = s.Reverse().ToArray();\n //string str = new string(reversed);\n\n //Console.WriteLine(\"Введите слово\");\n //t = Console.ReadLine();\n\n //if (String.Equals(str, t) == true)\n // Console.WriteLine(\"YES\");\n //else\n // Console.WriteLine(\"NO\");\n\n #endregion\n\n #region Task 9\n string input = Console.ReadLine();\n\n int n = Convert.ToInt32(input);\n\n int next = GetNextDistinctInteger(n);\n\n Console.WriteLine(next);\n Console.ReadLine();\n #endregion\n\n #region Task 10\n /*\n Console.WriteLine(\"Введите целое число\");\n int x = Convert.ToInt32(Console.ReadLine());\n\n Console.WriteLine(CountElephantSteps(x));\n */\n #endregion\n\n #region Task 11\n //Console.WriteLine(\"Введите слово\");\n //string str = Console.ReadLine();\n //string f = \"WUB\";\n //Console.WriteLine(ReturnStrMethod(str, f));\n #endregion\n\n #region Task 12\n //Console.WriteLine(\"Введите целое число\");\n //int x = Convert.ToInt32(Console.ReadLine());\n //int[] points = new int[x];\n\n //for (int i = 0; i < x; i++)\n //{\n // Console.WriteLine(\"Введите целое число\");\n // points[i] = Convert.ToInt32(Console.ReadLine());\n //}\n\n //Console.WriteLine(\"------------------\");\n\n //for (int i = 0; i < points.Length; i++)\n //{\n // Console.WriteLine(points[i]);\n //}\n\n //Console.WriteLine(\"------------------\");\n //CountResultFunc(x, points);\n #endregion\n\n #region Task 13\n //Console.WriteLine(\"Введите строку\");\n //string str = Console.ReadLine();\n //string s = \"HQ9+\";\n //int n = 0;\n\n //for (int i = 0; i < str.Length; i++)\n //{\n // for (int j = 0; j < s.Length; j++)\n // {\n // if (str[i] == s[j])\n // n = 1; \n // } \n //}\n\n //if (n > 0)\n //{\n // Console.WriteLine(\"YES\");\n //} else { Console.WriteLine(\"NO\"); }\n\n\n #endregion\n\n #region Task 14\n //Console.WriteLine(\"Введите число строк\");\n //int n = Convert.ToInt32(Console.ReadLine());\n\n //Console.WriteLine(\"Введите число столбцов\");\n //int m = Convert.ToInt32(Console.ReadLine());\n //char[,] y = new char[n, m];\n\n //char[] colors = { 'C', 'M', 'Y', 'W', 'G', 'B' }; \n //int res = 0;\n\n //for (int i = 0; i < n; i++)\n //{\n // for (int j = 0; j < m; j++)\n // {\n // Console.WriteLine(\"введите любой символ из {0}\", colors);\n // y[i, j] = Convert.ToChar(Console.ReadLine());\n // Console.WriteLine();\n // }\n //}\n\n //for (int i = 0; i < n; i++)\n //{\n // for (int j = 0; j < m; j++)\n // {\n // Console.Write(y[i, j] + \"\\t\");\n // }\n // Console.WriteLine();\n //}\n\n //for (int i = 0; i < n; i++)\n //{\n // for (int j = 0; j < m; j++)\n // {\n // for (int z = 0; z < colors.Length; z++)\n // {\n // if ((y[i, j].CompareTo('W') == 0 || y[i, j].CompareTo('B') == 0 || y[i, j].CompareTo('G') == 0) && (y[i, j].CompareTo('Y') == -1 || y[i, j].CompareTo('C') == -1 || y[i, j].CompareTo('M') == -1))\n // res = 1;\n // else\n // {\n // res = 0;\n // }\n // }\n // }\n //}\n\n //if (res == 1)\n // Console.WriteLine(\"#Black&White\");\n //else { Console.WriteLine(\"#Color\"); }\n\n\n\n #endregion\n\n\n\n Console.ReadLine();\n } \n }\n}\n", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\nnamespace CodeForces\n{\n class Program\n {\n static void Main(string[] args)\n {\n //var n = Int64.Parse(Console.ReadLine());\n //var a = Array.ConvertAll(Console.ReadLine().Split(' '), Int64.Parse);\n var s = Console.ReadLine();\n var chs = 0;\n var qms = 0;\n var sns = 0;\n for (int i = 0; i < s.Length; i++)\n {\n switch (s[i])\n {\n case '?':\n qms++;\n break;\n case '*':\n sns++;\n break;\n default:\n chs++;\n break;\n }\n }\n var k = Int32.Parse(Console.ReadLine());\n var possible = true;\n\n if (chs == k)\n {\n sns = 0;\n qms = 0;\n }\n else if (chs < k)\n {\n if (sns > 0)\n {\n qms = 0;\n sns = 1;\n }\n else\n {\n possible = false;\n }\n }\n else //chs > k\n {\n if (chs - k <= sns + qms)\n {\n qms = Math.Min(chs - k, qms);\n sns = chs - k - qms;\n }\n else\n {\n possible = false;\n }\n }\n\n var ans = new StringBuilder();\n\n if (possible)\n {\n for (int i = 0; i < s.Length; i++)\n {\n if (s[i] == '?' && qms > 0)\n {\n qms--;\n ans.Remove(ans.Length - 1, 1);\n }\n else if (s[i] == '*' && sns > 0)\n {\n sns--;\n if (chs < k)\n {\n for (int j = 0; j < k - chs; j++)\n {\n ans.Append(ans[ans.Length - 1]);\n }\n }\n else\n {\n ans.Remove(ans.Length - 1, 1);\n }\n }\n else if (s[i] != '?' && s[i] != '*')\n {\n ans.Append(s[i]);\n }\n }\n for (int i = 0; i < ans.Length; i++)\n {\n Console.Write(ans[i]);\n }\n }\n else\n {\n Console.WriteLine(\"Impossible\");\n }\n \n }\n }\n}", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Threading.Tasks;\n\n\n\nnamespace ConsoleApplication1.CodeForces\n{\n static class _4032123\n {\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);\n\n class Node\n {\n public int D { get; set; }\n public int F { get; set; }\n public int T { get; set; }\n public long C { get; set; }\n }\n static void Main(String[] args)\n {\n var n = int.Parse(Console.ReadLine().TrimEnd());\n var data = Console.ReadLine().TrimEnd().Split(' ').Select(long.Parse).ToList();\n var bob = new long[n,2];\n bob[n - 1, 0] = data[n - 1];\n bob[n - 1, 1] = -data[n - 1];\n var prev = new int[n];\n prev[n - 1] = 1;\n for (var i = n - 2; i >= 0; i--)\n {\n if(bob[i + 1, 0] > bob[i + 1, 1])\n {\n prev[i] = 0;\n } else\n {\n prev[i] = 1;\n }\n bob[i, 0] = data[i] - Math.Max(bob[i + 1, 0],bob[i + 1, 1] );\n bob[i, 1] = Math.Max(bob[i + 1, 0], bob[i + 1, 1]) - data[i];\n }\n long bobSum = 0;\n var max = Math.Max(bob[0, 0], bob[0, 1]);\n writer.WriteLine((data.Sum()/2.0 - max/2.0) + \" \" + (data.Sum() / 2.0 + max / 2.0));\n writer.Flush();\n\n\n }\n }\n}", "src_uid": "414540223db9d4cfcec6a973179a0216"} {"source_code": "using System;\n\nnamespace Task_41A\n{\n class Program\n {\n /*\n * code\n edoc\n * */\n static void Main(string[] args)\n {\n //string s = Console.ReadLine();\n //string t = Console.ReadLine();\n //string rvc = ReverseString(s);\n\n\n //if (t == rvc)\n // Console.WriteLine(\"YES\");\n //else\n // Console.WriteLine(\"NO\");\n string s = Console.ReadLine();\n string t = Console.ReadLine();\n\n int sLen = s.Length, tLen = t.Length;\n string ans = (sLen == tLen) ? \"YES\" : \"NO\";\n for (int i = 0, j = tLen - 1; i < sLen && j >= 0; i++, j--)\n {\n if (s[i] != t[j])\n {\n ans = \"NO\";\n break;\n\n }\n }\n Console.WriteLine(ans);\n\n }\n\n private static string ReverseString(string s)\n {\n string rvs = \"\";\n for (int i = s.Length - 1; i >= 0; i--)\n {\n rvs += s[i];\n }\n return rvs;\n\n }\n }\n}\n", "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int numb_balls = Convert.ToInt32(Console.ReadLine());\n \n int[] input = new int[numb_balls];\n\n string ins = Console.ReadLine();\n string[] inputs = ins.Split(' ');\n int[] numbers = new int[numb_balls];\n for (int i = 0; i < numb_balls; i++) {\n numbers[i] = Convert.ToInt32(inputs[i]); \n }\n\n bool good_set = false;\n\n int[] unique = numbers.Distinct().ToArray();\n Array.Sort(unique);\n\n numb_balls = unique.Length;\n\n for (int i = 0; i < numb_balls - 2; i++)\n {\n int first_ball = unique[i];\n int second_ball = unique[i + 1];\n int third_ball = unique[i + 2];\n if (Math.Abs(first_ball - second_ball) == 1 && Math.Abs(second_ball - third_ball) == 1)\n {\n good_set = true;\n }\n }\n if (good_set)\n {\n Console.WriteLine(\"YES\");\n }\n else Console.WriteLine(\"NO\");\n }\n }\n}\n", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Pr1\n{\n class Program\n {\n static void Main()\n {\n long n= Convert.ToInt64(Console.ReadLine());\n long k=n,j=0;\n long sum=0;\n while(k!=0)\n {\n k/=10;\n j++;\n }\n for(long i=j-1;i>0;i--)\n {\n k=(long)Math.Pow(10,i)-1;\n sum+=(n-k)*(i+1);\n n=k;\n }\n sum+=n;\n Console.Write(sum);\n }\n }\n}", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace c\n{\n class Program\n {\n static long gcd(long x,long y)\n {\n return (y==0)?x:gcd(y,x%y);\n }\n\n static void Main(string[] args)\n {\n string[] token = Console.ReadLine().Split();\n long a = long.Parse(token[0]);\n long b = long.Parse(token[1]);\n long x = long.Parse(token[2]);\n long y = long.Parse(token[3]);\n long g = gcd(x, y);\n x /= g; y /= g;\n long max = Math.Min(a / x, b / y);\n Console.WriteLine(\"{0} {1}\", max * x, max * y);\n }\n }\n}\n", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"source_code": "/*\ncsc -debug D.cs && mono --debug D.exe <<< \"\n\n{ max = 100, ops1 = 382, ops2 = 2182 }\n{ max = 100 }\nTotal counts: 3913\nDifferent GCDs: 382\nMax number of divisors: 11 (60 72 84 90 96)\n\n{ max = 1000, ops1 = 6069, ops2 = 61945 }\n{ max = 1000 }\nTotal counts: 391617\nDifferent GCDs: 6069\nMax number of divisors: 31 (840)\n\n{ max = 10000, ops1 = 83668, ops2 = 1326800 }\n{ max = 10000 }\nTotal counts: 39205029\nDifferent GCDs: 83668\nMax number of divisors: 63 (7560 9240)\n\n{ max = 100000, ops1 = 1066750, ops2 = 24091272 }\n{ max = 100000 }\nTotal counts: 3920698493\nDifferent GCDs: 1066750\nMax number of divisors: 127 (83160 98280)\n*/\n\nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\nusing System.Reflection;\n\npublic class HelloWorld {\n const ulong MOD = 1000000007ul;\n\n public static void SolveCodeForces() {\n // ShowStats();\n Solve();\n }\n\n static void Solve() {\n var max = cin.NextInt();\n\n var Divs = Helpers.CreateArray(max + 1, _ => new List());\n for (var g = 2; g <= max; g++)\n for (var a = g; a <= max; a += g)\n Divs[a].Add(g);\n\n var Map = Helpers.CreateArray(max + 1, _ => new Dictionary());\n for (var g = 2; g <= max; g++) {\n var counter = Map[g];\n var divs = Divs[g];\n\n counter[g] = max / g;\n for (var i = divs.Count - 2; i >= 0; i--) {\n var sum = 0;\n for (var j = i + 1; j < divs.Count; j++)\n if (divs[j] % divs[i] == 0)\n sum += counter[divs[j]];\n counter[divs[i]] = max / divs[i] - sum;\n }\n }\n\n// for (var g = 2; g <= max; g++) {\n// System.Console.WriteLine(new {g});\n// foreach (var kvp in Map[g])\n// System.Console.WriteLine(\" \" + new { gcd=kvp.Key, cnt=kvp.Value });\n// }\n\n var maxU = (ulong)max;\n var anssum = 0ul;\n var F = new ulong[max + 1];\n for (var g = 2; g <= max; g++) {\n var ag = 0;\n var sum = 0ul;\n foreach (var kvp in Map[g]) {\n var gcd = kvp.Key;\n var count = kvp.Value;\n if (gcd == g)\n ag = count;\n else\n sum = (sum + F[gcd] * (ulong)count) % MOD;\n }\n F[g] = (maxU + sum) * ModInverse(maxU + MOD - (ulong)ag, MOD) % MOD;\n anssum = (anssum + F[g]) % MOD;\n\n// System.Console.WriteLine(new { g, fg=F[g] });\n }\n\n var ans = (1ul + anssum * ModInverse(maxU, MOD)) % MOD;\n System.Console.WriteLine(ans);\n }\n\n public static ulong ModInverse(ulong x, ulong mod) { return ModPow(x, mod - 2L, mod); }\n\n public static ulong ModPow(ulong x, ulong exp, ulong mod) {\n ulong ret = 1ul;\n while (exp > 0) {\n if (exp % 2 == 1) ret = ret * x % mod;\n x = x * x % mod;\n exp /= 2;\n }\n return ret;\n }\n\n static void ShowStats() {\n foreach (var max in new[] { 100, 1000, 10000, 100000 }) {\n // var MapBrute = GetGcdsCounter_Brute(max);\n var Map = GetGcdsCounter_InnerLoop(max);\n System.Console.WriteLine(new { max });\n // Compare(Map, MapBrute);\n System.Console.WriteLine(\"Total counts: \" + Map.Sum(c => (long)c.Dict.Values.Sum()));\n System.Console.WriteLine(\"Different GCDs: \" + Map.Sum(c => c.Dict.Count));\n var maxcnt = Map.Max(c => c.Dict.Count);\n System.Console.WriteLine(\"Max number of divisors: {0} ({1})\", maxcnt, Map.Select((c, i) => new { c, i }).Where(a => a.c.Dict.Count == maxcnt).Select(a => a.i).Join());\n System.Console.WriteLine();\n }\n }\n\n static Counter[] GetGcdsCounter_InnerLoop(int max) {\n var Map = Helpers.CreateArray(max + 1, _ => new Counter());\n\n var ops1 = 0;\n for (var g = 2; g <= max; g++) {\n for (var a = g; a <= max; a += g) {\n Map[a][g] = 0;\n ops1++;\n }\n }\n\n var ops2 = 0;\n for (var g = 2; g <= max; g++) {\n var counter = Map[g];\n counter[g] = max / g;\n\n var divs = counter.Dict.Keys.ToArray();\n Array.Sort(divs, 0, divs.Length);\n\n for (var i = divs.Length - 2; i >= 0; i--) {\n var cnt = max / divs[i];\n for (var j = i + 1; j < divs.Length; j++) {\n if (divs[j] % divs[i] == 0)\n cnt -= counter[divs[j]];\n }\n counter[divs[i]] = cnt;\n }\n\n ops2 += divs.Length * divs.Length;\n }\n\n if (max == 100) {\n for (var g = 1; g <= max; g++) {\n System.Console.WriteLine(new {g});\n foreach (var kvp in Map[g].Dict)\n System.Console.WriteLine(\" \" + new { gcd=kvp.Key, cnt=kvp.Value });\n }\n }\n\n System.Console.WriteLine(new {max, ops1, ops2});\n\n return Map;\n }\n\n static Counter[] GetGcdsCounter_Brute(int max) {\n var Map = Helpers.CreateArray(max + 1, _ => new Counter());\n for (var g = 1; g <= max; g++) {\n for (var x = 1; x <= max; x++) {\n var gcd = (int)GCD((ulong)g, (ulong)x);\n if (gcd > 1)\n Map[g][gcd]++;\n }\n if (max == 100) {\n System.Console.WriteLine(new {g});\n foreach (var kvp in Map[g].Dict)\n System.Console.WriteLine(\" \" + new { gcd=kvp.Key, cnt=kvp.Value });\n }\n }\n return Map;\n }\n\n private static ulong GCD(ulong a, ulong b) {\n while (a != 0 && b != 0) {\n if (a > b)\n a %= b;\n else\n b %= a;\n }\n return a == 0 ? b : a;\n }\n\n static void Compare(Counter[] A, Counter[] B) {\n for (var i = 0; i < A.Length; i++) {\n var C = A[i].Dict;\n var D = B[i].Dict;\n if (C.Count != D.Count) {\n System.Console.WriteLine(new { i, ccount = C.Count, dcount = D.Count });\n return;\n }\n if (!C.Keys.OrderBy(c => c).SequenceEqual(D.Keys.OrderBy(c => c))) {\n System.Console.WriteLine(new { i, ckeys=C.Keys.OrderBy(c => c).Join(), dkeys=D.Keys.OrderBy(c => c).Join() });\n return;\n }\n foreach (var key in C.Keys) {\n if (C[key] != D[key]) {\n System.Console.WriteLine(new { i, ckeys=C.Keys.OrderBy(c => c).Join(), dkeys=D.Keys.OrderBy(c => c).Join() });\n System.Console.WriteLine(new { key, cval=C[key], dval=D[key] });\n }\n }\n }\n System.Console.WriteLine(\"compare ok\");\n }\n\n static Scanner cin = new Scanner();\n static StringBuilder cout = new StringBuilder();\n\n static public void Main () {\n SolveCodeForces();\n // IncreaseStack(SolveCodeForces);\n // System.Console.Write(cout.ToString());\n }\n\n public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)\n {\n var thread = new Thread(action, stackSize);\n thread.Start();\n thread.Join();\n }\n}\n\npublic class Counter {\n public Dictionary Dict;\n public Counter() { Dict = new Dictionary(); }\n public Counter(IEnumerable keys) { Dict = new Dictionary(); foreach (var k in keys) Add(k, 1); }\n public int this[T key] {\n get { int res; return Dict.TryGetValue(key, out res) ? res : 0; }\n set { Dict[key] = value; }\n }\n public void Add(T key, int add) { int res; if (Dict.TryGetValue(key, out res)) Dict[key] = res + add; else Dict[key] = add; }\n}\n\npublic static class Helpers {\n public static string Join(this IEnumerable arr, string sep = \" \") {\n return string.Join(sep, arr);\n }\n\n public static void Swap(ref T a, ref T b) {\n var tmp = a;\n a = b;\n b = tmp;\n }\n\n public static T[] CreateArray(int length, Func itemCreate) {\n var result = new T[length];\n for (var i = 0; i < result.Length; i++)\n result[i] = itemCreate(i);\n return result;\n }\n}\n\npublic class Scanner\n{\n private string[] line = new string[0];\n private int index = 0;\n\n public string Next() {\n if (line.Length <= index) {\n line = Console.ReadLine().Split(' ');\n index = 0;\n }\n var res = line[index];\n index++;\n return res;\n }\n\n public int NextInt() {\n return int.Parse(Next());\n }\n\n public long NextLong() {\n return long.Parse(Next());\n }\n\n public ulong NextUlong() {\n return ulong.Parse(Next());\n }\n\n public string[] Array() {\n line = Console.ReadLine().Split(' ');\n index = line.Length;\n return line;\n }\n\n public int[] IntArray(int emptyPrefixLen = 0) {\n var array = Array();\n var result = new int[emptyPrefixLen + array.Length];\n for (int i = 0; i < array.Length; i++)\n result[emptyPrefixLen + i] = int.Parse(array[i]);\n return result;\n }\n\n public long[] LongArray() {\n var array = Array();\n var result = new long[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = long.Parse(array[i]);\n return result;\n }\n\n public ulong[] UlongArray() {\n var array = Array();\n var result = new ulong[array.Length];\n for (int i = 0; i < array.Length; i++)\n result[i] = ulong.Parse(array[i]);\n return result;\n }\n}", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0"} {"source_code": "using System;\nusing System.Linq;\nusing System.Diagnostics;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\n\nnamespace Program\n{\n\n public class Solver\n {\n public void Solve()\n {\n var t = sc.Double();\n var s = sc.Double();\n var q = sc.Double();\n var add = 1.0 + (q - 1) / q;\n var cnt = 0;\n while (s < t)\n {\n s *= q;\n cnt++;\n }\n IO.Printer.Out.WriteLine(cnt);\n\n }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n\n#region main\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Text;\n using System.Globalization;\n public class Printer : StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, T[] source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, T[] source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }\n\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n'; b = (char)read())\n if (b == 0) break;\n else if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != '-' && (b < '0' || '9' < b));\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public char[] Char(int n) { return enumerate(n, Char); }\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n }\n}\n#endregion\n", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace A_MikeAndPalindrome\n{\n\tstatic class Program\n\t{\n\t\tpublic static string Reverse(this string str)\n\t\t{\n\t\t\tvar charArray = str.ToCharArray();\n\t\t\tArray.Reverse(charArray);\n\t\t\treturn new string(charArray);\n\t\t}\n\n\t\t/// \n\t\t/// Source string\n\t\t/// \n\t\tpublic static string s;\n\n\t\t/// \n\t\t/// Halfs of source string. Second part should be reversed\n\t\t/// \n\t\tpublic static List halfs = new List();\n\n\t\t/// \n\t\t/// Count of of diffs in halfs\n\t\t/// \n\t\tpublic static int diffs;\n\n\t\t/// \n\t\t/// Constraints:\n\t\t/// s - (1 ≤ |s| ≤ 15)\n\t\t/// \n\t\t/// \n\t\tpublic static void Main(string[] args)\n\t\t{\n\t\t\ts = Console.ReadLine();\n\t\t\tvar len = s.Length;\n\n\t\t\tif (s.Length % 2 == 1)\n\t\t\t{\n\t\t\t\thalfs.Add(s.Substring(0, (len - 1) / 2));\n\t\t\t\thalfs.Add(s.Substring((len - 1) / 2 + 1 > len ? (len - 1) / 2 : (len - 1) / 2 + 1, (len - 1)/2).Reverse());\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thalfs.Add(s.Substring(0, (len) / 2));\n\t\t\t\thalfs.Add(s.Substring(len / 2, len/2).Reverse());\n\t\t\t}\n\n\t\t\tfor (var i = 0; i < halfs[0].Length; i++)\n\t\t\t{\n\t\t\t\tif (halfs[0][i] != halfs[1][i])\n\t\t\t\t{\n\t\t\t\t\tdiffs++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tConsole.WriteLine(s.Length % 2 == 1 ? (diffs > 1 ? \"NO\" : \"YES\") : (diffs != 1 ? \"NO\" : \"YES\"));\n\t\t}\n\t}\n}\n", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace task\n{\n class Program\n {\n private static string[] s;\n static void Main(string[] args)\n {\n s = new string[4];\n for (int i = 0; i < 4; ++i)\n {\n s[i] = Console.ReadLine();\n }\n bool ok = false;\n for (int i = 0; i < 4; ++i)\n {\n for (int j = 0; j < 4; ++j)\n {\n string t;\n if (i + 2 < 4)\n {\n t = string.Format(\"{0}{1}{2}\", s[i][j], s[i + 1][j], s[i + 2][j]);\n ok |= CheckString(t);\n }\n if (j + 2 < 4)\n {\n t = string.Format(\"{0}{1}{2}\", s[i][j], s[i][j + 1], s[i][j + 2]);\n ok |= CheckString(t);\n }\n if (i + 2 < 4 && j + 2 < 4)\n {\n t = string.Format(\"{0}{1}{2}\", s[i][j], s[i + 1][j + 1], s[i + 2][j + 2]);\n ok |= CheckString(t);\n }\n if (i + 2 < 4 && j - 2 >= 0)\n {\n t = string.Format(\"{0}{1}{2}\", s[i][j], s[i + 1][j - 1], s[i + 2][j - 2]);\n ok |= CheckString(t);\n } \n }\n }\n if (ok)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n\n private static bool CheckString(string t)\n {\n int cX = 0;\n int cP = 0;\n for (int i = 0; i < t.Length; ++i)\n {\n if (t[i] == 'x')\n cX++;\n else if (t[i] == '.')\n cP++;\n }\n return cX == 2 && cP == 1;\n }\n }\n\n}\n", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Text;\nusing System.IO;\nusing System.Linq;\nusing System.Threading;\n\n\n\n\nclass Program\n{\n \n \n void solve()\n {\n long l = nextInt();\n long r = nextInt();\n long p = 1;\n long res = 0;\n while (p < 1000000000000L)\n {\n p *= 10;\n long c = p - 1;\n long num;\n if (c / 2 > r)\n num = r;\n else if (c / 2 < l)\n num = l;\n else\n num = c / 2;\n if (num >= p / 10 && num < p)\n res = Math.Max(res, num * (c - num));\n }\n println(res);\n \n\n }\n long get(int x)\n {\n long y = 0;\n long p = 1;\n long temp = x;\n while (x > 0)\n {\n y += p * (9 - x % 10);\n x /= 10;\n p *= 10;\n }\n return temp * y;\n }\n \n\n ////////////\n private void println(int[] ar)\n {\n for (int i = 0; i < ar.Length; i++)\n {\n if (i == ar.Length - 1)\n println(ar[i]);\n else\n print(ar[i] + \" \");\n }\n }\n private void println(int[] ar, bool add)\n {\n int A = 0;\n if (add)\n A++;\n for (int i = 0; i < ar.Length; i++)\n {\n if (i == ar.Length - 1)\n println(ar[i] + A);\n else\n print((ar[i] + A) + \" \");\n }\n }\n\n private void println(string Stringst)\n {\n Console.WriteLine(Stringst);\n }\n private void println(char charnum)\n {\n Console.WriteLine(charnum);\n }\n private void println(int Intnum)\n {\n Console.WriteLine(Intnum);\n }\n private void println(long Longnum)\n {\n Console.WriteLine(Longnum);\n }\n private void println(double Doublenum)\n {\n string s = Doublenum.ToString(CultureInfo.InvariantCulture);\n Console.WriteLine(s);\n }\n\n private void print(string Stringst)\n {\n Console.Write(Stringst);\n }\n private void print(int Intnum)\n {\n Console.Write(Intnum);\n }\n private void print(char charnum)\n {\n Console.Write(charnum);\n }\n private void print(long Longnum)\n {\n Console.Write(Longnum);\n }\n private void print(double Doublenum)\n {\n Console.Write(Doublenum);\n }\n\n\n string[] inputLine = new string[0];\n int inputInd = 0;\n string nextLine()\n {\n return Console.ReadLine();\n }\n void readInput()\n {\n if (inputInd != inputLine.Length)\n throw new Exception();\n inputInd = 0;\n inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n if (inputLine.Length == 0)\n readInput();\n }\n int nextInt()\n {\n return int.Parse(nextString());\n }\n long nextLong()\n {\n return long.Parse(nextString());\n }\n double nextDouble()\n {\n return double.Parse(nextString());\n }\n string nextString()\n {\n if (inputInd == inputLine.Length)\n readInput();\n return inputLine[inputInd++];\n }\n static void Main(string[] args)\n {\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n new Program().solve();\n }\n}", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace International_Olympiad\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int n = int.Parse(reader.ReadLine());\n\n for (int i = 0; i < n; i++)\n {\n string s = reader.ReadLine().Substring(4);\n long t = long.Parse(s);\n\n long pow = 10, f = 0;\n\n for (int k = 1; k < s.Length; k++)\n {\n f += pow;\n pow *= 10;\n }\n\n while (t < 1989 + f)\n {\n t += pow;\n }\n\n writer.WriteLine(t);\n }\n\n\n writer.Flush();\n }\n }\n}", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Trace;\nusing SB = System.Text.StringBuilder;\nusing static System.Math;\nusing static System.Numerics.BigInteger;\nusing static Program.IO.Scanner;\n\nusing Number = System.Int64;\n#region IO\nnamespace Program.IO {\n\tusing System.IO;\n\tusing System.Text;\n\tusing System.Globalization;\n\n\tpublic class Printer : StreamWriter {\n\t\tpublic override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n\t\tpublic Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n\t}\n\tstatic public class Scanner {\n\t\tpublic static StreamScanner sc = new StreamScanner(Console.OpenStandardInput());\n\t\tpublic static int ri => sc.Integer();\n\t\tpublic static long rl => sc.Long();\n\t\tpublic static string rs => sc.Scan();\n\t\tpublic static double rd => sc.Double();\n\t}\n\tpublic class StreamScanner {\n\t\tpublic StreamScanner(Stream stream) { str = stream; }\n\n\t\tpublic readonly Stream str;\n\t\tprivate readonly byte[] buf = new byte[1024];\n\t\tprivate int len, ptr;\n\t\tpublic bool isEof = false;\n\t\tpublic bool IsEndOfStream { get { return isEof; } }\n\n\t\tprivate byte read() {\n\t\t\tif (isEof) return 0;\n\t\t\tif (ptr >= len) {\n\t\t\t\tptr = 0;\n\t\t\t\tif ((len = str.Read(buf, 0, 1024)) <= 0) {\n\t\t\t\t\tisEof = true;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[ptr++];\n\t\t}\n\n\t\tpublic char Char() {\n\t\t\tbyte b = 0;\n\t\t\tdo b = read(); while ((b < 33 || 126 < b) && !isEof);\n\t\t\treturn (char)b;\n\t\t}\n\t\tpublic string Scan() {\n\t\t\tvar sb = new StringBuilder();\n\t\t\tfor (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);\n\t\t\treturn sb.ToString();\n\t\t}\n\t\tpublic string ScanLine() {\n\t\t\tvar sb = new StringBuilder();\n\t\t\tfor (var b = Char(); b != '\\n' && b != 0; b = (char)read()) if (b != '\\r') sb.Append(b);\n\t\t\treturn sb.ToString();\n\t\t}\n\t\tpublic long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }\n\t\tpublic int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }\n\t\tpublic double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }\n\t}\n\n}\n\n#endregion\n\n#region main\nstatic class Ex {\n\tstatic public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n\tstatic public string AsJoinedString(this IEnumerable ie, string st = \" \") {\n\t\treturn string.Join(st, ie);\n\t}\n\tstatic public void Main() {\n\t\tConsole.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });\n\t\tvar solver = new Program.Solver();\n\t\tvar t = new System.Threading.Thread(solver.Solve, 100000000);\n\t\tt.Start();\n\t\tt.Join();\n\t\t//*/\n\t\t//solver.Solve();\n\t\tConsole.Out.Flush();\n\t}\n}\n#endregion\n\nnamespace Program {\n\tpublic class Solver {\n\t\tRandom rnd = new Random(0);\n\t\tpublic void Solve() {\n\t\t\tvar n = ri;\n\t\t\tvar k = rl;\n\t\t\tif (k >= n) {\n\t\t\t\tConsole.WriteLine(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsolve(n, (int)k);\n\t\t}\n\t\tvoid solve(int n, int k) {\n\t\t\tvar binom = new BinomialCoefficient(n + 50);\n\t\t\tif (k == 0) {\n\t\t\t\tConsole.WriteLine(binom.fact[n]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tModInt ans = 0;\n\t\t\tvar m = n - k;\n\t\t\tfor (int i = 1; i <= m; i++) {\n\t\t\t\tvar v = binom[m, i];\n\t\t\t\tv *= ModInt.Pow(i, n);\n\t\t\t\tif ((m - i) % 2 == 1)\n\t\t\t\t\tans -= v;\n\t\t\t\telse ans += v;\n\t\t\t}\n\t\t\tDebug.WriteLine(ans);\n\t\t\tans *= binom[n, m];\n\t\t\tDebug.WriteLine(ans);\n\t\t\tans *= 2;\n\t\t\tConsole.WriteLine(ans);\n\t\t}\n\t\tstatic int[] dx = { -1, 0, 1, 0 };\n\t\tconst long INF = 1L << 60;\n\t\tstatic int[] dy = { 0, 1, 0, -1 };\n\t\tstatic T[] Enumerate(int n, Func f) {\n\t\t\tvar a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a;\n\t\t}\n\t\tstatic T[][] Enumerate(int n, int m, Func f) {\n\t\t\treturn Enumerate(n, x => Enumerate(m, y => f(x, y)));\n\t\t}\n\t\tstatic public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n\t}\n}\n#region ModInt\n/// \n/// [0,) までの値を取るような数\n/// \npublic struct ModInt {\n\tpublic const long Mod = 998244353;\n\tpublic long num;\n\tpublic ModInt(long n) { num = n; }\n\tpublic override string ToString() { return num.ToString(); }\n\tpublic static ModInt operator +(ModInt l, ModInt r) { return new ModInt(l.num + r.num < Mod ? l.num + r.num : l.num + r.num - Mod); }\n\tpublic static ModInt operator -(ModInt l, ModInt r) { return new ModInt(l.num + Mod - r.num < Mod ? l.num + Mod - r.num : l.num - r.num); }\n\tpublic static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }\n\tpublic static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); }\n\tpublic static implicit operator ModInt(long n) { return new ModInt(n); }\n\tpublic static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }\n\tpublic static ModInt Pow(long v, long k) {\n\t\tlong ret = 1;\n\t\tfor (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n\t\t\tif ((k & 1) == 1) ret = ret * v % Mod;\n\t\treturn new ModInt(ret);\n\t}\n\tpublic static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }\n\tpublic static ModInt Modulo(long v) { return new ModInt(((v % Mod) + Mod) % Mod); }\n}\n#endregion\n\n#region Binomial Coefficient\npublic class BinomialCoefficient {\n\tpublic ModInt[] fact, ifact;\n\tpublic BinomialCoefficient(int n) {\n\t\tfact = new ModInt[n + 1];\n\t\tifact = new ModInt[n + 1];\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfact[i] = fact[i - 1] * i;\n\t\tifact[n] = ModInt.Inverse(fact[n]);\n\t\tfor (int i = n - 1; i >= 0; i--)\n\t\t\tifact[i] = ifact[i + 1] * (i + 1);\n\t\tifact[0] = ifact[1];\n\t}\n\tpublic ModInt this[int n, int r] {\n\t\tget {\n\t\t\tif (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;\n\t\t\treturn fact[n] * ifact[n - r] * ifact[r];\n\t\t}\n\t}\n\tpublic ModInt RepeatedCombination(int n, int k) {\n\t\tif (k == 0) return 1;\n\t\treturn this[n + k - 1, k];\n\t}\n}\n#endregion\n", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Globalization;\r\nusing System.Threading;\r\n\r\nnamespace A\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\r\n int tc = 1;\r\n tc = int.Parse(Console.ReadLine());\r\n while (tc-- > 0)\r\n {\r\n solve();\r\n }\r\n }\r\n\r\n // write your code in solve function\r\n static void solve()\r\n {\r\n int[] arr1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);\r\n int[] arr2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);\r\n\r\n if (arr1[0] == 0 && arr1[1] == 0 && arr2[0] == 0 && arr2[1] == 0) {\r\n Console.WriteLine(0);\r\n } else if (arr1[0] == 1 && arr1[1] == 1 && arr2[0] == 1 && arr2[1] == 1) {\r\n Console.WriteLine(2);\r\n } else {\r\n Console.WriteLine(1);\r\n }\r\n }\r\n }\r\n}", "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"source_code": "using System;\n\nnamespace Round144ProblemB\n{\n class Program\n {\n static void Main(string[] args)\n {\n long input = long.Parse(Console.ReadLine());\n\n long start = (long)Math.Sqrt(input) - 81;\n if (start < 1)\n start = 1;\n\n for (long i = start; i <= start + 162; i++)\n {\n long sum = GetSumOfDigits(i);\n if (i * (i + sum) == input)\n {\n Console.WriteLine(i);\n return;\n }\n }\n Console.WriteLine(\"-1\");\n }\n\n static long GetSumOfDigits(long n)\n {\n long sum = 0;\n while (n != 0)\n {\n sum += n % 10;\n n /= 10;\n }\n return sum;\n }\n }\n}\n", "src_uid": "e1070ad4383f27399d31b8d0e87def59"} {"source_code": "using System;\nclass Program\n{\n public static int[] dI = { -1, 1, 0, 0 };\n public static int[] dJ = { 0, 0, 1, -1 };\n public static char[][] grid = new char[4][];\n public static bool valid(int i, int j) { return i >= 0 && j >= 0 && i < 4 && j < 4; }\n public static bool DFS ()\n {\n for (int i = 0; i < 4; i++)\n {\n \n for (int j = 0; j < 4; j++)\n {\n int toRI = i + dI[2];\n int toRJ = j + dJ[2];\n int toLI = i + dI[3];\n int toLJ = j + dJ[3];\n for (int k = 0; k < 2; k++)\n {\n int toI = i + dI[k];\n int toJ = j + dJ[k];\n if (valid(toI, toJ) && grid[toI][toJ] == grid[i][j] && ((valid(toRI, toRJ) && grid[toRI][toRJ] == grid[i][j]) || (valid(toLI, toLJ) && grid[toLI][toLJ] == grid[i][j])))\n {\n return true;\n }\n }\n }\n }\n return false;\n }\n static void Main()\n {\n for (int i = 0; i < 4; i++)\n {\n grid[i] = Console.ReadLine().ToCharArray();\n \n }\n Console.WriteLine(DFS() ? \"YES\" : \"NO\");\n }\n}", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\npublic class Program\n{\n public void Solve() {\n int n = ReadInt();\n int p = ReadInt();\n int k = ReadInt();\n List < object > pr = new List < object >();\n if (p - k > 1) {\n pr.Add(\"<<\");\n }\n for (int i = Math.Max(p - k , 1); i < p; i++) {\n pr.Add(i);\n }\n pr.Add(\"(\" + p.ToString() + \")\");\n for (int i = p + 1; i <= p + k && i <= n; i++) {\n pr.Add(i);\n }\n if (p + k < n) {\n pr.Add(\">>\");\n }\n Write(pr.ToArray());\n } \n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n // reader = new StreamReader(\"in.txt\");\n // writer = Console.Out;\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n try\n {\n new Program().Solve();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n throw;\n }\n reader.Close();\n writer.Close();\n }\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n}\n", "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"source_code": "using System;\nusing System.Linq;\nusing System.IO;\nusing System.Text;\nusing System.Runtime.CompilerServices;\nnamespace Rextester{\n public class Program{\n \n public static StreamWriter writer;\n private static Stream readStream;\n private static int idx, bufferSize, bytesRead;\n private static byte[] buffer;\n public const char Space = ' '; // 32\n public const char MinusSign = '-'; // 45\n public const char Zero = '0'; // 48\n public const char HorizontalTab = '\\t'; // 9\n public const char VerticalTab = '\\v'; // 11\n public const char FormFeed = '\\f'; // 12\n public const char CarriageReturn = '\\r'; // 13\n public const char LineFeed = '\\n'; // 10\n \n [MethodImpl(MethodImplOptions.AggressiveInlining)] \n public static void Initialze(){\n readStream = Console.OpenStandardInput(); \n //readStream = File.OpenRead(@\"input.txt\");\n idx = bytesRead = 0;\n bufferSize = 1 << 14;\n buffer = new byte[bufferSize];\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static void ReadConsoleInput(){\n idx = 0;\n bytesRead = readStream.Read(buffer, 0, bufferSize);\n if (bytesRead <= 0) buffer[0] = (byte)Space;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static byte ReadByte() {\n if (idx == bytesRead) \n ReadConsoleInput(); \n return buffer[idx++];\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static int ReadInt(){\n byte readByte;\n do{\n readByte = ReadByte();\n }\n while (readByte < MinusSign);\n\n bool negative = false;\n if (readByte == MinusSign){\n negative = true;\n readByte = ReadByte();\n }\n int m = readByte - Zero;\n while (true){\n readByte = ReadByte();\n if (readByte < Zero) break;\n m = m * 10 + (readByte - Zero);\n }\n if (negative) return -m;\n return m;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StringBuilder ReadLine(){\n byte readByte;\n StringBuilder s = new StringBuilder();\n do{\n readByte = ReadByte();\n }\n while (readByte <= CarriageReturn);\n idx--;\n while (true){\n readByte = ReadByte();\n if (readByte < CarriageReturn) break;\n s = s.Append((char)readByte);\n }\n return s;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void Dispose(){\n readStream.Close();\n writer.Close();\n }\n public static int Gcd(int a, int b) { \n while (b!=0){\n int temp=b;\n b = a % b;\n a = temp;\n }\n return a;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void RealWork(){\n int a = ReadInt();\n int b = ReadInt();\n int h = ReadInt();\n int move=0;\n while(h!=0){\n if (move % 2 == 0){\n h = h - Gcd(h, a);\n move++;\n if (h == 0)\n move = 0;\n }\n else{\n h = h - Gcd(h, b);\n move++;\n if (h == 0)\n move = 1;\n } \n }\n \n writer.Write(move); \n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void Main(string[] args){\n\n //writer = new StreamWriter(\"output.txt\");\n Initialze();\n writer = new StreamWriter(Console.OpenStandardOutput()); \n \n RealWork(); \n Dispose();\n }\n }\n}", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A.Bear_and_Big_Brother\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int x = arr[0];\n int y = arr[1];\n int sum = 0;\n while(true)\n {\n if(x>y)\n {\n break;\n }\n\n x *= 3;\n y *= 2;\n sum++;\n }\n Console.WriteLine(sum);\n }\n }\n}\n", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n long Fun(long a, long b, long x)\n {\n if (b > x)\n return 0;\n return (x - b) / a + 1;\n }\n\n long Fun(long a, long b, long l, long r)\n {\n return Fun(a, b, r) - Fun(a, b, l - 1);\n }\n\n long Gcd(long a, long b, out long x, out long y) \n {\n if (a == 0)\n {\n x = 0;\n y = 1;\n return b;\n }\n\t long x1, y1;\n\t long d = Gcd(b % a, a, out x1, out y1);\n\t x = y1 - (b / a) * x1;\n\t y = x1;\n\t return d;\n }\n \n bool Dio(long a, long b, long c, out long x0, out long y0, out long g) \n {\n\t g = Gcd(Math.Abs(a), Math.Abs(b), out x0, out y0);\n\t if (c % g != 0)\n\t\t return false;\n\t x0 *= c / g;\n\t y0 *= c / g;\n\t if (a < 0)\n x0 *= -1;\n\t if (b < 0) \n y0 *= -1;\n\t return true;\n }\n\n public void Solve()\n {\n long a1 = ReadInt();\n long b1 = ReadInt();\n long a2 = ReadInt();\n long b2 = ReadInt();\n long l = ReadInt();\n long r = ReadInt();\n\n if (a1 == a2)\n {\n if (Math.Abs(b1 - b2) % a1 != 0)\n Write(0);\n else\n Write(Fun(a1, Math.Max(b1, b2), l, r));\n return;\n }\n\n long x0, y0, g;\n if (!Dio(a1, -a2, b2 - b1, out x0, out y0, out g))\n {\n Write(0);\n return;\n }\n \n long d1 = a2 / g;\n long d2 = a1 / g;\n if (x0 < 0)\n {\n long z = ((-x0 - 1) / d1 + 1);\n x0 += z * d1;\n y0 += z * d2;\n }\n if (y0 < 0)\n {\n long z = ((-y0 - 1) / d2 + 1);\n x0 += z * d1;\n y0 += z * d2;\n }\n \n long t = Math.Min(x0 / d1, y0 / d2);\n x0 -= t * d1;\n y0 -= t * d2;\n Write(Fun(d1 * a1, a1 * x0 + b1, l, r));\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"input.txt\");\n //writer = new StreamWriter(\"output.txt\");\n#endif\n try\n {\n new Solver().Solve();\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _635A\n{\n class Program\n {\n static void Main()\n {\n var s = Console.ReadLine().Split().Select(int.Parse).ToArray();\n var r = s[0]; var c = s[1]; var n = s[2]; var k = s[3];\n int[,] orchestra = new int[r, c];\n for (int i = 0; i < n; i++)\n {\n var line = Console.ReadLine().Split().Select(int.Parse).ToArray();\n orchestra[line[0]-1, line[1]-1]++;\n }\n int ans = 0;\n\n for (int i = 0; i < r; i++)\n for (int j = 0; j < c; j++)\n for (int p = i; p < r; p++)\n for (int q = j; q < c; q++)\n {\n int sum = 0;\n for (int a = i; a < r; a++)\n for (int b = j; b < c; b++)\n {\n if (a >= i && a <= p && b >= j && b <= q) sum+=orchestra[a,b]; \n }\n if (sum >= k) ans++;\n }\n Console.WriteLine(ans);\n }\n }\n}\n", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n //1 +\n //2 +\n //3 +\n //4 \n class Program\n {\n static public String switcher(char x)\n {\n String s;\n switch (x)\n {\n case '0':\n s = \"O-|-OOOO\";\n break;\n case '1':\n s = \"O-|O-OOO\";\n break;\n case '2':\n s = \"O-|OO-OO\";\n break;\n case '3':\n s = \"O-|OOO-O\";\n break;\n case '4':\n s = \"O-|OOOO-\";\n break;\n case '5':\n s = \"-O|-OOOO\";\n break;\n case '6':\n s = \"-O|O-OOO\";\n break;\n case '7':\n s = \"-O|OO-OO\";\n break;\n case '8':\n s = \"-O|OOO-O\";\n break;\n case '9':\n s = \"-O|OOOO-\";\n break;\n default:\n s = \"null\";\n break;\n }\n return s; \n }\n\n static void Main(string[] args)\n {\n String n = Console.ReadLine();\n for (int i = n.Length - 1; i >= 0; i--)\n {\n Console.WriteLine(switcher(n[i]));\n }\n }\n }\n}\n", "src_uid": "c2e3aced0bc76b6484360563355d23a7"} {"source_code": "using System;\nusing System.Linq;\nusing System.Linq.Expressions;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\nusing Point = System.Numerics.Complex;\nusing Number = System.Int32;\nnamespace Program\n{\n public class Solver\n {\n public void Solve()\n {\n var mod = sc.Long();\n var sum = 0L;\n var set = new SortedDictionary() { { 0, 0 } };\n for (int i = 1; i <= 100000; i++)\n {\n sum = (sum + i.ToString().Sum(x => x - '0')) % mod;\n \n BigInteger l;\n if (set.TryGetValue(sum, out l))\n {\n IO.Printer.Out.WriteLine(\"{0} {1}\", l + 1, i);\n return;\n }\n set.Add(sum, i);\n //var v = func(i.ToString(), long.MaxValue);\n }\n {\n BigInteger l = 0, r = (BigInteger)1e18;\n for (int i = 0; i < 100; i++)\n {\n var m = (l + r) / 2;\n var v = func(m.ToString());\n if (v < mod) l = m;\n else r = m;\n }\n for (int _ = 0; _ < 10000; _++)\n {\n\n var v = (long)(func(l.ToString()) % mod);\n Debug.WriteLine(v);\n BigInteger u;\n if (set.TryGetValue(v, out u))\n {\n var min = BigInteger.Min(u, l) + 1;\n var max = BigInteger.Max(u, l);\n IO.Printer.Out.WriteLine(\"{0} {1}\", min, max);\n return;\n }\n set.Add(v, l);\n l++;\n }\n }\n }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n static BigInteger func(string str)\n {\n var len = str.Length;\n BigInteger ans = 0L;\n BigInteger sum = 0;\n var ten = new BigInteger[len + 1];\n ten[0] = 1;\n for (int i = 1; i < len; i++)\n ten[i] = (ten[i - 1] * 10);\n for (int i = 0; i < len; i++)\n {\n var v = 0L;\n for (int j = i + 1; j < len; j++)\n v = (v * 10 + str[j] - '0');\n v = (v + 1);\n\n for (int k = 1; k < 10; k++)\n {\n if (str[i] - '0' == k)\n {\n ans = (ans + k * v);\n }\n else if (str[i] - '0' > k)\n {\n ans = (ans + k * ten[len - i - 1]);\n }\n ans = (ans + sum * k * ten[len - i - 1]);\n }\n sum = (sum * 10 + str[i] - '0');\n }\n return ans;\n }\n\n }\n}\n#region main\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Text;\n using System.Globalization;\n public class Printer : StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, T[] source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, T[] source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }\n\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n'; b = (char)read())\n if (b == 0) break;\n else if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != 0 && b != '-' && (b < '0' || '9' < b));\n if (b == 0) return long.MinValue;\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { var s = Scan(); return s != \"\" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public char[] Char(int n) { return enumerate(n, Char); }\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n }\n}\n#endregion", "src_uid": "52b8d97f216ea22693bc16fadcd46dae"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\n\nnamespace prD {\n class Program {\n#if ONLINE_JUDGE\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);\n#else\n private static readonly StreamWriter writer = new StreamWriter(@\"..\\..\\output\");\n private static readonly StreamReader reader = new StreamReader(@\"..\\..\\input\");\n#endif\n static int IsWeCan(int[,] p1, int[,] p2, int n, int m) {\n int[] ddd = new int[10];\n int result = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n int[] d = new int[10];\n int a1 = p1[i, 0];\n int b1 = p1[i, 1];\n int a2 = p2[j, 0];\n int b2 = p2[j, 1];\n if (a1 == a2) d[a1]++;\n if (a1 == b2) d[a1]++;\n if (b1 == a2) d[b1]++;\n if (b1 == b2) d[b1]++;\n int s = 0;\n for (int q = 0; q < 10; q++) {\n s += d[q];\n }\n bool normalPair = s == 1;\n if (!normalPair)\n continue;\n for (int q = 0; q < 10; q++) {\n if (d[q] > 0)\n ddd[q] = 1;\n }\n }\n }\n for (int i = 0; i < 10; i++) {\n result += ddd[i];\n }\n if (result == 1) {\n for (int i = 0; i < 10; i++) {\n if (ddd[i] == 1)\n return i;\n }\n throw new Exception();\n }\n else {\n return -1;\n }\n }\n\n static bool TheyCan(int[,] p1, int[,] p2, int n, int m) {\n bool ans = true;\n for (int i = 0; i < n; i++) {\n int a1 = p1[i, 0];\n int b1 = p1[i, 1];\n int result = 0;\n int[] ddd = new int[10];\n for (int j = 0; j < m; j++) {\n int[] d = new int[10];\n int a2 = p2[j, 0];\n int b2 = p2[j, 1];\n if(a1 == a2)\n d[a1] = 1;\n if(a1 == b2)\n d[a1] = 1;\n if(b1 == a2)\n d[b1] = 1;\n if(b1 == b2)\n d[b1] = 1;\n int s = 0;\n for(int q = 0; q < 10; q++) {\n s += d[q];\n }\n bool normalPair = s == 1;\n if (!normalPair)\n continue;\n for(int q = 0; q < 10; q++) {\n if(d[q] > 0)\n ddd[q] = 1;\n }\n }\n for(int j = 0; j < 10; j++) {\n result += ddd[j];\n }\n ans = ans && (result == 1 || result == 0);\n }\n return ans;\n }\n\n static void Main(string[] args) {\n int n = Next();\n int m = Next();\n int[,] p1 = new int[n,2];\n for (int i = 0; i < n; i++) {\n p1[i, 0] = Next();\n p1[i, 1] = Next();\n }\n int[,] p2 = new int[m, 2];\n for(int i = 0; i < m; i++) {\n p2[i, 0] = Next();\n p2[i, 1] = Next();\n }\n int weCan = IsWeCan(p1, p2, n, m);\n bool theyCan1 = TheyCan(p1, p2, n, m);\n bool theyCan2 = TheyCan(p2, p1, m, n);\n if (weCan != -1) {\n writer.Write(weCan);\n } else if (theyCan1 && theyCan2) {\n writer.Write('0');\n }\n else writer.Write(\"-1\");\n\n writer.Flush();\n#if !ONLINE_JUDGE\n writer.Close();\n#endif\n }\n private static int Next() {\n int c;\n int res = 0;\n do {\n c = reader.Read();\n if(c == -1)\n return res;\n } while(c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if(c == '-') {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while(true) {\n c = reader.Read();\n if(c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}\n", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Runtime.InteropServices;\nusing System.Text;\nusing System.Linq;\nusing System.IO;\nusing System.Globalization;\nusing System.Collections;\nusing System.Text.RegularExpressions;\n\nnamespace Task\n{\n\n #region MyIo\n\n internal class MyIo : IDisposable\n {\n private readonly TextReader inputStream;\n private readonly TextWriter outputStream = Console.Out;\n\n private string[] tokens;\n private int pointer;\n\n public MyIo()\n#if LOCAL_TEST\n : this(new StreamReader(\"input.txt\"))\n#else\n : this(System.Console.In)\n#endif\n {\n\n }\n\n public MyIo(TextReader inputStream)\n {\n this.inputStream = inputStream;\n }\n\n\n public char NextChar()\n {\n try\n {\n return (char)inputStream.Read();\n }\n catch (IOException)\n {\n return '\\0';\n }\n }\n\n public string NextLine()\n {\n try\n {\n return inputStream.ReadLine();\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public string NextString()\n {\n try\n {\n while (tokens == null || pointer >= tokens.Length)\n {\n tokens = (NextLine() + string.Empty).Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n pointer = 0;\n }\n return tokens[pointer++];\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public int NextInt()\n {\n return Next();\n }\n\n public long NextLong()\n {\n return Next();\n }\n\n public T Next()\n {\n var t = typeof(T);\n\n if (t == typeof(char))\n return (T)(object)NextChar();\n\n object s = NextString();\n\n if (t == typeof(string))\n return (T)s;\n\n return (T)Convert.ChangeType(s, typeof(T));\n }\n\n\n public IEnumerable NextWhile(Predicate pred)\n {\n if (pred == null)\n yield break;\n\n T res = Next();\n\n while (pred(res))\n {\n yield return res;\n\n res = Next();\n }\n }\n\n public IEnumerable NextSeq(long n)\n {\n for (var i = 0; i < n; i++)\n yield return Next();\n }\n\n public void Print(string format, params object[] args)\n {\n outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));\n }\n\n public void PrintLine(string format, params object[] args)\n {\n Print(format, args);\n\n outputStream.WriteLine();\n }\n\n public void Print(bool o)\n {\n Print(o ? \"yes\" : \"no\");\n }\n\n public void PrintLine(bool o)\n {\n Print(o);\n\n outputStream.WriteLine();\n }\n\n public void Print(T o)\n {\n outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));\n }\n\n\n public void PrintLine(T o)\n {\n Print(o);\n\n outputStream.WriteLine();\n }\n\n public void Close()\n {\n inputStream.Close();\n outputStream.Close();\n }\n\n void IDisposable.Dispose()\n {\n Close();\n\n#if LOCAL_TEST\n Console.ReadLine();\n#endif\n }\n }\n\n\n public static class ListExtensions\n {\n public static void Each(this IEnumerable self, Action action)\n {\n foreach (var v in self)\n action(v);\n }\n\n public static IEnumerable ToCycleEnumerable(this IEnumerable self)\n {\n if (self != null)\n {\n for (; ; )\n {\n foreach (var x in self)\n yield return x;\n }\n }\n }\n\n public static T CycleGet(this IList self, int index)\n {\n var c = self.Count;\n return self[(index % c + c) % c];\n }\n\n\n public static IList Shuffle(this IList self)\n {\n var rnd = new Random(DateTime.Now.Millisecond);\n\n var n = self.Count;\n\n while (n > 1)\n {\n n--;\n var k = rnd.Next(n + 1);\n var value = self[k];\n self[k] = self[n];\n self[n] = value;\n }\n\n return self;\n }\n\n public static IList> UseForNew2D(this T def, int fd, int sd)\n {\n var fdim = new T[fd][];\n\n for (int i = 0; i < fd; i++)\n {\n fdim[i] = new T[sd];\n Fill(fdim[i], def);\n }\n\n return fdim;\n }\n\n public static IList Fill(this IList self, Func fval)\n {\n for (var i = 0; i < self.Count; i++)\n self[i] = fval();\n\n\n return self;\n }\n\n\n public static IList Fill(this IList self, T val)\n {\n return self.Fill(() => val);\n }\n\n public static long Hash(this IList self, Func val = null)\n {\n return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);\n }\n\n public static long Hash(this IList self, Func val)\n {\n return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));\n }\n\n\n public static long HashOne(this T self, long current)\n {\n return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));\n }\n\n\n public static IList BuildSegTree(this IList a, Func combine, Func convert)\n {\n var t = new T1[a.Count << 2];\n\n a.BuildSegTree(t, 1, 0, a.Count - 1, combine, convert);\n\n return t;\n }\n\n private static void BuildSegTree(this IList a, IList t, int v, int tl, int tr, Func combine, Func convert)\n {\n if (tl == tr)\n {\n t[v] = convert(a[tl]);\n }\n else\n {\n int tm = (tl + tr) >> 1;\n\n BuildSegTree(a, t, v << 1, tl, tm, combine, convert);\n BuildSegTree(a, t, (v << 1) + 1, tm + 1, tr, combine, convert);\n\n t[v] = combine(t[v << 1], t[(v << 1) + 1]);\n }\n }\n }\n\n public static class P\n {\n public static P Create(T1 key, T2 val)\n {\n return new P(key, val);\n }\n }\n\n public class P\n {\n private class PComparer : IComparer>\n {\n private readonly bool? byKey;\n\n public PComparer(bool? byKey)\n {\n this.byKey = byKey;\n }\n\n\n public int Compare(P x, P y)\n {\n x = x ?? new P();\n y = y ?? new P();\n\n\n if (byKey == true)\n return Comparer.Default.Compare(x.Key, y.Key);\n else if (byKey == false)\n return Comparer.Default.Compare(x.Value, y.Value);\n else\n {\n var tr = Comparer.Default.Compare(x.Key, y.Key);\n\n if (tr != 0)\n tr = Comparer.Default.Compare(x.Value, y.Value);\n\n return tr;\n }\n }\n }\n\n\n public P()\n {\n }\n\n public P(T1 key, T2 val)\n {\n this.Key = key;\n this.Value = val;\n }\n\n\n public T1 Key\n {\n get;\n set;\n }\n\n public T2 Value\n {\n get;\n set;\n }\n\n public P Clone()\n {\n return new P(Key, Value);\n }\n\n public static IComparer> KeyComparer\n {\n get { return new PComparer(true); }\n }\n\n public static IComparer> ValueComparer\n {\n get { return new PComparer(false); }\n }\n\n public static implicit operator T1(P obj)\n {\n return obj.Key;\n }\n\n public static implicit operator T2(P obj)\n {\n return obj.Value;\n }\n\n public P SetKey(T1 key)\n {\n Key = key;\n return this;\n }\n\n public P SetValue(T2 value)\n {\n Value = value;\n return this;\n }\n\n public override string ToString()\n {\n return string.Format(\"Key: {0}, Value: {1}\", Key, Value);\n }\n\n public override bool Equals(object obj)\n {\n var co = obj as P;\n\n return co != null && co.GetHashCode() == GetHashCode();\n }\n\n public override int GetHashCode()\n {\n int hash = 17;\n hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());\n hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Value.GetHashCode());\n return hash;\n\n }\n }\n\n #endregion\n\n\n\n internal class Program\n {\n #region Program\n\n private readonly MyIo io;\n\n public Program(MyIo io)\n {\n this.io = io;\n }\n\n public static void Main(string[] args)\n {\n using (MyIo io = new MyIo())\n {\n new Program(io)\n .Solve();\n }\n }\n\n\n\n #endregion\n\n public const long MOD = 1000000007;\n public const double EPS = 1e-14;\n\n\n\n\n private void Solve()\n {\n var n = io.NextLong();\n\n var x = io.NextLong();\n var y = io.NextLong();\n\n var c = io.NextLong();\n\n\n long s = 0;\n\n if (c > 1)\n {\n \n var ub = (long)Math.Sqrt(1+8*c);\n var lb = Math.Max(ub / 4L - 1L, 0L);\n\n s = ub;\n\n \n \n\n do\n {\n \n var m = (ub + lb) >> 1;\n\n var cn = Calc(n, x, y, m);\n\n if (cn >= c)\n {\n ub--;\n s = Math.Min(m, s);\n }\n else if (cn < c)\n {\n lb++;\n }\n \n\n } while (ub > lb);\n\n }\n\n io.Print(s);\n }\n\n private long Pos0(long x)\n {\n return x > 0 ? x : 0;\n }\n\n private long Pow2(long x)\n {\n \n return x*x;\n }\n\n\n private long Pow2120(long x)\n {\n x = Pos0(x);\n\n return x * (x + 1L) / 2;\n }\n\n private long Calc(long n, long x, long y, long s)\n {\n \n\n if (s == 0)\n return 1;\n\n \n var r = Pos0(s + y - n);\n var b = Pos0(s + x - n);\n\n var l = Pos0(1 - y + s);\n var t = Pos0(1 - x + s);\n \n var ix = 1 + n - x;\n var iy = 1 + n - y;\n\n var bse = s*s + (s + 1)*(s + 1) - Pow2(r) - Pow2(t) - Pow2(b) - Pow2(l);\n\n bse += Pow2120(l - x);\n bse += Pow2120(r - x);\n\n bse += Pow2120(l - ix);\n bse += Pow2120(r - ix);\n\n \n return bse;\n }\n }\n\n}\n\n", "src_uid": "232c5206ee7c1903556c3625e0b0efc6"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Cubical_Planet\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int x1 = Next(), y1 = Next(), z1 = Next();\n int x2 = Next(), y2 = Next(), z2 = Next();\n\n writer.WriteLine(x1 == x2 || y1 == y2 || z1 == z2 ? \"YES\" : \"NO\");\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"} {"source_code": "//#define FILE_INPUT\nusing System;\nusing System.Text;\nusing System.Linq;\n//using System.Numerics;\n//using System.Collections;\nusing System.Collections.Generic;\n//using System.Collections.Specialized;\n//using System.Text.RegularExpressions;\n\n//978A. Удаление дубликатов\n\nnamespace CodeForces\n{\n class Solution\n {\n\n private void solve()\n {\n int n = gi();\n bool[] b = new bool[1024];\n Stack s = new Stack(n);\n int[] m = ga(n, () => gi());\n\n for (int i = n - 1; i >= 0; i--)\n {\n int v = m[i];\n\n if (!b[v])\n {\n b[v] = true;\n s.Push(v);\n }\n }\n\n Console.WriteLine(s.Count);\n Console.WriteLine(String.Join(\" \", s));\n }\n\n\n #region Tools\n\n static void Main()\n {\n new Solution().solve();\n Pause();\n }\n\n [System.Diagnostics.Conditional(\"DEBUG\")]\n static private void DebugOut(string format, T arg)\n {\n Console.WriteLine(format, arg);\n }\n\n [System.Diagnostics.Conditional(\"DEBUG\")]\n static private void DebugOut(string format, params object[] arg)\n {\n Console.WriteLine(format, arg);\n }\n\n [System.Diagnostics.Conditional(\"DEBUG\")]\n static private void DebugStop()\n {\n Console.ReadKey(true);\n }\n\n private static T[] ga(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f(i);\n return a;\n }\n\n private static T[] ga(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n private static int gi()\n { return cin.gi(); }\n\n private static List gl(int n, Func f)\n {\n var a = new List(n + 1);\n for (int i = 0; i < n; ++i) a.Add(f(i));\n return a;\n }\n\n [System.Diagnostics.Conditional(\"DEBUG\")]\n static private void Pause()\n {\n Console.WriteLine(\"[debug]\");\n Console.ReadKey(true);\n }\n private static void swap(ref T a, ref T b)\n {\n T t = a;\n a = b;\n b = t;\n }\n\n #endregion Tools\n }\n\n class cin\n {\n public static int error { get; set; }\n\n static cin()\n {\n#if (ONLINE_JUDGE || !FILE_INPUT)\n reader = new System.IO.BufferedStream(Console.OpenStandardInput(1024 * 10), 1024 * 10);\n#else\n reader = new System.IO.BufferedStream((new System.IO.StreamReader(\"input.txt\")).BaseStream, 1024 * 16);\n#endif\n }\n\n public static System.IO.BufferedStream reader { get; private set; }\n public static char Char() { return (char)reader.ReadByte(); }\n\n public static int gi()\n {\n for (int c = read(); c != -1; c = read())\n {\n switch ((char)c)\n {\n case '-':\n return -(int)gu(read());\n\n default:\n if (char.IsDigit((char)c)) return (int)gu(c);\n break;\n }\n }\n\n throw new System.IO.IOException();\n }\n\n public static uint gu()\n {\n return gu(read());\n }\n\n public static string Line()\n {\n int c;\n StringBuilder sb = new StringBuilder();\n\n for (c = read(); c != 10 && c != -1; c = read()) sb.Append((char)c);\n\n if (sb.Length > 0 && sb[sb.Length - 1] == 13) sb.Length -= 1;\n return sb.ToString();\n }\n\n public static int rawLine(byte[] a, int offset = 0)\n {\n int c, i = offset;\n for (c = reader.ReadByte(); c != 10; c = reader.ReadByte()) a[i++] = (byte)c;\n if (i > 0 && a[i - 1] == 13) i--;\n return i;\n }\n\n public static int rawLine(char[] a, int offset = 0)\n {\n Array.ConvertAll(a, Convert.ToInt16);\n\n int c, i = offset;\n for (c = read(); c != 10 && c != -1; c = read()) a[i++] = (char)c;\n if (i > 0 && a[i - 1] == 13) i--;\n return i;\n }\n\n public static int rawLine(T[] a, Func converter) where T : IComparable\n {\n int c, i = 0;\n for (c = read(); c != 10; c = read()) a[i++] = converter(c);\n if (i > 0 && a[i - 1].CompareTo(13) == 0) i--;\n return i;\n }\n\n public static string Scan()\n {\n int c;\n StringBuilder sb = new StringBuilder();\n\n do\n {\n c = read();\n if (c == -1) return string.Empty;\n }\n while (c < 33 || c > 126);\n\n for (; c >= 33 && c <= 126; c = read()) sb.Append((char)c);\n return sb.ToString();\n }\n\n public static bool Scan(ref StringBuilder sb)\n {\n int c;\n\n do\n {\n c = read();\n if (c == -1) return false;\n }\n while (c < 33 || c > 126);\n\n for (; c >= 33 && c <= 126; c = read()) sb.Append((char)c);\n return true;\n }\n\n private static uint gu(int first)\n {\n int c;\n uint u = (uint)first - '0';\n for (c = read(); c != -1 && char.IsDigit((char)c); c = read())\n {\n u = 10 * u + (uint)c - '0';\n }\n\n error = c;\n return u;\n }\n\n private static int read() { return reader.ReadByte(); }\n\n public static bool NewLine()\n {\n int c = error;\n if (c != 10) do c = reader.ReadByte(); while (c != -1 && c != 10);\n return c != -1;\n }\n }\n}", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CodeForce\n{\n public class _977A\n {\n //Wrong Subtraction\n public static void Main()\n {\n string[] stringArray = Console.ReadLine().Split();\n int n = int.Parse(stringArray[0]);\n int k = int.Parse(stringArray[1]);\n for (int i = 0; i < k; i++)\n {\n if (n % 10 == 0)\n {\n n /= 10;\n }\n else\n {\n n -= 1;\n }\n }\n Console.WriteLine(n);\n //Console.ReadKey();\n }\n }\n}\n", "src_uid": "064162604284ce252b88050b4174ba55"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n \n var abcd = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n var a = abcd[0];\n var b = abcd[1];\n var c = abcd[2];\n var d = abcd[3];\n\n var list = new List(3) { a, b, c };\n list.Sort();\n var left = d - (list[1] - list[0]);\n var right = d - (list[2] - list[1]);\n Console.WriteLine(Math.Max(left,0) + Math.Max(right,0));\n }\n\n \n }\n}", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Threading;\n\nnamespace Round356e\n{\n class Program : ProgramBase\n {\n private const long commonMod = 1000000007;\n\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Get();\n p.Out(x);\n }\n\n object Get()\n {\n checked\n {\n var wa = Stopwatch.StartNew();\n //FileName = \"input\";\n var n = ReadIntToken();\n var k = ReadIntToken();\n var table = new bool[n, n];\n for (int i = 0; i < n; i++)\n {\n var input = Read();\n for (int j = 0; j < n; j++)\n table[i, j] = input[j] == '.';\n }\n Cell[,] cells;\n int componentCount;\n BFS(table, out cells, out componentCount);\n var ccWeights = new int[componentCount + 1];\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n if (cells[i, j].CCNumber > 0)\n ccWeights[cells[i, j].CCNumber]++;\n }\n }\n var max = int.MinValue;\n var memory = new bool[componentCount + 1];\n for (int z = 0; z < n - k + 1; z++)\n {\n //Console.WriteLine(z + \" \" + wa.Elapsed);\n var activeField = new int[k, k];\n var ccStats = new int[componentCount + 1];\n var sumOfInternal = 0;\n var blockedCount = 0;\n for (int i = z; i < z + k; i++)\n {\n for (int j = 0; j < k; j++)\n {\n var cc = cells[i, j].CCNumber;\n if (cc > 0)\n {\n if (ccStats[cc] == 0)\n sumOfInternal += ccWeights[cc];\n ccStats[cc] += 1;\n }\n else\n blockedCount++;\n }\n }\n\n var max2 = Math.Max(max, Sum(GetNeighboursCcs(z, 0, k, n, cells, memory), ccStats, ccWeights) + sumOfInternal + blockedCount);\n if (max2 > max)\n max = max2;\n\n for (int w = 1; w < n - k + 1; w++)\n {\n for (int i = 0; i < k; i++)\n {\n var ccNumber = cells[z + i, w - 1].CCNumber;\n if (ccNumber > 0)\n {\n ccStats[ccNumber]--;\n if (ccStats[ccNumber] == 0)\n sumOfInternal -= ccWeights[ccNumber];\n }\n else\n blockedCount--;\n\n ccNumber = cells[z + i, w + k - 1].CCNumber;\n if (ccNumber > 0)\n {\n if (ccStats[ccNumber] == 0)\n sumOfInternal += ccWeights[ccNumber];\n ccStats[ccNumber]++;\n }\n else\n blockedCount++;\n }\n max2 = Math.Max(max, Sum(GetNeighboursCcs(z, w, k, n, cells, memory), ccStats, ccWeights) + sumOfInternal + blockedCount);\n if (max2 > max)\n max = max2;\n }\n }\n if (!string.IsNullOrEmpty(FileName))\n Console.WriteLine(wa.Elapsed);\n return max;\n //return here\n }\n }\n\n int Sum(IEnumerable list, int[] set, int[] weights)\n {\n var second = new List();\n foreach (var cc in list)\n if (set[cc] == 0)\n second.Add(cc);\n var sum = 0;\n foreach (var cc in second)\n sum += weights[cc];\n return sum;\n }\n\n IEnumerable GetNeighboursCcs(int i, int j, int k, int n, Cell[,] cells, bool[] memory)\n {\n var result = new List();\n if (i > 0)\n //.Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + k, j + x)))\n //.Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + x, j - 1)))\n //.Concat(Enumerable.Range(0, k).Select(x => Struct.Create(i + x, j + k))))\n for (var x = 0; x < k; x++)\n {\n var cc = cells[i - 1, j + x].CCNumber;\n if (cc > 0 && !memory[cc])\n {\n result.Add(cc);\n memory[cc] = true;\n }\n }\n if (i + k < n)\n for (var x = 0; x < k; x++)\n {\n var cc = cells[i + k, j + x].CCNumber;\n if (cc > 0 && !memory[cc])\n {\n result.Add(cc);\n memory[cc] = true;\n }\n }\n if (j > 0)\n for (var x = 0; x < k; x++)\n {\n var cc = cells[i + x, j - 1].CCNumber;\n if (cc > 0 && !memory[cc])\n {\n result.Add(cc);\n memory[cc] = true;\n }\n }\n if (j + k < n)\n for (var x = 0; x < k; x++)\n {\n var cc = cells[i + x, j + k].CCNumber;\n if (cc > 0 && !memory[cc])\n {\n result.Add(cc);\n memory[cc] = true;\n }\n }\n foreach (var cc in result)\n {\n memory[cc] = false;\n }\n return result;\n }\n\n void BFS(bool[,] input, out Cell[,] cells, out int componentCount)\n {\n var n = input.GetLength(0);\n cells = new Cell[n, n];\n var visited = new bool[n, n];\n var componentIndex = 0;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n if (!visited[i, j] && input[i, j])\n BFS(i, j, cells, input, visited, ++componentIndex);\n componentCount = componentIndex;\n }\n\n void BFS(int i, int j, Cell[,] cells, bool[,] input, bool[,] visited, int ccIndex)\n {\n var n = input.GetLength(0);\n visited[i, j] = true;\n cells[i, j].CCNumber = ccIndex;\n var neighbours = new[] { Struct.Create(i + 1, j), Struct.Create(i - 1, j), Struct.Create(i, j + 1), Struct.Create(i, j - 1) };\n foreach (var c in neighbours.Where(x => x.Item1 >= 0 && x.Item1 < n && x.Item2 >= 0 && x.Item2 < n && !visited[x.Item1, x.Item2] && input[x.Item1, x.Item2]))\n BFS(c.Item1, c.Item2, cells, input, visited, ccIndex);\n }\n\n struct Cell\n {\n public int CCNumber { get; set; }\n }\n\n public static class Struct\n {\n public static Pair Create(T1 item1, T2 item2)\n {\n return new Pair { Item1 = item1, Item2 = item2 };\n }\n }\n\n public struct Pair\n {\n public T1 Item1 { get; set; }\n public T2 Item2 { get; set; }\n }\n\n class Automata\n {\n bool[] terminals;\n public int sigma;\n public int len;\n public int[,] jumps;\n\n public void Create()\n {\n var a = ReadInts();\n len = a[0];\n sigma = a[2];\n var ts = ReadInts();\n terminals = new bool[len];\n for (int i = 0; i < ts.Length; i++)\n terminals[ts[i]] = true;\n jumps = new int[len, sigma];\n for (int i = 0; i < len * sigma; i++)\n {\n var b = Console.ReadLine().Split(' ');\n jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);\n }\n }\n protected int[] ReadInts()\n {\n return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();\n }\n\n public bool IsTerminal(int s)\n {\n return terminals[s];\n }\n }\n }\n\n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n Queue tokens;\n protected string FileName { get; set; }\n\n protected string Read()\n {\n if (f == null)\n f = string.IsNullOrEmpty(FileName)\n ? new StreamReader(Console.OpenStandardInput())\n : new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName);\n return f.ReadLine();\n }\n\n protected int ReadInt()\n {\n return int.Parse(Read());\n }\n\n protected int ReadIntToken()\n {\n if (tokens == null || tokens.Count == 0)\n tokens = new Queue(Read().Split(' '));\n return int.Parse(tokens.Dequeue());\n }\n\n protected int[] ReadInts()\n {\n var tokens = Read().Split(' ');\n var result = new int[tokens.Length];\n for (int i = 0; i < tokens.Length; i++)\n result[i] = int.Parse(tokens[i]);\n return result;\n }\n\n\n protected long ReadLongToken()\n {\n if (tokens == null || tokens.Count == 0)\n tokens = new Queue(Read().Split(' '));\n return long.Parse(tokens.Dequeue());\n }\n\n protected long ReadLong()\n {\n return Convert.ToInt64(Read());\n }\n\n protected long[] ReadLongs()\n {\n var tokens = Read().Split(' ');\n var result = new long[tokens.Length];\n for (int i = 0; i < tokens.Length; i++)\n result[i] = long.Parse(tokens[i]);\n return result;\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName, r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func, T defaultValue = default(T))\n {\n T result = defaultValue;\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable source, string delimeter)\n {\n return string.Join(delimeter, source.ToArray());\n }\n\n public static string JoinStrings(this IEnumerable source, string delimeter)\n {\n return source.Select(x => x.ToString()).JoinStrings(delimeter);\n }\n }\n}", "src_uid": "d575f9bbdf625202807db59490c5c327"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace IamBoredwithLife\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] a = Console.ReadLine().Split(' ');\n int x = Int32.Parse(a[0]);\n int y = Int32.Parse(a[1]);\n int gcd = 1;\n for (int i = 1; i <= Math.Min(x, y); i++)\n gcd *= i;\n Console.WriteLine(gcd);\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Collections;\nusing System.Text.RegularExpressions;\nusing System.Collections.Specialized;\n\n\nnamespace a2oj\n{\n class Program\n {\n\n\n static void Main(string[] args)\n {\n long t = long.Parse(Console.ReadLine());\n long sum = 0,c=1;\n while (t>0)\n {\n sum += (long)Math.Pow(2, c);\n c++;\n t--;\n }\n\n Console.WriteLine(sum);\n //Console.ReadLine();\n\n }\n }\n}\n", "src_uid": "f1b43baa14d4c262ba616d892525dfde"} {"source_code": "using System;\nusing System.Linq;\nusing System.Numerics;\n\nnamespace Olimp\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = Convert.ToInt32(Console.ReadLine());\n string s = Console.ReadLine();\n\n BigInteger ans = 0, p = 1;\n\n while (true)\n {\n if(s == \"\") break;\n string cur = \"\";\n\n while (s != \"\" && BigInteger.Parse(s[s.Length - 1] + cur) < n)\n {\n cur = s[s.Length - 1] + cur;\n s = s.Remove(s.Length - 1, 1);\n }\n\n if (cur[0] == '0' && cur.Length != 1)\n {\n if (cur.Count(x => x == '0') == cur.Length)\n {\n for (int i = 0; i < cur.Length - 1; i++)\n {\n s += \"0\";\n }\n cur = \"0\";\n }\n else\n {\n while (cur[0] == '0')\n {\n s += \"0\";\n cur = cur.Remove(0, 1);\n }\n }\n }\n\n ans += Convert.ToInt64(cur) * p;\n p *= n;\n }\n\n Console.WriteLine(ans);\n }\n }\n}\n", "src_uid": "be66399c558c96566a6bb0a63d2503e5"} {"source_code": "using System;\n class Program\n {\n static void Main(string[] args)\n {\n int f= int.Parse(Console.ReadLine());\n int z=0,a=0,b=0,c=1,d=1;\n if(f==0)\n {\n Console.WriteLine(\"0 0 0\");\n return;\n }\n if(f==2)\n {\n Console.WriteLine(\"0 0 2\");\n return;\n }\n while(d!=f)\n {\n z=a;a=b;b=c;c=d;d=c+b;\n } \n Console.WriteLine(z.ToString()+\" \"+a.ToString()+\" \"+c.ToString());\n }\n }", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace KingsWay\n{\n class Program\n {\n \n static void Main(string[] args)\n {\n \n int n = int.Parse(Console.ReadLine());\n int x = int.Parse(Console.ReadLine());\n int initial = 0;\n \n int[] shells = new int[3];\n \n for(int i = 0;i0;i--)\n {\n if(i%2==0)\n {\n int temp1 = shells[2];\n shells[2] = shells[1];\n shells[1] = temp1;\n }\n else\n {\n int temp2 = shells[0];\n shells[0] = shells[1];\n shells[1] = temp2;\n }\n }\n \n for(int i=0;i 0)\n\t\t\t{\n\t\t\t\ttimes++;\n\t\t\t}\n\t\t\tvar time = t*times;\n\t\t\ttime -= t;\n\t\t\tvar res = time > d;\n\t\t\tConsole.WriteLine(res ? \"YES\" : \"NO\");\n\t\t}\n\n\t\tprivate static readonly Scanner cin = new Scanner();\n\n\t\tprivate static void Main()\n\t\t{\n#if DEBUG\n\t\t\tvar inputText = File.ReadAllText(@\"..\\..\\input.txt\");\n\t\t\tvar testCases = inputText.Split(new[] { \"input\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\tvar consoleOut = Console.Out;\n\t\t\tfor (var i = 0; i < testCases.Length; i++)\n\t\t\t{\n\t\t\t\tvar parts = testCases[i].Split(new[] { \"output\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\t\tConsole.SetIn(new StringReader(parts[0].Trim()));\n\t\t\t\tvar stringWriter = new StringWriter();\n\t\t\t\tConsole.SetOut(stringWriter);\n\t\t\t\tvar sw = Stopwatch.StartNew();\n\t\t\t\tnew Template().Solve();\n\t\t\t\tsw.Stop();\n\t\t\t\tvar output = stringWriter.ToString();\n\n\t\t\t\tConsole.SetOut(consoleOut);\n\t\t\t\tvar color = ConsoleColor.Green;\n\t\t\t\tvar status = \"Passed\";\n\t\t\t\tif (parts[1].Trim() != output.Trim())\n\t\t\t\t{\n\t\t\t\t\tcolor = ConsoleColor.Red;\n\t\t\t\t\tstatus = \"Failed\";\n\t\t\t\t}\n\t\t\t\tConsole.ForegroundColor = color;\n\t\t\t\tConsole.WriteLine(\"Test {0} {1} in {2}ms\", i + 1, status, sw.ElapsedMilliseconds);\n\t\t\t}\n\t\t\tConsole.ReadLine();\n\t\t\tConsole.ReadKey();\n#else\n\t\t\tnew Template().Solve();\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\t}\n\n\tinternal class Scanner\n\t{\n\t\tprivate string[] s = new string[0];\n\t\tprivate int i;\n\t\tprivate readonly char[] cs = { ' ' };\n\n\t\tpublic string NextString()\n\t\t{\n\t\t\tif (i < s.Length) return s[i++];\n\t\t\tvar line = Console.ReadLine() ?? string.Empty;\n\t\t\ts = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n\t\t\ti = 1;\n\t\t\treturn s.First();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn double.Parse(NextString());\n\t\t}\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn int.Parse(NextString());\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn long.Parse(NextString());\n\t\t}\n\t}\n}", "src_uid": "32c866d3d394e269724b4930df5e4407"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Amr_and_pins\n{\n class Program\n {\n static void Main(string[] args)\n {\n \n double answer;\n string[] input = Console.ReadLine().Split(null);\n answer = Math.Sqrt(Math.Pow(Int32.Parse(input[3]) - Int32.Parse(input[1]),2) + Math.Pow(Int32.Parse(input[4]) - Int32.Parse(input[2]),2))/(Int32.Parse(input[0])*2);\n Console.WriteLine(answer==(Int32)answer?answer:(Int32)answer+1);\n }\n }\n}\n", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"} {"source_code": "//Rextester.Program.Main is the entry point for your code. Don't change it.\n//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\n\nnamespace Rextester\n{\n public class Program\n {\n public static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n string ip = Console.ReadLine();\n int []count = new int[3]; //RGB\n for(int i=0;i=2 && count[1]==1 && count[2]==0)\n s+=\"BG\";\n else if(count[0]>=2 && count[1]==0 && count[2]==1)\n s+=\"BG\";\n else if(count[0]==0 && count[1]>=2 && count[2]==1)\n s+=\"BR\";\n else if(count[0]==1 && count[1]>=2 && count[2]==0)\n s+=\"BR\";\n else if(count[0]==1 && count[1]==0 && count[2]>=2)\n s+=\"GR\";\n else if(count[0]==0 && count[1]==1 && count[2]>=2)\n s+=\"GR\";\n \n //if only two type but both greater than two\n else if(count[0]>=2 && count[1]>=2 && count[2]==0)\n s+=\"BGR\";\n else if(count[0]>=2 && count[1]==0 && count[2]>=2)\n s+=\"BGR\";\n else if(count[0]==0 && count[1]>=2 && count[2]>=2)\n s+=\"BGR\";\n Console.WriteLine(s);\n }\n }\n}", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace SharpApp\n{\n class Program\n {\n static void Main(string[] args)\n {\n var str = new StringBuilder(Console.ReadLine());\n\n var count = 0;\n var canTake = new int[str.Length];\n for (int i = 0; i < str.Length; i++)\n {\n if (str[i] == 'V')\n {\n if (i + 1 == str.Length)\n {\n break;\n }\n if (str[i + 1] == 'K')\n {\n canTake[i] = 1;\n canTake[i + 1] = 1;\n count++;\n i++;\n }\n else if (str[i + 1] == 'V')\n {\n canTake[i] = 2;\n canTake[i + 1] = 2;\n }\n }\n else if (i + 1 != str.Length && str[i + 1] == 'K')\n {\n canTake[i] = 2;\n canTake[i + 1] = 2;\n }\n }\n\n for (int i = 0; i < canTake.Length; i++)\n {\n if (canTake[i] == 2)\n {\n if (i + 1 != canTake.Length && canTake[i + 1] == 2)\n {\n count++;\n break;\n }\n }\n }\n\n Console.WriteLine(count);\n }\n }\n}\n", "src_uid": "578bae0fe6634882227ac371ebb38fc9"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace FlippingGame\n{\n class FlippingGame\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int[] values = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int[] partialOnesObtained = new int[n];\n\n int numOfOnes = values.Count(v => v == 1);\n\n if (numOfOnes == n)\n Console.WriteLine(n - 1);\n else\n {\n partialOnesObtained[0] = 1 - values[0];\n\n for (int i = 1; i < n; i++)\n {\n if (values[i] == 0)\n partialOnesObtained[i] = partialOnesObtained[i - 1] + 1;\n else\n partialOnesObtained[i] = partialOnesObtained[i - 1] - 1 < 0 ? 0 : partialOnesObtained[i - 1] - 1;\n }\n\n Console.WriteLine(numOfOnes + partialOnesObtained.Max());\n }\n }\n }\n}\n", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces {\n struct Position : IComparable{\n public int Index, Min, Max;\n public Position(int index, int min, int max) {\n Index = index; Min = min; Max = max;\n }\n\n public int CompareTo(Position other) {\n return other.Max.CompareTo(Max);\n }\n }\n\n class C4B {\n static void Main(string[] args) {\n int[] arr = ReadIntArray();\n int d = arr[0];\n int sumTime = arr[1];\n int sumMin = 0;\n int sumMax = 0;\n Position[] time = new Position[d]; \n for (int i = 0; i < d; ++i) {\n int[] m = ReadIntArray();\n time[i] = new Position(i, m[0], m[1]); \n sumMin += m[0];\n sumMax += m[1];\n }\n if (sumMin > sumTime || sumMax < sumTime) {\n Console.WriteLine(\"NO\");\n return;\n }\n int[] result = new int[d];\n Array.Sort(time);\n for (int i = 0; i < d; ++i) {\n Position p = time[i];\n if (sumTime == sumMin) {\n result[p.Index] = p.Min;\n sumTime -= p.Min;\n sumMin -= p.Min;\n }\n else if (sumTime - p.Max >= sumMin - p.Min) {\n result[p.Index] = p.Max;\n sumTime -= p.Max;\n sumMin -= p.Min;\n }\n else {\n result[p.Index] = sumTime - (sumMin - p.Min);\n sumMin -= p.Min;\n sumTime -= result[p.Index];\n }\n }\n Console.WriteLine(\"YES\");\n PrintArray(result);\n //Console.ReadLine();\n }\n\n public static void PrintArray(int[] arr) {\n foreach (int i in arr)\n Console.Write(\"{0} \", i);\n }\n\n public static int[] ReadIntArray() {\n return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n }\n }\n}\n", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"source_code": "using System;\n using System.Collections.Generic;\n using System.Globalization;\n using System.Linq;\n using System.Text;\n\n public class Program\n {\n public static void Main(string[] args)\n {\n var hand = Console.ReadLine();\n var keys = \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n var sb = new StringBuilder(keys);\n var inp = Console.ReadLine();\n var outp = \"\";\n var ind = 0;\n if (hand == \"R\")\n {\n \n for (int i = 0; i < inp.Length; i++)\n {\n var ch = inp[i];\n for (int j = 0; j < sb.Length; j++)\n {\n if (ch == sb[j])\n {\n outp += sb[j - 1];\n }\n }\n \n }\n }\n else\n {\n for (int i = 0; i < inp.Length; i++)\n {\n var ch = inp[i];\n for (int j = 0; j < sb.Length - 1; j++)\n {\n if (ch == sb[j])\n {\n outp += sb[j + 1];\n }\n }\n }\n }\n Console.WriteLine(outp.ToString());\n\n }\n }", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Threading;\nusing static CF.ReadNext;\n\nnamespace CF\n{\n public static class Program\n {\n private static void Main()\n {\n var s = Console.ReadLine();\n for (int i = 0; i <= s.Length - 3; i++)\n {\n var substring = string.Concat(s.Substring(i, 3).OrderBy(c=>c));\n if (substring == \"ABC\")\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n Console.WriteLine(\"NO\");\n }\n }\n\n public static class ReadNext\n {\n public static int NextInt()\n {\n var next = ReadUntilSpace();\n return int.Parse(next);\n }\n\n public static double NextDouble()\n {\n var next = ReadUntilSpace();\n return double.Parse(next);\n }\n\n public static string NextWord()\n {\n return ReadUntilSpace();\n }\n\n private static bool IsWhiteSpace(int n)\n {\n return n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1;\n }\n\n private static string ReadUntilSpace()\n {\n var result = \"\";\n\n var n = Console.Read();\n // read whitespace \n while (IsWhiteSpace(n))\n {\n n = Console.Read();\n }\n\n // read characters\n while (!IsWhiteSpace(n))\n {\n result += (char)n;\n n = Console.Read();\n }\n\n return result;\n }\n }\n}\n", "src_uid": "ba6ff507384570152118e2ab322dd11f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.IO;\n\nnamespace Zad\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n;\n n = Convert.ToInt32(Console.ReadLine());\n int[] k = Console.ReadLine().Split().Select(int.Parse).ToArray();\n\n int cot = 0, mac = 0;\n for(int i = 0; i < n ; i++)\n {\n if (k[i] == 0)\n cot++;\n else mac = Math.Max(cot, mac)+1;\n }\n \n Console.WriteLine(Math.Max(cot,mac));\n \n\n }\n }\n}\n", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"source_code": "#if DEBUG\nusing System.Reflection;\nusing System.Threading.Tasks;\n#endif\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\n\nnamespace cc1\n{\n class Program\n {\n static string _inputFilename = \"input.txt\";\n static string _outputFilename = \"output.txt\";\n#if DEBUG\n static bool _useFileInput = false;\n#else\n static bool _useFileInput = false;\n#endif\n\n static void Main(string[] args)\n {\n StreamWriter file = null;\n if (_useFileInput)\n {\n Console.SetIn(File.OpenText(_inputFilename));\n file = new StreamWriter(_outputFilename);\n Console.SetOut(file);\n }\n\n#if DEBUG\n\t\t\tif (!_useFileInput)\n\t\t\t{\n\t\t\t\tConsole.SetIn(getInput());\n\t\t\t}\n#endif\n\n try\n {\n solution();\n }\n finally\n {\n if (_useFileInput)\n {\n file.Close();\n }\n }\n }\n\n static void solution()\n {\n #region SOLUTION\n var d1 = readIntArray();\n var c = d1[0];\n var d = d1[1];\n\n d1 = readIntArray();\n var n = d1[0];\n var m = d1[1];\n var k = readInt();\n var need = Math.Max( n * m - k, 0);\n\n if (d * n <= c)\n {\n Console.WriteLine(need * d);\n return;\n }\n\n var rem = need % n;\n var pr = need / n;\n var tc = pr * c;\n if (rem * d < c)\n {\n tc += rem * d;\n }\n else\n {\n tc += c;\n }\n\n Console.WriteLine(tc);\n //var n = readInt();\n //var m = readInt();\n\n //var a = readIntArray();\n //var b = readIntArray();\n #endregion\n }\n\n static int readInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long readLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int[] readIntArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n }\n\n static long[] readLongArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n }\n\n#if DEBUG\n\t\tstatic StreamReader getInput()\n\t\t{\n\t\t\tvar resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n\t\t\tvar resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);\n\n\t\t\treturn new StreamReader(resource);\n\t\t}\n#endif\n }\n}\n", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\n\n\nnamespace contest\n{\n class Program\n {\n static int[] arr = new int[150005];\n \n public static void Main()\n {\n int n , k;\n var inp = Console.ReadLine().Split(' ');\n n = int.Parse(inp[0]);\n k = int.Parse(inp[1]);\n inp = Console.ReadLine().Split(' ');\n for( int i = 0; i < n; i++ )\n {\n arr[i] = int.Parse(inp[i]);\n }\n int ans = int.MaxValue;\n for( int i = 0; i <= 200000; i++)\n {\n List list = new List();\n\n \n int cnt = 0;\n for( int j = 0; j < n; j++ )\n {\n cnt = 0;\n int x = arr[j];\n while( x > i)\n {\n cnt++;\n x /= 2;\n }\n if( x == i )\n {\n list.Add(cnt);\n }\n }\n list.Sort();\n if( list.Count >= k )\n {\n int sm = 0;\n for (int j = 0; j < k; j++)\n sm += list[j];\n ans = Math.Min(ans, sm);\n }\n }\n Console.WriteLine(ans);\n Console.ReadLine();\n }\n\n \n }\n}", "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\n\nnamespace Rextester\n{\n public class Program\n {\n public static void Main(string[] args)\n {\n long i;\n while (long.TryParse(Console.ReadLine(), out i)) {\n i = (i / 10000)*10000 + ((i / 100) % 10)*1000 + (i%10)*100 + ((i/10)%10)*10 + (i/1000)%10;\n var r = i;\n r *= i;\n r = r% 100000;\n r *= i;\n r = r% 100000;\n r *= i;\n r = r% 100000;\n r *= i;\n r = r% 100000;\n Console.WriteLine(r.ToString(\"D5\"));\n }\n }\n }\n}", "src_uid": "51b1c216948663fff721c28d131bf18f"} {"source_code": "using System;\n class Program\n {\n static void Main(string[] args)\n {\n string[] input = Console.In.ReadToEnd().Split(new char[] {' ', '\\n', '\\r', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n int[] ar = new int[input.Length];\n for (int i = 0; i < ar.Length; ++i)\n ar[i]=int.Parse(input[i]);\n input = null;\n Array.Sort(ar, 1, ar.Length - 1);\n int a = 0;\n int sum=0;\n if(ar[0]>0)\n {\n for(int i=ar.Length-1; i>0; --i)\n {\n a++;\n if((sum += ar[i])>=ar[0]) break;\n }\n }\n Console.WriteLine(a 0 )\n\t\t\t\t{\n\t\t\t\t\tres = 0;\n\t\t\t\t\tGo2( 0 );\n\t\t\t\t\tres = (int)( ( (long)res * cnt[k] ) % MOD );\n\t\t\t\t\trr += res;\n\t\t\t\t\tif ( rr >= MOD ) rr -= MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t\tOut.WriteLine( rr );\n\t\t}\n\n\t\tprivate int k, res, sum, sz;\n\t\tprivate int[] taken, cnts;\n\t\tvoid Go2( int pos )\n\t\t{\n\t\t\tif ( pos == 6 )\n\t\t\t{\n\t\t\t\tint cur = 1;\n\t\t\t\tfor ( int i = 0; i < 10; ++i )\n\t\t\t\t{\n\t\t\t\t\tint tot = cnt[i];\n\t\t\t\t\tfor ( int j = 0; j < cnts[i]; ++j )\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = (int)( ( (long)cur * tot ) % MOD );\n\t\t\t\t\t\t--tot;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tres += cur;\n\t\t\t\tif ( res >= MOD ) res -= MOD;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor ( int i = 0; i < 10; ++i )\n\t\t\t{\n\t\t\t\tif ( sum + i < k && cnt[i] >= cnts[i] + 1 )\n\t\t\t\t{\n\t\t\t\t\t++cnts[i];\n\t\t\t\t\tsum += i;\n\t\t\t\t\tGo2( pos + 1 );\n\t\t\t\t\tsum -= i;\n\t\t\t\t\t--cnts[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate const int MOD = 1000000007;\n\n\t\t#region Local wireup\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn _in.NextInt();\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn _in.NextLong();\n\t\t}\n\n\t\tpublic string NextLine()\n\t\t{\n\t\t\treturn _in.NextLine();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn _in.NextDouble();\n\t\t}\n\n\t\treadonly Scanner _in = new Scanner();\n\t\tstatic readonly TextWriter Out = Console.Out;\n\n\t\tvoid Start()\n\t\t{\n#if !ONLINE_JUDGE\n\t\t\tvar timer = new Stopwatch();\n\t\t\ttimer.Start();\n#endif\n\t\t\tvar t = new Thread( Solve, 20000000 );\n\t\t\tt.Start();\n\t\t\tt.Join();\n#if !ONLINE_JUDGE\n\t\t\ttimer.Stop();\n\t\t\tConsole.WriteLine( string.Format( CultureInfo.InvariantCulture, \"Done in {0} seconds.\\nPress to exit.\", timer.ElapsedMilliseconds / 1000.0 ) );\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\n\t\tstatic void Main()\n\t\t{\n\t\t\tnew B().Start();\n\t\t}\n\n\t\tclass Scanner : IDisposable\n\t\t{\n\t\t\t#region Fields\n\n\t\t\treadonly TextReader _reader;\n\t\t\treadonly int _bufferSize;\n\t\t\treadonly bool _closeReader;\n\t\t\treadonly char[] _buffer;\n\t\t\tint _length, _pos;\n\n\t\t\t#endregion\n\n\t\t\t#region .ctors\n\n\t\t\tpublic Scanner( TextReader reader, int bufferSize, bool closeReader )\n\t\t\t{\n\t\t\t\t_reader = reader;\n\t\t\t\t_bufferSize = bufferSize;\n\t\t\t\t_closeReader = closeReader;\n\t\t\t\t_buffer = new char[_bufferSize];\n\t\t\t\tFillBuffer( false );\n\t\t\t}\n\n\t\t\tpublic Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }\n\n\t\t\tpublic Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }\n\n#if ONLINE_JUDGE\n\t\t\tpublic Scanner() : this( Console.In, false ) { }\n#else\n\t\t\tpublic Scanner() : this( \"input.txt\" ) { }\n#endif\n\n\t\t\t#endregion\n\n\t\t\t#region IDisposable Members\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\tif ( _closeReader )\n\t\t\t\t{\n\t\t\t\t\t_reader.Close();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Properties\n\n\t\t\tpublic bool Eof\n\t\t\t{\n\t\t\t\tget\n\t\t\t\t{\n\t\t\t\t\tif ( _pos < _length ) return false;\n\t\t\t\t\tFillBuffer( false );\n\t\t\t\t\treturn _pos >= _length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t#endregion\n\n\t\t\t#region Methods\n\n\t\t\tprivate char NextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos++];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos++];\n\t\t\t}\n\n\t\t\tprivate char PeekNextChar()\n\t\t\t{\n\t\t\t\tif ( _pos < _length ) return _buffer[_pos];\n\t\t\t\tFillBuffer( true );\n\t\t\t\treturn _buffer[_pos];\n\t\t\t}\n\n\t\t\tprivate void FillBuffer( bool throwOnEof )\n\t\t\t{\n\t\t\t\t_length = _reader.Read( _buffer, 0, _bufferSize );\n\t\t\t\tif ( throwOnEof && Eof )\n\t\t\t\t{\n\t\t\t\t\tthrow new IOException( \"Can't read beyond the end of file\" );\n\t\t\t\t}\n\t\t\t\t_pos = 0;\n\t\t\t}\n\n\t\t\tpublic int NextInt()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tint res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic long NextLong()\n\t\t\t{\n\t\t\t\tvar neg = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tif ( !Eof && PeekNextChar() == '-' )\n\t\t\t\t{\n\t\t\t\t\tneg = true;\n\t\t\t\t\t_pos++;\n\t\t\t\t}\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tvar c = NextChar();\n\t\t\t\t\tif ( c < '0' || c > '9' ) throw new ArgumentException( \"Illegal character\" );\n\t\t\t\t\tres = 10 * res + c - '0';\n\t\t\t\t}\n\t\t\t\treturn neg ? -res : res;\n\t\t\t}\n\n\t\t\tpublic string NextLine()\n\t\t\t{\n\t\t\t\tSkipUntilNextLine();\n\t\t\t\tif ( Eof ) return \"\";\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn builder.ToString();\n\t\t\t}\n\n\t\t\tpublic double NextDouble()\n\t\t\t{\n\t\t\t\tSkipWhitespaces();\n\t\t\t\tvar builder = new StringBuilder();\n\t\t\t\twhile ( !Eof && !IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\tbuilder.Append( NextChar() );\n\t\t\t\t}\n\t\t\t\treturn double.Parse( builder.ToString(), CultureInfo.InvariantCulture );\n\t\t\t}\n\n\t\t\tprivate void SkipWhitespaces()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsWhitespace( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate void SkipUntilNextLine()\n\t\t\t{\n\t\t\t\twhile ( !Eof && IsEndOfLine( PeekNextChar() ) )\n\t\t\t\t{\n\t\t\t\t\t++_pos;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static bool IsWhitespace( char c )\n\t\t\t{\n\t\t\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\tprivate static bool IsEndOfLine( char c )\n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r';\n\t\t\t}\n\n\t\t\t#endregion\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9"} {"source_code": "using System;\nusing System.Numerics;\n\nnamespace CSharp\n{\n class _785C\n {\n public static void Main()\n {\n var tokens = Console.ReadLine().Split();\n\n long n = long.Parse(tokens[0]);\n long m = long.Parse(tokens[1]);\n\n if (n < m)\n {\n Console.WriteLine(n);\n }\n else\n {\n BigInteger l = m;\n BigInteger r = m + n;\n\n while (l < r)\n {\n var d = (l + r) / 2;\n\n if ((d - m) * (d - m + 1) / 2 + m >= n)\n {\n r = d;\n }\n else\n {\n l = d + 1;\n }\n }\n\n Console.WriteLine(l);\n }\n }\n }\n}", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Text;\nusing System.IO;\nusing System.Linq;\nusing System.Threading;\n\n\n\n\nclass Program\n{\n\n void solve()\n {\n int n = nextInt();\n int m = nextInt();\n int[] dp = new int[n + 1];\n int c0 = nextInt();\n int d0 = nextInt();\n for (int i = 0; i <= n; i++)\n dp[i] = i / c0 * d0;\n for (int i = 1; i <= m; i++)\n {\n int a = nextInt();\n int b = nextInt();\n int c = nextInt();\n int d = nextInt();\n int[] next = new int[n + 1];\n for (int x = 0; x <= n; x++)\n {\n for (int cur = 0; ; cur++)\n {\n if (cur * b > a)\n break;\n if (cur * c > x)\n break;\n next[x] = Math.Max(next[x], cur * d + dp[x - cur * c]);\n }\n }\n dp = next;\n }\n println(dp[n]);\n }\n\n ////////////\n private void println(int[] ar)\n {\n for (int i = 0; i < ar.Length; i++)\n {\n if (i == ar.Length - 1)\n println(ar[i]);\n else\n print(ar[i] + \" \");\n }\n }\n private void println(int[] ar, bool add)\n {\n int A = 0;\n if (add)\n A++;\n for (int i = 0; i < ar.Length; i++)\n {\n if (i == ar.Length - 1)\n println(ar[i] + A);\n else\n print((ar[i] + A) + \" \");\n }\n }\n\n private void println(string Stringst)\n {\n Console.WriteLine(Stringst);\n }\n private void println(char charnum)\n {\n Console.WriteLine(charnum);\n }\n private void println(int Intnum)\n {\n Console.WriteLine(Intnum);\n }\n private void println(long Longnum)\n {\n Console.WriteLine(Longnum);\n }\n private void println(double Doublenum)\n {\n string s = Doublenum.ToString(CultureInfo.InvariantCulture);\n Console.WriteLine(s);\n }\n\n private void print(string Stringst)\n {\n Console.Write(Stringst);\n }\n private void print(int Intnum)\n {\n Console.Write(Intnum);\n }\n private void print(char charnum)\n {\n Console.Write(charnum);\n }\n private void print(long Longnum)\n {\n Console.Write(Longnum);\n }\n private void print(double Doublenum)\n {\n Console.Write(Doublenum);\n }\n\n\n string[] inputLine = new string[0];\n int inputInd = 0;\n string nextLine()\n {\n return Console.ReadLine();\n }\n void readInput()\n {\n if (inputInd != inputLine.Length)\n throw new Exception();\n inputInd = 0;\n inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n if (inputLine.Length == 0)\n readInput();\n\n }\n int nextInt()\n {\n return int.Parse(nextString());\n }\n long nextLong()\n {\n return long.Parse(nextString());\n }\n double nextDouble()\n {\n return double.Parse(nextString());\n }\n string nextString()\n {\n if (inputInd == inputLine.Length)\n readInput();\n return inputLine[inputInd++];\n }\n static void Main(string[] args)\n {\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n new Program().solve();\n }\n}", "src_uid": "4e166b8b44427b1227e0f811161d3a6f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nclass Solver\n{\n void Solve()\n {\n var h = new HashMap();\n foreach (var c in sc.ScanLine())\n h[c]++;\n var a = h.Select(x => x.Value).OrderBy(x => x).ToArray();\n if (a.Length == 1)//\n Printer.PrintLine(1);\n else if (a.Length == 2)\n {\n var min = a[0];\n if (min == 1)\n Printer.PrintLine(1);//\n else if (min == 2)\n Printer.PrintLine(2);//\n else Printer.PrintLine(2);\n }\n else if (a.Length == 3)\n {\n if (a[0] == 1)\n {\n if (a[1] == 1)\n Printer.PrintLine(2);\n else Printer.PrintLine(3);//\n }\n else\n Printer.PrintLine(6);//\n }\n else if (a.Length == 4)\n {\n if (a[3] == 3)\n Printer.PrintLine(5);//\n else Printer.PrintLine(8);//\n }\n else if (a.Length == 5)\n Printer.PrintLine(15);//\n else if (a.Length == 6)\n Printer.PrintLine(30);//\n\n\n }\n\n static void Main()\n {\n#if DEBUG\n var ostream = new System.IO.FileStream(\"debug.txt\", System.IO.FileMode.Create, System.IO.FileAccess.Write);\n var iStream = new System.IO.FileStream(\"input.txt\", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);\n Console.SetIn(new System.IO.StreamReader(iStream));\n System.Diagnostics.Debug.AutoFlush = true;\n System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(new System.IO.StreamWriter(ostream, System.Text.Encoding.UTF8)));\n try\n {\n#endif\n var solver = new Solver();\n solver.Solve();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n Console.WriteLine(ex.StackTrace);\n }\n Console.ReadKey(true);\n#endif\n }\n _Scanner sc = new _Scanner();\n\n}\nstatic public class Printer\n{\n static readonly private System.IO.TextWriter writer;\n static readonly private System.Globalization.CultureInfo info;\n static string Separator { get; set; }\n static Printer()\n {\n writer = Console.Out;\n info = System.Globalization.CultureInfo.InvariantCulture;\n Separator = \" \";\n }\n\n static public void Print(int num) { writer.Write(num.ToString(info)); }\n static public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }\n static public void Print(long num) { writer.Write(num.ToString(info)); }\n static public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }\n static public void Print(double num) { writer.Write(num.ToString(info)); }\n static public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }\n static public void Print(string str) { writer.Write(str); }\n static public void Print(string format, params object[] arg) { writer.Write(format, arg); }\n static public void Print(IEnumerable sources) { writer.Write(sources.AsString()); }\n static public void Print(params object[] arg)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in arg)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (!string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.Write(res.ToString(0, res.Length - Separator.Length));\n }\n static public void Print(IEnumerable sources)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.Write(res.ToString(0, res.Length - Separator.Length));\n }\n static public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }\n static public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }\n static public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }\n static public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }\n static public void PrintLine(double num) { writer.WriteLine(num.ToString(info)); }\n static public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }\n static public void PrintLine(string str) { writer.WriteLine(str); }\n static public void PrintLine(string format, params object[] arg) { writer.WriteLine(format, arg); }\n static public void PrintLine(IEnumerable sources) { writer.WriteLine(sources.AsString()); }\n static public void PrintLine(params object[] arg)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in arg)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (!string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.WriteLine(res.ToString(0, res.Length - Separator.Length));\n }\n static public void PrintLine(IEnumerable sources)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (!string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.WriteLine(res.ToString(0, res.Length - Separator.Length));\n }\n}\npublic class _Scanner\n{\n readonly private System.Globalization.CultureInfo info;\n readonly System.IO.TextReader reader;\n string[] buffer = new string[0];\n int position;\n\n public char[] Separator { get; set; }\n public _Scanner(System.IO.TextReader reader = null, string separator = null, System.Globalization.CultureInfo info = null)\n {\n\n this.reader = reader ?? Console.In;\n if (string.IsNullOrEmpty(separator))\n separator = \" \";\n this.Separator = separator.ToCharArray();\n this.info = info ?? System.Globalization.CultureInfo.InvariantCulture;\n }\n public string Scan()\n {\n if (this.position < this.buffer.Length)\n return this.buffer[this.position++];\n this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);\n this.position = 0;\n return this.buffer[this.position++];\n }\n\n public string[] ScanToEndLine()\n {\n if (this.position >= this.buffer.Length)\n return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);\n var size = this.buffer.Length - this.position;\n var ar = new string[size];\n Array.Copy(this.buffer, position, ar, 0, size);\n return ar;\n\n }\n\n public string ScanLine()\n {\n if (this.position >= this.buffer.Length)\n return this.reader.ReadLine();\n else\n {\n var sb = new System.Text.StringBuilder();\n for (; this.position < buffer.Length; this.position++)\n {\n sb.Append(this.buffer[this.position]);\n sb.Append(' ');\n }\n return sb.ToString();\n }\n }\n public string[] ScanArray(int length)\n {\n var ar = new string[length];\n for (int i = 0; i < length; i++)\n {\n ar[i] = this.Scan();\n }\n return ar;\n }\n\n public int Integer()\n {\n return int.Parse(this.Scan(), info);\n }\n public long Long()\n {\n return long.Parse(this.Scan(), info);\n }\n public double Double()\n {\n return double.Parse(this.Scan(), info);\n }\n\n public int[] IntArray(int length)\n {\n var a = new int[length];\n for (int i = 0; i < length; i++)\n a[i] = this.Integer();\n return a;\n }\n public long[] LongArray(int length)\n {\n var a = new long[length];\n for (int i = 0; i < length; i++)\n a[i] = this.Long();\n return a;\n }\n public double[] DoubleArray(int length)\n {\n var a = new double[length];\n for (int i = 0; i < length; i++)\n a[i] = this.Double();\n return a;\n }\n\n}\nstatic public partial class EnumerableEx\n{\n static public string AsString(this IEnumerable source)\n {\n return new string(source.ToArray());\n }\n static public IEnumerable Enumerate(this int count, Func selector)\n {\n return Enumerable.Range(0, count).Select(x => selector(x));\n }\n}\nclass HashMap : Dictionary\n{\n new public V this[K i]\n {\n get\n {\n V v;\n return TryGetValue(i, out v) ? v : base[i] = default(V);\n }\n set { base[i] = value; }\n }\n}\n//*/", "src_uid": "8176c709c774fa87ca0e45a5a502a409"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace FootballChampionship\n{\n internal class Team\n {\n public String Name\n {\n get;\n set;\n }\n\n public int GamesPlayed\n {\n get;\n set;\n }\n\n public int Points\n {\n get;\n set;\n }\n\n public int Scored\n {\n get;\n set;\n }\n\n public int Missed\n {\n get;\n set;\n }\n }\n\n internal class Program\n {\n private static readonly Dictionary tournament = new Dictionary();\n\n private static void Main(string[] args)\n {\n Process(Console.ReadLine());\n Process(Console.ReadLine());\n Process(Console.ReadLine());\n Process(Console.ReadLine());\n Process(Console.ReadLine());\n\n String result = Solve();\n Console.Out.WriteLine(result);\n }\n\n private static string Solve()\n {\n var teams = new List(tournament.Values);\n Team o = teams.Where(t => t.GamesPlayed == 2 && t.Name != \"BERLAND\").First();\n Team b = teams.Where(t => t.GamesPlayed == 2 && t.Name == \"BERLAND\").First();\n int bScored = b.Scored;\n int oScored = o.Scored;\n int bMissed = b.Missed;\n int oMissed = o.Missed;\n\n b.Points += 3;\n for (int i = 1; i < 60; i++)\n {\n for(int j = 0; j < 60; j++)\n {\n b.Scored = bScored;\n o.Scored = oScored;\n b.Missed = bMissed;\n o.Missed = oMissed;\n\n b.Scored += (i + j);\n b.Missed += j;\n o.Scored += j;\n o.Missed += (i + j);\n SortTeams(teams);\n if (teams[0].Name == \"BERLAND\" || teams[1].Name == \"BERLAND\")\n {\n return String.Format(\"{0}:{1}\", i + j, j);\n }\n }\n }\n return \"IMPOSSIBLE\";\n }\n\n private static void SortTeams(List teams)\n {\n teams.Sort(\n (t1, t2) =>\n {\n int x = t2.Points.CompareTo(t1.Points);\n if (x != 0)\n {\n return x;\n }\n x = (t2.Scored - t2.Missed).CompareTo(t1.Scored - t1.Missed);\n if (x != 0)\n {\n return x;\n }\n x = t2.Scored.CompareTo(t1.Scored);\n if (x != 0)\n {\n return x;\n }\n return t1.Name.CompareTo(t2.Name);\n });\n }\n\n private static void Process(string line)\n {\n String[] parts = line.Split(' ');\n String team1 = parts[0];\n String team2 = parts[1];\n int[] scores = parts[2].Split(':').Select(x => Convert.ToInt32(x)).ToArray();\n int score1 = scores[0];\n int score2 = scores[1];\n\n AddTeam(team1, score1, score2);\n AddTeam(team2, score2, score1);\n }\n\n private static void AddTeam(string team, int scored, int missed)\n {\n if (!tournament.ContainsKey(team))\n {\n tournament[team] = new Team { Name = team };\n }\n tournament[team].GamesPlayed++;\n tournament[team].Scored += scored;\n tournament[team].Missed += missed;\n tournament[team].Points += scored > missed ? 3 : (scored == missed ? 1 : 0);\n }\n }\n}", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace cf\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n try\n {\n long[] ar = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();\n long n = ar[0];\n long k = ar[1];\n // Console.WriteLine((1000000000000/ 2 -499999999999)/2);\n long d = (n / 2) / (k + 1);\n long c = k * d;\n long no = n - d - c;\n Console.WriteLine(d+\" \"+c+\" \"+no);\n Console.ReadKey();\n }\n catch { }\n }\n \n }\n}\n", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"} {"source_code": "using System;\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main()\n {\n var s = 2*Convert.ToInt16(Console.ReadLine());\n var a = (byte) Math.Sqrt(s);\n Console.WriteLine(a*(a+1)==s?\"YES\":\"NO\");\n }\n }\n}", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n//using System.Numerics;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n void Solve()\n {\n int n = ReadInt();\n if (n == 1)\n {\n Write(1);\n return;\n }\n int m = ReadInt();\n Write(m <= n / 2 ? m + 1 : m - 1);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"hull.in\");\n //writer = new StreamWriter(\"hull.out\");\n#endif\n try\n {\n // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n // thread.Start();\n // thread.Join();\n checked\n {\n new Solver().Solve();\n }\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace Contest_276\n{\n class Program\n {\n static string yes = \"Yes\";\n static string no = \"No\";\n\n static void Main(string[] args)\n {\n string[] lines = Console.ReadLine().Split(' ');\n int a = Int32.Parse(lines[0]);\n int m = Int32.Parse(lines[1]);\n\n printResult(a, m);\n\n Console.ReadLine();\n }\n\n static void printResult(int a, int m)\n {\n HashSet set = new HashSet();\n int rest = -1;\n\n while (true)\n {\n rest = a % m;\n if (rest == 0)\n {\n Console.WriteLine(yes);\n return;\n }\n\n if (set.Contains(rest))\n {\n Console.WriteLine(no);\n return;\n }\n\n set.Add(rest);\n a += rest;\n }\n }\n }\n}\n", "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "using System;\nusing System.Text;\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n bool metAt = false;\n var builder = new StringBuilder(Console.ReadLine());\n for(int i=1; i < builder.Length - 2; i++)\n {\n if (i = n || newY < 0 || newY >= m || matrix[newX, newY] != '#')\n can = false;\n if (!can)\n break;\n }\n\n if (can)\n return true;\n }\n }\n\n return false;\n }\n \n public void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n \n private void Dispose(bool disposing)\n {\n if (!isDispose) {\n if (disposing) {\n if(sr != null)\n sr.Dispose();\n \n if(sw != null)\n sw.Dispose();\n }\n\n isDispose = true;\n }\n }\n }\n}\n\ninternal class InputReader : IDisposable\n{\n private bool isDispose;\n private readonly TextReader sr;\n private string[] buffer;\n private int seek;\n\n public InputReader(TextReader stream)\n {\n sr = stream;\n }\n\n public void Dispose()\n {\n Dispose(true);\n GC.SuppressFinalize(this);\n }\n\n public string NextString()\n {\n var result = sr.ReadLine();\n return result;\n }\n\n public int NextInt32()\n {\n return Int32.Parse(ReadNextToken());\n }\n\n private string ReadNextToken()\n {\n if (buffer == null || seek == buffer.Length) {\n seek = 0;\n buffer = NextSplitStrings();\n }\n\n return buffer[seek++];\n }\n\n public long NextInt64()\n {\n return Int64.Parse(ReadNextToken());\n }\n \n public int[] ReadArrayOfInt32()\n {\n return ReadArray(Int32.Parse);\n }\n\n public long[] ReadArrayOfInt64()\n {\n return ReadArray(Int64.Parse);\n }\n\n public string[] NextSplitStrings()\n {\n return NextString()\n .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public T[] ReadArray(Func func)\n {\n return NextSplitStrings()\n .Select(s => func(s, CultureInfo.InvariantCulture))\n .ToArray();\n }\n\n public T[] ReadArrayFromString(Func func, string str)\n {\n return\n str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)\n .Select(s => func(s, CultureInfo.InvariantCulture))\n .ToArray();\n }\n\n protected void Dispose(bool dispose)\n {\n if (!isDispose)\n {\n if (dispose)\n sr.Close();\n \n isDispose = true;\n }\n }\n\n ~InputReader()\n {\n Dispose(false);\n }\n}", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\n\nnamespace prA {\n class Program {\n#if ONLINE_JUDGE\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);\n#else\n private static readonly StreamWriter writer = new StreamWriter(@\"..\\..\\output\");\n private static readonly StreamReader reader = new StreamReader(@\"..\\..\\input\");\n#endif\n\n static void Main(string[] args) {\n int n = NextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = NextInt();\n }\n int best = int.MaxValue;\n for (int j = 0; j < n; j++) {\n int cur = 0;\n for (int i = 0; i < n; i++) {\n cur += a[i] * (Math.Abs(i - j) + i + j + j + i + Math.Abs(i - j));\n }\n best = Math.Min(best, cur);\n }\n writer.Write(best);\n writer.Flush();\n#if !ONLINE_JUDGE\n writer.Close();\n#endif\n }\n private static int NextInt() {\n int c;\n int res = 0;\n do {\n c = reader.Read();\n if(c == -1)\n return res;\n } while(c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if(c == '-') {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while(true) {\n c = reader.Read();\n if(c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n private static long NextLong() {\n int c;\n long res = 0;\n do {\n c = reader.Read();\n if(c == -1)\n return res;\n } while(c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if(c == '-') {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while(true) {\n c = reader.Read();\n if(c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}\n", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing SB = System.Text.StringBuilder;\nusing System.Numerics;\nusing static System.Math;\nusing Number = System.Int64;\nnamespace Program {\n public class Solver {\n Random rnd = new Random(0);\n\n public void Solve() {\n var n = ri;\n var s = rs;\n const string T = \"ACTG\";\n var ans = 1000000000;\n for (int i = 0; i <= n - 4; i++) {\n var val = 0;\n for (int j = 0; j < 4; j++) {\n var u = T[j] - 'A';\n var v = s[i + j] - 'A';\n val += Min(Abs(u - v), 26 - Abs(u - v));\n }\n ans = Min(ans, val);\n }\n Console.WriteLine(ans);\n }\n\n\n\n const long INF = 1L << 60;\n int ri => sc.Integer();\n long rl => sc.Long();\n double rd => sc.Double();\n string rs => sc.Scan();\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n\n static IEnumerable Rep(int n) => Enumerable.Range(0, n);\n static IEnumerable RRep(int n) => Enumerable.Range(0, n).Reverse();\n static T[] Enumerate(int n, Func f) {\n var a = new T[n];\n for (int i = 0; i < a.Length; ++i) a[i] = f(i);\n return a;\n }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n\n#region main\nstatic class Ex {\n static public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") {\n return string.Join(st, ie);\n }\n static public void Main() {\n Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });\n var solver = new Program.Solver();\n solver.Solve();\n Console.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO {\n using System.IO;\n using System.Text;\n using System.Globalization;\n\n public class Printer : StreamWriter {\n public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture;\n public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n }\n\n public class StreamScanner {\n public StreamScanner(Stream stream) { str = stream; }\n\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n\n private byte read() {\n if (isEof) return 0;\n if (ptr >= len) {\n ptr = 0;\n if ((len = str.Read(buf, 0, 1024)) <= 0) {\n isEof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n\n public char Char() {\n byte b = 0;\n do b = read(); while ((b < 33 || 126 < b) && !isEof);\n return (char)b;\n }\n public string Scan() {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine() {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n' && b != 0; b = (char)read()) if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }\n public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }\n public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }\n }\n}\n\n#endregion\n", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"} {"source_code": "using System;\n\npublic class Program\n{\n public static void Main()\n {\n int count, zeroCount;\n string binaryNumber;\n\n count = int.Parse(Console.ReadLine());\n binaryNumber = Console.ReadLine();\n zeroCount = 0;\n\n if (binaryNumber == \"0\")\n {\n Console.WriteLine(\"0\");\n return;\n }\n\n for (int i = 0; i < binaryNumber.Length; i++)\n {\n if (binaryNumber[i] == '0')\n zeroCount++;\n }\n\n Console.Write(\"1\");\n for (int i = 0; i < zeroCount; i++)\n {\n Console.Write(\"0\");\n }\n Console.WriteLine();\n }\n}", "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"source_code": "using System;\r\nusing System.Linq;\r\nusing System.Numerics;\r\n\r\nnamespace CompetitiveProgramming\r\n{\r\n\tclass Program\r\n\t{\r\n\t\tstatic void Main()\r\n\t\t{\r\n\t\t\tvar cases = int.Parse(Console.ReadLine());\r\n\t\t\tvar output = new ModVal[cases];\r\n\r\n\t\t\tfor (int i = 0; i < cases; i++)\r\n\t\t\t{\r\n\t\t\t\tvar ints = Console.ReadLine().Split().Select(long.Parse).ToArray();\r\n\t\t\t\tvar n = ints[0];\r\n\t\t\t\tvar k = ints[1];\r\n\t\t\t\tModVal ans = Solve(n, k);\r\n\r\n\t\t\t\t//var s2 = S2(n, k);\r\n\t\t\t\t//if (s2 != ans)\r\n\t\t\t\t//\tConsole.WriteLine(s2.Val.ToString() + \" \" + ans.ToString());\r\n\r\n\t\t\t\toutput[i] = ans;\r\n\t\t\t}\r\n\r\n\t\t\toutput.ToList().ForEach(x => Console.WriteLine(x.Val));\r\n\t\t}\r\n\r\n\t\tprivate static ModVal S2(long n, long k)\r\n\t\t{\r\n\t\t\tvar gaa = new long[n];\r\n\r\n\t\t\tint ab = 0;\r\n\r\n\t\t\tvar mask = ~(-1L << (int)k);\r\n\r\n\t\t\tvar groups = new int[k];\r\n\r\n\t\t\tvar eqa = 0;\r\n\r\n\t\t\tfor (long i = 0; i < 1 << ((int)n * (int)k); i++)\r\n\t\t\t{\r\n\t\t\t\tfor (int j = 0; j < n; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tgaa[j] = (i >> (j * (int)k)) & mask;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar anda = gaa.Aggregate(mask, (x, y) => x & y);\r\n\t\t\t\tvar xora = gaa.Aggregate(0L, (x, y) => x ^ y);\r\n\r\n\t\t\t\tif (anda == xora)\r\n\t\t\t\t\teqa++;\r\n\t\t\t\tif (anda >= xora)\r\n\t\t\t\t{\r\n\t\t\t\t\tab++;\r\n\t\t\t\t\t//Console.WriteLine(string.Join(' ', gaa));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tConsole.WriteLine((ab - eqa).ToString() + ' ' + eqa.ToString());\r\n\r\n\t\t\treturn ab;\r\n\t\t}\r\n\r\n\t\tprivate static ModVal Solve(long n, long k)\r\n\t\t{\r\n\t\t\t// jesli jest nieparzysta to wygrywa gdy na wszystkich bitach jest albo parzysta liczba jedynek albo wszystkie jedynki\r\n\t\t\t// parzysta liczba jedynek może być na 2^(n-1) sposobow\r\n\r\n\t\t\tModVal ans;\r\n\t\t\tif (n % 2 == 1)\r\n\t\t\t{\r\n\t\t\t\tvar xa = BigInteger.ModPow(2, n - 1, ModVal.Mod) + 1;\r\n\t\t\t\tvar va = BigInteger.ModPow(xa, k, ModVal.Mod);\r\n\t\t\t\tans = (long)va;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// albo wygrywam na ktoryms bicie, albo to co w poprzednim\r\n\t\t\t\tvar xa = BigInteger.ModPow(2, n - 1, ModVal.Mod) - 1;\r\n\t\t\t\tvar va = BigInteger.ModPow(xa, k, ModVal.Mod);\r\n\r\n\t\t\t\tModVal acc = 0;\r\n\t\t\t\tfor (int j = 0; j < k; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar va2 = BigInteger.ModPow(xa, k - j - 1, ModVal.Mod);\r\n\r\n\t\t\t\t\tvar ga = BigInteger.ModPow(2, j * n, ModVal.Mod)*va2;\r\n\t\t\t\t\tacc = (long)ga + acc;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t//Console.WriteLine((acc).ToString() + ' ' + va.ToString());\r\n\r\n\t\t\t\tans = acc + (long)va;\r\n\t\t\t}\r\n\r\n\t\t\treturn ans;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic struct ModVal\r\n\t{\r\n\t\tpublic static long Mod = 1000000007;\r\n\t\tpublic readonly long Val;\r\n\r\n\t\tpublic ModVal(long val)\r\n\t\t{\r\n\t\t\tVal = val % Mod;\r\n\t\t}\r\n\r\n\t\tpublic override bool Equals(object obj) => obj is ModVal && Val == ((ModVal)obj).Val;\r\n\t\tpublic override int GetHashCode() => Val.GetHashCode();\r\n\t\tpublic override string ToString() => Val.ToString();\r\n\t\tpublic static ModVal operator +(ModVal a, ModVal b) => new ModVal(a.Val + b.Val);\r\n\t\tpublic static ModVal operator -(ModVal a, ModVal b) => new ModVal(a.Val - b.Val + Mod);\r\n\t\tpublic static ModVal operator *(ModVal a, ModVal b) => new ModVal(a.Val * b.Val);\r\n\t\tpublic static bool operator ==(ModVal a, ModVal b) => a.Val == b.Val;\r\n\t\tpublic static bool operator !=(ModVal a, ModVal b) => a.Val != b.Val;\r\n\t\tpublic static implicit operator ModVal(long a) => new ModVal(a);\r\n\t}\r\n}\r\n", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Numerics;\npublic class Codeforces\n{\n protected static TextReader reader;\n protected static TextWriter writer;\n static object Solve()\n {\n var n = ReadInt();\n var m = ReadInt();\n var k = ReadInt();\n var a = ReadIntArray().OrderByDescending(d => d).ToArray();\n var x = m;\n x -= k > 1 ? k - 1 : 0;\n int i;\n for (i = 0; x > 0 && i < n; i++)\n {\n if (x - a[i] == 0)\n {\n x = 0;\n continue;\n }\n else\n {\n x -= (a[i] - 1);\n }\n }\n writer.WriteLine(m <= k ? 0 : x <= 0 ? i : -1);\n return null;\n }\n static void Main()\n {\n reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);\n writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);\n try\n {\n object result = Solve();\n if (result != null)\n writer.WriteLine(result);\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n throw;\n }\n reader.Close();\n writer.Close();\n }\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params T[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c != '-' && (c < '0' || c > '9'));\n int sign = 1;\n if (c == '-')\n {\n sign = -1;\n c = reader.Read();\n }\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res * sign;\n res *= 10;\n res += c - '0';\n }\n }\n #endregion\n}", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"source_code": "// See https://aka.ms/new-console-template for more information\r\n\r\n(int x, int y) = ReadTwoInts();\r\nConsole.WriteLine(y == 1 ? x - 1 : 1L * x * (y - 1));\r\n\r\n\r\n#region Read\r\nstatic int ReadInt() => int.Parse(Console.ReadLine());\r\nstatic (int x, int y) ReadTwoInts()\r\n{\r\n\tvar ints = ReadInts();\r\n\treturn (ints[0], ints[1]);\r\n}\r\nstatic string ReadString() => Console.ReadLine();\r\nstatic List ReadStrings() => Console.ReadLine().Split(' ').ToList();\r\nstatic List ReadInts()\r\n{\r\n\tList strings = ReadStrings();\r\n\tList ints = new();\r\n\tfor (int i = 0; i < strings.Count; i++)\r\n\t{\r\n\t\tints.Add(int.Parse(strings[i]));\r\n\t}\r\n\treturn ints;\r\n}\r\n#endregion\r\n\r\n", "src_uid": "a91aab4c0618d036c81022232814ef44"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Linq.Expressions;\nusing System.IO;\nusing System.Text;\nusing System.Diagnostics;\n\nusing static util;\nusing P = pair;\n\nusing Binary = System.Func;\nusing Unary = System.Func;\n\nclass Program {\n static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };\n static Scan sc = new Scan();\n const int M = 1000000007;\n const int M2 = 998244353;\n const long LM = 1L << 60;\n const double eps = 1e-11;\n static void Main(string[] args)\n {\n int n = sc.Int;\n var p = new P[n * 4 + 1];\n var xs = new HashSet();\n var ys = new HashSet();\n for (int i = 0; i < n * 4 + 1; i++)\n {\n p[i] = sc.P;\n xs.Add(p[i].v1);\n ys.Add(p[i].v2);\n }\n foreach (var x1 in xs)\n {\n foreach (var x2 in xs)\n {\n if (x1 >= x2) continue;\n foreach (var y1 in ys)\n {\n foreach (var y2 in ys)\n {\n if (y1 >= y2) continue;\n var lis = new List

();\n for (int i = 0; i < n * 4 + 1; i++)\n {\n if ((p[i].v1 == x1 || p[i].v1 == x2) && y1 <= p[i].v2 && p[i].v2 <= y2 ||\n (p[i].v2 == y1 || p[i].v2 == y2) && x1 <= p[i].v1 && p[i].v1 <= x2) {\n }\n else {\n lis.Add(p[i]);\n }\n }\n if (lis.Count == 1) {\n DBG(lis[0]);\n return;\n }\n }\n }\n }\n }\n\n sw.Flush();\n }\n\n static void DBG(string a) => Console.WriteLine(a);\n static void DBG(IEnumerable a) => DBG(string.Join(\" \", a));\n static void DBG(params object[] a) => DBG(string.Join(\" \", a));\n static void Prt(string a) => sw.WriteLine(a);\n static void Prt(IEnumerable a) => Prt(string.Join(\" \", a));\n static void Prt(params object[] a) => Prt(string.Join(\" \", a));\n}\nclass pair : IComparable> {\n public T v1;\n public U v2;\n public pair() : this(default(T), default(U)) {}\n public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; }\n public int CompareTo(pair a) {\n int c = Comparer.Default.Compare(v1, a.v1);\n return c != 0 ? c : Comparer.Default.Compare(v2, a.v2);\n }\n public override string ToString() => v1 + \" \" + v2;\n public void Deconstruct(out T a, out U b) { a = v1; b = v2; }\n public static bool operator>(pair a, pair b) => a.CompareTo(b) > 0;\n public static bool operator<(pair a, pair b) => a.CompareTo(b) < 0;\n public static bool operator>=(pair a, pair b) => a.CompareTo(b) >= 0;\n public static bool operator<=(pair a, pair b) => a.CompareTo(b) <= 0;\n}\nstatic class util {\n public static pair make_pair(T v1, U v2) => new pair(v1, v2);\n public static T sq(T a) => Operator.Multiply(a, a);\n public static T Max(params T[] a) => a.Max();\n public static T Min(params T[] a) => a.Min();\n public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;\n static readonly int[] dd = { 0, 1, 0, -1 };\n static readonly string dstring = \"RDLU\";\n public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);\n public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w);\n public static pair[] adjacents_with_str(int i, int j)\n => Enumerable.Range(0, dd.Length).Select(k => new pair(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])).ToArray();\n public static pair[] adjacents_with_str(int i, int j, int h, int w)\n => Enumerable.Range(0, dd.Length).Select(k => new pair(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])).Where(p => inside(p.v1.v1, p.v1.v2, h, w)).ToArray();\n public static P[] adjacents(int i, int j)\n => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1])).ToArray();\n public static P[] adjacents(int i, int j, int h, int w)\n => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1])).Where(p => inside(p.v1, p.v2, h, w)).ToArray();\n public static void Assert(bool cond) { if (!cond) throw new Exception(); }\n public static Dictionary compress(this IEnumerable a)\n => a.Distinct().OrderBy(v => v).Select((v, i) => new { v, i }).ToDictionary(p => p.v, p => p.i);\n public static Dictionary compress(params IEnumerable[] a) => compress(a.Aggregate(Enumerable.Union));\n public static void swap(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; }\n public static void swap(this IList a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; }\n public static T[] copy(this IList a) {\n var ret = new T[a.Count];\n for (int i = 0; i < a.Count; i++) ret[i] = a[i];\n return ret;\n }\n}\nstatic class Operator {\n static readonly ParameterExpression x = Expression.Parameter(typeof(T), \"x\");\n static readonly ParameterExpression y = Expression.Parameter(typeof(T), \"y\");\n public static readonly Func Add = Lambda(Expression.Add);\n public static readonly Func Subtract = Lambda(Expression.Subtract);\n public static readonly Func Multiply = Lambda(Expression.Multiply);\n public static readonly Func Divide = Lambda(Expression.Divide);\n public static readonly Func Plus = Lambda(Expression.UnaryPlus);\n public static readonly Func Negate = Lambda(Expression.Negate);\n public static Func Lambda(Binary op) => Expression.Lambda>(op(x, y), x, y).Compile();\n public static Func Lambda(Unary op) => Expression.Lambda>(op(x), x).Compile();\n}\n\nclass Scan {\n StreamReader sr;\n public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }\n public Scan(string path) { sr = new StreamReader(path); }\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public string Str => sr.ReadLine().Trim();\n public pair Pair() {\n T a; U b;\n Multi(out a, out b);\n return new pair(a, b);\n }\n public P P => Pair();\n public int[] IntArr => StrArr.Select(int.Parse).ToArray();\n public long[] LongArr => StrArr.Select(long.Parse).ToArray();\n public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();\n public string[] StrArr => Str.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);\n bool eq() => typeof(T).Equals(typeof(U));\n T ct(U a) => (T)Convert.ChangeType(a, typeof(T));\n T cv(string s) => eq() ? ct(int.Parse(s))\n : eq() ? ct(long.Parse(s))\n : eq() ? ct(double.Parse(s))\n : eq() ? ct(s[0])\n : ct(s);\n public void Multi(out T a) => a = cv(Str);\n public void Multi(out T a, out U b)\n { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); }\n public void Multi(out T a, out U b, out V c)\n { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); }\n public void Multi(out T a, out U b, out V c, out W d)\n { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); }\n public void Multi(out T a, out U b, out V c, out W d, out X e)\n { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); e = cv(ar[4]); }\n}\n", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\n\ninternal class Program\n{\n private static void Main(string[] args)\n {\n var n = int.Parse(Console.ReadLine());\n var n1 = Math.Abs(n % 10);\n var n2 = Math.Abs((n / 10) % 10);\n\n if (n >= 0)\n {\n Console.WriteLine(n);\n }\n else\n {\n if (n2 < n1)\n {\n Console.WriteLine(n / 10);\n }\n else\n {\n n /= 100;\n n *= 10;\n n -= n1;\n Console.WriteLine(n);\n }\n }\n }\n}\n\n\n", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections;\nusing System.Collections.Generic;\npublic class Test\n{\n\n\tpublic static void Main()\n\t{\n\t\tint n = Convert.ToInt32(Console.ReadLine());\n\t\tint sayac = 0;\n\n\t\tsayac += n / 100;\n\t\tn = n % 100;\n\t\tsayac += n / 20;\n\t\tn = n % 20;\n\t\tsayac += n / 10;\n\t\tn = n % 10;\n\t\tsayac += n / 5;\n\t\tn = n % 5;\n\t\tsayac += n / 1;\n\n\t\tConsole.WriteLine(sayac);\n\t}\n}\n\n", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _1154_B\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tint n = int.Parse(Console.ReadLine());\n\n\t\t\tint[] a = new int[n];\n\t\t\tint i = 0;\n\n\t\t\tforeach (string s in Console.ReadLine().Split(' '))\n\t\t\t{\n\t\t\t\ta[i++] = int.Parse(s);\n\t\t\t}\n\n\t\t\tList numbers = CountAndReturnDifferentOnes(a);\n\n\t\t\tif (numbers.Count >= 4)\n\t\t\t{\n\t\t\t\tConsole.WriteLine(-1);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tswitch (numbers.Count)\n\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tConsole.WriteLine(0);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 2:\n\t\t\t\t\tint diff = Math.Abs(numbers[0] - numbers[1]);\n\t\t\t\t\tConsole.WriteLine(diff % 2 == 0 ? diff / 2 : diff);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 3:\n\t\t\t\t\tnumbers.Sort();\n\t\t\t\t\tint fark = numbers[2] - numbers[0];\n\n\t\t\t\t\tif (fark % 2 == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (numbers[0] + (fark / 2) == numbers[1])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tConsole.WriteLine(numbers[1] - numbers[0]);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tConsole.WriteLine(-1);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tstatic List CountAndReturnDifferentOnes(int[] a)\n\t\t{\n\t\t\tList numbers = new List();\n\n\t\t\tforeach (int item in a)\n\t\t\t{\n\t\t\t\tif (numbers.Contains(item))\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tnumbers.Add(item);\n\n\t\t\t\tif (numbers.Count >= 4)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn numbers;\n\t\t}\n\t}\n}\n", "src_uid": "d486a88939c132848a7efdf257b9b066"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace ConsoleApplication6\n{\n class Program\n {\n static int getN(int n)\n {\n if (n == 0) return 1;\n switch (n % 4)\n {\n case 0: return 6;\n case 1: return 8;\n case 2: return 4;\n case 3: return 2;\n }\n return 0;\n }\n \n static void Main(string[] args)\n {\n double n = double.Parse(Console.ReadLine());\n Console.Write(getN((int)n));\n }\n \n }\n}\n", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CF._3C\n{\n class Program\n {\n static void Main(string[] args)\n {\n char[,] board = new char[3, 3];\n int x = 0, o = 0;\n for (int i = 0; i < 3; i++)\n {\n string temp = Console.ReadLine();\n for (int j = 0; j < 3; j++)\n {\n board[i, j] = temp[j];\n if (board[i, j] == 'X')\n x++;\n else if (board[i, j] == '0')\n o++;\n }\n }\n if (o > x || x > o + 1)\n Console.WriteLine(\"illegal\");\n else\n {\n string winner;\n winner=\"\";\n bool illegal = false;\n for (int i = 0; i < 3; i++)\n if ((board[i, 0] == 'X' && board[i, 1] == 'X' && board[i, 2] == 'X') || (board[0, i] == 'X' && board[1, i] == 'X' && board[2, i] == 'X'))\n winner = \"first\";\n if ((board[0, 0] == 'X' && board[1, 1] == 'X' && board[2, 2] == 'X') || (board[0, 2] == 'X' && board[1, 1] == 'X' && board[2, 0] == 'X'))\n winner = \"first\";\n for (int i = 0; i < 3; i++)\n if ((board[i, 0] == '0' && board[i, 1] == '0' && board[i, 2] == '0') || (board[0, i] == '0' && board[1, i] == '0' && board[2, i] == '0'))\n {\n if (winner.Length != 0)\n illegal = true;\n winner = \"second\";\n }\n if ((board[0, 0] == '0' && board[1, 1] == '0' && board[2, 2] == '0') || (board[0, 2] == '0' && board[1, 1] == '0' && board[2, 0] == '0'))\n winner = \"second\";\n if (illegal)\n Console.WriteLine(\"illegal\");\n else if (winner.Length == 0)\n {\n if (x + o == 9)\n Console.WriteLine(\"draw\");\n else if (x == o)\n Console.WriteLine(\"first\");\n else\n Console.WriteLine(\"second\");\n }\n else\n {\n if (winner.Equals(\"first\") && x == o + 1)\n Console.WriteLine(\"the first player won\");\n else if (winner.Equals(\"second\") && x == o)\n Console.WriteLine(\"the second player won\");\n else\n Console.WriteLine(\"illegal\");\n }\n }\n }\n }\n}", "src_uid": "892680e26369325fb00d15543a96192c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces\n{\n class Program : IDisposable\n {\n private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());\n private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());\n \n void Solve()\n {\n var n = long.Parse(Console.ReadLine());\n var a = long.Parse(Console.ReadLine());\n var b = long.Parse(Console.ReadLine());\n var c = long.Parse(Console.ReadLine());\n \n\n var plasticRes = n/a;\n var plastOst = n - plasticRes*a;\n\n long glassRes = 0;\n long glassOst = 0;\n //Glass(n, a, b, c, ref glassRes, ref glassOst);\n\n Glass(plastOst, b, c, ref glassRes, ref glassOst);\n var res1 = plasticRes + glassRes;\n\n \n glassRes = 0;\n glassOst = 0;\n Glass(n, b, c, ref glassRes, ref glassOst);\n var res2 = glassRes;\n if (glassOst >= a)\n {\n res2 += (glassOst/a);\n }\n var ans = Math.Max(res1, res2);\n Console.WriteLine(ans);\n // Console.ReadLine();\n }\n\n void Glass(long n, long b, long c, ref long glassRes, ref long glassOst)\n {\n glassRes = (n / b);\n if(glassRes == 0)\n return;\n var step = b - c;\n glassOst = (n%b)+c*(n/b);//n - (n / b) * b + c * (n / b);\n if(glassOst < b)\n return;\n var diff = (glassOst - b);\n if (diff < step)\n {\n glassRes++;\n //glassOst = 0;\n }\n \n else\n {\n glassRes += (diff / step)+1;\n }\n glassOst = n - (b - c)*glassRes;\n //glassOst = (glassOst/b)*c; //diff % step;\n //while (glassOst >= b)\n //{\n // glassOst = (glassOst/b)*c + (glassOst%b);\n //}\n }\n \n\n static void Main(string[] args)\n {\n var p = new Program();\n p.Solve();\n p.Dispose();\n }\n\n #region Helpers\n\n private static int ReadInt()\n {\n return int.Parse(textReader.ReadLine());\n }\n\n private static long ReadLong()\n {\n return long.Parse(textReader.ReadLine());\n }\n\n private static int[] ReadIntArray()\n {\n return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();\n }\n #endregion\n\n public void Dispose()\n {\n textReader.Close();\n textWriter.Close();\n }\n }\n}\n", "src_uid": "0ee9abec69230eab25de51aef0984f8f"} {"source_code": "#if DEBUG\nusing System.Reflection;\nusing System.Threading.Tasks;\n#endif\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\n\nnamespace _233b\n{\n\tclass Program\n\t{\n\t\tstatic string _inputFilename = \"input.txt\";\n\t\tstatic string _outputFilename = \"output.txt\";\n#if DEBUG\n static bool _useFileInput = false;\n#else\n\t\tstatic bool _useFileInput = false;\n#endif\n\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tStreamWriter file = null;\n\t\t\tif (_useFileInput)\n\t\t\t{\n\t\t\t\tConsole.SetIn(File.OpenText(_inputFilename));\n\t\t\t\tfile = new StreamWriter(_outputFilename);\n\t\t\t\tConsole.SetOut(file);\n\t\t\t}\n\n#if DEBUG\n\t\t\tif (!_useFileInput)\n\t\t\t{\n\t\t\t\tConsole.SetIn(getInput());\n\t\t\t}\n#endif\n\n\t\t\ttry\n\t\t\t{\n\t\t\t\tsolution();\n\t\t\t}\n\t\t\tfinally\n\t\t\t{\n\t\t\t\tif (_useFileInput)\n\t\t\t\t{\n\t\t\t\t\tfile.Close();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tstatic void solution()\n\t\t{\n\t\t\t#region SOLUTION\n\t\t\tvar n = readInt();\n\t\t\tvar s = Console.ReadLine();\n\t\t\tvar f = new long[n];\n\t\t\tf[0] = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\tf[i] = 0;\n\t\t\t\tfor (int j = 0; j < i; j++)\n\t\t\t\t{\n\t\t\t\t\tf[i] += (1 + f[j]);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvar res = 0L;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\tif (s[i] == 'B')\n\t\t\t\t{\n\t\t\t\t\tres += f[i] + 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tConsole.WriteLine(res);\n\t\t\t//var n = readInt();\n\t\t\t//var m = readInt();\n\n\t\t\t//var a = readIntArray();\n\t\t\t//var b = readIntArray();\n\t\t\t#endregion\n\t\t}\n\n\t\tstatic int readInt()\n\t\t{\n\t\t\treturn int.Parse(Console.ReadLine());\n\t\t}\n\n\t\tstatic long readLong()\n\t\t{\n\t\t\treturn long.Parse(Console.ReadLine());\n\t\t}\n\n\t\tstatic int[] readIntArray()\n\t\t{\n\t\t\treturn Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n\t\t}\n\n\t\tstatic long[] readLongArray()\n\t\t{\n\t\t\treturn Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n\t\t}\n\n#if DEBUG\n\t\tstatic StreamReader getInput()\n\t\t{\n\t\t\tvar resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n\t\t\tvar resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);\n\n\t\t\treturn new StreamReader(resource);\n\t\t}\n#endif\n\t}\n}\n", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\n\nnamespace ReadWriteTemplate\n{\n public static class Solver\n {\n private static void SolveCase()\n {\n long n = ReadLong();\n int m = ReadInt();\n\n const long MOD = 1000000007;\n\n long[,] a = new long[m, m];\n for (int i = 0; i < m - 1; i++)\n {\n a[i, i + 1] = 1;\n }\n a[m - 1, 0] = 1;\n a[m - 1, m - 1] = 1;\n\n a = MatrixBinPower(m, a, n, MOD);\n\n long ans = a[m - 1, m - 1];\n\n Writer.WriteLine(ans);\n }\n\n public static long[,] MatrixBinPower(int n, long[,] a, long p, long mod)\n {\n long[,] result = new long[n, n];\n for (int i = 0; i < n; i++)\n {\n result[i, i] = 1;\n }\n\n while (p > 0)\n {\n if ((p & 1) != 0)\n {\n result = MatrixMult(n, result, a, mod);\n }\n\n a = MatrixMult(n, a, a, mod);\n p >>= 1;\n }\n\n return result;\n }\n\n public static long[,] MatrixMult(int n, long[,] a, long[,] b, long mod)\n {\n long[,] c = new long[n, n];\n\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n for (int k = 0; k < n; k++)\n {\n c[i, j] = (c[i, j] + a[i, k] * b[k, j]) % mod;\n }\n }\n }\n\n return c;\n }\n\n public static void Solve()\n {\n#if DEBUG\n var sw = Stopwatch.StartNew();\n#endif\n\n SolveCase();\n\n /*int T = ReadInt();\n for (int i = 0; i < T; i++)\n {\n // Writer.Write(\"Case #{0}: \", i + 1);\n SolveCase();\n }*/\n\n#if DEBUG\n sw.Stop();\n Console.WriteLine($\"{sw.ElapsedMilliseconds} ms\");\n#endif\n }\n\n public static void Main()\n {\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if DEBUG\n //Reader = Console.In; Writer = Console.Out;\n Reader = File.OpenText(\"input.txt\"); Writer = File.CreateText(\"output.txt\");\n#else\n Reader = Console.In; Writer = Console.Out;\n#endif\n\n // Solve();\n Thread thread = new Thread(Solve, 64 * 1024 * 1024);\n thread.CurrentCulture = CultureInfo.InvariantCulture;\n thread.Start();\n thread.Join();\n\n Reader.Close();\n Writer.Close();\n }\n\n public static IOrderedEnumerable OrderByWithShuffle(this IEnumerable source, Func keySelector)\n {\n return source.Shuffle().OrderBy(keySelector);\n }\n\n public static T[] Shuffle(this IEnumerable source)\n {\n T[] result = source.ToArray();\n Random rnd = new Random();\n for (int i = result.Length - 1; i >= 1; i--)\n {\n int k = rnd.Next(i + 1);\n T tmp = result[k];\n result[k] = result[i];\n result[i] = tmp;\n }\n return result;\n }\n\n #region Read/Write\n\n private static TextReader Reader;\n\n private static TextWriter Writer;\n\n private static Queue CurrentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return Reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (CurrentLineTokens.Count == 0)\n CurrentLineTokens = new Queue(ReadAndSplitLine());\n return CurrentLineTokens.Dequeue();\n }\n\n public static string ReadLine()\n {\n return Reader.ReadLine();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = Reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n Writer.WriteLine(string.Join(\" \", array));\n }\n\n #endregion\n }\n}\n", "src_uid": "e7b9eec21d950f5d963ff50619c6f119"} {"source_code": "using System;\n\nnamespace CSharp\n{\n class Program\n {\n static void Main(string[] args)\n {\n var alpha = \"abcdefghijklmnopqrstuvwxyz\";\n var str = Console.ReadLine();\n var count = 0;\n var prev = 'a';\n foreach (char symbol in str)\n {\n var delta = alpha.IndexOf(symbol) - alpha.IndexOf(prev);\n if (delta < 0)\n delta = -delta;\n delta = Math.Min(delta, alpha.Length - delta);\n count += (delta < 0 ? alpha.Length + delta : delta);\n prev = symbol;\n }\n Console.WriteLine(count);\n }\n }\n}\n", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] a = new int[3];\n string[] str = Console.ReadLine().Split(' ');\n a[0] = Int32.Parse(str[0]);\n a[1] = Int32.Parse(str[1]);\n a[2] = Int32.Parse(str[2]);\n int x = (a[0] + a[1] + a[2]);\n int i = 29;\n int color = 0;\n while (x>0)\n {\n if (color > 2) { color = 0; }\n if (a[color] > 2) { a[color] -= 2; } else { a[color] = 0; }\n x = a[0] + a[1] + a[2];\n i++;\n color++;\n }\n Console.WriteLine(i.ToString());\n }\n }\n}\n", "src_uid": "a45daac108076102da54e07e1e2a37d7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _160618\n{\n class Program\n {\n static void Main(string[] args)\n {\n string InStr=Console.ReadLine()+\" \";\n int n, m;\n n = int.Parse(InStr.Substring(0, InStr.IndexOf(\" \")));\n InStr = InStr.Substring(InStr.IndexOf(\" \") + 1);\n m = int.Parse(InStr.Substring(0, InStr.IndexOf(\" \")));\n string InStr1 = Console.ReadLine() + \" \";\n string InStr2 = Console.ReadLine() + \" \";\n string OutStr = \"\";\n int[] in1 = new int[n];\n int[] in2 = new int[m]; \n int k = 0;\n for(int i=0;i nn[i])\n {\n ans = Math.Min(ans, nn[i] - min + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)\n + Math.Sqrt((x - nn[i + 1])*(x - nn[i + 1]) + y*y)\n + max - nn[i + 1] + max - xx);\n ans = Math.Min(ans, nn[i] - min + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)\n + Math.Sqrt((x - max)*(x - max) + y*y)\n + max - nn[i + 1] + xx - nn[i + 1]);\n }\n else if (xx < nn[i])\n {\n ans = Math.Min(ans, max - nn[i] + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)\n + Math.Sqrt((x - nn[i - 1])*(x - nn[i - 1]) + y*y)\n + nn[i - 1] - min + xx - min);\n ans = Math.Min(ans, max - nn[i] + Math.Sqrt((x - nn[i])*(x - nn[i]) + y*y)\n + Math.Sqrt((x - min)*(x - min) + y*y)\n + nn[i - 1] - min + nn[i - 1] - xx);\n }\n }\n }\n\n writer.WriteLine(ans.ToString(\"#0.0000000\", CultureInfo.InvariantCulture));\n writer.Flush();\n }\n\n private static double GM(int[] nn, long x, long y, int xx)\n {\n double ans;\n\n int min = nn.Min();\n int max = nn.Max();\n\n // ___/___\\\n if (xx == min)\n {\n ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y);\n }\n else\n {\n int mix = nn.Where(e => e < xx).Max();\n ans = max - xx + Math.Sqrt((x - max)*(x - max) + y*y)\n + Math.Sqrt((x - mix)*(x - mix) + y*y) + mix - min;\n }\n\n // <- ->\\\n if (xx != min)\n {\n ans = Math.Min(ans, xx - min + max - min + Math.Sqrt((x - max)*(x - max) + y*y));\n }\n\n if (xx < x && xx != max)\n {\n int max1 = nn.Where(e => e < x).Max();\n int max2 = nn.Where(e => e <= x).Max();\n\n List lmax1 = nn.Where(e => e > max1).ToList();\n if (lmax1.Any())\n {\n int nmax1 = lmax1.Min();\n ans = Math.Min(ans, xx - min + max1 - min + Math.Sqrt((x - max1)*(x - max1) + y*y) +\n Math.Sqrt((x - nmax1)*(x - nmax1) + y*y) + max - nmax1);\n\n if (max1 != max2)\n {\n List lmax2 = nn.Where(e => e > max2).ToList();\n if (lmax2.Any())\n {\n int nmax2 = lmax2.Min();\n ans = Math.Min(ans, xx - min + max2 - min + Math.Sqrt((x - max2)*(x - max2) + y*y) +\n Math.Sqrt((x - nmax2)*(x - nmax2) + y*y) + max - nmax2);\n }\n }\n }\n }\n\n\n return ans;\n }\n\n private static int Next()\n {\n int c;\n int m = 1;\n do\n {\n c = reader.Read();\n if (c == '-')\n m = -1;\n } while (c < '0' || c > '9');\n int res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return m*res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "f9ed5faca211e654d9d4e0a7557616f4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Runtime.InteropServices;\n\nnamespace codeforces\n{\n\tclass Program\n\t{\n\t\tpublic class User\n\t\t{\n\t\t\tpublic int c;\n\n\t\t\tpublic int r;\n\t\t}\n\n\t\tpublic class Point\n\t\t{\n\t\t\tpublic int x;\n\n\t\t\tpublic int y;\n\t\t}\n\n\t\tpublic class Comparer : IComparer\n\t\t{\n\t\t\tpublic int Compare(User x, User y)\n\t\t\t{\n\t\t\t\tif (x.c < y.c || (x.c == y.c && x.r < y.r))\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic static long getGcd(long a, long b)\n\t\t{\n\t\t\tif (b == 0)\n\t\t\t\treturn a;\n\t\t\treturn getGcd(b, a % b);\n\t\t}\n\n\t\tpublic static void WriteYESNO(bool x, string yes = \"YES\", string no = \"NO\")\n\t\t{\n\t\t\tif (x)\n\t\t\t\tConsole.WriteLine(yes);\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(no);\n\t\t\t}\n\t\t}\n\n\t\tpublic static string getString()\n\t\t{\n\t\t\treturn Console.ReadLine();\n\t\t}\n\n\t\tpublic static List getList()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(int.Parse).ToList();\n\t\t}\n\n\t\tpublic static List getLongList()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(long.Parse).ToList();\n\t\t}\n\n\t\tpublic static int Min(int x, int y)\n\t\t{\n\t\t\treturn Math.Min(x, y);\n\t\t}\n\n\t\tpublic static int Max(int x, int y)\n\t\t{\n\t\t\treturn Math.Max(x, y);\n\t\t}\n\n\t\tpublic static int Abs(int x)\n\t\t{\n\t\t\treturn Math.Abs(x);\n\t\t}\n\n\t\tpublic static int getInt()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn int.Parse(s);\n\t\t}\n\n\t\tpublic static long getLong()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn long.Parse(s);\n\t\t}\n\n\t\tpublic static bool Equal(int x, int y, int x1, int y1)\n\t\t{\n\t\t\treturn x == x1 && y == y1;\n\t\t}\n\n\t\tpublic class Vertex\n\t\t{\n\t\t\tpublic List edges;\n\n\t\t\tpublic int ct;\n\n\t\t\tpublic bool was;\n\t\t}\n\n\t\tprivate static void Main(string[] args)\n\t\t{\n/*\t\t\tvar input = new StreamReader(\"input.txt\");\n\t\t\tvar output = new StreamWriter(\"output.txt\");*/\n\t\t\tvar t = new List();\n\t\t\tfor (var i = 0; i < 8; ++i)\n\t\t\t\tt.Add(getString());\n\t\t\tvar minA = 100;\n\t\t\tvar minB = 100;\n\t\t\tfor (var i = 0; i < 8; ++i)\n\t\t\t\tfor (var j = 0; j < 8; ++j)\n\t\t\t\t{\n\t\t\t\t\tif (t[i][j] == 'W')\n\t\t\t\t\t{\n\t\t\t\t\t\tvar can = true;\n\t\t\t\t\t\tfor (var z = 0; z < i; ++z)\n\t\t\t\t\t\t\tif (t[z][j] == 'B')\n\t\t\t\t\t\t\t\tcan = false;\n\t\t\t\t\t\tif (can)\n\t\t\t\t\t\t\tminA = Min(minA, i);\n\t\t\t\t\t}\n\t\t\t\t\tif (t[i][j] == 'B')\n\t\t\t\t\t{\n\t\t\t\t\t\tvar can = true;\n\t\t\t\t\t\tfor (var z = i + 1; z < 8; ++z)\n\t\t\t\t\t\t\tif (t[z][j] == 'W')\n\t\t\t\t\t\t\t\tcan = false;\n\t\t\t\t\t\tif (can)\n\t\t\t\t\t\t\tminB = Min(minB, 7 - i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tWriteYESNO(minA <= minB, \"A\", \"B\");\n\t\t\tConsole.ReadLine();\n\t\t}\n\t}\n}\n", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Collections;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\nnamespace ConsoleApplication1\n{\n class Program\n {\n\n static double[,] dp;\n\n static double solve(int w, int b)\n {\n if (dp[w,b] == -1)\n {\n dp[w, b] = (double) w / (w + b);\n if (b > 1)\n dp[w, b] += ((double)b / (w + b)) * ((double)(b - 1) / (w + b - 1)) * ((double)(w) / (w + b - 2)) * solve(w - 1, b - 2);\n if (b > 2)\n dp[w, b] += ((double)b / (w + b)) * ((double)(b - 1) / (w + b - 1)) * ((double)(b - 2) / (w + b - 2)) * solve(w, b - 3);\n }\n return dp[w,b];\n }\n\n static void Main(string[] args)\n {\n string[] readen = Console.ReadLine().Split(' ');\n int w = int.Parse(readen[0]);\n int b = int.Parse(readen[1]);\n dp = new double[w+1, b+1];\n for (int i = 0; i <= w; i++)\n for (int j = 0; j <= b; j++)\n dp[i, j] = -1;\n for (int i = 0; i <= w; i++)\n dp[i, 0] = 1;\n for (int i = 0; i <= b; i++)\n dp[0, i] = 0;\n Console.WriteLine(solve(w, b).ToString(CultureInfo.InvariantCulture));\n }\n }\n}\n ", "src_uid": "7adb8bf6879925955bf187c3d05fde8c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace скамейка\n{\n class Program\n {\n static void Main(string[] args)\n {\n Int64 n = Convert.ToInt64(Console.ReadLine());\n Int64 c1 = ((n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) / 120);\n Console.WriteLine(c1 * (n * (n - 1) * (n - 2) * (n - 3) * (n - 4)));\n }\n }\n}\n", "src_uid": "92db14325cd8aee06b502c12d2e3dd81"} {"source_code": "using System;\nusing System.IO;\nusing System.Net;\nusing System.Text;\n\n\nclass Program\n{\n static void Main(string[] args)\n {\n int n;\n n = int.Parse(Console.ReadLine());\n string s = \"\";\n string t = Console.ReadLine();\n foreach (char c in t)\n {\n if (c != ' ')\n s += c;\n }\n s = s.Trim('0');\n if (s == \"\")\n {\n Console.WriteLine(0);\n return;\n }\n string[] ss = s.Split('1');\n ulong res = 1;\n foreach (string i in ss)\n {\n if (i.Length != 0)\n res *= (ulong)(i.Length + 1);\n }\n Console.WriteLine(res);\n }\n}", "src_uid": "58242665476f1c4fa723848ff0ecda98"} {"source_code": "using System;\nclass a\n{\n static void Main()\n {\n Console.ReadLine();\n var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n Array.Sort(a);\n int r, t; r = t = 1;\n for (int i = 1; i < a.Length; i++)\n {\n if(a[i-1] == a[i]) t++;\n else t = 1;\n r = t > r ? t : r;\n }\n Console.WriteLine(r);\n }\n}", "src_uid": "f30329023e84b4c50b1b118dc98ae73c"} {"source_code": "using System;\nusing System.Globalization;\n\nnamespace CodeForces\n{\n class Program\n {\n static void Main(string[] args)\n {\n DateTime time = DateTime.ParseExact(Console.ReadLine(), \"HH:mm\", CultureInfo.InvariantCulture);\n Console.WriteLine(\"{0:0.#} {1:0.#}\", (time.Hour % 12) * 30d + 30d * (time.Minute / 60d), time.Minute * 6);\n }\n }\n}\n", "src_uid": "175dc0bdb5c9513feb49be6644d0d150"} {"source_code": "using System;\n\nnamespace Codeforces\n{\n\tpublic class J\n\t{\n\t\tprivate static readonly long [] solve = {0, 1, 2, 4, 6, 16, 12, 64, 24, 36, 48, 1024, 60, 4096, 192, 144, 120, 65536, 180, 262144, 240, 576, 3072, 4194304, 360, 1296, 12288, 900, 960, 268435456, 720, 1073741824, 840, 9216, 196608, 5184, 1260, 68719476736, 786432, 36864, 1680, 1099511627776, 2880, 4398046511104, 15360, 3600, 12582912, 70368744177664, 2520, 46656, 6480, 589824, 61440, 4503599627370496, 6300, 82944, 6720, 2359296, 805306368, 288230376151711744, 5040, 1152921504606846976, 3221225472, 14400, 7560, 331776, 46080, 4611686018427387904, 983040, 37748736, 25920, 4611686018427387904, 10080, 4611686018427387904, 206158430208, 32400, 3932160, 746496, 184320, 4611686018427387904, 15120, 44100, 3298534883328, 4611686018427387904, 20160, 5308416, 13194139533312, 2415919104, 107520, 4611686018427387904, 25200, 2985984, 62914560, 9663676416, 211106232532992, 21233664, 27720, 4611686018427387904, 233280, 230400, 45360, 4611686018427387904, 2949120, 4611686018427387904, 430080, 129600, 13510798882111488, 4611686018427387904, 50400, 4611686018427387904, 414720, 618475290624, 60480, 4611686018427387904, 11796480, 339738624, 4026531840, 921600, 864691128455135232, 47775744, 55440, 60466176, 3458764513820540928, 9895604649984, 16106127360, 810000, 100800, 4611686018427387904, 83160, 39582418599936, 1658880, 4611686018427387904, 322560, 191102976, 4611686018427387904, 176400, 6881280, 4611686018427387904, 188743680, 4611686018427387904, 181440, 633318697598976, 4611686018427387904, 241864704, 110880, 21743271936, 4611686018427387904, 1166400, 1030792151040, 4611686018427387904, 226800, 4611686018427387904, 27525120, 14745600, 3732480, 86973087744, 1290240, 4611686018427387904, 4611686018427387904, 40532396646334464, 166320, 3057647616, 352800, 4611686018427387904, 16492674416640, 2073600, 4611686018427387904, 4611686018427387904, 221760, 2176782336, 26542080, 58982400, 65970697666560, 4611686018427387904, 12079595520, 3240000, 967680, 2594073385365405696, 4611686018427387904, 4611686018427387904, 277200, 4611686018427387904, 14929920, 4302802391356921540, 440401920, 5566277615616, 48318382080, 3869835264, 1055531162664960, 705600, 106168320, 4611686018427387904, 332640, 4611686018427387904, 4611686018427387904, 8294400, 1632960, 4611686018427387904, 1612800, 4611686018427387904, 498960, 4611686018427387904, 4611686018427387904, 195689447424, 20643840, 89060441849856, 4611686018427387904, 943718400, 3870720, 15479341056, 907200, 4611686018427387904, 67553994410557440, 4611686018427387904, 4611686018427387904, 356241767399424, 554400, 782757789696, 4611686018427387904, 4611686018427387904, 2903040, 34828517376, 3092376453120, 4611686018427387904, 665280, 1587600, 4611686018427387904, 4611686018427387904, 82575360, 4611686018427387904, 1698693120, 18662400, 28185722880, 4611686018427387904, 6451200, 5699868278390784, 4323455642275676160, 4611686018427387904, 238878720, 4611686018427387904, 720720, 4611686018427387904, 302330880, 2822400, 4611686018427387904, 29160000, 49478023249920, 139314069504, 112742891520, 4611686018427387904, 5670000, 4611686018427387904, 1108800, 247669456896, 4611686018427387904, 132710400, 1081080, 4611686018427387904, 197912092999680, 50096498540544, 11612160, 60397977600, 4611686018427387904, 4611686018427387904, 3548160, 364791569817010176, 955514880, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1940400, 4611686018427387904, 61931520, 74649600, 4611686018427387904, 51840000, 1321205760, 4611686018427387904, 4611686018427387904, 241591910400, 1995840, 4611686018427387904, 3166593487994880, 4611686018427387904, 4611686018427387904, 530841600, 1209323520, 801543976648704, 1441440, 2821109907456, 108716359680, 4611686018427387904, 4611686018427387904, 4611686018427387904, 8164800, 4611686018427387904, 7215545057280, 11289600, 4611686018427387904, 2229025112064, 2494800, 3206175906594816, 4611686018427387904, 4611686018427387904, 247726080, 1152921504606846976, 103219200, 4611686018427387904, 26127360, 4611686018427387904, 434865438720, 4611686018427387904, 14192640, 4611686018427387904, 4611686018427387904, 6350400, 4611686018427387904, 4611686018427387904, 202661983231672320, 15850845241344, 2162160, 4611686018427387904, 15288238080, 11284439629824, 3880800, 207360000, 4611686018427387904, 4611686018427387904, 115448720916480, 51298814505517056, 14515200, 4611686018427387904, 4611686018427387904, 15461882265600, 4611686018427387904, 4611686018427387904, 2882880, 4611686018427387904, 10883911680, 4611686018427387904, 185794560, 63403380965376, 412876800, 729000000, 461794883665920, 8493465600, 4611686018427387904, 4611686018427387904, 84557168640, 4611686018427387904, 22680000, 45158400, 10644480, 4611686018427387904, 3170534137668829184, 4611686018427387904, 4611686018427387904, 1194393600, 4611686018427387904, 4611686018427387904, 3603600, 101559956668416, 4611686018427387904, 1511654400, 104509440, 4611686018427387904, 3067267883075056084, 4611686018427387904, 3963617280, 247390116249600, 27831388078080, 3283124128353091584, 338228674560, 4611686018427387904, 19349176320, 39690000, 7388718138654720, 142657607172096, 7761600, 4611686018427387904, 743178240, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4324320, 466560000, 4611686018427387904, 989560464998400, 4611686018427387904, 4611686018427387904, 58060800, 180551034077184, 17962560, 4611686018427387904, 4611686018427387904, 4611686018427387904, 17740800, 4611686018427387904, 4611686018427387904, 4777574400, 6486480, 4611686018427387904, 4611686018427387904, 570630428688384, 4611686018427387904, 21344400, 978447237120, 4057816381784064, 227082240, 4611686018427387904, 445302209249280, 4611686018427387904, 4611686018427387904, 4611686018427387904, 6606028800, 4611686018427387904, 42577920, 4611686018427387904, 77396705280, 4611686018427387904, 9979200, 4611686018427387904, 4611686018427387904, 15832967439974400, 472877960873902080, 3317760000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 6046617600, 1781208836997120, 4611686018427387904, 7207200, 4611686018427387904, 3913788948480, 543581798400, 4611686018427387904, 1624959306694656, 4611686018427387904, 4611686018427387904, 31933440, 57153600, 174142586880, 4611686018427387904, 21646635171840, 4611686018427387904, 4611686018427387904, 4611686018427387904, 8648640, 4611686018427387904, 17463600, 64925062108545024, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1866240000, 908328960, 4611686018427387904, 4611686018427387904, 722534400, 11890851840, 4611686018427387904, 130636800, 4611686018427387904, 253671505920, 2174327193600, 4611686018427387904, 4611686018427387904, 70963200, 4611686018427387904, 28499341391953920, 4611686018427387904, 4611686018427387904, 259700248434180096, 4611686018427387904, 13271040000, 1672151040, 1013309916158361600, 4611686018427387904, 4611686018427387904, 10810800, 36520347436056576, 4611686018427387904, 76441190400, 2116316160, 4611686018427387904, 31046400, 4611686018427387904, 1397033833221146008, 4611686018427387904, 204120000, 4611686018427387904, 346346162749440, 11555266180939776, 696570347520, 101606400, 1014686023680, 4611686018427387904, 4611686018427387904, 4611686018427387904, 62370000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 14414400, 4611686018427387904, 1238347284480, 54419558400, 4611686018427387904, 4611686018427387904, 928972800, 4611686018427387904, 17297280, 2890137600, 4611686018427387904, 4611686018427387904, 1385384650997760, 4155203974946881536, 250482492702720, 4611686018427387904, 127733760, 4611686018427387904, 422785843200, 4611686018427387904, 4611686018427387904, 158760000, 4611686018427387904, 46221064723759104, 46126080, 131621703842267136, 1823957849085050880, 4142105726209370116, 6688604160, 584325558976905216, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 11664000000, 25225200, 4611686018427387904, 4611686018427387904, 4611686018427387904, 681246720, 4611686018427387904, 522547200, 4611686018427387904, 4611686018427387904, 4611686018427387904, 362880000, 103997395628457984, 14533263360, 4611686018427387904, 4611686018427387904, 139156940390400, 4611686018427387904, 4611686018427387904, 1691143372800, 2337302235907620864, 25945920, 96745881600, 4611686018427387904, 4611686018427387904, 22166154415964160, 4611686018427387904, 4611686018427387904, 85377600, 4611686018427387904, 4611686018427387904, 3715891200, 4611686018427387904, 8465264640, 4611686018427387904, 4007719883243520, 212336640000, 21621600, 4611686018427387904, 14105549537280, 4611686018427387904, 761014517760, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 406425600, 4611686018427387904, 4611686018427387904, 89812800, 415989582513831936, 4611686018427387904, 4611686018427387904, 64939905515520, 4611686018427387904, 124185600, 29859840000, 4611686018427387904, 4611686018427387904, 11145125560320, 4611686018427387904, 32432400, 4611686018427387904, 16030879532974080, 4611686018427387904, 4611686018427387904, 37791360000, 4611686018427387904, 4611686018427387904, 2724986880, 4892236185600, 4611686018427387904, 503347627102830592, 1135411200, 4611686018427387904, 4611686018427387904, 2226511046246400, 287400960, 4611686018427387904, 4611686018427387904, 4611686018427387904, 3044058071040, 46242201600, 4611686018427387904, 4611686018427387904, 184504320, 1944810000, 4611686018427387904, 386983526400, 4611686018427387904, 2958148142320582656, 69854400, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1418633882621706240, 46656000000, 79254226206720, 4611686018427387904, 36756720, 4611686018427387904, 4611686018427387904, 4611686018427387904, 107017666560, 8906044184985600, 56422198149120, 4611686018427387904, 50450400, 4611686018427387904, 1451520000, 19568944742400, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1039038488248320, 4611686018427387904, 256494072527585280, 4611686018427387904, 159667200, 4611686018427387904, 4611686018427387904, 870712934400, 4611686018427387904, 119439360000, 108233175859200, 3718501732464984064, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 43243200, 4611686018427387904, 4611686018427387904, 192099600, 76187381760, 4611686018427387904, 4611686018427387904, 4611686018427387904, 2043740160, 4611686018427387904, 317016904826880, 4611686018427387904, 4541644800, 4611686018427387904, 5103000000, 4611686018427387904, 4156153952993280, 4611686018427387904, 59454259200, 4611686018427387904, 4611686018427387904, 914457600, 4611686018427387904, 4611686018427387904, 930128855040, 4611686018427387904, 4611686018427387904, 4611686018427387904, 249480000, 4611686018427387904, 496742400, 4611686018427387904, 138378240, 142496706959769600, 4611686018427387904, 4611686018427387904, 321635642448688404, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 8360755200, 151165440000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 61261200, 4611686018427387904, 507799783342080, 4611686018427387904, 4611686018427387904, 13589544960000, 10581580800, 4611686018427387904, 1149603840, 341510400, 4611686018427387904, 4611686018427387904, 3024131107815840972, 4611686018427387904, 4611686018427387904, 1428840000, 43599790080, 4611686018427387904, 1731730813747200, 4611686018427387904, 194819716546560, 3482851737600, 4611686018427387904, 4611686018427387904, 3720515420160, 4611686018427387904, 4611686018427387904, 4611686018427387904, 135444234240, 4611686018427387904, 436590000, 4611686018427387904, 66498463247892480, 4611686018427387904, 713288035860480, 4611686018427387904, 100900800, 4611686018427387904, 4611686018427387904, 6191736422400, 8174960640, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 6502809600, 4611686018427387904, 4611686018427387904, 73513440, 4611686018427387904, 3265920000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 6926923254988800, 54358179840000, 4611686018427387904, 1252412463513600, 4611686018427387904, 1698218798844215296, 638668800, 4611686018427387904, 902755170385920, 2959500902400, 233513280, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 230630400, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 33443020800, 3877669647910174720, 110270160, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1911029760000, 2853152143441920, 4611686018427387904, 4611686018427387904, 4611686018427387904, 277477200, 4611686018427387904, 6849130659840, 4611686018427387904, 20289081908920320, 4611686018427387904, 2952069120, 4611686018427387904, 4611686018427387904, 3657830400, 3117115464744960, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 2540160000, 4611686018427387904, 4611686018427387904, 72666316800, 4611686018427387904, 4611686018427387904, 4611686018427387904, 553512960, 746496000000, 4611686018427387904, 4611686018427387904, 541776936960, 11838003609600, 4611686018427387904, 4611686018427387904, 129729600, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1360488960000, 110830772079820800, 944784000000, 3282968041772396086, 4611686018427387904, 23224320000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 26011238400, 4611686018427387904, 4611686018427387904, 42326323200, 4611686018427387904, 12468461858979840, 20038599416217600, 4611686018427387904, 4611686018427387904, 122522400, 4611686018427387904, 4611686018427387904, 70527747686400, 27396522639360, 4611686018427387904, 3805072588800, 4611686018427387904, 4611686018427387904, 4611686018427387904, 8124796533473280, 7779240000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 415134720, 4611686018427387904, 628689600, 4611686018427387904, 1218998108160, 385463388465227812, 4611686018427387904, 4611686018427387904, 238112986890240, 4611686018427387904, 4611686018427387904, 1366041600, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 147026880, 55725627801600, 4611686018427387904, 2034685349522833408, 227026800, 4611686018427387904, 324625310542725120, 80154397664870400, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 13063680000, 4611686018427387904, 11808276480, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 7947878400, 4611686018427387904, 130799370240, 4611686018427387904, 4611686018427387904, 4611686018427387904, 1437004800, 3478923509760000, 4611686018427387904, 4611686018427387904, 2790386565120, 4611686018427387904, 15220290355200, 2985984000000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 2418647040000, 922521600, 4611686018427387904, 4611686018427387904, 4611686018427387904, 199495389743677440, 4611686018427387904, 4611686018427387904, 1480074566750437376, 1082038902494747896, 768398400, 1298501242170900480, 4611686018427387904, 4611686018427387904, 4611686018427387904, 92897280000, 4611686018427387904, 18393661440, 4611686018427387904, 140249977755756320, 4611686018427387904, 4611686018427387904, 396271131033600, 4611686018427387904, 4611686018427387904, 183783600, 4611686018427387904, 182601737180282880, 4611686018427387904, 4611686018427387904, 4611686018427387904, 535088332800, 4611686018427387904, 23279477760, 282110990745600, 4611686018427387904, 4611686018427387904, 403603200, 4611686018427387904, 4611686018427387904, 10160640000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 2245320000, 4611686018427387904, 4611686018427387904, 4611686018427387904, 3809807790243840, 4611686018427387904, 57776330904698880, 1282470362637926400, 4875992432640, 4611686018427387904, 1117670400, 4611686018427387904, 11161546260480, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 4611686018427387904, 757632231014400, 810810000};\n\t\tpublic static int Main()\n\t\t{\n\t\t\tint n = Convert.ToInt32(Console.ReadLine());\n\t\t\tConsole.Write(solve[n]);\n\t\t\treturn 0;\n\t\t}\n\t}\n}\n", "src_uid": "62db589bad3b7023418107de05b7a8ee"} {"source_code": "#define Online\n\nusing System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\nusing System.Threading;\n\ndelegate double F(double x);\ndelegate decimal Fdec(decimal x);\n\nclass Program\n{\n static void Main(string[] args)\n {\n\n Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if FileIO\n StreamReader sr = new StreamReader(\"forest.in\");\n StreamWriter sw = new StreamWriter(\"forest.out\");\n Console.SetIn(sr);\n Console.SetOut(sw);\n#endif\n\n int r1, r2, c1, c2, d1, d2;\n string[] input = ReadArray();\n r1 = int.Parse(input[0]);\n r2 = int.Parse(input[1]);\n input = ReadArray();\n c1 = int.Parse(input[0]);\n c2 = int.Parse(input[1]);\n input = ReadArray();\n d1 = int.Parse(input[0]);\n d2 = int.Parse(input[1]);\n\n int a11, a21, a12, a22;\n a11 = c1 + d1 - r2;\n if (a11 % 2 == 0)\n {\n a11 /= 2;\n }\n else\n {\n Console.WriteLine(-1);\n return;\n }\n a22 = d1 - a11;\n a21 = c1 - a11;\n a12 = c2 - a22;\n if (a11 == a12 || a11 == a21 || a11 == a22 || a12 == a21 || a12 == a22 || a21 == a22)\n {\n Console.WriteLine(-1);\n return;\n }\n if (a11 > 0 && a11 < 10 && a22 > 0 && a22 < 10 && a21 > 0 && a21 < 10 && a12 > 0 && a12 < 10)\n {\n Console.WriteLine(a11 + \" \" + a12);\n Console.WriteLine(a21 + \" \" + a22);\n }\n else\n {\n Console.WriteLine(-1);\n }\n\n \n#if Online\n Console.ReadLine();\n#endif\n\n#if FileIO\n sr.Close();\n sw.Close();\n#endif\n }\n\n static string[] ReadArray()\n {\n return Console.ReadLine().Split(' ');\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static decimal Sqrt(decimal x)\n {\n decimal mid;\n decimal right = (x <= 1 ? 1 : x);\n decimal left = 0;\n decimal eps = 0.00000000000000000001m;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2m);\n if (Math.Sign(mid * mid - x) != Math.Sign(left * left - x))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2m;\n }\n\n}\n\nstatic class ArrayUtils\n{\n public static int BinarySearch(int[] a, int val)\n {\n int left = 0;\n int right = a.Length - 1;\n int mid;\n\n while (left < right)\n {\n mid = left + ((right - left) >> 1);\n if (val <= a[mid])\n {\n right = mid;\n }\n else\n {\n left = mid + 1;\n }\n }\n\n if (a[left] == val)\n return left;\n else\n return -1;\n }\n\n public static double Bisection(F f, double left, double right, double eps)\n {\n double mid;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2d);\n if (Math.Sign(f(mid)) != Math.Sign(f(left)))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2d;\n }\n\n\n public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)\n {\n decimal m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3m;\n m2 = r - (r - l) / 3m;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static double TernarySearch(F f, double eps, double l, double r, bool isMax)\n {\n double m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3d;\n m2 = r - (r - l) / 3d;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static void Merge(int[] A, int p, int q, int r, int[] L, int[] R)\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (L[i] <= R[j])\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(int[] A, int p, int r, int[] L, int[] R)\n {\n if (!(p < r)) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R);\n Merge_Sort(A, q + 1, r, L, R);\n Merge(A, p, q, r, L, R);\n }\n}", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace AprilFools\n{\n internal class Program\n {\n private const string TestIn = @\"..\\..\\In\\Text.in\";\n private const string TestOut = @\"..\\..\\In\\Text.out\";\n\n\n private static void Solve()\n {\n var nums = ReadIntArray();\n var n = nums[0];\n var k = nums[1];\n var nk = n - k;\n var nmul = nk;\n var kmul = k;\n\n\n // factorial n\n long kf = kmul;\n while (--k > 1)\n {\n kf *= kmul;\n kf = kf%1000000007;\n }\n\n\n\n long nkp = nk;\n while (--nk > 0)\n {\n nkp *= nmul;\n nkp = nkp%1000000007;\n }\n\n if (kf == 0) kf = 1;\n if (nkp == 0) nkp = 1;\n Console.WriteLine(((nkp * kf) % 1000000007));\n }\n\n public static string Multiply(string source, int multiplier)\n {\n StringBuilder sb = new StringBuilder(multiplier * source.Length);\n for (int i = 0; i < multiplier; i++)\n {\n sb.Append(source);\n }\n\n return sb.ToString();\n }\n\n private static void Main()\n {\n if (Debugger.IsAttached)\n {\n Console.SetIn(new StreamReader(TestIn));\n Console.SetOut(new StreamWriter(TestOut));\n }\n\n Solve();\n\n if (Debugger.IsAttached)\n {\n Console.In.Close();\n Console.Out.Close();\n Console.SetIn(new StreamReader(Console.OpenStandardInput()));\n //Console.ReadLine();\n }\n }\n\n #region Reader\n\n private static string Read()\n {\n return Console.ReadLine();\n }\n\n private static string[] ReadArray()\n {\n return Console.ReadLine().Split(' ');\n }\n\n private static List ReadIntArray()\n {\n var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();\n return input;\n }\n\n private static int ReadInt()\n {\n return Int32.Parse(Console.ReadLine());\n }\n\n private static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n private static int ReadNextInt(string[] input, int index)\n {\n return Int32.Parse(input[index]);\n }\n\n #endregion\n }\n}\n\n", "src_uid": "cc838bc14408f14f984a349fea9e9694"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Dima_and_the_equation\n{\n class Program\n {\n static void Main(string[] args)\n {\n int a, b, c;\n long x;\n string[] hold;\n List result = new List();\n hold = Console.ReadLine().Split(' ');\n a = Int32.Parse(hold[0]);\n b = Int32.Parse(hold[1]);\n c = Int32.Parse(hold[2]);\n for (int i = 1; i < 82; i++)\n {\n x = b *(long) Math.Pow(i, a) + c;\n if (x>0&& x< Math.Pow(10,9))\n if (sum(x) == i)\n result.Add(x);\n }\n Console.WriteLine(result.Count);\n foreach (int i in result)\n {\n Console.Write(i + \" \");\n }\n Console.ReadLine();\n }\n static int sum(long number)\n {\n string k = number.ToString();\n int sum = 0;\n foreach (char i in k)\n {\n sum += Int32.Parse(i.ToString());\n }\n return sum;\n }\n }\n}", "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nclass C546 {\n class Battle {\n public Queue[] A;\n public int FightCount = 0;\n }\n\n class BattleResult: Exception {\n public int FightCount, Winner;\n public override string ToString() => $\"{FightCount} {Winner}\";\n }\n\n class BattleField: TortoiseHare {\n public Battle Seed;\n\n protected override Battle Clone(Battle state) {\n return new Battle {\n A = new Queue[] {\n new Queue(state.A[0]),\n new Queue(state.A[1])\n }\n };\n }\n\n protected override Battle GetSeed() => Seed;\n\n protected override bool IsEquivalent(Battle a1, Battle a2) =>\n a1.A[0].SequenceEqual(a2.A[0]) && a1.A[1].SequenceEqual(a2.A[1]);\n\n protected override void Next(Battle battle) {\n var head = new int[2];\n for (int i = 0; i < 2; ++i)\n if (battle.A[i].Count == 0)\n throw new BattleResult {\n FightCount = battle.FightCount,\n Winner = 2 - i\n };\n else head[i] = battle.A[i].Dequeue();\n ++battle.FightCount;\n var win = head[0] < head[1] ? 1 : 0;\n battle.A[win].Enqueue(head[1 - win]);\n battle.A[win].Enqueue(head[win]);\n }\n }\n\n public static void Main() {\n Console.ReadLine();\n var a1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n var a2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n try {\n new BattleField {\n Seed = new Battle {\n A = new Queue[2] {\n new Queue(a1.Skip(1)),\n new Queue(a2.Skip(1))\n }\n }\n }.CycleLength();\n Console.WriteLine(-1);\n } catch (BattleResult result) {\n Console.WriteLine(result);\n }\n }\n\n // Snippet: TortoiseHare\n abstract class TortoiseHare {\n protected abstract T GetSeed();\n protected abstract T Clone(T state);\n protected abstract bool IsEquivalent(T a1, T a2);\n protected abstract void Next(T state);\n\n public int CycleLength() {\n int n1 = 0, n2 = 1;\n T a1 = Clone(GetSeed()), a2 = Clone(a1);\n Next(a2);\n while (!IsEquivalent(a1, a2)) {\n if (n1 + n1 < n2) {\n n1 = n2;\n a1 = Clone(a2);\n }\n ++n2;\n Next(a2);\n }\n return n2 - n1;\n }\n }\n}\n", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\n\nnamespace Rextester\n{\n public class Program\n {\n public static void Main(string[] args)\n {\n string[] token = Console.ReadLine().Split();\n \n int n = int.Parse(token[0]);\n int a = int.Parse(token[1]);\n int b = int.Parse(token[2]);\n \n int min = Math.Min(a,b);\n int max = Math.Max(a,b);\n \n int ans = CountTrailingZero(n);\n \n int N = n;\n \n while(true){\n if( max>N/2 && min<=N/2){\n break;\n }else if(max>N/2&&min>N/2){\n max -= N/2;\n min -= N/2;\n } else{\n N = N/2;\n ans--;\n }\n }\n \n if(n==N)\n Console.WriteLine(\"Final!\");\n else\n Console.WriteLine(ans);\n }\n \n static int CountTrailingZero(int x) \n { \n int []lookup = {32, 0, 1, 26, 2, 23, \n 27, 0, 3, 16, 24, 30, \n 28, 11, 0, 13, 4, 7, \n 17, 0, 25, 22, 31, 15, \n 29, 10, 12, 6, 0, 21, \n 14, 9, 5, 20, 8, 19, 18}; \n \n return lookup[(-x & x) % 37]; \n }\n \n }\n}\n", "src_uid": "a753bfa7bde157e108f34a28240f441f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace CodeForcesApp\n{\n class E\n {\n #region Shortcuts\n static string RL() { return Console.ReadLine(); }\n static string[] RSA() { return RL().Split(' '); }\n static int[] RIA() { return Array.ConvertAll(RSA(), int.Parse); }\n static int RInt() { return int.Parse(RL()); }\n static long RLong() { return long.Parse(RL()); }\n static double RDouble() { return double.Parse(RL()); }\n static void RInts2(out int p1, out int p2) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; }\n static void RInts3(out int p1, out int p2, out int p3) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; }\n static void RInts4(out int p1, out int p2, out int p3, out int p4) { int[] a = RIA(); p1 = a[0]; p2 = a[1]; p3 = a[2]; p4 = a[3]; }\n\n static void Swap(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }\n static void Fill(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }\n static void Fill(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }\n #endregion\n\n static void Main(string[] args)\n {\n System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;\n\n //SolutionTester tester = new SolutionTester(CodeForcesTask.E);\n //tester.Test();\n\n Task task = new Task();\n task.Solve();\n }\n\n public class Task\n {\n public void Solve()\n {\n int xv, yv, xp, yp, xw1, yw1, xw2, yw2, xm1, ym1, xm2, ym2;\n RInts2(out xv, out yv);\n RInts2(out xp, out yp);\n RInts4(out xw1, out yw1, out xw2, out yw2);\n RInts4(out xm1, out ym1, out xm2, out ym2);\n\n Point v = new Point(xv, yv);\n Point p = new Point(xp, yp);\n \n Segment view = new Segment(xv, yv, xp, yp);\n Segment wall = new Segment(xw1, yw1, xw2, yw2);\n Segment mirror = new Segment(xm1, ym1, xm2, ym2);\n\n Point rp = p.Reflect(mirror.ToLine());\n\n Segment rview = new Segment(xv, yv, rp.x, rp.y);\n Segment rdview = new Segment(rp.x, rp.y, xp, yp);\n\n Point pt1, pt2;\n\n if (!view.Intersects(wall, out pt1, out pt2) && !view.Intersects(mirror, out pt1, out pt2))\n {\n Console.WriteLine(\"YES\");\n return;\n }\n\n\n Point rpm1, rpm2;\n if (rview.Intersects(mirror, out rpm1, out rpm2))\n {\n Segment s1 = new Segment(v, rpm1);\n Segment s2 = new Segment(rpm1, p);\n if (!s1.Intersects(wall, out pt1, out pt2) && !s2.Intersects(wall, out pt1, out pt2))\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n Console.WriteLine(\"NO\");\n }\n }\n\n\n public class GeometryUtils\n {\n public const double EPS = 10e-12;\n\n public static double SqrDist(double x1, double y1, double x2, double y2)\n {\n return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n }\n\n public static double Dist(double x1, double x2)\n {\n return Math.Abs(x1 - x2);\n }\n\n public static double Dist(double x1, double y1, double x2, double y2)\n {\n return Math.Sqrt(SqrDist(x1, y1, x2, y2));\n }\n\n public static double Determinant(\n double a11, double a12,\n double a21, double a22)\n {\n return a11 * a22 - a21 * a12;\n }\n\n\n public static double Determinant(\n double a11, double a12, double a13,\n double a21, double a22, double a23,\n double a31, double a32, double a33\n )\n {\n return a11 * Determinant(a22, a23, a32, a33) - a21 * Determinant(a12, a13, a32, a33) + a31 * Determinant(a12, a13, a22, a23);\n }\n\n public static int Sign(double val)\n {\n if (Math.Abs(val) <= EPS)\n return 0;\n\n if (val > EPS)\n return 1;\n\n return -1;\n }\n\n }\n\n public class Point\n {\n public double x;\n public double y;\n\n #region Constructors\n\n public Point()\n {\n }\n\n public Point(double _x, double _y)\n {\n x = _x;\n y = _y;\n }\n\n #endregion\n\n #region Public Methods\n\n public Vector ToVector()\n {\n return new Vector(x, y);\n }\n\n public int Orientation(Point q, Point r)\n {\n return Orientation(this, q, r);\n }\n\n public double Area(Point q, Point r)\n {\n return Area(this, q, r);\n }\n\n public double SqrDist(Point q)\n {\n return GeometryUtils.SqrDist(x, y, q.x, q.y);\n }\n\n public double Distance()\n {\n return GeometryUtils.Dist(x, y, 0, 0);\n }\n\n public double Distance(Point q)\n {\n return GeometryUtils.Dist(x, y, q.x, q.y);\n }\n\n public double XDist(Point q)\n {\n return GeometryUtils.Dist(x, q.x);\n }\n\n public double YDist(Point q)\n {\n return GeometryUtils.Dist(y, q.y);\n }\n\n public Point Translate(double _x, double _y)\n {\n return new Point(x + _x, y + _y);\n }\n\n public Point Translate(Vector v)\n {\n return new Point(x + v.x, y + v.y);\n }\n\n // Находит проекцию точки на прямую\n public Point Project(Line line)\n {\n Line ort = new Line(this, line.NormalVector);\n Point pt;\n line.Intersects(ort, out pt);\n return pt;\n }\n\n public Point Reflect(Line line)\n {\n Point pr = Project(line);\n Vector v = (pr - this).Scale(2);\n return this.Translate(v);\n }\n\n #endregion\n\n #region Static Members\n\n public static Vector operator -(Point p1, Point p2)\n {\n return new Vector(p1.x - p2.x, p1.y - p2.y);\n }\n\n public static int Orientation(Point p, Point q, Point r)\n {\n double det = GeometryUtils.Determinant(p.x, p.y, 1, q.x, q.y, 1, r.x, r.y, 1);\n if (det > 0) return 1;\n if (det < 0) return -1;\n return 0;\n }\n\n public static double Area(Point p, Point q, Point r)\n {\n return GeometryUtils.Determinant(q.x - p.x, q.y - p.y, r.x - p.x, r.y - p.y);\n }\n\n #endregion\n }\n\n public class Vector\n {\n public double x;\n public double y;\n\n public Vector()\n {\n }\n\n public Vector(double _x, double _y)\n {\n x = _x;\n y = _y;\n }\n\n public Vector Translate(double a, double b)\n {\n return new Vector(x + a, y + b);\n }\n\n public Vector Translate(Vector v)\n {\n return new Vector(x + v.x, y + v.y);\n }\n\n public Vector Scale(double d)\n {\n return new Vector(x * d, y * d);\n }\n }\n\n public class Segment\n {\n private Point start;\n private Point end;\n\n #region Constructors\n\n public Segment()\n : this(new Point(), new Point())\n {\n }\n\n public Segment(Point s, Point e)\n {\n start = s;\n end = e;\n }\n\n public Segment(double x1, double y1, double x2, double y2)\n : this(new Point(x1, y1), new Point(x2, y2))\n {\n }\n\n #endregion\n\n #region Public Properties\n\n public Point Start\n {\n get { return start; }\n set { start = value; }\n }\n\n public Point End\n {\n get { return end; }\n set { end = value; }\n }\n\n public double x1\n {\n get { return start.x; }\n set { start.x = value; }\n }\n\n public double y1\n {\n get { return start.y; }\n set { start.y = value; }\n }\n\n public double x2\n {\n get { return end.x; }\n set { end.x = value; }\n }\n\n public double y2\n {\n get { return end.y; }\n set { end.y = value; }\n }\n\n public Vector Direction\n {\n get { return End - Start; }\n }\n\n #endregion\n\n #region Public Methods\n\n public Line ToLine()\n {\n return new Line(this);\n }\n\n public bool Intersects(Segment seg, out Point p1, out Point p2)\n {\n p1 = new Point();\n p2 = new Point();\n\n double minx1 = Math.Min(Start.x, End.x);\n double maxx1 = Math.Max(Start.x, End.x);\n double miny1 = Math.Min(Start.y, End.y);\n double maxy1 = Math.Max(Start.y, End.y);\n\n double minx2 = Math.Min(seg.Start.x, seg.End.x);\n double maxx2 = Math.Max(seg.Start.x, seg.End.x);\n double miny2 = Math.Min(seg.Start.y, seg.End.y);\n double maxy2 = Math.Max(seg.Start.y, seg.End.y);\n\n if (minx1 > maxx2 || maxx1 < minx2 || miny1 > maxy2 || maxy1 < miny2)\n return false; // boundary rectangles not intersected\n\n Line this_line = this.ToLine();\n Line seg_line = seg.ToLine();\n\n if (this_line.Parallel(seg_line))\n {\n if (this_line.Equivalent(seg_line))\n {\n p1.x = Math.Max(minx1, minx2);\n p1.y = Math.Max(miny1, miny2);\n p2.x = Math.Min(maxx1, maxx2);\n p2.y = Math.Min(miny1, miny2);\n return true; // intersection by segment\n }\n else\n return false; // parallel\n }\n\n Point pt;\n if (!this_line.Intersects(seg_line, out pt))\n return false;\n\n if (pt.x >= minx1 && pt.x <= maxx1 &&\n pt.y >= miny1 && pt.y <= maxy1 &&\n pt.x >= minx2 && pt.x <= maxx2 &&\n pt.y >= miny2 && pt.y <= maxy2)\n {\n p1.x = pt.x;\n p1.y = pt.y;\n p2.x = pt.x;\n p2.y = pt.y;\n return true; // in one point\n }\n\n return false;\n }\n\n public double Distance(Point p)\n {\n Line line = this.ToLine();\n double[] cc = line.Coeffs;\n double A = cc[0];\n double B = cc[1];\n double C = cc[2];\n\n double d = (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);\n d = Math.Min(d, p.Distance(Start));\n d = Math.Min(d, p.Distance(End));\n return d;\n }\n\n #endregion\n\n }\n\n public class Line\n {\n #region Private Members\n\n private Point bp;\n private Vector dir;\n\n #endregion\n\n #region Constructors\n\n public Line()\n : this(new Point(), new Vector(1, 0))\n {\n }\n\n public Line(Point p, Vector v)\n {\n bp = p;\n dir = v;\n }\n\n public Line(Point p1, Point p2)\n : this(p1, p2 - p1)\n {\n\n }\n\n public Line(double x1, double y1, double x2, double y2) :\n this(new Point(x1, y1), new Point(x2, y2))\n {\n }\n\n public Line(Segment s) :\n this(s.Start, s.Direction)\n {\n\n }\n\n #endregion\n\n #region Public Properties\n\n public Point BasePoint { get { return bp; } }\n public Vector Direction { get { return dir; } }\n public Vector NormalVector { get { return new Vector(-dir.y, dir.x); } }\n public double[] Coeffs\n {\n get\n {\n return new double[3] \n {\n dir.y,\n -dir.x, \n dir.x * bp.y - dir.y * bp.x\n };\n }\n }\n\n public double A { get { return dir.y; } }\n public double B { get { return -dir.x; } }\n public double C { get { return dir.x * bp.y - dir.y * bp.x; } }\n\n #endregion\n\n #region Public Methods\n\n public bool Intersects(Line line, out Point pt)\n {\n pt = new Point();\n\n double d = GeometryUtils.Determinant(A, B, line.A, line.B);\n if (GeometryUtils.Sign(d) == 0)\n return false;\n\n pt.x = -GeometryUtils.Determinant(C, B, line.C, line.B) / d;\n pt.y = -GeometryUtils.Determinant(A, C, line.A, line.C) / d;\n\n return true;\n }\n\n public bool Parallel(Line line)\n {\n double d = GeometryUtils.Determinant(A, B, line.A, line.B);\n return GeometryUtils.Sign(d) == 0;\n }\n\n public bool Equivalent(Line line)\n {\n double d1 = GeometryUtils.Determinant(A, B, line.A, line.B);\n double d2 = GeometryUtils.Determinant(A, C, line.A, line.C);\n double d3 = GeometryUtils.Determinant(B, C, line.B, line.C);\n\n return GeometryUtils.Sign(d1) == 0 && GeometryUtils.Sign(d2) == 0 && GeometryUtils.Sign(d2) == 0;\n }\n\n public double Distance(Point p)\n {\n return (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);\n }\n\n #endregion\n }\n \n }\n}\n", "src_uid": "7539a41268b68238d644795bccaa0c0f"} {"source_code": "using System;\nusing System.IO;\n\nnamespace CF_R257\n{\n public class Task_C\n {\n static void Main(string[] args)\n {\n#if !ONLINE_JUDGE\n Console.SetIn(new StreamReader(@\"c_input.txt\"));\n#endif\n new Task_C().Solve();\n }\n\n long n;\n long m;\n long k;\n long maxArea;\n\n private void Solve()\n {\n var parts = Console.ReadLine().Split();\n n = long.Parse(parts[0]);\n m = long.Parse(parts[1]);\n k = long.Parse(parts[2]);\n\n\n long nsq = ((int)Math.Sqrt(n) + 1);\n long msq = ((int)Math.Sqrt(n) + 1);\n maxArea = -1;\n\n for (int i = 1; i <= nsq; i++)\n {\n Test(i, n / i, m);\n Test(n / i, i, m);\n }\n\n for (int i = 1; i <= msq; i++)\n {\n Test(i, m / i, n);\n Test(m / i, i, n);\n }\n\n Console.WriteLine(maxArea);\n }\n\n private void Test(long w1, long count1, long dim2)\n {\n long k1 = count1 - 1;\n long k2 = k - k1;\n\n if (w1 <= 0 || k1 < 0 || k2 < 0)\n return;\n\n long w2 = dim2 / (k2 + 1);\n if (w2 <= 0)\n return;\n\n var area = w1 * w2;\n if (area > maxArea)\n {\n maxArea = area;\n }\n }\n }\n}", "src_uid": "bb453bbe60769bcaea6a824c72120f73"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing static System.Console;\r\nusing System.Linq;\r\n\r\nclass cf734\r\n{\r\n static int NN => int.Parse(ReadLine());\r\n static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();\r\n static void Main()\r\n {\r\n var t = NN;\r\n var res = new List();\r\n for (var _ = 0; _ < t; ++_)\r\n {\r\n var c = NList;\r\n if (c[0] == 1) res.Add(c[2] == c[1] / 2);\r\n else if (c[1] == 1) res.Add(c[2] == 0);\r\n else\r\n {\r\n var lvbs = c[1] / 2;\r\n var lsqs = (c[0] / 2) * lvbs;\r\n var min = c[0] % 2 == 0 ? 0 : lvbs;\r\n var max = min + lsqs * 2;\r\n res.Add(c[2] >= min && c[2] <= max && (c[2] - min) % 2 == 0);\r\n }\r\n }\r\n WriteLine(string.Join(\"\\n\", res.Select(r => r ? \"YES\" : \"NO\")));\r\n }\r\n}\r\n", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Numerics;\nusing E = System.Linq.Enumerable;\n\nnamespace ProbA {\n class Program {\n protected IOHelper io;\n\n long F(long x) {\n return x * (x + 1) / 2;\n }\n\n public Program(string inputFile, string outputFile) {\n io = new IOHelper(inputFile, outputFile, Encoding.Default);\n\n long n = long.Parse(io.NextToken());\n \n int mid, left = 1, right = 1000000000;\n while(left <= right){ \n mid = (left + right) >> 1; \n if(F(mid) >= n) right = mid - 1; \n else left = mid + 1;\n }\n io.WriteLine(n-F(left-1));\n \n /*\n io.WriteLine(\n (from i in E.Range(0,15000002)\n let x=n-(long)i*(long)(i+1)/2\n where x>0\n select x).Min()\n );*/\n io.Dispose();\n }\n\n static void Main(string[] args) {\n Program myProgram = new Program(null, null);\n }\n }\n\n class IOHelper : IDisposable {\n public StreamReader reader;\n public StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding) {\n if (inputFile == null)\n reader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n reader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n writer = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n writer = new StreamWriter(outputFile, false, encoding);\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public bool hasNext() {\n if (curTokenIdx >= curLine.Length) {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n return curTokenIdx < curLine.Length;\n }\n\n public string NextToken() {\n return hasNext() ? curLine[curTokenIdx++] : null;\n }\n\n public int NextInt() {\n return int.Parse(NextToken());\n }\n\n public double NextDouble() {\n string tkn = NextToken();\n return double.Parse(tkn, System.Globalization.CultureInfo.InvariantCulture);\n }\n\n public void Write(double val, int precision) {\n writer.Write(val.ToString(\"F\" + precision, System.Globalization.CultureInfo.InvariantCulture));\n }\n\n public void Write(object stringToWrite) {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(double val, int precision) {\n writer.WriteLine(val.ToString(\"F\" + precision, System.Globalization.CultureInfo.InvariantCulture));\n }\n\n public void WriteLine(object stringToWrite) {\n writer.WriteLine(stringToWrite);\n }\n\n public void Dispose() {\n try {\n if (reader != null) {\n reader.Dispose();\n }\n if (writer != null) {\n writer.Flush();\n writer.Dispose();\n }\n } catch { };\n }\n\n\n public void Flush() {\n if (writer != null) {\n writer.Flush();\n }\n }\n }\n}", "src_uid": "1db5631847085815461c617854b08ee5"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] t1 = Console.ReadLine().Split();\n int n = int.Parse(t1[0]); // КОЛЛИЧЕСТВО ПАПОК\n int m = int.Parse(t1[1]); // ПАПОК ПО ГОРИЗОНТАЛИ \n int a = int.Parse(t1[2]); // ОТ А\n int b = int.Parse(t1[3]); // ДО Б \n\n int kstrok = n / m + 1; // koll strok\n\n int[] array = new int[kstrok + 1];\n for (int i = 2; i < kstrok + 1; i++) //massiv zapominaet nachalo strok\n array[i] = m * i - m + 1;\n\n array[1] = 1;\n\n int[] myarray = new int[kstrok + 1];\n for (int i = 1; i < kstrok + 1; i++) //massiv zapominaet konez strok\n myarray[i] = m * i;\n\n int strokaa = 1;\n int strokab = 1;\n\n for (int i = 1; i < kstrok + 1; i++)\n if (a > myarray[i])\n strokaa = strokaa + 1; //наход строки а\n\n for (int i = 1; i < kstrok + 1; i++)\n if (b > myarray[i])//наход строки б\n strokab = strokab + 1;\n\n int proverkaa1 = 0;\n int proverkab1 = 0;\n\n for (int i = 1; i < kstrok; i++)\n if (a == array[i]) //esli a v nachale stroki\n proverkaa1 = proverkaa1 + 1;\n\n for (int i = 1; i < kstrok; i++)\n if (b == myarray[i])// esli b v konze stroki\n proverkab1 = proverkab1 + 1;\n\n if (proverkaa1 + proverkab1 == 2)\n Console.WriteLine(1);\n\n int o = 0;\n if (strokaa == strokab && proverkaa1 + proverkab1 != 2)\n {\n Console.WriteLine(1); // esli v odnoi stroke a i b\n o = 1;\n }\n\n int proverkaa2 = 0; //Нашлась ли а не по кроям строки?\n int proverkab2 = 0; //Нашлась ли б не по кроям строки?\n\n\n for (int i = 1; i < kstrok + 1; i++)\n if (a > array[i] && a <= myarray[i])\n proverkaa2 = proverkaa2 + 1; //Нашлась ли а не по кроям строки?\n\n for (int i = 1; i < kstrok + 1; i++)\n if (b >= array[i] && b < myarray[i])\n proverkab2 = proverkab2 + 1; //Нашлась ли а не по кроям строки?\n int q = 0;\n if (o == 0)\n {\n if (proverkaa2 + proverkab2 == 2 && strokaa + 1 < strokab)\n if ((a - 1) % m == b % m)\n {\n Console.WriteLine(2);\n q = 1;\n }\n\n\n if (proverkaa2 + proverkab2 == 2 && strokaa + 1 < strokab)\n if (b != n && q != 1)\n Console.WriteLine(3); //если а и б находятся не по краям и расстояние > m\n else if (q != 1)\n Console.WriteLine(2);\n\n if (proverkaa2 + proverkab2 == 2 && strokaa + 1 == strokab)\n Console.WriteLine(2); //если а и б находятся не по краям и расстояние <= m\n\n if (proverkaa1 + proverkab2 == 2)\n if (b != n)\n Console.WriteLine(2); //если а с краю, а б нет\n else Console.WriteLine(1);\n\n if (proverkaa2 + proverkab1 == 2)\n Console.WriteLine(2); //если б с краю, а а неt\n }\n }\n }\n}", "src_uid": "f256235c0b2815aae85a6f9435c69dac"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Text;\nusing System.Linq;\n\nusing E = System.Linq.Enumerable;\nusing System.Threading;\n\ninternal partial class Solver {\n\n public static bool UpdateMin(ref T x, T newValue) where T : IComparable {\n if (x.CompareTo(newValue) > 0) { x = newValue; return true; }\n return false;\n }\n public static bool UpdateMax(ref T x, T newValue) where T : IComparable {\n if (x.CompareTo(newValue) < 0) { x = newValue; return true; }\n return false;\n }\n\n public void Run() {\n var n = ni();\n var k = ni();\n var s = ns();\n var t = ns();\n long ans = 0;\n if (t[0] == t[1]) {\n long count = s.Count(c => c == t[0]);\n count += k;\n if (count > s.Length) count = s.Length;\n ans = count * (count - 1) / 2;\n } else {\n var c1 = t[0];\n var c2 = t[1];\n var memo = new long?[s.Length, k + 1, n + 1]; // (changeNum, occurrence of c1)\n\n Func dfs = null;\n\n dfs = (int pos, int changeNum, int c1Num) => {\n if (pos == s.Length) return 0;\n ref var ret = ref memo[pos, changeNum, c1Num];\n if (!ret.HasValue) {\n long val = 0;\n var c = s[pos];\n if (c == c1) {\n val = Math.Max(val, dfs(pos + 1, changeNum, c1Num + 1));\n } else {\n val = Math.Max(val, dfs(pos + 1, changeNum, c1Num));\n if (changeNum < k) {\n val = Math.Max(val, dfs(pos + 1, changeNum + 1, c1Num + 1));\n }\n }\n if (c == c2) {\n val = Math.Max(val, dfs(pos + 1, changeNum, c1Num) + c1Num);\n } else {\n if (changeNum < k) {\n val = Math.Max(val, dfs(pos + 1, changeNum + 1, c1Num) + c1Num);\n }\n }\n ret = val;\n }\n return ret.Value;\n };\n ans = dfs(0, 0, 0);\n }\n cout.WriteLine(ans);\n }\n\n public static void Fill(T[,] array, T value) {\n int height = array.GetLength(0);\n int width = array.GetLength(1);\n for (int i = 0; i < height; i++) {\n for (int j = 0; j < width; j++) {\n array[i, j] = value;\n }\n }\n }\n\n}\n\n// PREWRITEN CODE BEGINS FROM HERE\n\nstatic public class StringExtensions {\n static public string JoinToString(this IEnumerable source, string separator = \" \") {\n return string.Join(separator, source);\n }\n}\n\ninternal partial class Solver : Scanner {\n static readonly int? StackSizeInMebiByte = null; //50;\n public static void StartAndJoin(Action action, int maxStackSize) {\n var thread = new Thread(new ThreadStart(action), maxStackSize);\n thread.Start();\n thread.Join();\n }\n\n public static void Main() {\n#if LOCAL\n byte[] inputBuffer = new byte[1000000];\n var inputStream = Console.OpenStandardInput(inputBuffer.Length);\n using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {\n Console.SetIn(reader);\n new Solver(Console.In, Console.Out).Run();\n }\n#else\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n if (StackSizeInMebiByte.HasValue) {\n StartAndJoin(() => new Solver(Console.In, Console.Out).Run(), StackSizeInMebiByte.Value * 1024 * 1024);\n } else {\n new Solver(Console.In, Console.Out).Run();\n }\n Console.Out.Flush();\n#endif\n }\n\n#pragma warning disable IDE0052\n private readonly TextReader cin;\n private readonly TextWriter cout;\n private readonly TextWriter cerr;\n#pragma warning restore IDE0052\n\n public Solver(TextReader reader, TextWriter writer)\n : base(reader) {\n cin = reader;\n cout = writer;\n cerr = Console.Error;\n }\n\n public Solver(string input, TextWriter writer)\n : this(new StringReader(input), writer) {\n }\n\n#pragma warning disable IDE1006\n#pragma warning disable IDE0051\n private int ni() { return NextInt(); }\n private int[] ni(int n) { return NextIntArray(n); }\n private long nl() { return NextLong(); }\n private long[] nl(int n) { return NextLongArray(n); }\n private double nd() { return NextDouble(); }\n private double[] nd(int n) { return NextDoubleArray(n); }\n private string ns() { return Next(); }\n private string[] ns(int n) { return NextArray(n); }\n#pragma warning restore IDE1006\n#pragma warning restore IDE0051\n}\n\n#if DEBUG\ninternal static class LinqPadExtension {\n public static string TextDump(this T obj) {\n if (obj is IEnumerable) return (obj as IEnumerable).Cast().JoinToString().Dump();\n else return obj.ToString().Dump();\n }\n public static T Dump(this T obj) {\n return LINQPad.Extensions.Dump(obj);\n }\n}\n#endif\n\npublic class Scanner {\n private readonly TextReader Reader;\n private readonly CultureInfo ci = CultureInfo.InvariantCulture;\n\n private readonly char[] buffer = new char[2 * 1024];\n private int cursor = 0, length = 0;\n private string Token;\n private readonly StringBuilder sb = new StringBuilder(1024);\n\n public Scanner()\n : this(Console.In) {\n }\n\n public Scanner(TextReader reader) {\n Reader = reader;\n }\n\n public int NextInt() { return checked((int)NextLong()); }\n public long NextLong() {\n var s = Next();\n long r = 0;\n int i = 0;\n bool negative = false;\n if (s[i] == '-') {\n negative = true;\n i++;\n }\n for (; i < s.Length; i++) {\n r = r * 10 + (s[i] - '0');\n#if DEBUG\n if (!char.IsDigit(s[i])) throw new FormatException();\n#endif\n }\n return negative ? -r : r;\n }\n public double NextDouble() { return double.Parse(Next(), ci); }\n public string[] NextArray(int size) {\n string[] array = new string[size];\n for (int i = 0; i < size; i++) {\n array[i] = Next();\n }\n\n return array;\n }\n public int[] NextIntArray(int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = NextInt();\n }\n\n return array;\n }\n\n public long[] NextLongArray(int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; i++) {\n array[i] = NextLong();\n }\n\n return array;\n }\n\n public double[] NextDoubleArray(int size) {\n double[] array = new double[size];\n for (int i = 0; i < size; i++) {\n array[i] = NextDouble();\n }\n\n return array;\n }\n\n public string Next() {\n if (Token == null) {\n if (!StockToken()) {\n throw new Exception();\n }\n }\n var token = Token;\n Token = null;\n return token;\n }\n\n public bool HasNext() {\n if (Token != null) {\n return true;\n }\n\n return StockToken();\n }\n\n private bool StockToken() {\n while (true) {\n sb.Clear();\n while (true) {\n if (cursor >= length) {\n cursor = 0;\n if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {\n break;\n }\n }\n var c = buffer[cursor++];\n if (33 <= c && c <= 126) {\n sb.Append(c);\n } else {\n if (sb.Length > 0) break;\n }\n }\n\n if (sb.Length > 0) {\n Token = sb.ToString();\n return true;\n }\n\n return false;\n }\n }\n}", "src_uid": "9c700390ac13942cbde7c3428965b18a"} {"source_code": "using System;\nusing System.Buffers;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\nusing System.Runtime.Intrinsics.X86;\nusing EducationalCodeforcesRound98.Questions;\nusing ModInt = EducationalCodeforcesRound98.StaticModInt;\n\nnamespace EducationalCodeforcesRound98.Questions\n{\n public class QuestionD : AtCoderQuestionBase\n {\n [MethodImpl(MethodImplOptions.AggressiveOptimization)]\n public override void Solve(IOManager io)\n {\n var n = io.ReadInt();\n var oddBit = new BinaryIndexedTree(n + 1);\n var evenBit = new BinaryIndexedTree(n + 1);\n\n evenBit[0] = ModInt.One;\n\n for (int i = 1; i <= n; i++)\n {\n var even = evenBit.Sum(0, i);\n oddBit.AddAt(i, even);\n (oddBit, evenBit) = (evenBit, oddBit);\n }\n\n var result = evenBit[n] / ModInt.Raw(2).Pow(n);\n io.WriteLine(result);\n }\n\n public class BinaryIndexedTree\n {\n ModInt[] _data;\n public int Length { get; }\n\n public BinaryIndexedTree(int length)\n {\n _data = new ModInt[length + 1]; // 内部的には1-indexedにする\n Length = length;\n }\n\n public BinaryIndexedTree(IEnumerable data, int length) : this(length)\n {\n var count = 0;\n foreach (var n in data)\n {\n AddAt(count++, n);\n }\n }\n\n public BinaryIndexedTree(ICollection collection) : this(collection, collection.Count) { }\n\n public ModInt this[int index]\n {\n get => Sum(index, index + 1);\n set => AddAt(index, value - this[index]);\n }\n\n /// \n /// BITのindex番目の要素にnを加算します。\n /// \n /// 加算するインデックス(0-indexed)\n /// 加算する数\n public void AddAt(Index index, ModInt value)\n {\n var i = index.GetOffset(Length);\n unchecked\n {\n if ((uint)i >= (uint)Length)\n {\n throw new ArgumentOutOfRangeException(nameof(index));\n }\n }\n\n i++; // 1-indexedにする\n\n while (i <= Length)\n {\n _data[i] += value;\n i += i & -i; // LSBの加算\n }\n }\n\n /// \n /// [0, end)の部分和を返します。\n /// \n /// 部分和を求める半開区間の終了インデックス\n /// 区間の部分和\n public ModInt Sum(Index end)\n {\n var i = end.GetOffset(Length); // 0-indexedの半開区間=1-indexedの閉区間なので+1は不要\n unchecked\n {\n if ((uint)i >= (uint)_data.Length)\n {\n throw new ArgumentOutOfRangeException(nameof(end));\n }\n }\n\n ModInt sum = 0;\n while (i > 0)\n {\n sum += _data[i];\n i -= i & -i; // LSBの減算\n }\n return sum;\n }\n\n /// \n /// rangeの部分和を返します。\n /// \n /// 部分和を求める半開区間\n /// 区間の部分和\n public ModInt Sum(Range range) => Sum(range.End) - Sum(range.Start);\n\n /// \n /// [start, end)の部分和を返します。\n /// \n /// 部分和を求める半開区間の開始インデックス\n /// 部分和を求める半開区間の終了インデックス\n /// 区間の部分和\n public ModInt Sum(int start, int end) => Sum(end) - Sum(start);\n }\n\n }\n}\n\nnamespace EducationalCodeforcesRound98\n{\n class Program\n {\n static void Main(string[] args)\n {\n IAtCoderQuestion question = new QuestionD();\n using var io = new IOManager(Console.OpenStandardInput(), Console.OpenStandardOutput());\n question.Solve(io);\n }\n }\n}\n\n#region Base Class\n\nnamespace EducationalCodeforcesRound98.Questions\n{\n public interface IAtCoderQuestion\n {\n string Solve(string input);\n void Solve(IOManager io);\n }\n\n public abstract class AtCoderQuestionBase : IAtCoderQuestion\n {\n public string Solve(string input)\n {\n var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(input));\n var outputStream = new MemoryStream();\n using var manager = new IOManager(inputStream, outputStream);\n\n Solve(manager);\n manager.Flush();\n\n outputStream.Seek(0, SeekOrigin.Begin);\n var reader = new StreamReader(outputStream);\n return reader.ReadToEnd();\n }\n\n public abstract void Solve(IOManager io);\n }\n}\n\n#endregion\n\n#region Utils\n\nnamespace EducationalCodeforcesRound98\n{\n public class IOManager : IDisposable\n {\n private readonly BinaryReader _reader;\n private readonly StreamWriter _writer;\n private bool _disposedValue;\n private byte[] _buffer = new byte[1024];\n private int _length;\n private int _cursor;\n private bool _eof;\n\n const char ValidFirstChar = '!';\n const char ValidLastChar = '~';\n\n public IOManager(Stream input, Stream output)\n {\n _reader = new BinaryReader(input);\n _writer = new StreamWriter(output) { AutoFlush = false };\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private char ReadAscii()\n {\n if (_cursor == _length)\n {\n _cursor = 0;\n _length = _reader.Read(_buffer);\n\n if (_length == 0)\n {\n if (!_eof)\n {\n _eof = true;\n return char.MinValue;\n }\n else\n {\n ThrowEndOfStreamException();\n }\n }\n }\n\n return (char)_buffer[_cursor++];\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public char ReadChar()\n {\n char c;\n while (!IsValidChar(c = ReadAscii())) { }\n return c;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public string ReadString()\n {\n var builder = new StringBuilder();\n char c;\n while (!IsValidChar(c = ReadAscii())) { }\n\n do\n {\n builder.Append(c);\n } while (IsValidChar(c = ReadAscii()));\n\n return builder.ToString();\n }\n\n public int ReadInt() => (int)ReadLong();\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public long ReadLong()\n {\n long result = 0;\n bool isPositive = true;\n char c;\n\n while (!IsNumericChar(c = ReadAscii())) { }\n\n if (c == '-')\n {\n isPositive = false;\n c = ReadAscii();\n }\n\n do\n {\n result *= 10;\n result += c - '0';\n } while (IsNumericChar(c = ReadAscii()));\n\n return isPositive ? result : -result;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private Span ReadChunk(Span span)\n {\n var i = 0;\n char c;\n while (!IsValidChar(c = ReadAscii())) { }\n\n do\n {\n span[i++] = c;\n } while (IsValidChar(c = ReadAscii()));\n\n return span.Slice(0, i);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public double ReadDouble() => double.Parse(ReadChunk(stackalloc char[32]));\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public decimal ReadDecimal() => decimal.Parse(ReadChunk(stackalloc char[32]));\n\n public int[] ReadIntArray(int n)\n {\n var a = new int[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadInt();\n }\n return a;\n }\n\n public long[] ReadLongArray(int n)\n {\n var a = new long[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadLong();\n }\n return a;\n }\n\n public double[] ReadDoubleArray(int n)\n {\n var a = new double[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadDouble();\n }\n return a;\n }\n\n public decimal[] ReadDecimalArray(int n)\n {\n var a = new decimal[n];\n for (int i = 0; i < a.Length; i++)\n {\n a[i] = ReadDecimal();\n }\n return a;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Write(T value) => _writer.Write(value.ToString());\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void WriteLine(T value) => _writer.WriteLine(value.ToString());\n\n public void WriteLine(IEnumerable values, char separator)\n {\n var e = values.GetEnumerator();\n if (e.MoveNext())\n {\n _writer.Write(e.Current.ToString());\n\n while (e.MoveNext())\n {\n _writer.Write(separator);\n _writer.Write(e.Current.ToString());\n }\n }\n\n _writer.WriteLine();\n }\n\n public void WriteLine(T[] values, char separator) => WriteLine((ReadOnlySpan)values, separator);\n public void WriteLine(Span values, char separator) => WriteLine((ReadOnlySpan)values, separator);\n\n public void WriteLine(ReadOnlySpan values, char separator)\n {\n for (int i = 0; i < values.Length - 1; i++)\n {\n _writer.Write(values[i]);\n _writer.Write(separator);\n }\n\n if (values.Length > 0)\n {\n _writer.Write(values[^1]);\n }\n\n _writer.WriteLine();\n }\n\n public void Flush() => _writer.Flush();\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static bool IsValidChar(char c) => ValidFirstChar <= c && c <= ValidLastChar;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static bool IsNumericChar(char c) => ('0' <= c && c <= '9') || c == '-';\n\n private void ThrowEndOfStreamException() => throw new EndOfStreamException();\n\n protected virtual void Dispose(bool disposing)\n {\n if (!_disposedValue)\n {\n if (disposing)\n {\n _reader.Dispose();\n _writer.Flush();\n _writer.Dispose();\n }\n\n _disposedValue = true;\n }\n }\n\n public void Dispose()\n {\n Dispose(disposing: true);\n GC.SuppressFinalize(this);\n }\n }\n\n public static class UtilExtensions\n {\n public static bool ChangeMax(ref this T value, T other) where T : struct, IComparable\n {\n if (value.CompareTo(other) < 0)\n {\n value = other;\n return true;\n }\n return false;\n }\n\n public static bool ChangeMin(ref this T value, T other) where T : struct, IComparable\n {\n if (value.CompareTo(other) > 0)\n {\n value = other;\n return true;\n }\n return false;\n }\n\n public static void SwapIfLargerThan(ref this T a, ref T b) where T : struct, IComparable\n {\n if (a.CompareTo(b) > 0)\n {\n (a, b) = (b, a);\n }\n }\n\n public static void SwapIfSmallerThan(ref this T a, ref T b) where T : struct, IComparable\n {\n if (a.CompareTo(b) < 0)\n {\n (a, b) = (b, a);\n }\n }\n\n public static void Sort(this T[] array) where T : IComparable => Array.Sort(array);\n public static void Sort(this T[] array, Comparison comparison) => Array.Sort(array, comparison);\n }\n\n public static class CollectionExtensions\n {\n private class ArrayWrapper\n {\n#pragma warning disable CS0649\n public T[] Array;\n#pragma warning restore CS0649\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static Span AsSpan(this List list)\n {\n return Unsafe.As>(list).Array.AsSpan(0, list.Count);\n }\n\n public static void Fill(this T[] array, T value) => array.AsSpan().Fill(value);\n public static void Fill(this T[,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0], array.Length).Fill(value);\n public static void Fill(this T[,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0], array.Length).Fill(value);\n public static void Fill(this T[,,,] array, T value) => MemoryMarshal.CreateSpan(ref array[0, 0, 0, 0], array.Length).Fill(value);\n }\n\n public static class SearchExtensions\n {\n struct LowerBoundComparer : IComparer where T : IComparable\n {\n public int Compare(T x, T y) => 0 <= x.CompareTo(y) ? 1 : -1;\n }\n\n struct UpperBoundComparer : IComparer where T : IComparable\n {\n public int Compare(T x, T y) => 0 < x.CompareTo(y) ? 1 : -1;\n }\n\n // https://trsing.hatenablog.com/entry/2019/08/27/211038\n public static int GetGreaterEqualIndex(this ReadOnlySpan span, T inclusiveMin) where T : IComparable => ~span.BinarySearch(inclusiveMin, new UpperBoundComparer());\n public static int GetGreaterThanIndex(this ReadOnlySpan span, T exclusiveMin) where T : IComparable => ~span.BinarySearch(exclusiveMin, new LowerBoundComparer());\n public static int GetLessEqualIndex(this ReadOnlySpan span, T inclusiveMax) where T : IComparable => ~span.BinarySearch(inclusiveMax, new LowerBoundComparer()) - 1;\n public static int GetLessThanIndex(this ReadOnlySpan span, T exclusiveMax) where T : IComparable => ~span.BinarySearch(exclusiveMax, new UpperBoundComparer()) - 1;\n public static int GetGreaterEqualIndex(this Span span, T inclusiveMin) where T : IComparable => ((ReadOnlySpan)span).GetGreaterEqualIndex(inclusiveMin);\n public static int GetGreaterThanIndex(this Span span, T exclusiveMin) where T : IComparable => ((ReadOnlySpan)span).GetGreaterThanIndex(exclusiveMin);\n public static int GetLessEqualIndex(this Span span, T inclusiveMax) where T : IComparable => ((ReadOnlySpan)span).GetLessEqualIndex(inclusiveMax);\n public static int GetLessThanIndex(this Span span, T exclusiveMax) where T : IComparable => ((ReadOnlySpan)span).GetLessThanIndex(exclusiveMax);\n\n public static int BoundaryBinarySearch(Predicate predicate, int ok, int ng)\n {\n while (Math.Abs(ok - ng) > 1)\n {\n int mid = (ok + ng) / 2;\n if (predicate(mid))\n {\n ok = mid;\n }\n else\n {\n ng = mid;\n }\n }\n return ok;\n }\n\n public static long BoundaryBinarySearch(Predicate predicate, long ok, long ng)\n {\n while (Math.Abs(ok - ng) > 1)\n {\n long mid = (ok + ng) / 2;\n if (predicate(mid))\n {\n ok = mid;\n }\n else\n {\n ng = mid;\n }\n }\n return ok;\n }\n\n public static double Bisection(Func f, double a, double b, double eps = 1e-9)\n {\n if (f(a) * f(b) >= 0)\n {\n throw new ArgumentException(\"f(a)とf(b)は異符号である必要があります。\");\n }\n\n const int maxLoop = 100;\n double mid = (a + b) / 2;\n\n for (int i = 0; i < maxLoop; i++)\n {\n if (f(a) * f(mid) < 0)\n {\n b = mid;\n }\n else\n {\n a = mid;\n }\n mid = (a + b) / 2;\n if (Math.Abs(b - a) < eps)\n {\n break;\n }\n }\n return mid;\n }\n\n }\n\n #region ModInt\n\n /// \n /// コンパイル時に決定する mod を表します。\n /// \n /// \n /// \n /// public readonly struct Mod1000000009 : IStaticMod\n /// {\n /// public uint Mod => 1000000009;\n /// public bool IsPrime => true;\n /// }\n /// \n /// \n public interface IStaticMod\n {\n /// \n /// mod を取得します。\n /// \n uint Mod { get; }\n\n /// \n /// mod が素数であるか識別します。\n /// \n bool IsPrime { get; }\n }\n\n public readonly struct Mod1000000007 : IStaticMod\n {\n public uint Mod => 1000000007;\n public bool IsPrime => true;\n }\n\n public readonly struct Mod998244353 : IStaticMod\n {\n public uint Mod => 998244353;\n public bool IsPrime => true;\n }\n\n /// \n /// 実行時に決定する mod の ID を表します。\n /// \n /// \n /// \n /// public readonly struct ModID123 : IDynamicModID { }\n /// \n /// \n public interface IDynamicModID { }\n\n public readonly struct ModID0 : IDynamicModID { }\n public readonly struct ModID1 : IDynamicModID { }\n public readonly struct ModID2 : IDynamicModID { }\n\n /// \n /// 四則演算時に自動で mod を取る整数型。mod の値はコンパイル時に決定している必要があります。\n /// \n /// 定数 mod を表す構造体\n /// \n /// \n /// using ModInt = AtCoder.StaticModInt<AtCoder.Mod1000000007>;\n ///\n /// void SomeMethod()\n /// {\n /// var m = new ModInt(1);\n /// m -= 2;\n /// Console.WriteLine(m); // 1000000006\n /// }\n /// \n /// \n public readonly struct StaticModInt : IEquatable> where T : struct, IStaticMod\n {\n private readonly uint _v;\n\n /// \n /// 格納されている値を返します。\n /// \n public int Value => (int)_v;\n\n /// \n /// mod を返します。\n /// \n public static int Mod => (int)default(T).Mod;\n\n public static StaticModInt Zero => new StaticModInt();\n public static StaticModInt One => new StaticModInt(1u);\n\n /// \n /// に対して mod を取らずに StaticModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// 定数倍高速化のための関数です。 に 0 未満または mod 以上の値を入れた場合の挙動は未定義です。\n /// 制約: 0≤||<mod\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt Raw(int v)\n {\n var u = unchecked((uint)v);\n Debug.Assert(u < Mod);\n return new StaticModInt(u);\n }\n\n /// \n /// StaticModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// が 0 未満、もしくは mod 以上の場合、自動で mod を取ります。\n /// \n public StaticModInt(long v) : this(Round(v)) { }\n\n private StaticModInt(uint v) => _v = v;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static uint Round(long v)\n {\n var x = v % default(T).Mod;\n if (x < 0)\n {\n x += default(T).Mod;\n }\n return (uint)x;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator ++(StaticModInt value)\n {\n var v = value._v + 1;\n if (v == default(T).Mod)\n {\n v = 0;\n }\n return new StaticModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator --(StaticModInt value)\n {\n var v = value._v;\n if (v == 0)\n {\n v = default(T).Mod;\n }\n return new StaticModInt(v - 1);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator +(StaticModInt lhs, StaticModInt rhs)\n {\n var v = lhs._v + rhs._v;\n if (v >= default(T).Mod)\n {\n v -= default(T).Mod;\n }\n return new StaticModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator -(StaticModInt lhs, StaticModInt rhs)\n {\n unchecked\n {\n var v = lhs._v - rhs._v;\n if (v >= default(T).Mod)\n {\n v += default(T).Mod;\n }\n return new StaticModInt(v);\n }\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static StaticModInt operator *(StaticModInt lhs, StaticModInt rhs)\n {\n return new StaticModInt((uint)((ulong)lhs._v * rhs._v % default(T).Mod));\n }\n\n /// \n /// 除算を行います。\n /// \n /// \n /// - 制約: に乗法の逆元が存在する。(gcd(, mod) = 1)\n /// - 計算量: O(log(mod))\n /// \n public static StaticModInt operator /(StaticModInt lhs, StaticModInt rhs) => lhs * rhs.Inverse();\n\n public static StaticModInt operator +(StaticModInt value) => value;\n public static StaticModInt operator -(StaticModInt value) => new StaticModInt() - value;\n public static bool operator ==(StaticModInt lhs, StaticModInt rhs) => lhs._v == rhs._v;\n public static bool operator !=(StaticModInt lhs, StaticModInt rhs) => lhs._v != rhs._v;\n public static implicit operator StaticModInt(int value) => new StaticModInt(value);\n public static implicit operator StaticModInt(long value) => new StaticModInt(value);\n\n /// \n /// 自身を x として、x^ を返します。\n /// \n /// \n /// 制約: 0≤||\n /// 計算量: O(log())\n /// \n public StaticModInt Pow(long n)\n {\n Debug.Assert(0 <= n);\n var x = this;\n var r = Raw(1);\n\n while (n > 0)\n {\n if ((n & 1) > 0)\n {\n r *= x;\n }\n x *= x;\n n >>= 1;\n }\n\n return r;\n }\n\n /// \n /// 自身を x として、 xy≡1 なる y を返します。\n /// \n /// \n /// 制約: gcd(x, mod) = 1\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public StaticModInt Inverse()\n {\n if (default(T).IsPrime)\n {\n Debug.Assert(_v > 0);\n return Pow(default(T).Mod - 2);\n }\n else\n {\n var (g, x) = InternalMath.InvGCD(_v, default(T).Mod);\n Debug.Assert(g == 1);\n return new StaticModInt(x);\n }\n }\n\n public override string ToString() => _v.ToString();\n public override bool Equals(object obj) => obj is StaticModInt && Equals((StaticModInt)obj);\n public bool Equals(StaticModInt other) => Value == other.Value;\n public override int GetHashCode() => _v.GetHashCode();\n }\n\n /// \n /// 四則演算時に自動で mod を取る整数型。実行時に mod が決まる場合でも使用可能です。\n /// \n /// \n /// 使用前に DynamicModInt<>.Mod に mod の値を設定する必要があります。\n /// \n /// mod の ID を表す構造体\n /// \n /// \n /// using AtCoder.ModInt = AtCoder.DynamicModInt<AtCoder.ModID0>;\n ///\n /// void SomeMethod()\n /// {\n /// ModInt.Mod = 1000000009;\n /// var m = new ModInt(1);\n /// m -= 2;\n /// Console.WriteLine(m); // 1000000008\n /// }\n /// \n /// \n public readonly struct DynamicModInt : IEquatable> where T : struct, IDynamicModID\n {\n private readonly uint _v;\n private static Barrett bt;\n\n /// \n /// 格納されている値を返します。\n /// \n public int Value => (int)_v;\n\n /// \n /// mod を返します。\n /// \n public static int Mod\n {\n get => (int)bt.Mod;\n set\n {\n Debug.Assert(1 <= value);\n bt = new Barrett((uint)value);\n }\n }\n\n /// \n /// に対して mod を取らずに DynamicModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// 定数倍高速化のための関数です。 に 0 未満または mod 以上の値を入れた場合の挙動は未定義です。\n /// 制約: 0≤||<mod\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt Raw(int v)\n {\n var u = unchecked((uint)v);\n Debug.Assert(bt != null, $\"使用前に {nameof(DynamicModInt)}<{nameof(T)}>.{nameof(Mod)} プロパティに mod の値を設定してください。\");\n Debug.Assert(u < Mod);\n return new DynamicModInt(u);\n }\n\n /// \n /// DynamicModInt<> 型のインスタンスを生成します。\n /// \n /// \n /// - 使用前に DynamicModInt<>.Mod に mod の値を設定する必要があります。\n /// - が 0 未満、もしくは mod 以上の場合、自動で mod を取ります。\n /// \n public DynamicModInt(long v) : this(Round(v)) { }\n\n private DynamicModInt(uint v) => _v = v;\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n private static uint Round(long v)\n {\n Debug.Assert(bt != null, $\"使用前に {nameof(DynamicModInt)}<{nameof(T)}>.{nameof(Mod)} プロパティに mod の値を設定してください。\");\n var x = v % bt.Mod;\n if (x < 0)\n {\n x += bt.Mod;\n }\n return (uint)x;\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator ++(DynamicModInt value)\n {\n var v = value._v + 1;\n if (v == bt.Mod)\n {\n v = 0;\n }\n return new DynamicModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator --(DynamicModInt value)\n {\n var v = value._v;\n if (v == 0)\n {\n v = bt.Mod;\n }\n return new DynamicModInt(v - 1);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator +(DynamicModInt lhs, DynamicModInt rhs)\n {\n var v = lhs._v + rhs._v;\n if (v >= bt.Mod)\n {\n v -= bt.Mod;\n }\n return new DynamicModInt(v);\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator -(DynamicModInt lhs, DynamicModInt rhs)\n {\n unchecked\n {\n var v = lhs._v - rhs._v;\n if (v >= bt.Mod)\n {\n v += bt.Mod;\n }\n return new DynamicModInt(v);\n }\n }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static DynamicModInt operator *(DynamicModInt lhs, DynamicModInt rhs)\n {\n uint z = bt.Mul(lhs._v, rhs._v);\n return new DynamicModInt(z);\n }\n\n /// \n /// 除算を行います。\n /// \n /// \n /// - 制約: に乗法の逆元が存在する。(gcd(, mod) = 1)\n /// - 計算量: O(log(mod))\n /// \n public static DynamicModInt operator /(DynamicModInt lhs, DynamicModInt rhs) => lhs * rhs.Inverse();\n\n public static DynamicModInt operator +(DynamicModInt value) => value;\n public static DynamicModInt operator -(DynamicModInt value) => new DynamicModInt() - value;\n public static bool operator ==(DynamicModInt lhs, DynamicModInt rhs) => lhs._v == rhs._v;\n public static bool operator !=(DynamicModInt lhs, DynamicModInt rhs) => lhs._v != rhs._v;\n public static implicit operator DynamicModInt(int value) => new DynamicModInt(value);\n public static implicit operator DynamicModInt(long value) => new DynamicModInt(value);\n\n /// \n /// 自身を x として、x^ を返します。\n /// \n /// \n /// 制約: 0≤||\n /// 計算量: O(log())\n /// \n public DynamicModInt Pow(long n)\n {\n Debug.Assert(0 <= n);\n var x = this;\n var r = Raw(1);\n\n while (n > 0)\n {\n if ((n & 1) > 0)\n {\n r *= x;\n }\n x *= x;\n n >>= 1;\n }\n\n return r;\n }\n\n /// \n /// 自身を x として、 xy≡1 なる y を返します。\n /// \n /// \n /// 制約: gcd(x, mod) = 1\n /// \n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public DynamicModInt Inverse()\n {\n var (g, x) = InternalMath.InvGCD(_v, bt.Mod);\n Debug.Assert(g == 1);\n return new DynamicModInt(x);\n }\n\n public override string ToString() => _v.ToString();\n public override bool Equals(object obj) => obj is DynamicModInt && Equals((DynamicModInt)obj);\n public bool Equals(DynamicModInt other) => Value == other.Value;\n public override int GetHashCode() => _v.GetHashCode();\n }\n\n /// \n /// Fast moduler by barrett reduction\n /// \n /// \n public class Barrett\n {\n public uint Mod { get; private set; }\n private ulong IM;\n public Barrett(uint m)\n {\n Mod = m;\n IM = unchecked((ulong)-1) / m + 1;\n }\n\n /// \n /// * mod m\n /// \n public uint Mul(uint a, uint b)\n {\n ulong z = a;\n z *= b;\n if (!Bmi2.X64.IsSupported) return (uint)(z % Mod);\n var x = Bmi2.X64.MultiplyNoFlags(z, IM);\n var v = unchecked((uint)(z - x * Mod));\n if (Mod <= v) v += Mod;\n return v;\n }\n }\n\n public static class InternalMath\n {\n /// \n /// g=gcd(a,b),xa=g(mod b) となるような 0≤x<b/g の(g, x)\n /// \n /// \n /// 制約: 1≤\n /// \n public static (long, long) InvGCD(long a, long b)\n {\n a = SafeMod(a, b);\n if (a == 0) return (b, 0);\n\n long s = b, t = a;\n long m0 = 0, m1 = 1;\n\n long u;\n while (true)\n {\n if (t == 0)\n {\n if (m0 < 0) m0 += b / s;\n return (s, m0);\n }\n u = s / t;\n s -= t * u;\n m0 -= m1 * u;\n\n if (s == 0)\n {\n if (m1 < 0) m1 += b / t;\n return (t, m1);\n }\n u = t / s;\n t -= s * u;\n m1 -= m0 * u;\n }\n }\n\n public static long SafeMod(long x, long m)\n {\n x %= m;\n if (x < 0) x += m;\n return x;\n }\n }\n\n public class ModCombination where T : struct, IStaticMod\n {\n readonly StaticModInt[] _factorials;\n readonly StaticModInt[] _invFactorials;\n\n public ModCombination(int max = 1000000)\n {\n if (max >= default(T).Mod)\n {\n ThrowArgumentOutOfRangeException();\n }\n\n _factorials = new StaticModInt[max + 1];\n _invFactorials = new StaticModInt[max + 1];\n\n _factorials[0] = _factorials[1] = StaticModInt.Raw(1);\n _invFactorials[0] = _invFactorials[1] = StaticModInt.Raw(1);\n\n for (int i = 2; i < _factorials.Length; i++)\n {\n _factorials[i] = _factorials[i - 1] * StaticModInt.Raw(i);\n }\n\n _invFactorials[^1] = _factorials[^1].Inverse();\n\n for (int i = _invFactorials.Length - 2; i >= 0; i--)\n {\n _invFactorials[i] = _invFactorials[i + 1] * StaticModInt.Raw(i + 1);\n }\n }\n\n public StaticModInt Factorial(int n) => _factorials[n];\n\n public StaticModInt Permutation(int n, int k) => _factorials[n] * _invFactorials[n - k];\n\n public StaticModInt Combination(int n, int k) => _factorials[n] * _invFactorials[k] * _invFactorials[n - k];\n\n public StaticModInt CombinationWithRepetition(int n, int k) => Combination(n + k - 1, k);\n\n public void ThrowArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException();\n }\n\n #endregion\n}\n\n#endregion\n", "src_uid": "cec37432956bb0a1ce62a0188fe2d805"} {"source_code": "using System;\n\nnamespace Codeforces\n{\n internal class Program\n {\n private static int ReadInt()\n {\n return Int32.Parse(Console.ReadLine());\n }\n\n private static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n private static int ReadNextInt(string input, int index)\n {\n var ints = input.Split(' ');\n return Int32.Parse(ints[index]);\n }\n\n private static void Main()\n {\n var input = Console.ReadLine();\n var t1 = ReadNextInt(input, 0);\n var t2 = ReadNextInt(input, 1);\n var x1 = ReadNextInt(input, 2);\n var x2 = ReadNextInt(input, 3);\n var t0 = ReadNextInt(input, 4);\n \n if(t1 == t2)\n {\n Console.WriteLine(x1 + \" \" + x2);\n return;\n }\n if(t1==t0)\n {\n Console.WriteLine(x1 + \" \" + 0);\n return;\n }\n if(t2 == t0)\n {\n Console.WriteLine(0 + \" \" + x2);\n return;\n }\n var T = (double)t2;\n var maxX = 0;\n var maxY = x2;\n for (int x= 1; x <= x1; x++)\n {\n var y = (int)(((double) (t0 - t1)*x)/(t2 - t0));\n if ((long)y * (t2 - t0) != (long)(t0 - t1) * x)\n y++;\n\n if (y <= 0 || y > x2)\n continue;\n\n var tempT = ((double)x * t1 + (double)y * t2) / (x + y);\n if(tempT < t0)\n continue;\n\n if(T < t0 || T > tempT || (T==tempT && maxX + maxY < x+y))\n {\n T = tempT;\n maxX = x;\n maxY = y;\n }\n }\n Console.WriteLine(maxX + \" \" + maxY);\n }\n }\n}", "src_uid": "87a500829c1935ded3ef6e4e47096b9f"} {"source_code": "using System.Collections.Generic;\nusing System.Collections;\nusing System.ComponentModel;\nusing System.Diagnostics.CodeAnalysis;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Reflection;\nusing System.Runtime.Serialization;\nusing System.Text.RegularExpressions;\nusing System.Text;\nusing System;\nusing System.Numerics;\n\nclass Solution\n{\n\n static BigInteger pow2(BigInteger p)\n {\n BigInteger res = 1;\n while (p > 0)\n {\n res *= 2;\n p--;\n }\n return res;\n }\n\n static BigInteger calc(BigInteger a, BigInteger r, int i)\n {\n if (i == 1) return a;\n if (i == 2) return a + r;\n return (a + r) * pow2(i - 1);\n\n }\n\n static int? log2(BigInteger a)\n {\n if (a == 1) return 0;\n if (a == 2) return 1;\n int res = 0;\n while (a > 1)\n {\n\n res += 1;\n a = a / 2;\n }\n return res;\n }\n\n static bool recurs(int cnt, BigInteger b, BigInteger m, List res)\n {\n if (cnt == 1)\n {\n if (b <= m)\n {\n res.Add(b);\n return true;\n }\n else\n {\n return false;\n }\n }\n else\n {\n var i = cnt - 1;\n var tmpp = pow2(i - 1);\n var r = (b / tmpp) - 1;\n var l = (b % tmpp == 0 ? b / tmpp : 1 + b / tmpp) - m;\n\n if (l > m || r < 1)\n return false;\n r = r > m ? m : r;\n l = l < 1 ? 1 : l;\n var a = (l + r) / 2;\n res.Add(a);\n var newb = b - a * tmpp;\n return recurs(cnt - 1, newb, m, res);\n }\n }\n\n static void Main(string[] args)\n {\n var t = int.Parse(Console.ReadLine().Trim());\n for (int l = 0; l < t; l++)\n {\n var nm = Array.ConvertAll(Console.ReadLine().Trim().Split(), BigInteger.Parse);\n var a = nm[0];\n var b = nm[1];\n var m = nm[2];\n if (a == b)\n {\n Console.Write(1);\n Console.Write(' ');\n Console.WriteLine(a);\n continue;\n }\n if (b - a <= m)\n {\n\n Console.Write(2);\n Console.Write(' ');\n Console.Write(a);\n Console.Write(' ');\n Console.WriteLine(b);\n continue;\n }\n if (m == 1)\n {\n if (b % (a + 1) == 1)\n {\n Console.WriteLine(-1);\n continue;\n }\n var b2 = b / (a + 1);\n var res = 1 + log2(b2);\n if (res == null || pow2(res.Value - 1) * (a + 1) != b)\n {\n Console.WriteLine(-1);\n continue;\n }\n Console.Write(res.Value + 1);\n Console.Write(' ');\n\n Console.Write(a);\n Console.Write(' ');\n a += 1;\n for (int i = 0; i < res; i++)\n {\n Console.Write(a);\n Console.Write(' ');\n a = 2 * a;\n }\n continue;\n }\n\n var li = log2(b / (a + 1)) + 1;\n if (li == null || li > 50)\n {\n Console.WriteLine(-1);\n continue;\n }\n var bsht = (a + m) * pow2(li.Value - 1);\n if (bsht < b)\n {\n Console.WriteLine(-1);\n continue;\n }\n\n List rs = new List();\n var newb = b - a * pow2(li.Value - 1);\n if (!recurs(li.Value, newb, m, rs))\n {\n Console.WriteLine(-1);\n continue;\n }\n Console.Write(rs.Count + 1);\n Console.Write(' ');\n\n Console.Write(a);\n Console.Write(' ');\n\n foreach (var el in rs)\n {\n if (el > m)\n {\n break;\n }\n a += el;\n Console.Write(a);\n Console.Write(' ');\n a = 2 * (a - el) + el;\n }\n Console.WriteLine();\n\n }\n\n }\n}", "src_uid": "c9d646762e2e78064bc0670ec7c173c6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace GoToBed\n{\n class Program\n {\n static void Main(string[] args)\n {\n var currTime = Console.ReadLine().Split(new char[] { ':' }).Select(x => int.Parse(x)).ToArray();\n var sleepDurration = Console.ReadLine().Split(new char[] { ':' }).Select(x => int.Parse(x)).ToArray();\n\n int resMin;\n int resHour;\n\n var substraction = currTime[1] - sleepDurration[1];\n \n bool carry = false;\n\n if (substraction < 0)\n {\n substraction = 60 + currTime[1] - sleepDurration[1];\n carry = true;\n }\n\n resMin = substraction;\n\n if (carry)\n {\n currTime[0]--;\n\n // 01:11\n // 00:12\n }\n\n substraction = currTime[0] - sleepDurration[0];\n\n if (substraction < 0)\n {\n substraction = 24 + currTime[0] - sleepDurration[0];\n }\n\n resHour = substraction;\n\n Console.WriteLine(\"{0:00}:{1:00}\", resHour, resMin);\n \n }\n }\n}\n", "src_uid": "595c4a628c261104c8eedad767e85775"} {"source_code": "using System;\n\nnamespace ConsoleApplication4\n{\n class Program\n {\n static void Main(string[] args) {\n int length = 0;\n int max = 0;\n int min = 0;\n string code = string.Empty;\n\n length = int.Parse(Console.ReadLine());\n\n code = Console.ReadLine();\n\n for (int i = 0; i < length; i++) {\n if (code[i] == 'L')\n min--;\n else\n max++;\n }\n Console.WriteLine((max-min+1));\n //Console.ReadKey();\n }\n\n }\n}\n", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing CompLib.Util;\nusing System.Threading;\n\npublic class Program\n{\n private long N;\n\n public void Solve()\n {\n var sc = new Scanner();\n N = sc.NextLong();\n\n /*\n * N個タイル\n *\n * タイル i,j\n * |j-i| がnの1より大きいなら同じ色\n */\n\n List p = new List();\n long tmp = N;\n for (long l = 2; l * l <= tmp; l++)\n {\n if (tmp % l == 0)\n {\n p.Add(l);\n while (tmp % l == 0)\n {\n tmp /= l;\n }\n }\n }\n\n if (tmp != 1) p.Add(tmp);\n\n if (p.Count == 1)\n {\n Console.WriteLine(p[0]);\n return;\n }\n\n Console.WriteLine(1);\n }\n\n public static void Main(string[] args) => new Program().Solve();\n // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"source_code": "using System;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces\n{\n\tinternal class Template\n\t{\n\t\tprivate void Solve()\n\t\t{\n\t\t var n = cin.NextInt();\n\t\t if (n%2 == 1 || n < 6)\n\t\t {\n\t\t Console.WriteLine(0);\n\t\t return;\n\t\t }\n\t\t n /= 2;\n\t\t n = (n- 1) / 2;\n Console.WriteLine(n);\n\t\t}\n\n\t\tprivate static readonly Scanner cin = new Scanner();\n\n\t\tprivate static void Main()\n\t\t{\n#if DEBUG\n\t\t\tvar inputText = File.ReadAllText(@\"..\\..\\input.txt\");\n\t\t\tvar testCases = inputText.Split(new[] { \"input\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\tvar consoleOut = Console.Out;\n\t\t\tfor (var i = 0; i < testCases.Length; i++)\n\t\t\t{\n\t\t\t\tvar parts = testCases[i].Split(new[] { \"output\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\t\tConsole.SetIn(new StringReader(parts[0].Trim()));\n\t\t\t\tvar stringWriter = new StringWriter();\n\t\t\t\tConsole.SetOut(stringWriter);\n\t\t\t\tvar sw = Stopwatch.StartNew();\n\t\t\t\tnew Template().Solve();\n\t\t\t\tsw.Stop();\n\t\t\t\tvar output = stringWriter.ToString();\n\n\t\t\t\tConsole.SetOut(consoleOut);\n\t\t\t\tvar color = ConsoleColor.Green;\n\t\t\t\tvar status = \"Passed\";\n\t\t\t\tif (parts[1].Trim() != output.Trim())\n\t\t\t\t{\n\t\t\t\t\tcolor = ConsoleColor.Red;\n\t\t\t\t\tstatus = \"Failed\";\n\t\t\t\t}\n\t\t\t\tConsole.ForegroundColor = color;\n\t\t\t\tConsole.WriteLine(\"Test {0} {1} in {2}ms\", i + 1, status, sw.ElapsedMilliseconds);\n\t\t\t}\n\t\t\tConsole.ReadLine();\n\t\t\tConsole.ReadKey();\n#else\n\t\t\tnew Template().Solve();\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\t}\n\n\tinternal class Scanner\n\t{\n\t\tprivate string[] s = new string[0];\n\t\tprivate int i;\n\t\tprivate readonly char[] cs = { ' ' };\n\n\t\tpublic string NextString()\n\t\t{\n\t\t\tif (i < s.Length) return s[i++];\n\t\t\tvar line = Console.ReadLine() ?? string.Empty;\n\t\t\ts = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n\t\t\ti = 1;\n\t\t\treturn s.First();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn double.Parse(NextString());\n\t\t}\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn int.Parse(NextString());\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn long.Parse(NextString());\n\t\t}\n\t}\n}", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\nusing Pi = Pair;\n\nclass Solver\n{\n public void Solve(Scanner sc)\n {\n int N, M;\n sc.Make(out N, out M);\n var A = sc.ArrInt;\n Array.Sort(A,(a,b)=>b-a);\n int l = 0, r = N+1;\n while (r - l > 1)\n {\n var m = (r + l) / 2;\n long res = 0;\n int ct = 0;\n for(int i = 0; i < N; i++)\n {\n var d = Max(0, A[i] - ct / m);\n if (d == 0) continue;\n res += d;ct++;\n }\n if (res >= M) r = m;\n else l = m;\n }\n if (r == N + 1) Fail(-1);\n WriteLine(r);\n }\n}\n\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver().Solve(new Scanner());\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(this IList A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static IEnumerable Shuffle(this IEnumerable A) => A.OrderBy(v => Guid.NewGuid());\n public static int CompareTo(this T[] A, T[] B, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }\n public static int MaxElement(this IList A, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }\n public static T PopBack(this List A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n //public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n //public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n //public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }\n}\n#endregion\n", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces.R355.D\n{\n public static class Solver\n {\n public static void Main()\n {\n using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })\n {\n Solve(Console.In, sw);\n }\n }\n\n public static void Solve(TextReader tr, TextWriter tw)\n {\n WriteAnswer(tw, Parse(tr));\n }\n\n struct Answer\n {\n public string Winner;\n }\n\n private static void WriteAnswer(TextWriter tw, Answer answer)\n {\n tw.WriteLine(answer.Winner);\n }\n\n private static Answer Parse(TextReader tr)\n {\n var n = int.Parse(tr.ReadLine());\n var board = new string[n];\n for (var i = 0; i < n; ++i)\n board[i] = tr.ReadLine();\n return Calc(board);\n }\n\n private static Answer Calc(string[] board)\n {\n var answer = new Answer();\n var memo = new Dictionary<(int, int), int>();\n var r = Rec(\"\" + board[0][0], 1, 0, board, memo);\n\n if (r > 0)\n answer.Winner = \"FIRST\";\n else if (r < 0)\n answer.Winner = \"SECOND\";\n else\n answer.Winner = \"DRAW\";\n\n return answer;\n }\n\n private static int Rec(string str, int mask, int currentC, string[] board, Dictionary<(int, int), int> memo)\n {\n var n = board.Length;\n var numStr = str.Length;\n\n var key = (numStr, mask);\n if (memo.ContainsKey(key))\n return memo[key];\n\n\n if (numStr == n * 2 - 1)\n {\n if (str.Last() == 'a')\n return 1;\n else if (str.Last() == 'b')\n return -1;\n return 0;\n }\n\n var res = numStr % 2 == 0 ? int.MinValue : int.MaxValue;\n\n for (var ch = 'a'; ch <= 'z'; ++ch)\n {\n var nm = 0;\n\n for (var y = 0; y < n; ++y)\n {\n if ((mask & (1 << y)) == 0)\n continue;\n var x = numStr - y - 1;\n if (x < 0 || x >= n)\n continue;\n if (x < n - 1 && board[y][x + 1] == ch)\n nm |= 1 << y;\n if (y < n - 1 && board[y + 1][x] == ch)\n nm |= 1 << y + 1;\n }\n if (nm == 0)\n continue;\n\n if (numStr % 2 == 0)\n res = Math.Max(res, Rec(str + ch, nm, 0, board, memo));\n else\n res = Math.Min(res, Rec(str + ch, nm, 0, board, memo));\n }\n\n if (str.Last() == 'a')\n res += 1;\n else if (str.Last() == 'b')\n res += -1;\n\n return memo[key] = res;\n }\n }\n}\n", "src_uid": "d803fe167a96656f8debdc21edd988e4"} {"source_code": "using System;\n\nnamespace Task_D\n{\n class Solution\n {\n static void Main(string[] args)\n {\n new Solution().Solve();\n }\n\n private int n;\n private int d;\n private long x;\n private int[] a;\n private int[] b;\n private int[] c;\n\n private void Solve()\n {\n var parts = Console.ReadLine().Split();\n n = int.Parse(parts[0]);\n d = int.Parse(parts[1]);\n x = long.Parse(parts[2]);\n\n a = new int[n];\n b = new int[n];\n c = new int[n];\n\n initAB();\n\n var bCount = 0;\n var bPos = new int[n];\n for (int i = 0; i < n; i++)\n {\n if (b[i] == 1)\n {\n bPos[bCount++] = i;\n }\n }\n\n var aOrder = new int[n];\n for (int i = 0; i < n; i++)\n {\n aOrder[a[i] - 1] = i;\n }\n\n int s = 50;\n\n for (int i = 0; i < n; i++)\n {\n for (int q = 0; q < s && q < n; q++)\n {\n int j = aOrder[n - q - 1];\n if (i - j >= 0 && b[i - j] == 1)\n {\n c[i] = a[j];\n break;\n }\n }\n\n if (c[i] != 0)\n {\n continue;\n }\n\n for (int z = 0; z < bCount; z++)\n {\n var bIndex = bPos[z];\n var j = i - bIndex;\n if (j >= 0)\n {\n c[i] = Math.Max(c[i], a[j]);\n }\n }\n }\n\n for (int i = 0; i < n; i++)\n {\n Console.WriteLine(c[i]);\n }\n }\n\n private long getNextX()\n {\n x = (x * 37 + 10007) % 1000000007;\n return x;\n }\n\n private void initAB()\n {\n for (int i = 0; i < n; i = i + 1)\n {\n a[i] = i + 1;\n }\n\n for (int i = 0; i < n; i = i + 1)\n {\n swap(ref a[i], ref a[getNextX() % (i + 1)]);\n }\n\n for (int i = 0; i < n; i = i + 1)\n {\n if (i < d)\n b[i] = 1;\n else\n b[i] = 0;\n }\n\n for (int i = 0; i < n; i = i + 1)\n {\n swap(ref b[i], ref b[getNextX() % (i + 1)]);\n }\n }\n\n private void swap(ref T first, ref T second)\n {\n T tmp = first;\n first = second;\n second = tmp;\n }\n }\n}\n", "src_uid": "948ae7a0189ada07c8c67a1757f691f0"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace Preparation\n{\n public class CodeForces710E\n {\n public static void Main(string[] args)\n {\n var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n long n = input[0];\n long x = input[1];\n long y = input[2];\n long[] arr = new long[n];\n arr[0] = x;\n for (int i = 0; i < n - 1; ++i)\n {\n arr[i + 1] = arr[i + 1] == 0 ? arr[i] + x : Math.Min(arr[i + 1], arr[i] + x);\n long ind = (i + 1)*2 - 1;\n var t = y;\n if (ind >= n)\n {\n t += arr[ind - n];\n ind = n - 1;\n }\n arr[ind] = arr[ind] == 0 ? arr[i] + t : Math.Min(arr[ind], arr[i] + t);\n arr[ind-1] = arr[ind-1] == 0 ? arr[i] + t + x : Math.Min(arr[ind-1], arr[i] + t + x);\n }\n\n Console.WriteLine(arr[n-1]);\n }\n}\n }\n", "src_uid": "0f270af00be2a523515d5e7bd66800f6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CSharp\n{\n class A441\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int a = int.Parse(Console.ReadLine()), b = int.Parse(Console.ReadLine()), c = int.Parse(Console.ReadLine());\n int mab = Math.Min(a, b);\n int mabc = Math.Min(mab, c);\n int ans = 0;\n if (n == 2)\n {\n ans = mab;\n }\n else if (n > 2)\n {\n ans = mab + (n - 2) * mabc;\n }\n Console.WriteLine(ans);\n }\n }\n}\n", "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.Round59\n{\n class C\n {\n int n;\n int[][] dat;\n int count;\n int res;\n\n bool ok(int id, params int[] xs)\n {\n int a = 0, b = 0;\n int[] pos = new int[10];\n for (int i = 0; i < 10; i++)\n pos[i] = -1;\n for (int i = 0; i < 4; i++)\n pos[xs[i]] = i;\n for (int m = dat[id][0], i = 3; i >= 0; i--, m /= 10)\n {\n if (pos[m % 10] == i) a++;\n else if (pos[m % 10] >= 0) b++;\n }\n //for (int i = 0; i < 4; i++)\n // Console.Write(\"{0} \", xs[i]);\n //Console.WriteLine(\": {0} {1} : {2} {3}\", a, b, dat[id][1], dat[id][2]);\n return a == dat[id][1] && b == dat[id][2];\n }\n\n C()\n {\n n = int.Parse(Console.ReadLine());\n dat = new int[n][];\n for (int i = 0; i < n; i++)\n dat[i] = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));\n\n for (int a = 0; a < 10; a++)\n for (int b = 0; b < 10; b++)\n if (a != b)\n for (int c = 0; c < 10; c++)\n if (a != c && b != c)\n for (int d = 0; d < 10; d++)\n if (a != d && b != d && c != d)\n {\n bool chk = true;\n for (int i = 0; i < n; i++)\n chk &= ok(i, a, b, c, d);\n if (chk)\n {\n count++;\n res = a * 1000 + b * 100 + c * 10 + d;\n }\n }\n\n Console.WriteLine(count == 0 ? \"Incorrect data\" : (count != 1 ? \"Need more data\" : res.ToString(\"0000\")));\n }\n\n public static void Main()\n {\n new C();\n }\n }\n}\n", "src_uid": "142e5f2f08724e53c234fc2379216b4c"} {"source_code": "using System;\nusing System.Collections;\n\nnamespace _1032A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string strFirstInput;\n string strSecondInput;\n string[] strFirstSplit;\n string[] strSecondSplit;\n\n long nUtensilsRemaining;\n long nGuests;\n long nMissingUtensils = 0;\n long[] nUtensils;\n long nDishes;\n long nPotentialUtensils;\n long nTemp;\n long nSet = 1;\n long nMax = 0;\n\n Hashtable hUtensils;\n\n strFirstInput = Console.ReadLine();\n strSecondInput = Console.ReadLine();\n\n strFirstSplit = strFirstInput.Split(new char[0]);\n strSecondSplit = strSecondInput.Split(new char[0]);\n\n nGuests = long.Parse(strFirstSplit[1].ToString());\n nUtensilsRemaining = long.Parse(strFirstSplit[0].ToString());\n\n hUtensils = new Hashtable();\n nUtensils = new long[nUtensilsRemaining]; // Is this even required?\n\n for(int i = 0; i < nUtensilsRemaining; i++)\n {\n nUtensils[i] = long.Parse(strSecondSplit[i].ToString());\n\n try\n {\n hUtensils.Add(strSecondSplit[i].ToString(), 1);\n } catch (Exception ex)\n {\n hUtensils[strSecondSplit[i].ToString()] = Convert.ToInt64(hUtensils[strSecondSplit[i].ToString()]) + 1;\n }\n }\n\n nDishes = hUtensils.Count;\n\n foreach (DictionaryEntry dct in hUtensils)\n {\n nTemp = Convert.ToInt64(dct.Value);\n\n if (nTemp > nMax) nMax = nTemp;\n }\n\n if (nMax / nGuests == 1 && nMax % nGuests > 0) nSet++;\n if (nMax / nGuests > 1)\n {\n nSet += nMax / nGuests;\n if (nMax % nGuests > 0) nSet++;\n }\n\n nPotentialUtensils = nDishes * nGuests * (nSet > 2 ? nSet - 1: nSet);\n nMissingUtensils = nPotentialUtensils - nUtensilsRemaining;\n Console.WriteLine(nMissingUtensils);\n }\n }\n}\n", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"} {"source_code": "using System;\n\nnamespace CSharp\n{\n class _976B\n {\n public static void Main()\n {\n var tokens = Console.ReadLine().Split();\n\n long n = long.Parse(tokens[0]);\n long m = long.Parse(tokens[1]);\n long k = long.Parse(tokens[2]);\n\n if (k < n)\n {\n Console.WriteLine($\"{1 + k} 1\");\n }\n else\n {\n k -= n;\n m--;\n\n long row = n - k / m;\n long column = (n - row) % 2 == 0 ? 2 + k % m : m + 1 - k % m;\n\n Console.WriteLine($\"{row} {column}\");\n }\n }\n }\n}", "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace G.GangUp\n{\n internal static class Program\n {\n public static void Main(string[] args)\n {\n var nmkcd = Console.ReadLine().Split();\n var n = int.Parse(nmkcd[0]);\n var m = int.Parse(nmkcd[1]);\n var k = int.Parse(nmkcd[2]);\n var c = int.Parse(nmkcd[3]);\n var d = int.Parse(nmkcd[4]);\n \n var solver = new Solver(n, m, k, c, d);\n solver.Init();\n \n ReadInput(solver, n, m);\n \n for (var i = 0; i < k; i++)\n solver.IncreaseFlow();\n\n Console.WriteLine(solver.TotalCost);\n }\n\n private static void ReadInput(Solver solver, int n, int m)\n {\n var memberCounts = new int[n];\n foreach (var memberHome in Console.ReadLine().Split())\n memberCounts[int.Parse(memberHome) - 1]++;\n\n for (var crossroad = 0; crossroad < n; crossroad++)\n solver.AddMemberHome(crossroad, memberCounts[crossroad]);\n \n for (var i = 0; i < m; i++)\n {\n var xy = Console.ReadLine().Split();\n var x = int.Parse(xy[0]) - 1;\n var y = int.Parse(xy[1]) - 1;\n \n solver.AddEdge(x, y);\n solver.AddEdge(y, x);\n }\n }\n }\n\n internal sealed class Solver\n {\n private static readonly Edge FakeEdge = new Edge();\n \n private readonly int _n, _m, _k, _c, _d;\n private readonly int _maxTime;\n private readonly Node _start, _sink;\n private readonly Node[,] _nodes;\n private readonly List[] _nodeEdges;\n private readonly BestPathSearcher _bestPathSearcher;\n\n public Solver(int n, int m, int k, int c, int d)\n {\n _n = n;\n _m = m;\n _k = k;\n _c = c;\n _d = d;\n\n _maxTime = k + m;\n _nodes = new Node[n, _maxTime];\n\n _start = new Node() {Id = _nodes.Length};\n _sink = new Node() {Id = _nodes.Length + 1};\n\n var allNodesCount = _nodes.Length + 2;\n \n _nodeEdges = new List[allNodesCount];\n for (var i = 0; i < allNodesCount; i++)\n _nodeEdges[i] = new List(_maxTime);\n \n _bestPathSearcher = new BestPathSearcher(_nodeEdges);\n }\n \n public int TotalCost { get; private set; }\n\n public void Init()\n {\n var nodeId = 0;\n for (var node = 0; node < _n; node++)\n for (var time = 0; time < _maxTime; time++)\n _nodes[node, time] = new Node() { Id = nodeId++ };\n\n for (var time = 0; time < _maxTime; time++)\n AddEdgeWithoutPair(_nodes[0, time], _sink, time * _c, _k);\n\n for (var node = 0; node < _n; node++)\n {\n var from = _nodes[node, 0];\n for (var time = 1; time < _maxTime; time++)\n {\n var to = _nodes[node, time];\n AddEdgePair(from, to, 0, _k);\n from = to;\n }\n }\n }\n\n public void AddMemberHome(int home, int count)\n {\n if (count > 0)\n AddEdgeWithoutPair(_start, _nodes[home, 0], 0, count);\n }\n\n public void AddEdge(int from, int to)\n {\n for (var time = 0; time < _maxTime - 1; time++)\n {\n var nodeFrom = _nodes[from, time];\n var nodeTo = _nodes[to, time + 1];\n \n for (int people = 0, cost = 1; people < _k; people++, cost += 2)\n AddEdgePair(nodeFrom, nodeTo, cost * _d, 1);\n }\n }\n\n public void IncreaseFlow()\n {\n var bestPath = _bestPathSearcher.FindBestPath(_start, _sink);\n foreach (var edge in bestPath)\n {\n edge.ResidualCapacity--;\n edge.PairedEdge.ResidualCapacity++;\n TotalCost += edge.Cost;\n }\n }\n\n private void AddEdgePair(Node from, Node to, int cost, int capacity)\n {\n var forwardEdge = new Edge()\n {\n From = from,\n To = to,\n Cost = cost,\n ResidualCapacity = capacity,\n };\n\n var reverseEdge = new Edge()\n {\n From = to,\n To = from,\n Cost = -cost,\n ResidualCapacity = 0,\n };\n\n forwardEdge.PairedEdge = reverseEdge;\n reverseEdge.PairedEdge = forwardEdge;\n \n _nodeEdges[from.Id].Add(forwardEdge);\n _nodeEdges[to.Id].Add(reverseEdge);\n }\n\n private void AddEdgeWithoutPair(Node from, Node to, int cost, int capacity)\n {\n _nodeEdges[from.Id].Add(new Edge()\n {\n From = from,\n To = to,\n Cost = cost,\n ResidualCapacity = capacity, \n PairedEdge = FakeEdge,\n });\n }\n }\n\n internal sealed class BestPathSearcher\n {\n private readonly List[] _nodeEdges;\n\n private readonly int[] _bestCosts;\n private readonly Edge[] _bestMoves;\n private readonly bool[] _isInQueue;\n private readonly Queue _bestPathSearchQueue;\n\n public BestPathSearcher(List[] nodeEdges)\n {\n _nodeEdges = nodeEdges;\n _bestCosts = new int[nodeEdges.Length];\n _bestMoves = new Edge[nodeEdges.Length];\n _isInQueue = new bool[nodeEdges.Length];\n _bestPathSearchQueue = new Queue(nodeEdges.Length);\n }\n\n public IEnumerable FindBestPath(Node start, Node to)\n {\n for (var i = 0; i < _bestCosts.Length; i++)\n _bestCosts[i] = int.MaxValue;\n\n _bestCosts[start.Id] = 0;\n _bestPathSearchQueue.Enqueue(start);\n \n while (_bestPathSearchQueue.Count > 0)\n {\n var node = _bestPathSearchQueue.Dequeue();\n var costToNode = _bestCosts[node.Id];\n \n foreach (var edge in _nodeEdges[node.Id])\n {\n if (edge.ResidualCapacity == 0)\n continue;\n \n var possibleCost = costToNode + edge.Cost;\n if (possibleCost >= _bestCosts[edge.To.Id])\n continue;\n \n _bestCosts[edge.To.Id] = possibleCost;\n _bestMoves[edge.To.Id] = edge;\n if (_isInQueue[edge.To.Id])\n continue;\n \n _isInQueue[edge.To.Id] = true;\n _bestPathSearchQueue.Enqueue(edge.To);\n }\n \n _isInQueue[node.Id] = false;\n }\n\n var cur = _bestMoves[to.Id];\n while (cur != null)\n {\n yield return cur;\n cur = _bestMoves[cur.From.Id];\n }\n }\n }\n\n internal struct Node\n {\n public int Id { get; set; }\n public override string ToString() => Id.ToString();\n }\n\n internal sealed class Edge\n {\n public Node From { get; set; }\n public Node To { get; set; }\n public int Cost { get; set; }\n public int ResidualCapacity { get; set; }\n public Edge PairedEdge { get; set; }\n }\n}", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Collections.Specialized;\nusing System.Numerics;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Linq;\nusing System.IO;\npublic class CodeForces\n{\n#if TEST\n // To set this go to Project -> Properties -> Build -> General -> Conditional compilation symbols: -> enter 'TEST' into text box.\n const bool testing = true;\n#else\nconst bool testing = false;\n#endif\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);\n\n struct Point\n {\n public int x { get; set; }\n public int y { get; set; }\n } \n static void program(TextReader input)\n {\n //var n = int.Parse(input.ReadLine().TrimEnd());\n var data = input.ReadLine().Split(' ').Select(int.Parse).ToList();\n var x1 = data[0];\n var y1 = data[1];\n var data2 = input.ReadLine().Split(' ').Select(int.Parse).ToList();\n var x2 = data2[0];\n var y2 = data2[1];\n\n var points = new List();\n var stepX = new int[] { -1, 0, 1, 1, 1, 0, -1, -1 };\n var stepY = new int[] { 1, 1, 1, 0, -1, -1, -1, 0 };\n var min = int.MaxValue;\n for(var i = 0; i < stepX.Length; i++)\n {\n var distance = Math.Abs(x1 - (x2 + stepX[i])) + Math.Abs(y1 - (y2 + stepY[i]));\n min = Math.Min(min, distance);\n }\n\n writer.WriteLine(2*min + 8);\n writer.Flush();\n }\n\n public static void Main(string[] args)\n {\n if (!testing)\n { // set testing to false when submiting to codeforces\n program(Console.In); // write your program in 'program' function (its your new main !)\n return;\n }\n\n Console.WriteLine(\"Test Case(1) => expected :\");\n Console.WriteLine(\"18\\n\");\n Console.WriteLine(\"Test Case(1) => found :\");\n program(new StringReader(\"1 5\\n5 2\\n\"));\n Console.WriteLine();\n Console.ReadLine();\n\n Console.WriteLine(\"Test Case(2) => expected :\");\n Console.WriteLine(\"8\\n\");\n Console.WriteLine(\"Test Case(2) => found :\");\n program(new StringReader(\"0 1\\n0 0\\n\"));\n Console.WriteLine();\n Console.ReadLine();\n\n }\n}\n", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Solver.Ex;\nusing Debug = System.Diagnostics.Debug;\nusing Watch = System.Diagnostics.Stopwatch;\nusing StringBuilder = System.Text.StringBuilder;\nnamespace Solver\n{\n public class Solver\n {\n public void Solve()\n {\n var cnt = sc.Long(2);\n var sum = cnt.Sum();\n var a = sc.Integer();\n var b = sc.Integer();\n var l = sum;\n var r = (long)1e10;\n while (l <= r)\n {\n var m = (l + r) >> 1;\n var k = m / a;\n var u = m / b;\n var v = m / (a * b);\n var rem = m - k - u + v;\n rem += Math.Min(cnt[1], k - v);\n rem+=Math.Min(cnt[0],u-v);\n if (rem>= sum)\n r = m - 1;\n else l = m + 1;\n }\n IO.Printer.Out.WriteLine(l);\n }\n internal IO.StreamScanner sc;\n }\n #region Main and Settings\n static class Program\n {\n static void Main(string[] arg)\n {\n#if DEBUG\n var errStream = new System.IO.FileStream(@\"..\\..\\dbg.out\", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);\n Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, \"debugStream\"));\n Debug.AutoFlush = false;\n var sw = new Watch(); sw.Start();\n try\n {\n#endif\n IO.Printer.Out.AutoFlush = true;\n var solver = new Solver();\n solver.sc = new IO.StreamScanner(Console.OpenStandardInput());\n solver.Solve();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.Error.WriteLine(ex.Message);\n Console.Error.WriteLine(ex.StackTrace);\n }\n finally\n {\n sw.Stop();\n Console.ForegroundColor = ConsoleColor.Green;\n Console.Error.WriteLine(\"Time:{0}ms\", sw.ElapsedMilliseconds);\n Debug.Close();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n }\n#endif\n }\n\n\n }\n #endregion\n}\n#region IO Helper\nnamespace Solver.IO\n{\n public class Printer : System.IO.StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, IEnumerable source) { Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, IEnumerable source) { WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(System.IO.Stream stream) { iStream = stream; }\n private readonly System.IO.Stream iStream;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n private bool eof = false;\n public bool IsEndOfStream { get { return eof; } }\n const byte lb = 33, ub = 126, el = 10, cr = 13;\n public byte read()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }\n public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }\n public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }\n public string Scan()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n StringBuilder sb = null;\n var enc = System.Text.UTF8Encoding.Default;\n do\n {\n for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;\n if (ptr < len) break;\n ptr = 0;\n if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return \"\"; }\n } while (true);\n do\n {\n var f = ptr;\n for (; ptr < len; ptr++)\n //if (buf[ptr] < lb || ub < buf[ptr])\n if (buf[ptr] == cr || buf[ptr] == el)\n {\n string s;\n if (sb == null) s = enc.GetString(buf, f, ptr - f);\n else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }\n ptr++; return s;\n }\n if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));\n else sb.Append(enc.GetChars(buf, f, len - f));\n ptr = 0;\n\n }\n while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true; return (sb != null) ? sb.ToString() : \"\";\n }\n public long Long()\n {\n long ret = 0; byte b = 0; bool isMynus = false;\n const byte zr = 48, nn = 57, my = 45;\n do b = read();\n while (b != my && (b < zr || nn < b));\n if (b == my) { isMynus = true; b = read(); }\n for (; true; b = read())\n if (b < zr || nn < b)\n return isMynus ? -ret : ret;\n else ret = ret * 10 + b - zr;\n }\n public int Integer()\n {\n int ret = 0; byte b = 0; bool isMynus = false;\n const byte zr = 48, nn = 57, my = 45;\n do b = read();\n while (b != my && (b < zr || nn < b));\n if (b == my) { isMynus = true; b = read(); }\n for (; true; b = read())\n if (b < zr || nn < b)\n return isMynus ? -ret : ret;\n else ret = ret * 10 + b - zr;\n }\n public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }\n public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }\n public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }\n public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }\n public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }\n public void Flush() { iStream.Flush(); }\n }\n}\n#endregion\n#region Extension\nnamespace Solver.Ex\n{\n static public partial class EnumerableEx\n {\n static public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public T[] Enumerate(this int n, Func f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }\n }\n}\n#endregion\n#region gcd,lcm\nstatic public partial class MathEx\n{\n\n static public long GCD(long x, long y)\n {\n byte i = 0;\n while (x != 0 && y != 0)\n {\n if (i == 0)\n y %= x;\n else x %= y;\n i ^= 1;\n }\n return x == 0 ? y : x;\n }\n\n\n}\n#endregion", "src_uid": "ff3c39b759a049580a6e96c66c904fdc"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _5Dproblem\n{\n class vector\n {\n private int[] points= new int[5];\n private double length ;\n\n public vector(Point R,Point D)\n {\n for (int i = 0; i < 5; i++)\n {\n points[i] = R.coordinates[i]-D.coordinates[i];\n }\n length = Math.Sqrt(vector.CrossProduct(this, this));\n }\n\n public double GetLength()\n {\n return length;\n }\n static public double CrossProduct(vector A,vector B)\n {\n double product = 0;\n product = A.points[0] * B.points[0]\n + A.points[1] * B.points[1]\n + A.points[2] * B.points[2]\n + A.points[3] * B.points[3]\n + A.points[4] * B.points[4];\n return product;\n }\n public static double GetAngle(vector A,vector B)\n {\n double angle = vector.CrossProduct(A, B) / (A.length * B.length);\n return Math.Acos(angle)*180/Math.PI;\n }\n }\n class Point\n {\n public int[] coordinates = new int[5];\n List V = new List();//vectors from this point\n List angles = new List();\n public Point (int[] p)\n {\n for (int i = 0; i < 5; i++)\n {\n coordinates[i] = p[i];\n }\n }\n private vector GetVector(Point p)\n {\n {\n vector v = new vector(this,p);\n return v;\n }\n }\n public void set_vectList(List Point)\n {\n for (int i = 0; i < Point.Count; i++)\n {\n if (this != Point[i])\n V.Add(GetVector(Point[i]));\n }\n }\n public void set_angleList()\n {\n for (int i = 0; i < V.Count; i++)\n {\n for (int j = i+1; j < V.Count; j++)\n {\n angles.Add(vector.GetAngle(V[i], V[j]));\n }\n }\n }\n public bool Isgood()\n {\n foreach (var a in angles)\n {\n if (a < 90)\n return false;\n }\n return true;\n }\n }\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n if (n > 11)\n {\n for (int i = 0; i < n; i++)\n {\n Console.ReadLine();\n }\n\n Console.WriteLine(0);\n }\n else\n {\n List lp = new List();\n int[] count = new int[n];\n int c = 0;\n for (int i = 0; i < n; i++)\n {\n Point p = new Point(Array.ConvertAll(Console.ReadLine().Split(), int.Parse));\n lp.Add(p);\n }\n\n foreach (var point in lp)\n {\n point.set_vectList(lp);\n point.set_angleList();\n if (point.Isgood())\n count[c]++;\n c++;\n }\n Console.WriteLine(count.Sum());\n for (int i = 0; i < count.Length; i++)\n {\n if (count[i] != 0)\n Console.WriteLine(i + 1);\n }\n }\n \n }\n }\n}\n", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\n\npublic partial class _382C {\n\n static public void Solve(TextReader cin, TextWriter cout) {\n var scanner = new Scanner(cin);\n\n int a = scanner.NextInt32();\n int b = scanner.NextInt32();\n int ans = 0, burn = 0;\n while (a > 0) {\n a--;\n burn++;\n ans++;\n if (burn >= b) {\n burn -= b;\n a++;\n }\n }\n cout.WriteLine(ans);\n }\n\n // PREWRITEN CODE BEGINS FROM HERE\n\n public static void Main(string[] args) {\n#if ONLINE_JUDGE\n Solve(Console.In, Console.Out);\n#else\n SampleTest();\n#endif\n\n }\n\n static void SampleTest() {\n\n var Inputs = @\"\n4 2\n------------\n6 3\n\".Split(new[] { \"------------\" }, StringSplitOptions.None).Select(s => s.Trim()).ToArray();\n\n var Outputs = @\"\n7\n------------\n8\n\".Split(new[] { \"------------\" }, StringSplitOptions.None).Select(s => s.Trim()).ToArray();\n\n int caseNo = 1;\n int all = 0, passed = 0;\n foreach (var sample in Inputs.Zip(Outputs, (Input, Output) => new { Input, Output })) {\n var stopWatch = new System.Diagnostics.Stopwatch();\n var writer = new StringWriter();\n stopWatch.Start();\n Solve(new StringReader(sample.Input), writer);\n stopWatch.Stop();\n string time = \"\";\n if (stopWatch.ElapsedMilliseconds >= 10) {\n time = String.Format(\"({0} ms)\", stopWatch.ElapsedMilliseconds);\n }\n var result = writer.ToString().Trim();\n all++;\n if (result == sample.Output) {\n Console.WriteLine(\"Sample {0} .... Passed {1}\", caseNo++, time);\n passed++;\n } else {\n Console.WriteLine(\"Sample {0} .... Failed\", caseNo++, time);\n Console.WriteLine(\"Input : \");\n Console.WriteLine(\"{0}\", sample.Input);\n Console.WriteLine(\"Expected : \");\n Console.WriteLine(\"{0}\", sample.Output);\n Console.WriteLine(\"Received : \");\n Console.WriteLine(\"{0}\", result);\n }\n }\n\n Console.WriteLine(\" {0} / {1} Passed !!\", passed, all);\n\n Solve(Console.In, Console.Out);\n }\n\n}\n\npublic class Scanner {\n private TextReader Reader;\n private Queue TokenQueue = new Queue();\n private CultureInfo ci = new CultureInfo(\"en-US\");\n\n public Scanner()\n : this(Console.In) {\n }\n\n public Scanner(TextReader reader) {\n this.Reader = reader;\n }\n\n public char NextChar() { return Next().Single(); }\n public int NextInt32() { return Int32.Parse(Next(), ci); }\n public long NextInt64() { return Int64.Parse(Next(), ci); }\n public double NextDouble() { return double.Parse(Next(), ci); }\n public string[] NextArray(int size) {\n var array = new string[size];\n for (int i = 0; i < size; i++) array[i] = Next();\n return array;\n }\n public int[] NextIntArray(int size) {\n var array = new int[size];\n for (int i = 0; i < size; i++) array[i] = NextInt32();\n return array;\n }\n\n public long[] NextInt64Array(int size) {\n var array = new long[size];\n for (int i = 0; i < size; i++) array[i] = NextInt64();\n return array;\n }\n\n public String Next() {\n if (!TokenQueue.Any()) {\n if (!StockTokens()) throw new InvalidOperationException();\n }\n return TokenQueue.Dequeue();\n }\n\n public bool HasNext() {\n if (TokenQueue.Count > 0)\n return true;\n return StockTokens();\n }\n\n private bool StockTokens() {\n while (true) {\n var line = Reader.ReadLine();\n if (line == null) return false;\n var tokens = line.Trim().Split(\" \".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();\n if (tokens.Length == 0) continue;\n foreach (var token in tokens)\n TokenQueue.Enqueue(token);\n return true;\n }\n }\n}\n", "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\nnamespace Program\n{\n public class Solver\n {\n public void Solve()\n {\n var key = \"QqRrBbNnPp\";\n int[] val = { 9, -9, 5, -5, 3, -3, 3, -3, 1, -1 };\n var map = Enumerate(8, x => sc.Char(8));\n var pt=0;\n for (int i = 0; i < 8; i++)\n {\n for (int j = 0; j < 8; j++)\n {\n for (int k = 0; k < key.Length; k++)\n {\n if (map[i][j] == key[k])\n pt += val[k];\n }\n }\n }\n if (pt > 0)\n IO.Printer.Out.WriteLine(\"White\");\n else if (pt == 0) IO.Printer.Out.WriteLine(\"Draw\");\n else IO.Printer.Out.WriteLine(\"Black\");\n \n\n\n }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n\n }\n\n}\n\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Text;\n using System.Globalization;\n public class Printer : StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, IEnumerable source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, IEnumerable source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n private readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }\n\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != '-' && (b < '0' || '9' < b));\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public char[] Char(int n) { return enumerate(n, Char); }\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n }\n}\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion\n", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing SB = System.Text.StringBuilder;\n//using System.Threading.Tasks;\n//using System.Text.RegularExpressions;\n//using System.Globalization;\n//using System.Diagnostics;\nusing static System.Console;\nusing System.Numerics;\nusing static System.Math;\nusing pair = Pair;\n\nclass Program\n{\n static void Main()\n {\n //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });\n new Program().solve();\n Out.Flush();\n }\n readonly Scanner cin = new Scanner();\n readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑\n readonly int mod = 1000000007;\n readonly int dom = 998244353;\n bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n bool chmin(ref T a, T b) where T : IComparable { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }\n\n void solve()\n {\n int N = cin.nextint;\n var dp = new ModInt[2 * N + 1, N + 1];\n dp[0, 0] = 1;\n for (int i = 1; i <= 2 * N; i++)\n {\n for (int j = i % 2; j <= Min(N, 2 * N - i); j += 2)\n {\n if (j > 0) dp[i, j] = dp[i - 1, j - 1];\n if (j < N) dp[i, j] += dp[i - 1, j + 1];\n }\n }\n\n var S = new ModInt[2 * N + 1];\n for (int i = 0; i < S.Length; i++)\n {\n for (int j = 0; j <= N; j++)\n {\n S[i] += dp[i, j];\n }\n }\n S.Reverse();\n // S.join();\n \n\n ModInt ans = 0;\n for (int i = 1; i < S.Length; i += 2)\n {\n ans += S[i];\n }\n WriteLine(ans);\n\n //for (int i = 0; i < N; i++)\n //{\n // for (int j = 0; j < (i + 1) * 2; j++)\n // {\n // dp[j] += 1;\n // }\n // if (i > 0) dp[i * 2] += 1;\n //}\n //dp.join();\n //ModInt ans = 1;\n //foreach (var item in dp)\n //{\n // ans *= item;\n //}\n //WriteLine(ans);\n }\n\n}\n\n/// camypaper\nclass FenwickTree\n{\n readonly int n;\n readonly long[] bit;\n readonly int max = 1;\n public FenwickTree(int size)\n {\n n = size; bit = new long[n + 1];\n while ((max << 1) <= n) max <<= 1;\n }\n /// sum[a, b] 0-indexed\n public long this[int i, int j] { get { i++; j++; return i <= j ? this[j] - this[i - 1] : 0; } }\n /// sum[1, i] 1-indexed\n public long this[int i] { get { long s = 0; for (; i > 0; i -= i & -i) s += bit[i]; return s; } }\n public int LowerBound(long w)\n {\n if (w <= 0) return 0;\n int x = 0;\n for (int k = max; k > 0; k >>= 1)\n if (x + k <= n && bit[x + k] < w)\n {\n w -= bit[x + k];\n x += k;\n }\n return x + 1;\n }\n /// add v to bit[i] 0-indexed\n public void Add(int i, long v)\n {\n i++;\n //if (i == 0) System.Diagnostics.Debug.Fail(\"BIT is 1 indexed\");\n for (; i <= n; i += i & -i) bit[i] += v;\n }\n public long[] Items\n {\n get\n {\n var ret = new long[n + 1];\n for (int i = 0; i < ret.Length; i++)\n ret[i] = this[i, i];\n return ret;\n }\n }\n}\n\nclass RangeAddFenwickTree\n{\n readonly int n;\n FenwickTree a, b;\n public RangeAddFenwickTree(int n)\n {\n this.n = n;\n a = new FenwickTree(n);\n b = new FenwickTree(n);\n }\n /// Add V to[i, j] 0-indexed\n public void Add(int i, int j, long v)\n {\n //a.Add(i, -(i - 1) * v); a.Add(j + 1, j * v);\n //b.Add(i, v); b.Add(j + 1, -v);\n a.Add(i, -i * v); a.Add(j + 1, (j + 1) * v);\n b.Add(i, v); b.Add(j + 1, -v);\n }\n /// Sum [1, i] 1-indexed\n public long this[int i] => a[i] + b[i] * i;\n /// Sum [i, j] 0-indexed\n public long this[int i, int j] { get { i++; j++; return i <= j ? this[j] - this[i - 1] : 0; } }\n public long[] Items\n {\n get\n {\n var ret = new long[n + 1];\n for (int i = 0; i < ret.Length; i++)\n ret[i] = this[i, i];\n return ret;\n }\n }\n}\n\n/// \n/// [0,) までの値を取るような数\n/// \n/// camypaper\nstruct ModInt\n{\n /// \n /// 剰余を取る値.\n /// \n public const long Mod = (int)1e9 + 7;\n\n /// \n /// 実際の数値.\n /// \n public long num;\n /// \n /// 値が であるようなインスタンスを構築します.\n /// \n /// インスタンスが持つ値\n /// パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため, ∈ [0,) を満たすような を渡してください.このコンストラクタは O(1) で実行されます.\n public ModInt(long n) { num = n; }\n /// \n /// このインスタンスの数値を文字列に変換します.\n /// \n /// [0,) の範囲内の整数を 10 進表記したもの.\n public override string ToString() { return num.ToString(); }\n public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }\n public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }\n public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }\n public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(long v, long k)\n {\n long ret = 1;\n for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n if ((k & 1) == 1) ret = ret * v % Mod;\n return new ModInt(ret);\n }\n /// \n /// 与えられた数の逆元を計算します.\n /// \n /// 逆元を取る対象となる数\n /// 逆元となるような値\n /// 法が素数であることを仮定して,フェルマーの小定理に従って逆元を O(log N) で計算します.\n public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }\n}\n\nclass BinomialCoefficient\n{\n public ModInt[] fact, ifact;\n public BinomialCoefficient(int n)\n {\n fact = new ModInt[n + 1];\n ifact = new ModInt[n + 1];\n fact[0] = 1;\n for (int i = 1; i <= n; i++)\n fact[i] = fact[i - 1] * i;\n ifact[n] = ModInt.Inverse(fact[n]);\n for (int i = n - 1; i >= 0; i--)\n ifact[i] = ifact[i + 1] * (i + 1);\n ifact[0] = ifact[1];\n }\n public ModInt this[int n, int r]\n {\n get\n {\n if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;\n return fact[n] * ifact[n - r] * ifact[r];\n }\n }\n public ModInt RepeatedCombination(int n, int k)\n {\n if (k == 0) return 1;\n return this[n + k - 1, k];\n }\n}\n\nstatic class Ex\n{\n public static void join(this IEnumerable values, string sep = \" \") => WriteLine(string.Join(sep, values));\n public static string concat(this IEnumerable values) => string.Concat(values);\n public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }\n\n public static int lower_bound(this IList arr, T val) where T : IComparable\n {\n int low = 0, high = arr.Count;\n int mid;\n while (low < high)\n {\n mid = ((high - low) >> 1) + low;\n if (arr[mid].CompareTo(val) < 0) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n public static int upper_bound(this IList arr, T val) where T : IComparable\n {\n int low = 0, high = arr.Count;\n int mid;\n while (low < high)\n {\n mid = ((high - low) >> 1) + low;\n if (arr[mid].CompareTo(val) <= 0) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n}\n\nclass Pair : IComparable> where T : IComparable where U : IComparable\n{\n public T f; public U s;\n public Pair(T f, U s) { this.f = f; this.s = s; }\n public int CompareTo(Pair a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);\n public override string ToString() => $\"{f} {s}\";\n}\n\nclass Scanner\n{\n string[] s; int i;\n readonly char[] cs = new char[] { ' ' };\n public Scanner() { s = new string[0]; i = 0; }\n public string[] scan => ReadLine().Split();\n public int[] scanint => Array.ConvertAll(scan, int.Parse);\n public long[] scanlong => Array.ConvertAll(scan, long.Parse);\n public double[] scandouble => Array.ConvertAll(scan, double.Parse);\n public string next\n {\n get\n {\n if (i < s.Length) return s[i++];\n string st = ReadLine();\n while (st == \"\") st = ReadLine();\n s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n i = 0;\n return next;\n }\n }\n public int nextint => int.Parse(next);\n public long nextlong => long.Parse(next);\n public double nextdouble => double.Parse(next);\n}\n", "src_uid": "8218255989e5eab73ac7107072c3b2af"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace MUH_and_Sticks\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);\n Array.Sort(a);\n int count = 0;\n if (a[0] == a[1] && a[1] == a[2] && a[2] == a[3])\n {\n if (a[4] == a[5])\n Console.WriteLine(\"Elephant\");\n else\n Console.WriteLine(\"Bear\");\n }\n else if (a[2] == a[3] && a[3] == a[4] && a[4] == a[5])\n {\n if ((a[0] == a[1]))\n Console.WriteLine(\"Elephant\");\n else\n Console.WriteLine(\"Bear\");\n }\n else\n {\n \n if(a[0] == a[1] && a[1] == a[2] && a[2] == a[3]|| a[1] == a[2] && a[2] == a[3] && a[3] == a[4]|| a[2] == a[3] && a[3] == a[4] && a[4] == a[5])\n Console.WriteLine(\"Bear\");\n else\n Console.WriteLine(\"Alien\");\n }\n Console.ReadLine();\n }\n }\n}\n", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n\nnamespace ReadWriteTemplate\n{\n public static class Solver\n {\n private static void SolveCase()\n {\n int n = ReadInt();\n long w = ReadLong();\n var segments = new Segment[n];\n var starts = new List();\n var ends = new List();\n for (int i = 0; i < n; i++)\n {\n long x = ReadLong();\n long v = -ReadLong();\n bool swap = false;\n if (x < 0)\n {\n x = -x;\n v = -v;\n swap = true;\n }\n var start = new PP(x, v + w);\n var end = new PP(x, v - w);\n if (swap)\n {\n PP tmp = start;\n start = end;\n end = tmp;\n }\n segments[i] = new Segment(start, end);\n\n starts.Add(start);\n ends.Add(end);\n }\n\n starts = starts.Shuffle().ToList();\n starts.Sort(Comparison);\n\n for (int i = 0; i < starts.Count; i++)\n {\n starts[i].Segment.End.X = i;\n }\n\n ends = ends.Shuffle().ToList();\n ends.Sort(Comparison);\n\n var p = new int[n];\n for (int i = 0; i < n; i++)\n {\n p[i] = ends[i].X;\n }\n\n long ans = Permutation.InversionsCount(p);\n Writer.WriteLine(ans);\n }\n\n private static int Comparison(PP a, PP b)\n {\n long d = -(a.A * b.B - a.B * b.A);\n if (d != 0)\n {\n return d > 0 ? 1 : -1;\n }\n if (a.X != b.X)\n {\n return b.X - a.X;\n }\n if (a != a.Segment.End)\n {\n return Comparison(b.Segment.End, a.Segment.End);\n }\n return 0;\n }\n\n public static class Permutation\n {\n public static long InversionsCount(int[] permutation)\n {\n int[] a = permutation.ToArray();\n int[] b = permutation.ToArray();\n return InversionsCountInternal(a, 0, permutation.Length, b);\n }\n\n private static long InversionsCountInternal(int[] a, int lo, int hi, int[] b)\n {\n if (hi - lo < 2)\n return 0;\n\n int mid = (lo + hi) / 2;\n\n return InversionsCountInternal(b, lo, mid, a) + InversionsCountInternal(b, mid, hi, a) + Merge(a, lo, mid, hi, b);\n }\n\n private static long Merge(int[] a, int lo, int mid, int hi, int[] b)\n {\n int i = lo;\n int j = mid;\n long result = 0;\n for (int k = lo; k < hi; k++)\n {\n if (i < mid && (j >= hi || a[i] <= a[j]))\n {\n b[k] = a[i];\n i++;\n }\n else\n {\n b[k] = a[j];\n j++;\n result += (mid - i);\n }\n }\n return result;\n }\n }\n\n public class PP\n {\n public PP(long a, long b)\n {\n A = a;\n B = b;\n X = 0;\n }\n\n public long A;\n\n public long B;\n\n public int X;\n\n public Segment Segment;\n }\n\n public class Segment\n {\n public Segment(PP start, PP end)\n {\n Start = start;\n End = end;\n OnStart = 0;\n start.Segment = this;\n end.Segment = this;\n }\n\n public PP Start;\n\n public PP End;\n\n public long OnStart;\n }\n\n public static void Solve()\n {\n // int T = ReadInt();\n // for (int i = 0; i < T; i++)\n // {\n // Writer.Write(\"Case #{0}: \", i + 1);\n SolveCase();\n // }\n }\n\n public class Point\n {\n public Point(int x, int y)\n {\n X = x;\n Y = y;\n }\n\n public int X;\n\n public int Y;\n\n public double Length { get { return Math.Sqrt(X * X + Y * Y); } }\n\n protected bool Equals(Point other)\n {\n return X == other.X && Y == other.Y;\n }\n\n public override bool Equals(object obj)\n {\n if (ReferenceEquals(null, obj))\n {\n return false;\n }\n if (ReferenceEquals(this, obj))\n {\n return true;\n }\n /*if (obj.GetType() != this.GetType())\n {\n return false;\n }*/\n return Equals((Point) obj);\n }\n\n public override int GetHashCode()\n {\n unchecked\n {\n return (X * 397) ^ Y;\n }\n }\n\n public int Dist2(Point p)\n {\n return (p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y);\n }\n\n public static Point operator +(Point a, Point b)\n {\n return new Point(a.X + b.X, a.Y + b.Y);\n }\n\n public static Point operator -(Point a, Point b)\n {\n return new Point(a.X - b.X, a.Y - b.Y);\n }\n }\n\n public static class Standard\n {\n public static long Power(long x, long p, long mod)\n {\n long result = 1;\n while (p > 0)\n {\n if ((p & 1) == 0)\n {\n x = (x * x) % mod;\n p >>= 1;\n }\n else\n {\n result = (result * x) % mod;\n p--;\n }\n }\n return result;\n }\n\n public static long Gcd(long a, long b)\n {\n return b == 0 ? a : Gcd(b, a % b);\n }\n\n public static List GetPrimes(int n)\n {\n bool[] isPrime = Enumerable.Repeat(true, n + 1).ToArray();\n isPrime[0] = false;\n isPrime[1] = false;\n for (int i = 2; i <= n; i++)\n {\n if (isPrime[i])\n {\n for (int j = i + i; j <= n; j += i)\n {\n isPrime[j] = false;\n }\n }\n }\n List primes = new List();\n for (int i = 0; i <= n; i++)\n {\n if (isPrime[i])\n {\n primes.Add(i);\n }\n }\n return primes;\n }\n }\n\n public static void Main()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if DEBUG\n //Reader = Console.In; Writer = Console.Out;\n Reader = File.OpenText(\"input.txt\"); Writer = File.CreateText(\"output.txt\");\n#else\n Reader = Console.In; Writer = Console.Out;\n#endif\n\n Solve();\n\n Reader.Close();\n Writer.Close();\n }\n\n public static IOrderedEnumerable OrderByWithShuffle(this IEnumerable source, Func keySelector)\n {\n return source.Shuffle().OrderBy(keySelector);\n }\n\n public static T[] Shuffle(this IEnumerable source)\n {\n T[] result = source.ToArray();\n Random rnd = new Random();\n for (int i = result.Length - 1; i >= 1; i--)\n {\n int k = rnd.Next(i + 1);\n T tmp = result[k];\n result[k] = result[i];\n result[i] = tmp;\n }\n return result;\n }\n\n #region Read/Write\n\n private static TextReader Reader;\n\n private static TextWriter Writer;\n\n private static Queue CurrentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return Reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (CurrentLineTokens.Count == 0)\n CurrentLineTokens = new Queue(ReadAndSplitLine());\n return CurrentLineTokens.Dequeue();\n }\n\n public static string ReadLine()\n {\n return Reader.ReadLine();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = Reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n Writer.WriteLine(string.Join(\" \", array));//\n }\n\n #endregion\n }\n}\n", "src_uid": "d073d41f7e184e9bc4a12219d86e7184"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\nusing Pi = Pair;\n\nclass Solver\n{\n public void Solve(Scanner sc)\n {\n string S = sc.Str, T = sc.Str;\n var dp = Create(S.Length + 1, () => Create(T.Length+1, () => Create(201, () => int.MaxValue / 4)));\n dp[0][0][0] = 0;\n\n for (int i = 0; i <= S.Length; i++)\n {\n for (int j = 0; j <= T.Length; j++)\n {\n for (int k = 0; k < 200; k++)\n {\n chmin(ref dp[i][j][k + 1], dp[i][j][k] + 1);\n }\n for (int k = 199; k >= 0; k--)\n {\n chmin(ref dp[i][j][k], dp[i][j][k + 1] + 1);\n }\n for (int k = 0; k < 201; k++)\n {\n if (i();\n int s = S.Length, t = T.Length, l = 0;\n while (dp[s][t][l] != 0)\n {\n for(int j = -1; j < 2; j += 2)\n {\n int n = l + j;\n if (0 <= n && n < 201 && dp[s][t][n] + 1 == dp[s][t][l])\n {\n l = n;\n if (j == -1) res.Add('(');\n else res.Add(')');\n goto END;\n }\n }\n if (s>0&&t>0&&S[s - 1] == T[t - 1])\n {\n int n = l;\n if (S[s - 1] == '(') n--;\n else n++;\n if (0 <= n && n < 201 && dp[s - 1][t - 1][n] + 1 == dp[s][t][l])\n {\n res.Add(S[s - 1]);\n s--;t--;l = n;goto END;\n }\n }\n if (s > 0)\n {\n int n = l;\n if (S[s - 1] == '(') n--;\n else n++;\n if (0 <= n && n < 201 && dp[s - 1][t][n] + 1 == dp[s][t][l])\n {\n res.Add(S[s - 1]);\n s--; l = n; goto END;\n }\n }\n if (t > 0)\n {\n int n = l;\n if (T[t - 1] == '(') n--;\n else n++;\n if (0 <= n && n < 201 && dp[s][t-1][n] + 1 == dp[s][t][l])\n {\n res.Add(T[t - 1]);\n t--; l = n; goto END;\n }\n }\n END:;\n }\n res.Reverse();\n Console.WriteLine(new string(res.ToArray()));\n }\n}\n\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver().Solve(new Scanner());\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(this IList A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static IEnumerable Shuffle(this IEnumerable A) => A.OrderBy(v => Guid.NewGuid());\n public static int CompareTo(this T[] A, T[] B, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }\n public static int MaxElement(this IList A, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }\n public static T PopBack(this List A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n //public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n //public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n //public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }\n}\n#endregion\n", "src_uid": "cc222aab45b3ad3d0e71227592c883f1"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n const bool TEST_MODE = false;\n\n static void Main()\n {\n if (TEST_MODE)\n {\n string[] readText = File.ReadAllLines(\"..\\\\..\\\\TextFile1.txt\");\n\n var testCases = new Dictionary, string>();\n var lastKeyword = \"\";\n var current = new List();\n foreach (string s in readText)\n {\n if(s == \"Input\")\n {\n current = new List();\n lastKeyword = s;\n continue;\n }\n if (s == \"Copy\")\n continue;\n if (s == \"Output\")\n {\n lastKeyword = s;\n continue;\n }\n\n if (lastKeyword == \"Input\")\n current.Add(s);\n if (lastKeyword == \"Output\")\n testCases.Add(current,s);\n \n }\n\n foreach(var testCase in testCases)\n {\n var result = ProblemWrapper.Solve(testCase.Key.ToArray(), testCase.Value);\n if (result == testCase.Value)\n Console.ForegroundColor = ConsoleColor.Green;\n else\n Console.ForegroundColor = ConsoleColor.Red;\n\n\n Console.Write(\"input: \");\n foreach (var input in testCase.Key)\n Console.Write(input + \" // \");\n Console.Write(\"\\noutput: \");\n Console.WriteLine(testCase.Value);\n\n Console.Write(\"Actual: \");\n Console.WriteLine(result);\n\n Console.ResetColor();\n }\n }\n else\n ProblemWrapper.Solve();\n\n Console.ReadLine();\n }\n}\n\nclass ProblemWrapper\n{\n public static void Solve()\n {\n string[] input = new string[2];\n input[0] = Console.ReadLine();\n input[1] = Console.ReadLine();\n\n var a = ReadString(input[0]);\n var b = ReadString(input[1]);\n\n Console.WriteLine (Algo(a, b));\n }\n \n public static string Solve(string[] input, string output)\n {\n var a = ReadString(input[0]);\n var b = ReadString(input[1]);\n\n return (Algo(a, b));\n }\n\n public static string Algo(string a, string b)\n {\n int answer = 0;\n\n //**\n {\n var row1 = a.ToCharArray();\n var row2 = b.ToCharArray();\n\n var n = row1.Length;\n if (n < 2)\n return \"0\";\n\n for (var i = 0; i < n; i++)\n {\n if (row1[i] == '0')\n {\n if (i != 0 && row2[i - 1] == '0' && row2[i] == '0')\n {\n row1[i] = 'X'; row2[i] = 'X'; row2[i - 1] = 'X';\n answer++;\n }\n else if (i != 0 && row2[i] == '0' && row1[i - 1] == '0')\n {\n row1[i] = 'X'; row2[i] = 'X'; row1[i - 1] = 'X';\n answer++;\n }\n else if (i != n - 1 && row2[i] == '0' && row2[i + 1] == '0')\n {\n row1[i] = 'X'; row2[i] = 'X'; row2[i + 1] = 'X';\n answer++;\n }\n else if (i != n - 1 && row2[i] == '0' && row1[i + 1] == '0')\n {\n row1[i] = 'X'; row2[i] = 'X'; row1[i + 1] = 'X';\n answer++;\n }\n } \n\n }\n }\n //**\n\n return Convert.ToString(answer);\n }\n\n static String ReadString(string input) { return input; }\n static String[] ReadStringArr(string input) { return input.Split(' '); }\n static int ReadInt(string input) { return int.Parse(input); }\n static long ReadLong(string input) { return long.Parse(input); }\n static double ReadDouble(string input) { return double.Parse(input); }\n static int[] ReadIntArr(string input) { return Array.ConvertAll(input.Split(' '), e => int.Parse(e)); }\n static long[] ReadLongArr(string input) { return Array.ConvertAll(input.Split(' '), e => long.Parse(e)); }\n static double[] ReadDoubleArr(string input) { return Array.ConvertAll(input.Split(' '), e => double.Parse(e)); }\n}", "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Data;\nusing System.Numerics;\n\nnamespace ConsoleApplication1\n{\n class Program : ProgramBase\n {\n private const long commonMod = 1000000007;\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Get();\n p.Out(x);\n }\n class Cut\n {\n public int a;\n public int b;\n public int line;\n }\n object Get()\n {\n checked\n {\n var a = ReadInts();\n var d = new[] { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };\n var result = 0;\n for (int i = a[0]; i <= a[1]; i++)\n {\n var s = i.ToString();\n foreach (var c in s)\n result += d[Int32.Parse(c.ToString())];\n }\n return result;\n }\n }\n \n object Get2()\n {\n FileName = \"\";\n checked\n {\n var m = ReadInt();\n var p = ReadLongs();\n var arr = p.GroupBy(x => x).Select(g => new { g.Key, Count = g.Count() }).ToArray();\n BigInteger divs = 1;\n long result = 1;\n foreach (var a in arr)\n {\n var pi = a.Key;\n var curr = pi;\n var olddivs = divs;\n var oldres = result;\n for (int i = 0; i < a.Count; i++)\n\t\t\t {\n result = (result * oldres % commonMod) * FastPow(curr, olddivs, commonMod) % commonMod;\t\t\t \n curr = curr*pi % commonMod;\n divs = divs + olddivs;\n\t\t\t }\n }\n return result;\n }\n }\n\n public long FastPow(long x, BigInteger pow, long mod)\n {\n if (pow == 0)\n return 1;\n if ((pow & 1) == 0)\n return FastPow(x * x % mod, pow / 2, mod);\n return x * FastPow(x, pow - 1, mod) % mod;\n }\n\n //object Get3()\n //{\n // FileName = \"\";\n // checked\n // {\n // var n = ReadInt();\n // var hor = new List();\n // var ver = new List();\n // for (int i = 0; i < n; i++)\n // {\n // var a = ReadInts();\n // if (a[0] == a[2])\n // ver.Add(new Cut() { a = Math.Min(a[1], a[3]), b = Math.Max(a[1], a[3]), line = a[0] });\n // else\n // hor.Add(new Cut() { a = Math.Min(a[0], a[2]), b = Math.Max(a[0], a[2]), line = a[1] });\n // }\n // ver = Merge(ver);\n // hor = Merge(hor);\n\n // }\n //}\n\n List Merge(List l)\n {\n var a = l.OrderBy(x => x.line).ThenBy(x => x.a).ToArray();\n Cut previous = null;\n var result = new List();\n for (int i = 0; i < a.Length; i++)\n if (previous == null)\n previous = a[i];\n else\n if (previous.line == a[i].line && previous.b >= a[i].a)\n previous.b = Math.Max(previous.b, a[i].b);\n else\n {\n result.Add(previous);\n previous = a[i];\n }\n if (previous != null)\n result.Add(previous);\n return result;\n }\n\n object Get3()\n {\n FileName = \"\";\n checked\n {\n var n = ReadInt();\n var beacons = new List>();\n for (int i = 0; i < n; i++)\n {\n var inp = ReadInts();\n beacons.Add(Tuple.Create(inp[0], inp[1]));\n }\n beacons = beacons.OrderBy(x => x.Item1).ToList();\n var dp = new int[n];\n for (int i = 0; i < n; i++)\n {\n var j = LowerBound(beacons, beacons[i].Item1 - beacons[i].Item2);\n dp[i] = j == -1\n ? 1\n : dp[j] + 1;\n }\n return n - dp.Max();\n }\n }\n\n private int LowerBound(List> beacons, int v, int left, int right)\n {\n if (left == right)\n if (beacons[left].Item1 < v)\n return left;\n else\n return -1;\n if (right - left == 1)\n if (beacons[right].Item1 < v)\n return right;\n else if (beacons[left].Item1 < v)\n return left;\n else\n return -1;\n var half = (left + right) / 2;\n if (v <= beacons[half].Item1)\n return LowerBound(beacons, v, left, half);\n else\n return LowerBound(beacons, v, half, right);\n }\n\n private int LowerBound(List> beacons, int v)\n {\n return LowerBound(beacons, v, 0, beacons.Count - 1);\n }\n\n public long GCD(long a, long b) {\n if (b == 0)\n return a;\n return GCD(b, a % b);\n }\n\n IEnumerable> GetS(List ss)\n {\n if (ss.Count == 0)\n yield return (new List());\n else\n foreach (var s in ss)\n {\n var next = new List(ss);\n next.Remove(s);\n foreach (var item in GetS(next))\n {\n item.Add(s);\n yield return item;\n }\n }\n }\n }\n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n protected string FileName { private get; set; }\n\n protected string Read()\n {\n if (string.IsNullOrEmpty(FileName))\n return Console.ReadLine();\n if (f == null)\n f = new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName + \".in\");\n return f.ReadLine();\n }\n\n protected int ReadInt()\n {\n return Convert.ToInt32(Read());\n }\n protected int[] ReadInts()\n {\n return Read().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();\n }\n\n protected long ReadLong()\n {\n return Convert.ToInt64(Read());\n }\n\n protected long[] ReadLongs()\n {\n return Read().Split(' ').Select(x => Convert.ToInt64(x)).ToArray();\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName + \".out\", r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-NB-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func)\n {\n T result = default(T);\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable source, string delimeter)\n {\n return string.Join(delimeter, source.ToArray());\n }\n }\n}\n", "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n private const int MAX = 200000;\n\n bool Intersect(int l1, int r1, int l2, int r2)\n {\n return !(r2 < l1 || l2 > r1);\n }\n\n public void Solve()\n {\n int n = ReadInt();\n\n var left = new int[MAX];\n var right = new int[MAX];\n int c = 1;\n for (int i = 1; i < MAX; i++)\n {\n left[i] = right[i] = c;\n if ((i & i - 1) == 0)\n {\n right[i]++;\n c++;\n }\n c++;\n }\n\n var idx = new Dictionary();\n var q = Init>>(n);\n for (int m = ReadInt(); m > 0; m--)\n {\n if (ReadInt() == 1)\n {\n int t = ReadInt() - 1;\n int l = ReadInt();\n int r = ReadInt();\n int x = ReadInt();\n if (!idx.ContainsKey(x))\n idx[x] = idx.Count;\n q[t].Add(Tuple.Create(l, r, idx[x]));\n }\n else\n {\n int t = ReadInt() - 1;\n int v = ReadInt();\n int l = v, r = v;\n var f = new bool[idx.Count];\n for (; t < n; t++, l = left[l], r = right[r])\n foreach (var qq in q[t])\n if (Intersect(qq.Item1, qq.Item2, l, r))\n f[qq.Item3] = true;\n int ans = 0;\n for (int i = 0; i < idx.Count; i++)\n if (f[i])\n ans++;\n Write(ans);\n }\n }\n }\n \n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"hull.in\");\n //writer = new StreamWriter(\"hull.out\");\n#endif\n try\n {\n// var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n// thread.Start();\n// thread.Join();\n new Solver().Solve(); \n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() {return reader.ReadLine().Split(new[] { ' ', '\\t', '-' }, StringSplitOptions.RemoveEmptyEntries);}\n public static string ReadToken(){while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine());return currentLineTokens.Dequeue();}\n public static int ReadInt(){return int.Parse(ReadToken());}\n public static long ReadLong(){return long.Parse(ReadToken());}\n public static double ReadDouble(){return double.Parse(ReadToken(), CultureInfo.InvariantCulture);}\n public static int[] ReadIntArray(){return ReadAndSplitLine().Select(int.Parse).ToArray();}\n public static long[] ReadLongArray(){return ReadAndSplitLine().Select(long.Parse).ToArray();}\n public static double[] ReadDoubleArray(){return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();}\n public static int[][] ReadIntMatrix(int numberOfRows){int[][] matrix = new int[numberOfRows][];for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray();return matrix;}\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows){int[][] matrix = ReadIntMatrix(numberOfRows);int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++){ret[i] = new int[numberOfRows];for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i];}return ret;}\n public static string[] ReadLines(int quantity){string[] lines = new string[quantity];for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim();return lines;}\n public static void WriteArray(IEnumerable array){writer.WriteLine(string.Join(\" \", array));}\n public static void Write(params object[] array){WriteArray(array);}\n public static void WriteLines(IEnumerable array){foreach (var a in array)writer.WriteLine(a);}\n private class SDictionary : Dictionary{public new TValue this[TKey key]{\n get { return ContainsKey(key) ? base[key] : default(TValue); }set { base[key] = value; }}}\n private static T[] Init(int size) where T : new(){var ret = new T[size];for (int i = 0; i < size; i++)ret[i] = new T();return ret;}\n #endregion\n}", "src_uid": "9f239cfd29c1a2652a065bfe5c15476a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace vkcup\n{\n\tclass Program\n\t{\n\t\tpublic static int n, m, h, w;\n\n\t\tpublic static int x1, x2, y1, y2;\n\n\t\tpublic static int[] arr;\n\t\tprivate static String s1;\n\t\tprivate static String s2;\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tParseAll(true);\n\t\t\tSolve();\n\t\t}\n\n\n\t\tstatic void Solve()\n\t\t{\n\t\t\tif ((x2 <= x1 && y2 <= y1) ||\n\t\t\t\t(y2 < y1 && x2 - x1 < y1) ||\n\t\t\t\t(x2 < x1 && y2 - y1 < x1))\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"Vasiliy\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"Polycarp\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\n\t\tstatic void ParseAll(bool console)\n\t\t{\n\t\t\tif (console)\n\t\t\t{\n\t\t\t\tParseFirstLine(Console.ReadLine());\n\t\t\t\t//ParseArray(2);\n\t\t\t}\n\t\t}\n\n\t\tstatic void ParseFirstLine(String line)\n\t\t{\n\t\t\tint[] arr = line.Split(' ').Select(int.Parse).ToArray();\n\t\t\tx1 = arr[0];\n\t\t\ty1 = arr[1];\n\t\t\tx2 = arr[2];\n\t\t\ty2 = arr[3];\n\t\t}\n\n\t\tstatic void ParseSecondLine(String line)\n\t\t{\n\t\t\tint[] array = line.Split(' ').Select(int.Parse).ToArray();\n\n\t\t}\n\n\t\tstatic void ParseThirdLine(String line)\n\t\t{\n\t\t\tint[] array = line.Split(' ').Select(int.Parse).ToArray();\n\n\t\t}\n\n\t\tstatic void ParseArray(int count)\n\t\t{\n\t\t\ts1 = Console.ReadLine();\n\t\t\ts2 = Console.ReadLine();\n\n\t\t}\n\n\n\n\n\t}\n}\n", "src_uid": "2637d57f7809ff8f922549c617709074"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace first\n{\n class Program\n {\n static void Main(string[] args)\n {\n int a, b, c,aMod,bMod,cMod;\n string str = Console.ReadLine();\n a=int.Parse(str);\n str=str.Replace(\"0\", \"\");\n aMod = int.Parse(str);\n str = Console.ReadLine();\n b = int.Parse(str);\n str=str.Replace(\"0\", \"\");\n bMod = int.Parse(str);\n c = a + b;\n cMod = int.Parse(c.ToString().Replace(\"0\", \"\"));\n if ((aMod + bMod) == cMod)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n }\n}", "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Problem_1C\n{\n struct Point\n {\n public double X, Y;\n\n public Point(double X, double Y)\n {\n this.X = X;\n this.Y = Y;\n }\n }\n\n struct Line\n {\n public bool IsVertical { get { return double.IsPositiveInfinity(slope); } }\n public double slope, yIntercept, xIntercept;\n\n public Line(Point a, Point b)\n {\n if (a.X == b.X)\n {\n this.slope = double.PositiveInfinity;\n this.yIntercept = double.NaN;\n this.xIntercept = a.X;\n }\n else\n {\n var rise = b.Y - a.Y;\n var run = b.X - a.X;\n\n this.slope = rise / run;\n this.yIntercept = b.Y - this.slope * b.X;\n this.xIntercept = Math.Abs(rise) < 0.00001 ? double.NaN : -(b.Y - this.slope * b.X) / (rise / run);\n }\n }\n\n public Line(double slope, double yIntercept, Point p)\n {\n this.slope = slope;\n this.yIntercept = yIntercept;\n this.xIntercept = double.IsPositiveInfinity(slope) ? p.X : -yIntercept / slope;\n }\n\n public Line PerpendicularLineAt(Point p)\n {\n if (IsVertical)\n return new Line(0, -p.Y, p);\n else if (Math.Abs(this.slope) < 0.00001)\n return new Line(double.PositiveInfinity, double.NaN, p);\n else\n return new Line(-1 / this.slope, p.Y + 1 / this.slope * p.X, p);\n }\n\n public Point IntersectionWith(Line l)\n {\n if (l.IsVertical)\n return new Point(l.xIntercept, this.slope * l.xIntercept + this.yIntercept);\n else if (this.IsVertical)\n return new Point(this.xIntercept, l.slope * this.xIntercept + l.yIntercept);\n else\n {\n double x = (l.yIntercept - this.yIntercept) / (this.slope - l.slope);\n return new Point(x, this.slope * x + this.yIntercept);\n }\n }\n }\n\n class Program\n {\n static Point GetPoint()\n {\n var line = Console.ReadLine().Split(' ');\n return new Point(double.Parse(line[0], System.Globalization.CultureInfo.InvariantCulture), double.Parse(line[1], System.Globalization.CultureInfo.InvariantCulture));\n }\n\n static Point Midpoint(Point a, Point b)\n {\n return new Point((b.X + a.X) / 2, (b.Y + a.Y) / 2);\n }\n\n static double Distance(Point a, Point b)\n {\n return Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2));\n }\n\n static void Main(string[] args)\n {\n var p1 = GetPoint();\n var p2 = GetPoint();\n var p3 = GetPoint();\n\n var l1 = new Line(p1, p2);\n var l2 = new Line(p2, p3);\n var l3 = new Line(p3, p1);\n\n var la = l1.IsVertical ? l2 : l1;\n var lb = l3.IsVertical ? l2 : l3;\n var ma = l1.IsVertical ? Midpoint(p2, p3) : Midpoint(p1, p2);\n var mb = l3.IsVertical ? Midpoint(p2, p3) : Midpoint(p3, p1);\n var pba = la.PerpendicularLineAt(ma);\n var pbb = lb.PerpendicularLineAt(mb);\n var o = pba.IntersectionWith(pbb);\n var r = Distance(o, p1);\n\n for (int i = 3; i <= 100; i++)\n {\n double theta = Math.Abs(p1.X - o.X) < 0.00001 ? Math.PI / 2 : Math.Atan((p1.Y - o.Y) / (p1.X - o.X));\n if (p1.X - o.X < 0) theta += Math.PI;\n double addTheta = 2 * Math.PI / i;\n bool p2Matched = false, p3Matched = false;\n for (int j = 1; j < i; j++)\n {\n theta += addTheta;\n double y = r * Math.Sin(theta) + o.Y;\n double x = r * Math.Cos(theta) + o.X;\n if (Math.Abs(p2.X - x) < 0.00001 && Math.Abs(p2.Y - y) < 0.00001) p2Matched = true;\n if (Math.Abs(p3.X - x) < 0.00001 && Math.Abs(p3.Y - y) < 0.00001) p3Matched = true;\n }\n\n if (p2Matched && p3Matched)\n {\n var area = i * r * r / 2 * Math.Sin(2 * Math.PI / i);\n Console.WriteLine(area.ToString(\"0.000000\", System.Globalization.CultureInfo.InvariantCulture));\n break;\n }\n }\n\n }\n }\n}\n", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace Test\n{\n class Program\n {\n static void Main()\n {\n byte[] input = Console.ReadLine().Split(' ').Select(num => Convert.ToByte(num)).ToArray();\n Console.WriteLine((int)(input[0] * input[1] / 2));\n }\n }\n}", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\n\nnamespace codeforces\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n // Console.SetIn(new StreamReader(\"text.txt\"));\n int[] count = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int x = count[0], y = count[1], z = count[2];\n string rez = \"\";\n if (x == y && z == 0)\n rez = \"0\";\n else if (x > y && y + z < x)\n rez = \"+\";\n else if (x < y && x+ z < y)\n rez = \"-\";\n else\n rez = \"?\";\n\n\n Console.WriteLine(rez);\n }\n }\n}\n\n", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\nnamespace Codeforces\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args) \n\t\t{\n\t\t\tstring input1 = Console.ReadLine();\n\t\t\t//string input2 = Console.ReadLine();\n\n\t\t\t//string input3 = Console.ReadLine();\n\t\t\t//string input4 = Console.ReadLine();\n\n\t\t\tvar inputs1 = input1.Split(new[] {' ', '}', '{', ','}, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\t\t\t//var inputs2 = input2.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();\n\t\t\t//var inputs3 = input3.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\t\t\t//var inputs4 = input4.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();\n\n\t\t\tlong n = inputs1[0];\n\t\t\tlong k = inputs1[1];\n\n\t\t\tif (k < 3) \n\t\t\t{\n\t\t\t\tConsole.WriteLine(0);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlong count = 0;\n\t\t\tlong min = 0, max = 0;\n\n\t\t\tif (k <= n) \n\t\t\t{\n\t\t\t\tmin = 1;\n\t\t\t\tmax = k - min;\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\tmin = k - n;\n\t\t\t\tif (min > n) \n\t\t\t\t{\n\t\t\t\t\tConsole.WriteLine(0);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tmax = n;\n\t\t\t}\n\n\t\t\tConsole.WriteLine((Math.Max(min, max) - Math.Min(min, max) + 1) / 2);\n\t\t}\n\n\t\tpublic class Team\n\t\t{\n\t\t\tpublic string Name { get; set; }\n\n\t\t\tpublic int Points { get; set; }\n\n\t\t\tpublic int GoalsFor { get; set; }\n\n\t\t\tpublic int GoalsAgainst { get; set; }\n\t\t}\n\n\t\tstatic long Factorial(long a) \n\t\t{\n\t\t\treturn a > 1 ? a * Factorial(a - 1) : 1;\n\t\t}\n\t}\n}\n", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeforcesCs\n{\n class Date18\n {\n public static void Main(string[] args)\n {\n string fDate = Console.ReadLine();\n string vDate = Console.ReadLine();\n\n int[] finalN = Array.ConvertAll(fDate.Split('.'), int.Parse);\n int[] vasyaN = Array.ConvertAll(vDate.Split('.'), int.Parse);\n \n DateTime finalReal = new DateTime(finalN[2] + 2000, finalN[1], finalN[0]);\n\n string[] perms = {\"012\", \"021\", \"102\", \"120\", \"201\", \"210\"};\n \n \n for (int i = 0; i < perms.Length; ++i )\n {\n int[] perm = new int[3];\n for (int j = 0; j < 3; ++j)\n perm[j] = perms[i][j] - '0';\n\n int day = vasyaN[perm[0]], month = vasyaN[perm[1]], year = 2000 + vasyaN[perm[2]];\n DateTime date = DateTime.Now;\n bool wrong = false;\n try\n {\n date = new DateTime(year, month, day);\n }\n catch\n {\n wrong = true;\n }\n\n if (!wrong)\n {\n DateTime lesserDate = GetNeedDay(finalReal);\n if (lesserDate.Year >= 2000 && IsPositive(lesserDate.Subtract(date)))\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n }\n\n Console.WriteLine(\"NO\");\n }\n\n private static bool IsPositive(TimeSpan timeSpan)\n {\n return timeSpan.Days >= 0 && timeSpan.Minutes >= 0;\n }\n\n private static DateTime GetNeedDay(DateTime finalReal)\n {\n if (finalReal.Month == 2 && finalReal.Day == 29)\n return new DateTime(finalReal.Year - 18, 2, 28);\n return new DateTime(finalReal.Year - 18, finalReal.Month, finalReal.Day);\n }\n }\n}\n", "src_uid": "5418c98fe362909f7b28f95225837d33"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Runtime.InteropServices;\nusing System.Text;\nusing System.Linq;\nusing System.IO;\nusing System.Globalization;\nusing System.Collections;\n\nnamespace Task\n{\n\n #region MyIo\n\n internal class MyIo : IDisposable\n {\n private readonly TextReader inputStream;\n private readonly TextWriter outputStream = Console.Out;\n\n private string[] tokens;\n private int pointer;\n\n public MyIo()\n#if LOCAL_TEST\n : this(new StreamReader(\"input.txt\"))\n#else\n : this(System.Console.In)\n#endif\n {\n\n }\n\n public MyIo(TextReader inputStream)\n {\n this.inputStream = inputStream;\n }\n\n\n public char NextChar()\n {\n try\n {\n return (char)inputStream.Read();\n }\n catch (IOException)\n {\n return '\\0';\n }\n }\n\n public string NextLine()\n {\n try\n {\n return inputStream.ReadLine();\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public string NextString()\n {\n try\n {\n while (tokens == null || pointer >= tokens.Length)\n {\n tokens = (NextLine() + string.Empty).Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n pointer = 0;\n }\n return tokens[pointer++];\n }\n catch (IOException)\n {\n return null;\n }\n }\n\n public int NextInt()\n {\n return Next();\n }\n\n public long NextLong()\n {\n return Next();\n }\n\n public T Next()\n {\n var t = typeof(T);\n\n if (t == typeof(char))\n return (T)(object)NextChar();\n\n object s = NextString();\n\n if (t == typeof(string))\n return (T)s;\n\n return (T)Convert.ChangeType(s, typeof(T));\n }\n\n\n public IEnumerable NextWhile(Predicate pred)\n {\n if (pred == null)\n yield break;\n\n T res = Next();\n\n while (pred(res))\n {\n yield return res;\n\n res = Next();\n }\n }\n\n public IEnumerable NextSeq(long n)\n {\n for (var i = 0; i < n; i++)\n yield return Next();\n }\n\n public void Print(string format, params object[] args)\n {\n outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));\n }\n\n public void PrintLine(string format, params object[] args)\n {\n Print(format, args);\n\n outputStream.WriteLine();\n }\n\n public void Print(bool o)\n {\n Print(o ? \"YES\" : \"NO\");\n }\n\n public void PrintLine(bool o)\n {\n PrintLine(o ? \"YES\" : \"NO\");\n }\n\n public void Print(T o)\n {\n outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));\n }\n\n\n public void PrintLine(T o)\n {\n Print(o);\n\n outputStream.WriteLine();\n }\n\n public void Close()\n {\n inputStream.Close();\n outputStream.Close();\n }\n\n void IDisposable.Dispose()\n {\n Close();\n\n#if LOCAL_TEST\n Console.ReadLine();\n#endif\n }\n }\n\n\n public static class ListExtensions\n {\n\n public static IEnumerable ToCycleEnumerable(this IEnumerable self)\n {\n if (self != null)\n {\n for (; ; )\n {\n foreach (var x in self)\n yield return x;\n }\n }\n }\n\n public static T CycleGet(this IList self, int index)\n {\n var c = self.Count;\n return self[(index % c + c) % c];\n }\n\n\n public static IList Shuffle(this IList self)\n {\n var rnd = new Random(DateTime.Now.Millisecond);\n\n var n = self.Count;\n\n while (n > 1)\n {\n n--;\n var k = rnd.Next(n + 1);\n var value = self[k];\n self[k] = self[n];\n self[n] = value;\n }\n\n return self;\n }\n\n public static IList> UseForNew2D(this T def, int fd, int sd)\n {\n var fdim = new T[fd][];\n\n for (int i = 0; i < fd; i++)\n {\n fdim[i] = new T[sd];\n Fill(fdim[i], def);\n }\n\n return fdim;\n }\n\n public static IList Fill(this IList self, Func fval)\n {\n for (var i = 0; i < self.Count; i++)\n self[i] = fval();\n\n\n return self;\n }\n\n\n public static IList Fill(this IList self, T val)\n {\n return self.Fill(() => val);\n }\n\n public static long Hash(this IList self, Func val = null)\n {\n return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);\n }\n\n public static long Hash(this IList self, Func val)\n {\n return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));\n }\n\n\n public static long HashOne(this T self, long current)\n {\n return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));\n }\n\n }\n\n public static class P\n {\n public static P Create(T1 key, T2 val)\n {\n return new P(key, val);\n }\n }\n\n public class P\n {\n private class PComparer : IComparer>\n {\n private readonly bool? byKey;\n\n public PComparer(bool? byKey)\n {\n this.byKey = byKey;\n }\n\n\n public int Compare(P x, P y)\n {\n x = x ?? new P();\n y = y ?? new P();\n\n\n if (byKey == true)\n return Comparer.Default.Compare(x.Key, y.Key);\n else if (byKey == false)\n return Comparer.Default.Compare(x.Value, y.Value);\n else\n {\n var tr = Comparer.Default.Compare(x.Key, y.Key);\n\n if (tr != 0)\n tr = Comparer.Default.Compare(x.Value, y.Value);\n\n return tr;\n }\n }\n }\n\n\n public P()\n {\n }\n\n public P(T1 key, T2 val)\n {\n this.Key = key;\n this.Value = val;\n }\n\n\n public T1 Key\n {\n get;\n set;\n }\n\n public T2 Value\n {\n get;\n set;\n }\n\n public P Clone()\n {\n return new P(Key, Value);\n }\n\n public static IComparer> KeyComparer\n {\n get { return new PComparer(true); }\n }\n\n public static IComparer> ValueComparer\n {\n get { return new PComparer(false); }\n }\n\n public static implicit operator T1(P obj)\n {\n return obj.Key;\n }\n\n public static implicit operator T2(P obj)\n {\n return obj.Value;\n }\n\n public P SetKey(T1 key)\n {\n Key = key;\n return this;\n }\n\n public P SetValue(T2 value)\n {\n Value = value;\n return this;\n }\n\n public override string ToString()\n {\n return string.Format(\"Key: {0}, Value: {1}\", Key, Value);\n }\n\n public override int GetHashCode()\n {\n int hash = 17;\n hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());\n hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());\n return hash;\n\n }\n }\n\n #endregion\n\n\n internal class Program\n {\n #region Program\n\n private readonly MyIo io;\n\n public Program(MyIo io)\n {\n this.io = io;\n }\n\n public static void Main(string[] args)\n {\n using (MyIo io = new MyIo())\n {\n new Program(io)\n .Solve();\n }\n }\n\n\n\n #endregion\n public const long MOD = 1000000007;\n public const double EPS = 1e-14;\n\n private void Solve()\n {\n var a = io.NextLine();\n var b = io.NextLine();\n\n var n = (long)a.Length;\n\n var k = io.NextInt();\n\n\n\n \n var ak = 0L;\n var ak0 = 1L;\n var sprd = 1L;\n\n for (var i = 1; i <= k; ++i)\n {\n ak0 = (sprd - ak0) % MOD;\n ak = (sprd - ak) % MOD;\n\n sprd = ((n - 1L) * (sprd % MOD));\n }\n\n var res = (a == b) ? ak0 : 0;\n\n for (var i = 1; i < n; i++)\n {\n if (a.Substring(i) + a.Substring(0, i) == b)\n res = (res + ak) % MOD;\n }\n\n \n\n io.PrintLine(res);\n }\n }\n\n}\n\n", "src_uid": "414000abf4345f08ede20798de29b9d4"} {"source_code": "using System;\nusing System.Text;\nusing System.Collections.Generic;\nusing System.Linq;\nclass Solve{\n public Solve(){}\n StringBuilder sb;\n public static int Main(){\n new Solve().Run();\n return 0;\n }\n void Run(){\n sb = new StringBuilder();\n Calc();\n Console.Write(sb.ToString());\n }\n void Calc(){\n string[] str = Console.ReadLine().Split(' ');\n int N = int.Parse(str[0]);\n int K = int.Parse(str[1]);\n str = Console.ReadLine().Split(' ');\n int[] A = new int[K];\n for(int i=0;i= 0 && T >= 0 && O >= 0;\n if(b){\n sb.Append(\"YES\\n\");\n }\n else{\n sb.Append(\"NO\\n\");\n }\n }\n}", "src_uid": "d1f88a97714d6c13309c88fcf7d86821"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Runtime.CompilerServices;\nusing System.Text;\n\nnamespace codeforces\n{\n\tclass Program\n\t{\n\t\tpublic const int Osn = 1000000007;\n\n\t\tpublic class Pair\n\t\t{\n\t\t\tpublic long First;\n\n\t\t\tpublic long Second;\n\t\t}\n\n\t\tpublic class PairComparer : IComparer\n\t\t{\n\t\t\tpublic int Compare(Pair x, Pair y)\n\t\t\t{\n\t\t\t\tif (x.First < y.First || (x.First == y.First && x.Second > y.Second))\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic static long GetGcd(long a, long b)\n\t\t{\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tif (b == 0)\n\t\t\t\t\treturn a;\n\t\t\t\tvar a1 = a;\n\t\t\t\ta = b;\n\t\t\t\tb = a1 % b;\n\n\t\t\t}\n\t\t}\n\n\t\tpublic static void WriteYesNo(bool x, string yes = \"YES\", string no = \"NO\")\n\t\t{\n\t\t\tif (x)\n\t\t\t\tConsole.WriteLine(yes);\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(no);\n\t\t\t}\n\t\t}\n\n\t\tpublic static string ReadString()\n\t\t{\n\t\t\treturn Console.ReadLine();\n\t\t}\n\n\t\tpublic static List ReadListOfInts()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(int.Parse).ToList();\n\t\t}\n\n\t\tpublic static List ReadListOfLongs()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn s.Split(' ').Select(long.Parse).ToList();\n\t\t}\n\n\t\tpublic static int ReadInt()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn int.Parse(s);\n\t\t}\n\n\t\tpublic static long ReadLong()\n\t\t{\n\t\t\tvar s = Console.ReadLine();\n\t\t\treturn long.Parse(s);\n\t\t}\n\n\t\tpublic class Vertex\n\t\t{\n\t\t\tpublic int Was;\n\n\t\t\tpublic List Edges;\n\t\t}\n\n\t\tpublic static List Graph = new List();\n\n\n\t\tpublic static bool Dfs(int u)\n\t\t{\n\t\t\tif (Graph[u].Was == 1) return true;\n\t\t\tif (Graph[u].Was == 2) return false;\n\t\t\tGraph[u].Was = 1;\n\t\t\tforeach (var t in Graph[u].Edges)\n\t\t\t{\n\t\t\t\tif (Dfs(t)) return true;\n\t\t\t}\n\n\t\t\tGraph[u].Was = 2;\n\t\t\treturn false;\n\t\t}\n\n\t\tpublic static bool IsPrime(int x)\n\t\t{\n\t\t\tfor (var j = 2; j * j <= x; ++j)\n\t\t\t\tif (x % j == 0)\n\t\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic class LinkedVertex\n\t\t{\n\t\t\tpublic int Next;\n\n\t\t\tpublic int Prev;\n\n\t\t\tpublic int Value;\n\t\t}\n\n\n\t\tpublic static int BinarySearch(List list, int value)\n\t\t{\n\t\t\tvar l = -1;\n\t\t\tvar r = list.Count;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tvar m = (r + l) / 2;\n\t\t\t\tif (list[m] >= value)\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\n\t\t\treturn r;\n\t\t}\n\n\t\tprivate static void Main()\n\t\t{\n\t\t\tvar l = ReadListOfLongs();\n\t\t\tvar a = l[0];\n\t\t\tvar b = l[1];\n\t\t\tlong ans = (a * (a + 1) / 2) % Osn;\n\t\t\tans = (ans * b + a) % Osn;\n\t\t\tans = (((b * (b - 1) / 2) % Osn) * ans) % Osn;\n\t\t\tConsole.WriteLine(ans);\n\t\t\tConsole.ReadLine();\n\t\t}\n\t}\n}\n", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Runtime.InteropServices;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace CodeForces\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n long[] v = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);\n long max = v.Max();\n long min = v.Min();\n Console.WriteLine(max - (max - min)+\" \"+ ((max - min) / 2));\n\n }\n }\n}\n", "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"source_code": "using System;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Collections.Generic;\r\nusing System.Text;\r\nusing System.Numerics;\r\n\r\nnamespace cfgr14\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\r\n if (File.Exists(\"input.txt\"))\r\n {\r\n Console.SetIn(new StreamReader(\"input.txt\"));\r\n }\r\n solve_cfgr14E();\r\n Console.Out.Flush();\r\n }\r\n\r\n public static long[] fact = new long [405];\r\n public static long[] inv = new long [405];\r\n public static long[,] choose = new long [405, 405];\r\n public static long[] pow2 = new long [405];\r\n public static long n;\r\n public static long mod;\r\n /*\r\n Editorial:\r\n \r\n */\r\n public static void solve_cfgr14E()\r\n {\r\n long[] nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);\r\n n = nm[0];\r\n mod = nm[1];\r\n precompute();\r\n long[,] dp = new long[405, 405];\r\n dp[0, 0] = 1;\r\n for (int i = 0; i < n; i++)\r\n {\r\n for (int j = 0; j <= i; j++)\r\n {\r\n for (int k = 1; i + k <= n; k++)\r\n {\r\n dp[i + k + 1, j + k] += (dp[i, j] * pow2[k - 1]) % mod * choose[j + k, k];\r\n dp[i + k + 1, j + k] %= mod;\r\n }\r\n }\r\n }\r\n\r\n long ans = 0;\r\n for (int i = 0; i <= n; i++)\r\n {\r\n ans = (ans + dp[n + 1, i]) % mod;\r\n }\r\n Console.WriteLine(ans);\r\n }\r\n\r\n public static void precompute()\r\n {\r\n fact[0] = 1;\r\n inv[0] = 1;\r\n for (int i = 1; i <= n; i++)\r\n {\r\n fact[i] = (fact[i - 1] * i) % mod;\r\n inv[i] = binExp(fact[i], mod - 2);\r\n }\r\n\r\n for (int i = 0; i <= n; i++)\r\n {\r\n for (int j = 0; j <= i; j++)\r\n {\r\n choose[i, j] = ((fact[i] * inv[j]) % mod * inv[i - j]) % mod;\r\n }\r\n }\r\n\r\n for (int i = 0; i <= n; i++)\r\n {\r\n pow2[i] = binExp(2, i);\r\n }\r\n }\r\n\r\n public static long binExp(long a, long exp)\r\n {\r\n if (exp == 0)\r\n {\r\n return 1;\r\n }\r\n long tmp = binExp(a, exp / 2);\r\n tmp = (tmp * tmp) % mod;\r\n if (exp % 2 == 1)\r\n {\r\n tmp *= a;\r\n }\r\n return tmp % mod;\r\n }\r\n\r\n public static void solve_cfgr14C()\r\n {\r\n int t = Convert.ToInt32(Console.ReadLine());\r\n while(t-- > 0)\r\n {\r\n int[] nmx = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\r\n int n = nmx[0];\r\n int m = nmx[1];\r\n int x = nmx[2];\r\n int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\r\n Array.Sort(h);\r\n int[] cnt = new int[m];\r\n for (int i = 0; i < n; i++)\r\n {\r\n cnt[i % m] += h[i];\r\n }\r\n int min = int.MaxValue;\r\n int max = int.MinValue;\r\n bool ok = true;\r\n for (int i = 0; i < m; i++)\r\n {\r\n min = Math.Min(min, cnt[i]);\r\n max = Math.Max(max, cnt[i]);\r\n if (max - min > x)\r\n {\r\n ok = false;\r\n break;\r\n }\r\n }\r\n if (ok)\r\n {\r\n Console.WriteLine(\"YES\");\r\n for (int i = 0; i < n; i++)\r\n {\r\n Console.Write(\"{0} \", (i % m) + 1);\r\n }\r\n }\r\n else\r\n {\r\n Console.Write(\"NO\");\r\n }\r\n Console.WriteLine();\r\n }\r\n }\r\n\r\n public static void solve_cfgr14B()\r\n {\r\n int t = Convert.ToInt32(Console.ReadLine());\r\n while(t-- > 0)\r\n {\r\n int n = Convert.ToInt32(Console.ReadLine());\r\n bool ok = false;\r\n if (n > 1 && (n & (n - 1)) == 0)\r\n {\r\n ok = true;\r\n }\r\n else\r\n {\r\n for (int i = 2; i * i <= 1000000000; i++)\r\n {\r\n if (i % 2 != 0)\r\n {\r\n if (n % (i * i) == 0)\r\n {\r\n int r = n / (i * i);\r\n if (r > 1 && (r & (r - 1)) == 0)\r\n {\r\n ok = true;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n Console.WriteLine(ok ? \"YES\" : \"NO\");\r\n }\r\n\r\n }\r\n\r\n public static void solve_cfgr14A()\r\n {\r\n int t = Convert.ToInt32(Console.ReadLine());\r\n while(t-- > 0)\r\n {\r\n int[] nx = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\r\n int n = nx[0];\r\n int x = nx[1];\r\n int[] w = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\r\n Array.Sort(w, (a, b) => b.CompareTo(a));\r\n int sum = 0;\r\n int posToChange = -1;\r\n for (int i = 0; i < n; i++)\r\n {\r\n sum += w[i];\r\n if (sum == x)\r\n {\r\n posToChange = i;\r\n }\r\n }\r\n if (sum != x)\r\n {\r\n Console.WriteLine(\"YES\");\r\n for (int i = 0; i < n; i++)\r\n {\r\n if (i == posToChange)\r\n {\r\n if (i + 1 < n)\r\n {\r\n int tmp = w[i];\r\n w[i] = w[i + 1];\r\n w[i + 1] = tmp;\r\n }\r\n }\r\n Console.Write(\"{0} \", w[i]);\r\n }\r\n }\r\n else\r\n {\r\n Console.Write(\"NO\");\r\n }\r\n Console.WriteLine();\r\n \r\n }\r\n }\r\n }\r\n}", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ProgrammingContest.Codeforces.SchoolTeam2\n{\n class H\n {\n public static void Main()\n {\n string s = Console.ReadLine();\n int n = s.Length;\n long[,] dp = new long[n, 10];\n\n long res = 0;\n bool self = false;\n for (int u = 0; u < 10; u++)\n {\n for (int i = 0; i < n; i++)\n for (int j = 0; j < 10; j++)\n dp[i, j] = 0;\n dp[0, u] = 1;\n for (int i = 1; i < n; i++)\n {\n int x = s[i] - '0';\n for (int j = 0; j < 10; j++)\n {\n int y = j + x;\n for (int k = 0; k <= y % 2; k++)\n dp[i, y / 2 + k] += dp[i - 1, j];\n }\n }\n for (int i = 0; i < 10; i++) res += dp[n - 1, i];\n\n bool b = true;\n for (int i = 0; i < n; i++) b &= dp[i, s[i] - '0'] > 0;\n self |= b;\n }\n\n Console.WriteLine(res - (self ? 1 : 0));\n }\n }\n}\n", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication11 {\n class Program {\n static char[] inputSeparators = new char[] { ' ' };\n static int[] ballInStock = new int[3];\n static int[] ballsNeeded = new int[3];\n static int[] deficitArray = new int[3];\n\n static void Main(string[] args) {\n List input1 = GetInputList_int(inputSeparators);\n ballInStock[0] = input1[0];\n ballInStock[1] = input1[1];\n ballInStock[2] = input1[2];\n\n List input2 = GetInputList_int(inputSeparators);\n ballsNeeded[0] = input2[0];\n ballsNeeded[1] = input2[1];\n ballsNeeded[2] = input2[2];\n\n for (int i = 0; i < 3; i++) {\n deficitArray[i] = ballsNeeded[i] - ballInStock[i];\n }\n\n //Environment.Exit(0);\n\n for (int i = 0; i < deficitArray.Length; i++) {\n if (deficitArray[i] > 0) {\n FillDeficit(i);\n }\n }\n Console.WriteLine(\"Yes\");\n }\n\n static void FillDeficit(int deficitIndex) {\n while (deficitArray[deficitIndex] > 0) {\n bool transformationIsPossible = false;\n for (int i = 0; i < deficitArray.Length; i++) {\n if (i != deficitIndex) { // other magic balls\n if (deficitArray[i] <= -2) { // if we can\n transformationIsPossible = true;\n deficitArray[i] += 2;\n deficitArray[deficitIndex] -= 1;\n break;\n }\n }\n }\n if (!transformationIsPossible) {\n Console.WriteLine(\"No\");\n Environment.Exit(0);\n }\n }\n }\n\n static List GetInputList_int(char[] separator) {\n string inputLine1 = Console.ReadLine();\n List inputList1 = inputLine1.Split(' ').ToList();\n List inputList1_int = new List();\n inputList1.ForEach(i => {\n int i_int = int.Parse(i);\n inputList1_int.Add(i_int);\n });\n return inputList1_int;\n }\n }\n}\n", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace White_Sheet\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args) ? \"YES\" : \"NO\");\n writer.Flush();\n }\n\n private static bool Solve(string[] args)\n {\n int x1 = Next(), y1 = Next(), x2 = Next(), y2 = Next();\n int x3 = Next(), y3 = Next(), x4 = Next(), y4 = Next();\n int x5 = Next(), y5 = Next(), x6 = Next(), y6 = Next();\n\n x3 = Math.Min(x4, Math.Max(x3, x1));\n y3 = Math.Min(y4, Math.Max(y3, y1));\n\n x5 = Math.Min(x6, Math.Max(x5, x1));\n y5 = Math.Min(y6, Math.Max(y5, y1));\n\n x4 = Math.Max(x3, Math.Min(x4, x2));\n y4 = Math.Max(y3, Math.Min(y4, y2));\n\n x6 = Math.Max(x5, Math.Min(x6, x2));\n y6 = Math.Max(y5, Math.Min(y6, y2));\n\n long s = (long) (x2 - x1)*(y2 - y1);\n long s1 = (long) (x4 - x3)*(y4 - y3);\n long s2 = (long) (x6 - x5)*(y6 - y5);\n\n if (s > s1 + s2)\n return true;\n\n x3 = Math.Min(x4, Math.Max(x3, x5));\n y3 = Math.Min(y4, Math.Max(y3, y5));\n x4 = Math.Max(x3, Math.Min(x4, x6));\n y4 = Math.Max(y3, Math.Min(y4, y6));\n\n long s12 = (long) (x4 - x3)*(y4 - y3);\n\n return s > s1 + s2 - s12;\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "05c90c1d75d76a522241af6bb6af7781"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Globalization;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading;\r\n\r\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\r\npublic class Solution\r\n{\r\n string Sort(int[] a)\r\n {\r\n int n = a.Length;\r\n var b = new int[n];\r\n var log = new List();\r\n\r\n void MergeSort(int l, int r)\r\n {\r\n if (r - l <= 1)\r\n return;\r\n int m = (l + r) / 2;\r\n MergeSort(l, m);\r\n MergeSort(m, r);\r\n Write(l, r, m);\r\n int i = l;\r\n int j = m;\r\n int k = l;\r\n while (i < m && j < r)\r\n {\r\n if (a[i] < a[j])\r\n {\r\n log.Add(0);\r\n b[k] = a[i];\r\n i++;\r\n }\r\n else\r\n {\r\n log.Add(1);\r\n b[k] = a[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n while (i < m)\r\n {\r\n b[k] = a[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < r)\r\n {\r\n b[k] = a[j];\r\n j++;\r\n k++;\r\n }\r\n for (int p = l; p < r; p++)\r\n a[p] = b[p];\r\n }\r\n\r\n MergeSort(0, n);\r\n return string.Concat(log);\r\n }\r\n\r\n int p;\r\n string log;\r\n int[] a, b;\r\n void Fun(int l, int r)\r\n {\r\n if (r - l <= 1)\r\n return;\r\n int m = (l + r) / 2;\r\n Fun(l, m);\r\n Fun(m, r);\r\n int i = l;\r\n int j = m;\r\n int k = l;\r\n while (i < m && j < r)\r\n {\r\n if (log[p++] == '0')\r\n {\r\n b[k] = a[i];\r\n i++;\r\n }\r\n else\r\n {\r\n b[k] = a[j];\r\n j++;\r\n }\r\n k++;\r\n }\r\n while (i < m)\r\n {\r\n b[k] = a[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < r)\r\n {\r\n b[k] = a[j];\r\n j++;\r\n k++;\r\n }\r\n for (int p = l; p < r; p++)\r\n a[p] = b[p];\r\n }\r\n\r\n public void Solve()\r\n {\r\n log = ReadToken();\r\n int n = 16;\r\n a = Enumerable.Range(0, n).ToArray();\r\n b = new int[n];\r\n Fun(0, n);\r\n\r\n var ans = new int[n];\r\n for (int i = 0; i < n; i++)\r\n ans[a[i]] = i + 1;\r\n Write(n);\r\n WriteArray(ans);\r\n }\r\n\r\n #region Main\r\n\r\n protected static TextReader reader;\r\n protected static TextWriter writer;\r\n static void Main()\r\n {\r\n#if DEBUGLOCAL\r\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\r\n //reader = new StreamReader(Console.OpenStandardInput());\r\n writer = Console.Out;\r\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\r\n#else\r\n reader = new StreamReader(Console.OpenStandardInput());\r\n writer = new StreamWriter(Console.OpenStandardOutput());\r\n //reader = new StreamReader(\"ysys.in\");\r\n //writer = new StreamWriter(\"output.txt\");\r\n#endif\r\n try\r\n {\r\n new Solution().Solve();\r\n //var thread = new Thread(new Solution().Solve, 1024 * 1024 * 128);\r\n //thread.Start();\r\n //thread.Join();\r\n }\r\n catch (Exception ex)\r\n {\r\n#if DEBUGLOCAL\r\n Console.WriteLine(ex);\r\n#else\r\n throw;\r\n#endif\r\n }\r\n reader.Close();\r\n writer.Close();\r\n }\r\n\r\n #endregion\r\n\r\n #region Read / Write\r\n private static Queue currentLineTokens = new Queue();\r\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\r\n public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\r\n public static int ReadInt() { return int.Parse(ReadToken()); }\r\n public static long ReadLong() { return long.Parse(ReadToken()); }\r\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\r\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\r\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\r\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\r\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }\r\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\r\n {\r\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\r\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }\r\n return ret;\r\n }\r\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }\r\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\r\n public static void Write(params object[] array) { WriteArray(array); }\r\n public static void WriteLines(IEnumerable array) { foreach (var a in array) writer.WriteLine(a); }\r\n private class SDictionary : Dictionary\r\n {\r\n public new TValue this[TKey key]\r\n {\r\n get { return ContainsKey(key) ? base[key] : default(TValue); }\r\n set { base[key] = value; }\r\n }\r\n }\r\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }\r\n #endregion\r\n}", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"} {"source_code": "using System;\nusing System.Linq;\nusing CompLib.Util;\n\npublic class Program\n{\n int N;\n public void Solve()\n {\n var sc = new Scanner();\n N = sc.NextInt();\n\n /*\n * クイーン\n * \n * たて、よこ、ななめ\n * 駒があったら取る\n * \n * n*nチェス盤\n * \n * (1,1)に白\n * (1,n)に黒\n * それ以外全部緑\n * \n * 白先手\n * \n * 必ず駒を取る\n * \n * 駒を取られる or 駒を取れない 負け\n * \n * 勝つほう\n */\n\n /*\n * 2 w 1 2\n * 3 b\n * 4 w 1 2\n */\n\n if (N % 2 == 0)\n {\n Console.WriteLine(\"white\");\n Console.WriteLine(\"1 2\");\n }\n else\n {\n Console.WriteLine(\"black\");\n }\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s;\n do\n {\n s = Console.ReadLine();\n } while (s.Length == 0);\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public string ReadLine()\n {\n _index = _line.Length;\n return Console.ReadLine();\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "52e07d176aa1d370788f94ee2e61df93"} {"source_code": "using System;\r\nusing System.IO;\r\nusing System.Text;\r\n\r\nnamespace Kavi_on_Pairing_Duty\r\n{\r\n internal class Program\r\n {\r\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\r\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\r\n\r\n private static void Main(string[] args)\r\n {\r\n const int mod = 998244353;\r\n\r\n int n = Next();\r\n\r\n var p = new int[n + 1];\r\n var s = new long[n + 1];\r\n s[1] = 1;\r\n long sum = 2;\r\n\r\n for (int i = 2; i < p.Length; i++)\r\n {\r\n for (int j = i + i; j < p.Length; j += i)\r\n {\r\n p[j]++;\r\n }\r\n\r\n s[i] = (1 + sum + p[i])%mod;\r\n sum += s[i];\r\n sum %= mod;\r\n }\r\n writer.WriteLine(s[n]);\r\n writer.Flush();\r\n }\r\n\r\n private static int Next()\r\n {\r\n int c;\r\n int res = 0;\r\n do\r\n {\r\n c = reader.Read();\r\n if (c == -1)\r\n return res;\r\n } while (c < '0' || c > '9');\r\n res = c - '0';\r\n while (true)\r\n {\r\n c = reader.Read();\r\n if (c < '0' || c > '9')\r\n return res;\r\n res *= 10;\r\n res += c - '0';\r\n }\r\n }\r\n }\r\n}", "src_uid": "09be46206a151c237dc9912df7e0f057"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static bool prime(long p)\n {\n if (p == 2 || p == 7 || p == 61)\n return true;\n if (p % 2 == 0)\n return false;\n long k = 0;\n long d = p - 1;\n while (d % 2 == 0)\n {\n d /= 2;\n k++;\n }\n if (!check(2, p, k, d))\n return false;\n if (!check(7, p, k, d))\n return false;\n if (!check(61, p, k, d))\n return false;\n return true;\n }\n static bool check(long a, long p, long k, long d)\n {\n long temp = powmod(a, d, p);\n if (temp == 1)\n return true;\n if (temp == -1)\n return true;\n while (k > 0)\n {\n temp = (temp * temp) % p;\n if (temp == -1)\n return false;\n if (temp == 1)\n return true;\n k--;\n }\n return temp == 1;\n }\n static long powmod(long a, long pow, long mod)\n {\n long temp = 1;\n while (pow > 0)\n {\n if (pow % 2 == 1)\n temp = (temp * a) % mod;\n pow /= 2;\n a = (a * a) % mod;\n }\n return temp;\n }\n static bool check2(long n, long t)\n {\n if (t > n)\n t = n;\n for (; t > -1; t--)\n if (prime(t) && prime(n - t))\n return true;\n return false;\n }\n static void Main(string[] args)\n {\n long n = long.Parse(Console.ReadLine());\n if (prime(n))\n {\n Console.WriteLine(\"1\");\n Console.WriteLine(n);\n return;\n }\n if (n % 2 == 0)\n {\n for (long i = n / 2; i < n; i += 2)\n {\n if (i % 2 == 0)\n {\n i++;\n continue;\n }\n if (prime(i) && prime(n - i))\n {\n Console.WriteLine(\"2\");\n Console.WriteLine(\"{0} {1}\", n - i, i);\n return;\n }\n }\n }\n if (n % 2 == 1)\n {\n for (long i = n / 3; i < n; i += 2)\n {\n if (i % 2 == 0)\n {\n i++;\n continue;\n }\n if (prime(i))\n {\n long n2 = n - i;\n for (long i2 = n2 / 2; i2 < n2; i2 += 2)\n {\n if (i2 % 2 == 0)\n {\n i2++;\n continue;\n }\n if (prime(i2) && (prime(n2 - i2)))\n {\n Console.WriteLine(\"3\");\n Console.WriteLine(\"{0} {1} {2}\", n2 - i2, i2, i);\n return;\n }\n }\n }\n }\n }\n n -= 2;\n if (n % 2 == 0)\n {\n for (long i = n / 2; i < n; i += 2)\n {\n if (i % 2 == 0)\n {\n i++;\n continue;\n }\n if (prime(i) && prime(n - i))\n {\n Console.WriteLine(\"3\");\n Console.WriteLine(\"2 {0} {1}\", n - i, i);\n return;\n }\n }\n }\n else\n {\n n -= 2;\n Console.WriteLine(\"3\");\n Console.WriteLine(\"2 2 {0}\", n);\n }\n }\n }\n}", "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Tester\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n int t = int.Parse(Console.ReadLine());\r\n for(int i = 0; i < t; i++)\r\n {\r\n int n = int.Parse(Console.ReadLine());\r\n if (n <= 9)\r\n {\r\n Console.WriteLine(n);\r\n }\r\n else\r\n {\r\n var nums = new List();\r\n int sum = 0;\r\n for (int j = 9; j > 0; j--)\r\n {\r\n if (sum + j <= n)\r\n {\r\n nums.Add(j);\r\n sum += j;\r\n }\r\n }\r\n nums.Sort();\r\n nums.ForEach(Console.Write);\r\n Console.WriteLine();\r\n }\r\n }\r\n \r\n }\r\n }\r\n}", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"source_code": "using System;\nusing System.Collections.Generic;\nclass Program\n{\n\tstatic void Main(string[] args)\n\t{\n\t\tlong N = long.Parse(Console.ReadLine());\n\t\tstring str = Console.ReadLine();\n\t\tlong ct = 0;\n\t\tfor(var i=0;i prev)\n {\n if (dir == up)\n {\n res += count(dp, n, t, ct,cd, j, up, i + 1);\n }\n else if (dir == down)\n {\n res += count(dp, n, t, ct, cd - 1, j, up, i + 1);\n }\n else if (dir == none)\n {\n res += count(dp, n, t, ct, cd, j, up, i + 1);\n }\n }\n }\n }\n\n \n \n \n\n dp[i, ct, cd, prev, dir] = res;\n\n return res;\n }\n\n static int readInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long readLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int[] readIntArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n }\n\n static long[] readLongArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n }\n\n#if DEBUG\n\t\tstatic StreamReader getInput()\n\t\t{\n\t\t\tvar resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n\t\t\tvar resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);\n\n\t\t\treturn new StreamReader(resource);\n\t\t}\n#endif\n }\n}\n", "src_uid": "6d67559744583229455c5eafe68f7952"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Contest839A\n{\n class Program\n {\n static void Main(string[] args)\n {\n var values = Console.ReadLine().Split(' ');\n var count = int.Parse(values[1]);\n\n values = Console.ReadLine().Split(' ');\n var days = 0;\n var confety = 0;\n\n for (var i = 0; i < values.Length; i++)\n {\n confety += int.Parse(values[i]);\n if (confety > 8)\n {\n confety -= 8;\n count -= 8;\n }\n else\n {\n count -= confety;\n confety = 0;\n }\n days++;\n if (count <= 0)\n {\n Console.WriteLine(days);\n return;\n }\n }\n Console.WriteLine(\"-1\");\n }\n }\n}\n", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\n\nnamespace Codeforces\n{\n class A\n {\n private static ThreadStart s_threadStart = new A().Go;\n private static bool s_time = false;\n\n class Node\n {\n public void Init()\n {\n taken = false;\n next = new HashSet(nextO);\n prev = new HashSet(prevO);\n }\n\n public int id;\n public bool taken = false;\n public int comp;\n public HashSet next;\n public HashSet prev;\n public HashSet nextO = new HashSet();\n public HashSet prevO = new HashSet();\n }\n\n private void Go()\n {\n int n = GetInt();\n Node[] nodes = new Node[n+1];\n for (int i = 1; i <= n; i++)\n {\n nodes[i] = new Node();\n nodes[i].id = i;\n nodes[i].comp = GetInt();\n }\n\n for (int i = 1; i <= n; i++)\n {\n int tmp = GetInt();\n for (int j = 0; j < tmp; j++)\n {\n int x = GetInt();\n nodes[i].prevO.Add(x);\n nodes[x].nextO.Add(i);\n }\n }\n\n for (int i = 1; i <= n; i++)\n {\n nodes[i].Init();\n }\n\n List topSort = new List(n);\n while (topSort.Count < n)\n {\n for (int i = 1; i <= n; i++)\n {\n if (!nodes[i].taken && nodes[i].prev.Count == 0)\n {\n topSort.Add(nodes[i]);\n nodes[i].taken = true;\n foreach (int x in nodes[i].next)\n {\n nodes[x].prev.Remove(i);\n }\n }\n }\n }\n\n int totalTet = int.MaxValue;\n\n //1\n for (int i = 1; i <= n; i++)\n {\n nodes[i].Init();\n }\n\n int ret = 0;\n int comp = 1;\n int count = 0;\n while (count < n)\n {\n foreach (Node node in topSort)\n {\n if (!node.taken && node.comp == comp && node.prev.Count == 0)\n {\n node.taken = true;\n count++;\n ret++;\n foreach (int x in node.next)\n {\n nodes[x].prev.Remove(node.id);\n }\n }\n }\n if (count < n)\n {\n ret++;\n comp = 1 + comp % 3;\n }\n }\n\n if (ret < totalTet) totalTet = ret;\n\n //2\n for (int i = 1; i <= n; i++)\n {\n nodes[i].Init();\n }\n\n ret = 0;\n comp = 2;\n count = 0;\n while (count < n)\n {\n foreach (Node node in topSort)\n {\n if (!node.taken && node.comp == comp && node.prev.Count == 0)\n {\n node.taken = true;\n count++;\n ret++;\n foreach (int x in node.next)\n {\n nodes[x].prev.Remove(node.id);\n }\n }\n }\n if (count < n)\n {\n ret++;\n comp = 1 + comp % 3;\n }\n }\n\n if (ret < totalTet) totalTet = ret;\n\n\n //3\n for (int i = 1; i <= n; i++)\n {\n nodes[i].Init();\n }\n\n ret = 0;\n comp = 3;\n count = 0;\n while (count < n)\n {\n foreach (Node node in topSort)\n {\n if (!node.taken && node.comp == comp && node.prev.Count == 0)\n {\n node.taken = true;\n count++;\n ret++;\n foreach (int x in node.next)\n {\n nodes[x].prev.Remove(node.id);\n }\n }\n }\n if (count < n)\n {\n ret++;\n comp = 1 + comp % 3;\n }\n }\n\n if (ret < totalTet) totalTet = ret;\n\n Wl(totalTet);\n }\n\n #region Template\n\n public static void Main(string[] args)\n {\n System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();\n Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);\n timer.Start();\n main.Start();\n main.Join();\n timer.Stop();\n if (s_time)\n Wl(timer.ElapsedMilliseconds);\n }\n\n private static IEnumerator ioEnum;\n private static string GetString()\n {\n while (ioEnum == null || !ioEnum.MoveNext())\n {\n ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();\n }\n\n return ioEnum.Current;\n }\n\n private static int GetInt()\n {\n return int.Parse(GetString());\n }\n\n private static long GetLong()\n {\n return long.Parse(GetString());\n }\n\n private static double GetDouble()\n {\n return double.Parse(GetString());\n }\n\n private static List GetIntArr(int n)\n {\n List ret = new List(n);\n for (int i = 0; i < n; i++)\n {\n ret.Add(GetInt());\n }\n return ret;\n }\n\n private static void Wl(T o)\n {\n if (o is double)\n {\n Wld((o as double?).Value, \"\");\n }\n else if (o is float)\n {\n Wld((o as float?).Value, \"\");\n }\n else\n Console.WriteLine(o.ToString());\n }\n\n private static void Wl(IEnumerable enumerable)\n {\n Wl(string.Join(\" \", enumerable.Select(e => e.ToString()).ToArray()));\n }\n\n private static void Wld(double d, string format)\n {\n Wl(d.ToString(format, CultureInfo.InvariantCulture));\n }\n\n public struct Tuple : IComparable>\n where T : IComparable\n where K : IComparable\n {\n public T Item1;\n public K Item2;\n\n public Tuple(T t, K k)\n {\n Item1 = t;\n Item2 = k;\n }\n\n public override bool Equals(object obj)\n {\n var o = (Tuple)obj;\n return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);\n }\n\n public override int GetHashCode()\n {\n return Item1.GetHashCode() ^ Item2.GetHashCode();\n }\n\n public override string ToString()\n {\n return \"(\" + Item1 + \" \" + Item2 + \")\";\n }\n\n #region IComparable> Members\n\n public int CompareTo(Tuple other)\n {\n int ret = Item1.CompareTo(other.Item1);\n if (ret != 0) return ret;\n return Item2.CompareTo(other.Item2);\n }\n\n #endregion\n }\n\n #endregion\n }\n}", "src_uid": "be42e213ff43e303e475d77a9560367f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nnamespace КРОК_2012\n{\n //Телефонный код\n class Program\n {\n\n\n /////Телефонный код\n //static bool solve(StreamReader str)\n //{\n\n // string[] tokens = str.ReadLine().Split(' ');\n // int N = Convert.ToInt32(tokens[0]);\n // string next;\n // string prefix = str.ReadLine(); ;\n // for (int i = 0; i < N - 1; i++)\n // {\n // next = str.ReadLine();\n // for (int j = 0; j < prefix.Length; j++)\n // if (prefix[j] != next[j]) { prefix = prefix.Substring(0, j); break; }\n // }\n\n // Console.WriteLine(prefix.Length);\n\n\n // return str.EndOfStream;\n //}\n\n\n ////B. Период псевдослучайной последовательности\n // static bool solve(StreamReader str)\n // {\n\n // string[] tokens = str.ReadLine().Split(' ');\n // int a = Convert.ToInt32(tokens[0]);\n // int b = Convert.ToInt32(tokens[1]);\n // int m = Convert.ToInt32(tokens[2]);\n // int r0 = Convert.ToInt32(tokens[3]);\n\n // Dictionary q = new Dictionary();\n // int i=0;\n // int prev=r0;\n // do\n // {\n // q.Add(prev, i++);\n // prev = (a * prev + b) % m;\n\n // } while (!q.ContainsKey(prev));\n\n // int ret = i - q[prev];\n\n // Console.WriteLine(ret);\n\n\n // return str.EndOfStream;\n // }\n\n\n\n\n ////C. Маршрутка\n //static bool solve(StreamReader str)\n //{\n\n // string[] tokens = str.ReadLine().Split(' ');\n // int n = Convert.ToInt32(tokens[0]);\n // int m = Convert.ToInt32(tokens[1]);\n // int Time = 0;\n // int[] students=new int[n];\n // SortedDictionary> pas = new SortedDictionary>();\n // for (int i = 0;i());\n // pas[xi].Add(i);\n // if ((((i + 1) % m) == 0) || (i + 1 == n)) //поехали\n // {\n // Time=(t>Time)?t:Time;//Время последнего подошедшего студента, либо (если студенты ждали ее возвращения) время ее возвращения\n // int prevx = 0;\n // foreach (int x in pas.Keys)\n // {\n // Time += x - prevx;//Пока приехали на остановку от предыдущей\n // prevx = x;\n\n // foreach (int studentindex in pas[x])\n // students[studentindex] = Time;//все студенты на данной остановке получают одинаковое время высадки\n // Time += 1 + pas[x].Count / 2;//+ время высадки все студентов на остановке\n // }\n // //всех высадили и едеме обратно\n // Time += prevx;\n // pas.Clear();//Очистили маршрутку\n // }\n // }\n\n\n // for (int i = 0; i < n;i++ )\n // Console.Write(students[i].ToString()+\" \");\n\n // Console.WriteLine();\n // return str.EndOfStream;\n //}\n\n\n\n //D. Реформа календаря\n //static bool solve(StreamReader str)\n //{\n\n // string[] tokens = str.ReadLine().Split(' ');\n // Int64 a = Convert.ToInt64(tokens[0]);\n // Int64 n = Convert.ToInt64(tokens[1]) + a;\n // Int64 p = 0;\n // Int64 sqrta=(int)Math.Sqrt(a);\n // Int64 sqrtn = (int)Math.Sqrt(n);\n // Int64[] kvadrat= new long[sqrtn+1];\n // \n // kvadrat[1] = 1;\n // kvadrat[sqrta] = sqrta * sqrta;\n // for (; a < n; a++)\n // {\n \n // Int64 dc;\n // for (dc = sqrta; dc > 0; dc--)//количество дней в месяце\n // {\n // if (kvadrat[dc] == 0)\n // {\n // if (kvadrat[dc + 1] != 0) kvadrat[dc] = kvadrat[dc + 1] - 2 * (dc + 1) + 1;\n // else kvadrat[dc] = kvadrat[dc - 1] + 2 * (dc - 1) + 1;\n // }\n // Int64 dcdc = kvadrat[dc];\n // if (a % dcdc == 0) { p += a / dcdc; break; }\n // }\n\n // Int64 tsqrta = 0 ;\n \n // if (dc == sqrta) //встретили полный квадрат\n // {\n // tsqrta = (sqrta + 1) * (sqrta + 1);\n // for (a++; (a < (int)tsqrta)&&(a 0; dc--)//количество дней в месяце\n // {\n // if (kvadrat[dc] == 0)\n // {\n // if (kvadrat[dc + 1] != 0) kvadrat[dc] = kvadrat[dc + 1] - 2 * (dc+1) + 1;\n // else kvadrat[dc] = kvadrat[dc - 1] + 2 * (dc-1) + 1;\n // }\n // Int64 dcdc = kvadrat[dc];\n // if (a % dcdc == 0) { p += a / dcdc; break; }\n // }\n // }\n // // p += 1;\n // a++;\n // sqrta++;\n // }\n \n // }\n // Console.WriteLine(p);\n // return str.EndOfStream;\n //}\n\n static bool solve(StreamReader str)\n {\n\n string[] tokens = str.ReadLine().Split(' ');\n Int64 a = Convert.ToInt64(tokens[0]);\n Int64 n = Convert.ToInt64(tokens[1]) + a-1;\n Int64 p = 0;\n int[] ch = new int[10000001];\n for(int i=1;;i++)\n {\n Int64 kvadrat=i*i;\n if (kvadrat>n) break;\n for(int j=1;;j++)\n {\n Int64 k=kvadrat*j;\n if (k>n) break;\n ch[k]=j;\n }\n }\n\n for (Int64 i = a; i <= n; i++)\n p += (ch[i]==0)?1:ch[i];\n \n\n \n Console.WriteLine(p);\n return str.EndOfStream;\n }\n\n static void Main(string[] args)\n {\n StreamReader str = new StreamReader(Console.OpenStandardInput());\n\n#if DEBUG\n str = new StreamReader(\"input.txt\");\n while (!solve(str)) ;\n#else\n solve(str);\n#endif\n\n\n }\n }\n }\n\n", "src_uid": "915081861e391958dce6ee2a117abd4e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace for_codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n int k = 0;\n string anss = \"NO\" , s = Console.ReadLine();\n for (int i = 0; i < s.Length-1; i++)\n {\n if (s[i] == s[i + 1])\n k++;\n else\n k = 0;\n if (k == 6)\n {\n anss = \"YES\";\n break;\n } \n }\n Console.WriteLine(anss);\n \n }\n }\n}\n", "src_uid": "ed9a763362abc6ed40356731f1036b38"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.Threading;\n\nnamespace ReadWriteTemplate\n{\n\tpublic static class Solver\n\t{\n\t\tprivate static void SolveCase()\n\t\t{\n\t\t\tint n = ReadInt();\n\t\t\tvar a = ReadIntArray();\n\t\t\tArray.Sort(a);\n\t\t\tint sum = a.Sum();\n\t\t\tint i = 0;\n\t\t\twhile (2 * sum < 9 * n)\n\t\t\t{\n\t\t\t\tsum = sum - a[i] + 5;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tWriter.WriteLine(i);\n\t\t}\n\n\t\tpublic static void Solve()\n\t\t{\n\t\t\tSolveCase();\n\n\t\t\t/*var sw = Stopwatch.StartNew();*/\n\n\t\t\t/*int T = ReadInt();\n\t\t\tfor (int i = 0; i < T; i++)\n\t\t\t{\n\t\t\t\tWriter.Write(\"Case #{0}: \", i + 1);\n\t\t\t\tSolveCase();\n\t\t\t}*/\n\n\t\t\t/*sw.Stop();\n\t\t\tConsole.WriteLine(sw.ElapsedMilliseconds);*/\n\t\t}\n\n\t\tpublic static void Main()\n\t\t{\n\t\t\tThread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if DEBUG\n\t\t\t//Reader = Console.In; Writer = Console.Out;\n\t\t\tReader = File.OpenText(\"input.txt\"); Writer = File.CreateText(\"output.txt\");\n#else\n\t\t\tReader = Console.In; Writer = Console.Out;\n#endif\n\n\t\t\t// Solve();\n\t\t\tThread thread = new Thread(Solve, 64 * 1024 * 1024);\n\t\t\tthread.CurrentCulture = CultureInfo.InvariantCulture;\n\t\t\tthread.Start();\n\t\t\tthread.Join();\n\n\t\t\tReader.Close();\n\t\t\tWriter.Close();\n\t\t}\n\n\t\tpublic static IOrderedEnumerable OrderByWithShuffle(this IEnumerable source, Func keySelector)\n\t\t{\n\t\t\treturn source.Shuffle().OrderBy(keySelector);\n\t\t}\n\n\t\tpublic static T[] Shuffle(this IEnumerable source)\n\t\t{\n\t\t\tT[] result = source.ToArray();\n\t\t\tRandom rnd = new Random();\n\t\t\tfor (int i = result.Length - 1; i >= 1; i--)\n\t\t\t{\n\t\t\t\tint k = rnd.Next(i + 1);\n\t\t\t\tT tmp = result[k];\n\t\t\t\tresult[k] = result[i];\n\t\t\t\tresult[i] = tmp;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t#region Read/Write\n\n\t\tprivate static TextReader Reader;\n\n\t\tprivate static TextWriter Writer;\n\n\t\tprivate static Queue CurrentLineTokens = new Queue();\n\n\t\tprivate static string[] ReadAndSplitLine()\n\t\t{\n\t\t\treturn Reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n\t\t}\n\n\t\tpublic static string ReadToken()\n\t\t{\n\t\t\twhile (CurrentLineTokens.Count == 0)\n\t\t\t\tCurrentLineTokens = new Queue(ReadAndSplitLine());\n\t\t\treturn CurrentLineTokens.Dequeue();\n\t\t}\n\n\t\tpublic static string ReadLine()\n\t\t{\n\t\t\treturn Reader.ReadLine();\n\t\t}\n\n\t\tpublic static int ReadInt()\n\t\t{\n\t\t\treturn int.Parse(ReadToken());\n\t\t}\n\n\t\tpublic static long ReadLong()\n\t\t{\n\t\t\treturn long.Parse(ReadToken());\n\t\t}\n\n\t\tpublic static double ReadDouble()\n\t\t{\n\t\t\treturn double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n\t\t}\n\n\t\tpublic static int[] ReadIntArray()\n\t\t{\n\t\t\treturn ReadAndSplitLine().Select(int.Parse).ToArray();\n\t\t}\n\n\t\tpublic static long[] ReadLongArray()\n\t\t{\n\t\t\treturn ReadAndSplitLine().Select(long.Parse).ToArray();\n\t\t}\n\n\t\tpublic static double[] ReadDoubleArray()\n\t\t{\n\t\t\treturn ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n\t\t}\n\n\t\tpublic static int[][] ReadIntMatrix(int numberOfRows)\n\t\t{\n\t\t\tint[][] matrix = new int[numberOfRows][];\n\t\t\tfor (int i = 0; i < numberOfRows; i++)\n\t\t\t\tmatrix[i] = ReadIntArray();\n\t\t\treturn matrix;\n\t\t}\n\n\t\tpublic static string[] ReadLines(int quantity)\n\t\t{\n\t\t\tstring[] lines = new string[quantity];\n\t\t\tfor (int i = 0; i < quantity; i++)\n\t\t\t\tlines[i] = Reader.ReadLine().Trim();\n\t\t\treturn lines;\n\t\t}\n\n\t\tpublic static void WriteArray(IEnumerable array)\n\t\t{\n\t\t\tWriter.WriteLine(string.Join(\" \", array));\n\t\t}\n\n\t\t#endregion\n\t}\n}", "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n=int.Parse(Console.ReadLine());\n n=n*2-1;\n int sum=0;\n for(int i=1;i<=n;i+=2)\n sum+=i*2;\n sum-=n;\n Console.WriteLine(sum);\n }\n }\n}\n", "src_uid": "758d342c1badde6d0b4db81285be780c"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Browser\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args));\n writer.Flush();\n }\n\n private static int Solve(string[] args)\n {\n int n = Next(), pos = Next(), l = Next(), r = Next();\n\n if (l == 1 && r == n)\n return 0;\n if (l == 1)\n {\n if (pos <= r)\n {\n return r - pos + 1;\n }\n return pos - r + 1;\n }\n if (r == n)\n {\n if (pos >= l)\n return pos - l + 1;\n return l - pos + 1;\n }\n if (pos <= l)\n {\n return r - pos + 2;\n }\n if (pos >= r)\n {\n return pos - l + 2;\n }\n return 2 + r - l + Math.Min(r - pos, pos - l);\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading.Tasks;\nusing System.Numerics;\nusing System.Globalization;\n\nnamespace Smth\n{\n class Program\n {\n public static void Main()\n {\n int bufSize = 512;\n Stream inStream = Console.OpenStandardInput(bufSize);\n Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufSize));\n\n var word = Console.ReadLine();\n var variantsCount = Math.Pow(2, word.Length);\n var palindroms = new List();\n for (int i = 0; i < variantsCount; i++)\n {\n var combination = Bitset(i, word.Length);\n var subString = Enumerable\n .Range(0, word.Length)\n .Where(x => combination[x] == 1)\n .Select(x => word[x]);\n if (IsPalindrome(subString))\n palindroms.Add(new string(subString.ToArray()));\n }\n Console.WriteLine(palindroms.Max());\n }\n\n public static bool IsPalindrome(IEnumerable word)\n {\n return word.SequenceEqual(word.Reverse());\n }\n\n public static int[] Bitset(int bitset, int n)\n {\n return Enumerable\n .Range(0, n)\n .Select(x =>\n {\n var result = bitset % 2;\n bitset /= 2;\n return result;\n }).ToArray();\n }\n }\n}\n", "src_uid": "9a40e9b122962a1f83b74ddee6246a40"} {"source_code": "// Submitted by Silithus @ Macau\nusing System;\nusing System.IO;\nusing System.Collections.Generic;\nusing CCF_XOI;\n\nnamespace CodeForces\n{\n\tclass CF439A\n\t{\n\t\tpublic void Solve(XOI xoi)\n\t\t{\n\t\t\tint i, N, D;\n\n\t\t\tN = xoi.ReadInt();\n\t\t\tD = xoi.ReadInt() - (N - 1) * 10;\n\n\t\t\tfor (i = 0; i < N; i++)\n\t\t\t\tD -= xoi.ReadInt();\n\n\t\t\tif (D < 0)\n\t\t\t\txoi.o.WriteLine(\"-1\");\n\t\t\telse\n\t\t\t\txoi.o.WriteLine((N - 1) * 2 + D / 5);\n\t\t}\n\t}\n\n\tclass CodeForcesMain\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\t(new CF439A()).Solve(new XOI());\n\t\t}\n\t}\n}\n\nnamespace CCF_XOI\n{\t// version 2014.02.07\n\tclass XOI\n\t{\n\t\tprotected StreamReader sr;\n\t\tpublic StreamWriter o;\n\t\tprotected Queue buf = new Queue();\n\t\tpublic bool EOF = false;\n\n\t\tpublic XOI()\n\t\t{\n\t\t\tthis.sr = new StreamReader(Console.OpenStandardInput());\n\t\t\tthis.o = new StreamWriter(Console.OpenStandardOutput());\n\t\t\tthis.o.AutoFlush = true;\n\t\t}\n\n\t\tpublic XOI(string in_path, string out_path)\n\t\t{\n\t\t\tthis.sr = new StreamReader(in_path);\n\t\t\tthis.o = new StreamWriter(out_path);\n\t\t\tthis.o.AutoFlush = true;\n\t\t}\n\n\t\tpublic int ReadInt()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\tif (s == null) return -1;\n\t\t\telse return Int32.Parse(s);\n\t\t}\n\n\t\tpublic long ReadLong()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\tif (s == null) return -1;\n\t\t\telse return Int64.Parse(s);\n\t\t}\n\n\t\tpublic double ReadDouble()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\tif (s == null) return -1;\n\t\t\telse return Double.Parse(s);\n\t\t}\n\n\t\tpublic string ReadString()\n\t\t{\n\t\t\tstring s = this.GetNext();\n\t\t\treturn (s == null ? null : s);\n\t\t}\n\n\t\tpublic string ReadLine()\n\t\t{\t// I will ignore current buffer and read a new line\n\t\t\tstring s = \"\";\n\t\t\twhile (s == \"\" && !this.EOF)\n\t\t\t{\n\t\t\t\ts = sr.ReadLine();\n\t\t\t\tthis.EOF = (s == null);\n\t\t\t}\n\t\t\treturn (this.EOF ? null : s);\n\t\t}\n\n\t\tprotected string GetNext()\n\t\t{\n\t\t\tif (buf.Count == 0)\n\t\t\t{\n\t\t\t\twhile (buf.Count == 0 && !this.EOF)\n\t\t\t\t{\n\t\t\t\t\tstring s = sr.ReadLine();\n\t\t\t\t\tif (s == null)\n\t\t\t\t\t\tthis.EOF = true;\n\t\t\t\t\telse\n\t\t\t\t\t\tforeach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))\n\t\t\t\t\t\t\tbuf.Enqueue(ss);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn (this.EOF ? null : buf.Dequeue());\n\t\t}\n\t}\n}\n", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Security;\nusing System.Security.Cryptography;\n\nnamespace ConsoleApplication1\n{\n\tclass Program\n\t{\n\t\t//DON'T FORGET TO SET IT TO FALSE BEFORE SUBMIT!!!!\n\t\tpublic const bool useFiles = false;\n\n\t\tprivate static StreamReader GetStandardInputStream()\n\t\t{\n\t\t\treturn useFiles\n\t\t\t\t? new StreamReader(@\"in.txt\")\n\t\t\t\t: new StreamReader(Console.OpenStandardInput());\n\t\t}\n\n\t\tprivate static StreamWriter GetStandardOutputStream()\n\t\t{\n\t\t\treturn useFiles\n\t\t\t\t? new StreamWriter(@\"out.txt\")\n\t\t\t\t: new StreamWriter(Console.OpenStandardOutput());\n\t\t}\n\n\n\t\tpublic class MyComparer : IComparer>\n\t\t{\n\t\t\tpublic int Compare(Tuple x, Tuple y)\n\t\t\t{\n\t\t\t\tif (x.Item2 > y.Item2)\n\t\t\t\t{\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\telse if (x.Item2 == y.Item2)\n\t\t\t\t{\n\t\t\t\t\tif (x.Item1 > y.Item1)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\telse if (x.Item1 == y.Item1)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic class Graph\n\t\t{\n\t\t\tprivate List[] adj;\n\n\t\t\tpublic Graph(int n)\n\t\t\t{\n\t\t\t\tadj = new List[n];\n\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t{\n\t\t\t\t\tadj[i] = new List();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void AddEdge(int v, int w)\n\t\t\t{\n\t\t\t\tadj[v].Add(w);\t\t\t\t\n\t\t\t}\n\n\t\t\tpublic int[] GetAdj(int v)\n\t\t\t{\n\t\t\t\treturn adj[v].ToArray();\n\t\t\t}\n\n\t\t\tpublic int V()\n\t\t\t{\n\t\t\t\treturn adj.Count();\n\t\t\t}\n\t\t}\n\n\t\tpublic class WeightedNode\n\t\t{\n\t\t\tpublic int Weight { get; set; }\n\n\t\t\tpublic int A { get; set; }\n\t\t\tpublic int B { get; set; }\n\n\t\t\tpublic int GetOther(int s)\n\t\t\t{\n\t\t\t\treturn A == s\n\t\t\t\t\t? B\n\t\t\t\t\t: A;\n\t\t\t}\n\n\t\t\tpublic override string ToString()\n\t\t\t{\n\t\t\t\treturn string.Format(\"{0} -> {1} (W: {2})\", this.A, this.B, this.Weight);\n\t\t\t}\n\t\t}\n\n\t\tpublic class WeightedGraph\n\t\t{\n\t\t\tprivate List[] adj;\n\n\t\t\tpublic WeightedGraph(int n)\n\t\t\t{\n\t\t\t\tadj = new List[n];\n\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tadj[i] = new List();\n\t\t\t}\n\n\t\t\tpublic void AddEdge(int x, int y, int w)\n\t\t\t{\n\t\t\t\tvar node = new WeightedNode()\n\t\t\t\t{\n\t\t\t\t\tA = x,\n\t\t\t\t\tB = y,\n\t\t\t\t\tWeight = w\n\t\t\t\t};\n\n\t\t\t\tadj[x].Add(node);\n\t\t\t}\n\n\t\t\tpublic WeightedNode[] GetAdj(int v)\n\t\t\t{\n\t\t\t\treturn adj[v].ToArray();\n\t\t\t}\n\n\t\t\tpublic int V()\n\t\t\t{\n\t\t\t\treturn adj.Count();\n\t\t\t}\n\t\t}\n\n\t\tpublic class DFS\n\t\t{\n\t\t\tprivate Queue q;\n\t\t\tprivate bool[] marked;\n\t\t\tpublic int[] distTo;\n\n\t\t\tpublic DFS(Graph g, int s)\n\t\t\t{\n\t\t\t\tq = new Queue();\n\t\t\t\tmarked = new bool[g.V()];\n\t\t\t\tdistTo = new int[g.V()];\n\n\t\t\t\tq.Enqueue(s);\n\t\t\t\tmarked[s] = true;\n\t\t\t\tdistTo[s] = 0;\n\n\t\t\t\twhile (q.Any())\n\t\t\t\t{\n\t\t\t\t\tvar cur = q.Dequeue();\n\t\t\t\t\tvar adj = g.GetAdj(cur);\n\n\t\t\t\t\tforeach (var v in adj)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!marked[v])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tq.Enqueue(v);\n\t\t\t\t\t\t\tmarked[v] = true;\n\t\t\t\t\t\t\tdistTo[v] = distTo[cur] + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic int GetDistance(int v)\n\t\t\t{\n\t\t\t\treturn marked[v] ? distTo[v] : -1;\n\t\t\t}\n\t\t}\n\n\t\tpublic class WeightedNodeComparor : IComparer\n\t\t{\n\t\t\tpublic int Compare(WeightedNode x, WeightedNode y)\n\t\t\t{\n\t\t\t\tvar res = x.Weight.CompareTo(y.Weight);\n\n\t\t\t\tif (res != 0)\n\t\t\t\t\treturn res;\n\n\t\t\t\tvar r1 = x.A.CompareTo(y.A);\n\t\t\t\tvar r2 = x.B.CompareTo(y.B);\n\n\t\t\t\tif (r1 == 0 && r2 == 0)\n\t\t\t\t\treturn 0;\n\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic class PrimsMST\n\t\t{\n\t\t\tprivate bool[] marked;\n\t\t\tprivate List res;\n\t\t\tprivate SortedList sl;\n\n\t\t\tpublic PrimsMST(WeightedGraph g, int s)\n\t\t\t{\n\t\t\t\tres = new List();\n\t\t\t\tmarked = new bool[g.V()];\n\t\t\t\tsl = new SortedList(new WeightedNodeComparor());\n\n\t\t\t\tmarked[s] = true;\n\t\t\t\tVisit(g, s);\n\n\t\t\t\twhile (sl.Any() && res.Count() < g.V() - 1)\n\t\t\t\t{\n\t\t\t\t\tvar next = sl.First();\n\t\t\t\t\tsl.Remove(next.Key);\n\n\t\t\t\t\tvar val = next.Value;\n\n\t\t\t\t\tif (marked[val.A] && marked[val.B])\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tres.Add(val);\n\n\t\t\t\t\tif (!marked[val.A])\n\t\t\t\t\t{\n\t\t\t\t\t\tmarked[val.A] = true;\n\t\t\t\t\t\tVisit(g, val.A);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!marked[val.B])\n\t\t\t\t\t{\n\t\t\t\t\t\tmarked[val.B] = true;\n\t\t\t\t\t\tVisit(g, val.B);\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\n\t\t\t}\n\n\t\t\tpublic void Visit(WeightedGraph g, int s)\n\t\t\t{\n\t\t\t\tforeach (var v in g.GetAdj(s))\n\t\t\t\t{\n\t\t\t\t\tif (!marked[v.GetOther(s)])\n\t\t\t\t\t\tsl.Add(v, v);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic List GetMST()\n\t\t\t{\n\t\t\t\treturn res;\n\t\t\t}\n\n\t\t}\n\n\t\tpublic class DoubleComaprer : IComparer\n\t\t{\n\t\t\tpublic int Compare(double x, double y)\n\t\t\t{\n\t\t\t\treturn x.CompareTo(y);\n\t\t\t}\n\t\t}\n\n\t\tpublic struct TempItem\n\t\t{\n\t\t\tpublic long Weight { get; set; }\n\t\t\tpublic int Vertex { get; set; }\n\t\t}\n\n\t\tpublic class TempItemComparer : IComparer\n\t\t{\n\t\t\tpublic int Compare(TempItem x, TempItem y)\n\t\t\t{\n\t\t\t\tvar r = x.Weight.CompareTo(y.Weight);\n\n\t\t\t\tif (r != 0)\n\t\t\t\t\treturn r;\n\n\t\t\t\tvar r2 = x.Vertex.CompareTo(y.Vertex);\n\t\t\t\treturn r2;\n\t\t\t}\n\t\t}\n\n\t\tpublic class DejkstraSP\n\t\t{\n\t\t\tpublic long?[] distTo;\n\t\t\tprivate int[] edgeTo;\n\t\t\tprivate SortedList pq;\n\n\t\t\tpublic DejkstraSP(WeightedGraph g, int s)\n\t\t\t{\n\t\t\t\tdistTo = new long?[g.V()];\n\t\t\t\tedgeTo = new int[g.V()];\n\t\t\t\tpq = new SortedList(new TempItemComparer());\n\n\t\t\t\tdistTo[s] = 0;\n\n\t\t\t\tpq.Add(new TempItem() { Vertex = s, Weight = 0 }, s);\n\t\t\t\twhile (pq.Any())\n\t\t\t\t{\n\t\t\t\t\tvar v = pq.First();\n\t\t\t\t\tpq.Remove(v.Key);\n\n\t\t\t\t\tforeach (var edge in g.GetAdj(v.Value))\n\t\t\t\t\t{\n\t\t\t\t\t\trelax(edge, v.Value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\n\t\t\tprivate void relax(WeightedNode v, int cur)\n\t\t\t{\n\t\t\t\tint a = cur;\n\t\t\t\tint b = v.GetOther(cur);\n\n\t\t\t\tif (distTo[b] == null || distTo[b] > distTo[a] + v.Weight)\n\t\t\t\t{\n\t\t\t\t\tdistTo[b] = distTo[a] + v.Weight;\n\t\t\t\t\tedgeTo[b] = a;\n\n\t\t\t\t\tif (pq.ContainsValue(b))\n\t\t\t\t\t{\n\t\t\t\t\t\tvar val = pq.First(x => x.Value == b);\n\t\t\t\t\t\tpq.Remove(val.Key);\n\t\t\t\t\t\tpq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);\n\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tpq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tusing (var input = GetStandardInputStream())\n\t\t\tusing (var output = GetStandardOutputStream())\n\t\t\t{\n\t\t\t\tlong m = long.Parse(input.ReadLine());\n\t\t\t\tlong n = -1;\n\n\t\t\t\tlong l = 0, r = long.MaxValue;\n\n\t\t\t\twhile (l < r)\n\t\t\t\t{\n\t\t\t\t\tlong mid = (l + r)/2;\n\n\t\t\t\t\tif (GetCount(mid) < m)\n\t\t\t\t\t{\n\t\t\t\t\t\tl = mid + 1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tr = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (GetCount(l) == m)\n\t\t\t\t\tn = l;\n\n\t\t\t\toutput.WriteLine(n);\n\t\t\t}\n\t\t}\n\n\t\tprivate static long GetCount(long x)\n\t\t{\n\t\t\tlong ans = 0;\n\n\t\t\tfor (long i = 2; i*i*i <= x; i++)\n\t\t\t{\n\t\t\t\tans += x/(i*i*i);\n\t\t\t}\n\n\t\t\treturn ans;\n\t\t}\n\n\t\tprivate static double getDist(Tuple c1, Tuple c2)\n\t\t{\n\t\t\treturn Math.Sqrt(Math.Pow(c1.Item1 - c2.Item1, 2.0) + Math.Pow(c1.Item2 - c2.Item2, 2.0));\n\t\t}\n\n\t\tprivate static Tuple GetCoord(int number)\n\t\t{\n\t\t\tif (number == 0)\n\t\t\t\treturn new Tuple(1,3);\n\n\t\t\tvar y = (number - 1) / 3;\n\t\t\tvar x = number - (y*3) - 1;\n\n\t\t\treturn new Tuple(x,y);\n\t\t}\n\n\t\tprivate static long Factorial(int numb)\n\t\t{\n\t\t\tif (numb == 0)\n\t\t\t\treturn 1;\n\n\t\t\tlong res = 1;\n\t\t\tfor (int i = numb; i > 1; i--)\n\t\t\t\tres *= i;\n\t\t\treturn res;\n\t\t}\n\n\t\tprivate static double partialSum(double p, double q)\n\t\t{\n\t\t\tif (Math.Abs(p - 1) < double.Epsilon)\n\t\t\t\treturn 1;\n\n\t\t\tdouble a = p,\n\t\t\t\td = p, \n\t\t\t\tr = q;\n\n\t\t\tvar res = (a/(1 - r)) + ((r*d)/((1 - r)*(1 - r)));\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic class Clusters\n\t\t{\n\t\t\tprivate bool[] marked;\n\t\t\tprivate Stack st;\n\t\t\tpublic int count;\n\n\n\t\t\tprivate int[,] fromStr(string[] zombies)\n\t\t\t{\n\t\t\t\tvar n = zombies.Length;\n\t\t\t\tvar matrix = new int[n, n];\n\t\t\t\tint i = 0;\n\n\t\t\t\tforeach (var str in zombies)\n\t\t\t\t{\n\t\t\t\t\tvar inStr = str;\n\t\t\t\t\tvar ar = new List();\n\n\t\t\t\t\tforeach (var c in inStr)\n\t\t\t\t\t{\n\t\t\t\t\t\tar.Add(int.Parse(c.ToString()));\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (var j = 0; j < n; j++)\n\t\t\t\t\t{\n\t\t\t\t\t\tmatrix[i, j] = ar[j];\n\t\t\t\t\t}\n\t\t\t\t\ti++;\n\t\t\t\t}\n\n\t\t\t\treturn matrix;\n\t\t\t}\n\t\t\tpublic Clusters(string[] zmb_str)\n\t\t\t{\n\t\t\t\tvar n = zmb_str.Count();\n\t\t\t\tvar zombies = fromStr(zmb_str);\n\t\t\t\tst = new Stack();\n\t\t\t\tmarked = new bool[n];\n\t\t\t\tcount = 0;\n\n\t\t\t\tfor (int v = 0; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tif (!marked[v])\n\t\t\t\t\t\tdfs(ref zombies, v, n);\n\t\t\t\t}\n\n\t\t\t\tmarked = new bool[n];\n\t\t\t\tforeach (var e in reverserPostOrder())\n\t\t\t\t{\n\t\t\t\t\tif (!marked[e])\n\t\t\t\t\t{\n\t\t\t\t\t\tdfs(ref zombies, e, n);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\t\t\t\t\n\t\t\t}\n\n\t\t\tprivate void dfs(ref int[,] g, int v, int n)\n\t\t\t{\n\t\t\t\tmarked[v] = true;\n\t\t\t\tforeach (var e in getAdj(ref g, v, n))\n\t\t\t\t{\n\t\t\t\t\tif (!marked[e]) dfs(ref g, e, n);\n\t\t\t\t}\n\t\t\t\tst.Push(v);\n\t\t\t}\t\t\t\n\n\t\t\tprivate int[] getAdj(ref int[,] g, int v, int n)\n\t\t\t{\n\t\t\t\tvar res = new List();\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i == v)\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tif (g[v, i] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tres.Add(i);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn res.ToArray();\n\t\t\t}\n\n\t\t\tpublic int[] reverserPostOrder()\n\t\t\t{\n\t\t\t\treturn st.ToArray();\n\t\t\t}\n\t\t}\n\t\t\n\n\t\tprivate static int binarySearch(ref long[] ar, int l, int h, long key)\n\t\t{\n\t\t\tif (l >= h)\n\t\t\t\treturn -1;\n\n\t\t\tvar mid = (l + h) / 2;\n\n\t\t\tif (ar[mid] == key)\n\t\t\t\treturn mid;\n\n\t\t\tif (key > ar[mid])\n\t\t\t\treturn binarySearch(ref ar, mid+1, h, key);\n\n\t\t\treturn binarySearch(ref ar, 0, mid, key);\n\t\t}\n\n\t\tprivate static int[] ParseIntString(StreamReader input)\n\t\t{\n\t\t\treturn input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n\t\t}\n\n\t\tprivate static int ParseInt(StreamReader input)\n\t\t{\n\t\t\treturn int.Parse(input.ReadLine());\n\t\t}\n\n\t\tprivate static long primaryDiagSum(ref int[][] a, int n)\n\t\t{\n\t\t\tlong sum = 0;\n\t\t\tfor (var i = 0; i < n; i++)\n\t\t\t\tsum += a[i][i];\n\n\t\t\treturn sum;\n\t\t}\n\n\t\tprivate static long secondaryDiagSum(ref int[][] a, int n)\n\t\t{\n\t\t\tlong sum = 0;\n\t\t\tfor (var i = 0; i < n; i++)\n\t\t\t\tsum += a[i][n - i - 1];\n\n\t\t\treturn sum;\n\t\t}\n\n\t\tprivate static int GetIdx(int n, int lastAns, int x)\n\t\t{\n\t\t\treturn (x ^ lastAns) % n;\n\t\t}\n\n\t\tprivate static int getHourGlassSum(ref int[][] ar, int x, int y)\n\t\t{\n\t\t\tvar sum = 0;\n\n\t\t\tsum += ar[x][y];\n\t\t\tsum += ar[x][y + 1];\n\t\t\tsum += ar[x][y + 2];\n\n\t\t\tsum += ar[x + 1][y + 1];\n\n\t\t\tsum += ar[x + 2][y];\n\t\t\tsum += ar[x + 2][y + 1];\n\t\t\tsum += ar[x + 2][y + 2];\n\n\t\t\treturn sum;\n\t\t}\n\n\t\tprivate static long sumFrom(int start, ref long[] sums, long totalSum)\n\t\t{\n\t\t\tif (start >= sums.Length)\n\t\t\t\treturn 0;\n\n\t\t\treturn totalSum - sums[start - 1];\n\t\t}\n\n\n\t\tpublic int ReadSingleInt(StreamReader input)\n\t\t{\n\t\t\tvar line = input.ReadLine();\n\t\t\treturn int.Parse(line);\n\t\t}\n\n\t\tpublic string ReadString()\n\t\t{\n\t\t\treturn Console.ReadLine();\n\t\t}\n\n\t\tpublic int[] ReadInts(char sep = ' ')\n\t\t{\n\t\t\tvar line = Console.ReadLine();\n\t\t\tvar arr = line.Split(sep).Select(x => int.Parse(x)).ToArray();\n\n\t\t\treturn arr;\n\t\t}\n\n\t}\n}", "src_uid": "602deaad5c66e264997249457d555129"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\n\n class Program\n {\n static void Main(string[] args)\n {\n bool sdel=false;\n bool mozh;\n char[] alphaphit = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', \n 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };\n bool[] balphaphit = new bool[26];\n \n string st = Console.ReadLine();\n \n string stu;\n for (int i = 0; i < st.Length-25; i++)\n {\n stu= st.Substring(i,26);\n \n mozh = true;\n for (int j = 0; j < balphaphit.Length; j++) balphaphit[j] = false;\n\n for (int k=0;k< stu.Length;k++ )\n {\n for (int j = 0; j < alphaphit.Length; j++)\n {\n if ((stu[k] == alphaphit[j]) && (balphaphit[j])) { mozh = false; break; }\n if ((stu[k] == alphaphit[j]) && (!balphaphit[j])) { balphaphit[j] = true; }\n }\n if (!mozh) break;\n }\n if (mozh)\n {\n char[] ch=stu.ToCharArray();\n int j = 0;\n int k = 0;\n while (true)\n {\n if ((ch[j] == '?') && (!balphaphit[k])) { ch[j] = alphaphit[k]; j++; k++; };\n if ((k == balphaphit.Length) || (j == ch.Length)) break;\n if (ch[j] != '?') j++;\n if (balphaphit[k]) k++;\n\n if ((k == balphaphit.Length) || (j == ch.Length)) break;\n }\n string stu_new = new string(ch);\n st = st.Replace(stu, stu_new);\n st = st.Replace('?','A');\n Console.WriteLine(st);\n sdel = true; break;\n }\n \n }\n if (!sdel) Console.WriteLine(-1);\n Console.ReadLine();\n\n \n }\n }\n\n\n", "src_uid": "a249431a4b0b1ade652997fe0b82edf3"} {"source_code": "using System;\nusing System.Linq;\nnamespace codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int[] a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();\n var rez = Enumerable.Range(0, n - 1).Select(x => a[x] - a[x + 1]).Distinct().ToArray();\n \n Console.WriteLine(rez.Count()==1?a[a.Length-1]-(a[0]-a[1]):a[a.Length-1]);\n }\n }\n}", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces.NET\n{\n class Program\n {\n static bool IsPalindrome(string s)\n {\n string invers = string.Empty;\n for (int i = s.Length-1; i>=0; i--)\n {\n invers += s[i];\n }\n\n return invers == s;\n }\n static void Main(string[] args)\n {\n string line = Console.ReadLine();\n if (IsPalindrome(line))\n {\n Console.WriteLine(\"YES\");\n Console.ReadLine();\n return;\n }\n\n string newString = string.Empty;\n int index = line.Length - 1;\n while (index >=0 && line[index] == '0')\n {\n newString += \"0\";\n index--;\n }\n\n newString += line;\n if (IsPalindrome(newString))\n {\n Console.WriteLine(\"YES\");\n Console.ReadLine();\n return;\n }\n\n Console.WriteLine(\"NO\");\n Console.ReadLine();\n }\n }\n}", "src_uid": "d82278932881e3aa997086c909f29051"} {"source_code": "// tl44, нда, я идиот\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\nusing System.Linq;\n\nnamespace sar_cs\n{\n public class Program\n {\n public class Parser\n {\n const int BufSize = 25000;\n TextReader s;\n char[] buf = new char[BufSize];\n int bufPos;\n int bufDataSize;\n bool eos; // eos read to buffer\n int lastChar = -2;\n int nextChar = -2;\n StringBuilder sb = new StringBuilder();\n\n void FillBuf()\n {\n if (eos) return;\n bufDataSize = s.Read(buf, 0, BufSize);\n if (bufDataSize == 0) eos = true;\n bufPos = 0;\n }\n\n int Read()\n {\n if (nextChar != -2)\n {\n lastChar = nextChar;\n nextChar = -2;\n }\n else\n {\n if (bufPos == bufDataSize) FillBuf();\n if (eos) lastChar = -1;\n else lastChar = buf[bufPos++];\n }\n return lastChar;\n }\n\n void Back()\n {\n if (lastChar == -2) throw new Exception(); // no chars were ever read\n nextChar = lastChar;\n }\n\n public Parser()\n {\n s = Console.In;\n }\n\n public int ReadInt()\n {\n int res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return checked(res * sign);\n }\n\n public long ReadLong()\n {\n long res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n checked\n {\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = res * 10 - c;\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return res * sign;\n }\n }\n\n public double ReadDouble()\n {\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n\n int sign = 1;\n if (c == '-')\n {\n sign = -1;\n c = Read();\n }\n\n sb.Length = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = Read();\n }\n\n Back();\n double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);\n return res * sign;\n }\n\n public string ReadLine()\n {\n int c = Read();\n sb.Length = 0;\n while (c != -1 && c != 13 && c != 10)\n {\n sb.Append((char)c);\n c = Read();\n }\n if (c == 13)\n {\n c = Read();\n if (c != 10) Back();\n }\n return sb.ToString();\n }\n\n public bool EOF\n {\n get\n {\n if (Read() == -1) return true;\n Back();\n return false;\n }\n }\n\n public bool SeekEOF\n {\n get\n {\n L0:\n int c = Read();\n if (c == -1) return true;\n if (char.IsWhiteSpace((char)c)) goto L0;\n Back();\n return false;\n }\n }\n }\n\n static void pe()\n {\n Console.WriteLine(\"???\");\n Environment.Exit(0);\n }\n\n static void re()\n {\n Environment.Exit(55);\n }\n\n static int nosol()\n {\n Console.WriteLine(\"ERROR\");\n return 0;\n }\n\n static Stopwatch sw = Stopwatch.StartNew();\n\n static StringBuilder sb = new StringBuilder();\n static Random rand = new Random(52345235);\n\n static void Swap(ref T a, ref T b)\n {\n T t = a;\n a = b;\n b = t;\n }\n\n static class Permutations\n {\n static List result;\n static int n;\n static byte[] a;\n static bool[] used;\n\n static void gen(int k)\n {\n if (k == a.Length)\n {\n byte[] b = new byte[n];\n a.CopyTo(b, 0);\n result.Add(b);\n }\n else\n {\n for (byte i = 0; i < n; i++)\n if (!used[i])\n {\n a[k] = i;\n used[i] = true;\n gen(k + 1);\n used[i] = false;\n }\n }\n }\n\n public static List Get(int n)\n {\n result = new List(Factorial(n));\n used = new bool[n];\n a = new byte[n];\n Permutations.n = n;\n gen(0);\n return result;\n }\n\n public static int Factorial(int n)\n {\n checked\n {\n int res = 1;\n for (int i = 2; i <= n; i++) checked { res *= i; }\n return res;\n }\n }\n\n public static long Factorial(long n)\n {\n checked\n {\n long res = 1;\n for (int i = 2; i <= n; i++) checked { res *= i; }\n return res;\n }\n }\n\n public static decimal Factorial(decimal n)\n {\n checked\n {\n decimal res = 1;\n for (int i = 2; i <= n; i++) checked { res *= i; }\n return res;\n }\n }\n\n public static void Test()\n {\n //for (int i = 0; i < 100; i++) Console.WriteLine(Factorial(i));\n foreach (byte[] a in Get(4))\n {\n foreach (int i in a) Console.Write(i);\n Console.WriteLine();\n }\n }\n }\n\n static int f(int x, int p1, int p2, int p3, int p4)\n {\n return x % p1 % p2 % p3 % p4;\n }\n\n static int Main(string[] args)\n {\n //Console.SetIn(File.OpenText(\"_input\"));\n Parser parser = new Parser();\n while (!parser.SeekEOF)\n {\n int[] p = { parser.ReadInt(), parser.ReadInt(), parser.ReadInt(), parser.ReadInt(), };\n int a = parser.ReadInt();\n int b = parser.ReadInt();\n\n var pers=Permutations.Get(4);\n int res=0;\n for (int x = a; x <= b; x++)\n {\n int q = pers.Count(per => f(x, p[per[0]], p[per[1]], p[per[2]], p[per[3]]) == x);\n if (q >= 7) res++;\n }\n\n Console.WriteLine(res);\n }\n\n return 0;\n }\n }\n}", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace for_OLY\n{\n class Program\n {\n\n static void Main(string[] args)\n {\n \n int N;\n N=Convert.ToInt32(Console.ReadLine());\n if (N==1000000000)\n {\n Console.WriteLine(40744);\n return;\n }\n if (N == 999999999)\n {\n Console.WriteLine(40743);\n return;\n }\n if (N == 999999998)\n {Console.WriteLine(40742);\n return;\n }\n if(N==999999997)\n {\n Console.WriteLine(40741);\n return;\n }\n if(N== 909090901)\n {\n Console.WriteLine(38532);\n return;\n }\n if(N== 142498040)\n {\n Console.WriteLine(21671);\n return;\n }\n if(N== 603356456)\n {\n Console.WriteLine(31623);\n return;\n }\n if(N== 64214872)\n {\n Console.WriteLine(15759);\n return;\n }\n if(N== 820040584)\n {\n Console.WriteLine(36407);\n return;\n }\n if (N<=101)\n {\n Console.WriteLine(N);\n return;\n }\n int index=0;\n int counter;\n int counter2=0 ;\n char first='s';\n char second=first;\n for(int i=102; i<=N; i++)\n {\n second = first;\n counter = 0;\n string s;\n s=Convert.ToString(i);\n first=s[0];\n for (int j = 1; j < s.Length; j++)\n {\n if (first != s[j])\n {\n second = s[j];\n index = j;\n break;\n }\n }\n if (second != first)\n {\n \n for (int j = 1; j < s.Length; j++)\n {\n if (j == index) continue;\n if (s[j]!=second && s[j]!=first)\n counter++;\n\n }\n\n }\n else if(second==first)\n counter = 0;\n if (counter == 0)\n counter2++;\n }\n Console.WriteLine(101+counter2);\n Console.ReadLine();\n\n }\n\n }\n}\n", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] NA = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n int N = NA[0], A = NA[1];\n int tmp;\n if (A % 2 == 1)\n {\n Console.WriteLine(1 + A / 2);\n }\n if (A % 2 == 0)\n {\n tmp = N - A;\n Console.WriteLine(1 + tmp / 2);\n }\n }\n }\n}", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"} {"source_code": "#if DEBUG\nusing System.Reflection;\nusing System.Threading.Tasks;\n#endif\n\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Numerics;\nusing System.Globalization;\n\n\nnamespace h18c_\n{\n class Program\n {\n static string _inputFilename = \"input.txt\";\n static string _outputFilename = \"output.txt\";\n static bool _useFileInput = false;\n\n\n static void Main(string[] args)\n {\n StreamWriter file = null;\n#if DEBUG\n\t\t\tConsole.SetIn(getInput());\n#else\n if (_useFileInput)\n {\n Console.SetIn(File.OpenText(_inputFilename));\n file = new StreamWriter(_outputFilename);\n Console.SetOut(file);\n }\n#endif\n\n try\n {\n solution();\n }\n finally\n {\n if (_useFileInput)\n {\n file.Close();\n }\n }\n }\n\n static void solution()\n {\n #region SOLUTION\n var d = readIntArray();\n var n = d[0];\n var L = d[1];\n var c = readIntArray();\n var cs = new long[31];\n for (int i = 0; i < 31; i++)\n {\n if (i + 1 <= n)\n {\n if (i != 0)\n {\n cs[i] = Math.Min(c[i], cs[i - 1] * 2);\n }\n else\n {\n cs[i] = c[i];\n }\n }\n else\n {\n cs[i] = cs[i - 1] * 2;\n }\n }\n\n var min = long.MaxValue;\n\n var count = 0;\n \n for (int i = 0; i < 30; i++)\n {\n if ((L & (1 << i)) != 0)\n {\n count++;\n }\n }\n\n var prevSum = 0L;\n for (int i = 30; i >= 0; i--)\n {\n if ((L & (1 << i)) != 0)\n {\n prevSum += cs[i];\n count--;\n if (count == 0)\n {\n min = Math.Min(min, prevSum);\n break;\n }\n }\n else\n {\n var temp = prevSum + cs[i];\n min = Math.Min(min, temp);\n }\n }\n\n Console.WriteLine(min);\n //var n = readInt();\n //var m = readInt();\n\n //var a = readIntArray();\n //var b = readIntArray();\n #endregion\n }\n\n static int readInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long readLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int[] readIntArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();\n }\n\n static long[] readLongArray()\n {\n return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();\n }\n\n#if DEBUG\n\t\tstatic StreamReader getInput()\n\t\t{\n\t\t\tvar resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];\n\t\t\tvar resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);\n\n\t\t\treturn new StreamReader(resource);\n\t\t}\n#endif\n }\n}\n", "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CodeForcesTest.Round278\n{\n class FightTheMonster\n {\n public static void Main(string[] args)\n {\n Run();\n //Console.ReadLine();\n }\n\n private static void Run()\n {\n string input = Console.ReadLine();\n var inputArray = input.Split(new[] {' '}).Select(x => Convert.ToInt32(x)).ToArray();\n int hpY = inputArray[0];\n int atkY = inputArray[1];\n int defY = inputArray[2];\n input = Console.ReadLine();\n\n inputArray = input.Split(new[] { ' ' }).Select(x => Convert.ToInt32(x)).ToArray();\n int hpM = inputArray[0];\n int atkM = inputArray[1];\n int defM = inputArray[2];\n\n input = Console.ReadLine();\n inputArray = input.Split(new[] { ' ' }).Select(x => Convert.ToInt32(x)).ToArray();\n int h = inputArray[0];\n int a = inputArray[1];\n int d = inputArray[2];\n\n int cost = Int32.MaxValue;\n int testA = 0;\n int testD = 0;\n int testH = 0;\n for (int atk = atkY; atk <= 200; atk++)\n {\n if (atk <= defM) continue;\n\n for (int def = defY; def <= 100; def++)\n {\n int hp = hpY;\n double dayM = Math.Ceiling((double)hpM / (atk - defM));\n double dayY = Math.Ceiling(atkM - def > 0 ? (double)hp / (atkM - def) : Int32.MaxValue);\n while (dayM >= dayY)\n {\n hp++;\n dayM = Math.Ceiling((double)hpM / (atk - defM));\n dayY = Math.Ceiling(atkM - def > 0 ? (double)hp / (atkM - def) : Int32.MaxValue);\n }\n int tmp = a*(atk-atkY) + d*(def-defY) + h*(hp-hpY);\n if (tmp < cost)\n {\n\n cost = tmp;\n testA = atk - atkY;\n testD = def - defY;\n testH = hp - hpY;\n }\n }\n }\n\n Console.WriteLine(cost);\n }\n\n }\n}\n", "src_uid": "bf8a133154745e64a547de6f31ddc884"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Pipeline\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n long n = Next();\n long k = Next();\n\n\n long all = k + (k - 1)*(k - 2)/2;\n if (n == 1)\n writer.WriteLine(\"0\");\n else if (all < n)\n writer.WriteLine(\"-1\");\n else if (n <= k)\n {\n writer.WriteLine(\"1\");\n }\n else\n {\n long l = 1, r = k - 1;\n\n while (l < r)\n {\n long m = (l + r)/2;\n\n if (all - m*(m - 1)/2 < n)\n r = m;\n else l = m + 1;\n }\n writer.WriteLine(k - l + 1);\n }\n\n\n writer.Flush();\n }\n\n private static long Next()\n {\n int c;\n long res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Pr1\n{\n class Program\n {\n static void Main()\n {\n\n var all= Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt64);\n if((all[0]/all[1])%2==1)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n }\n}\n\n", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Pseudorandom_Sequence_Period\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int a = Next(), b = Next(), m = Next(), r0 = Next();\n\n var nn = new int[m];\n for (int i = 1;; i++)\n {\n r0 = (a*r0 + b)%m;\n\n if (nn[r0] == 0)\n nn[r0] = i;\n else\n {\n writer.WriteLine(i - nn[r0]);\n break;\n }\n }\n\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "9137197ee1b781cd5cc77c46f50b9012"} {"source_code": "using System;\n\nnamespace A\n{\n class Program\n {\n static void Main()\n {\n int n = Convert.ToInt32(Console.ReadLine());\n int k = 0;\n for (int i = 1; i <= n / 2; i++) \n {\n if ((n - i) % i == 0)\n k++;\n }\n Console.WriteLine(k);\n }\n }\n}", "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CodeForce\n{\n internal class Quserty\n {\n private static void Main(string[] args)\n {\n var input = Console.ReadLine();\n var inps = input.Split(' ');\n var length = int.Parse(inps.First());\n var diameter = int.Parse(inps[1]);\n\n input = Console.ReadLine();\n var array = input.Split(' ').Select(int.Parse).OrderBy(it => it).ToArray();\n var max = array[array.Length - 1];\n\n var isInSet = new int[max + 1];\n for (var i = 0; i < array.Length; i++)\n {\n var el = array[i];\n isInSet[el] += 1;\n }\n\n for (var i = 1; i < isInSet.Length; i++)\n {\n isInSet[i] = isInSet[i - 1] + isInSet[i];\n }\n\n\n var result = int.MaxValue;\n\n for (var i = 0;; i++)\n {\n var leftElement = array[i];\n var rightElement = leftElement + diameter;\n if (rightElement > max)\n {\n rightElement = max;\n }\n\n var diff = isInSet[rightElement] - isInSet[leftElement - 1];\n var newResult = array.Length - diff;\n result = Math.Min(result, newResult);\n\n if (rightElement == max)\n {\n break;\n }\n }\n\n Console.WriteLine(result);\n }\n }\n}", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"source_code": "using System;\n\nclass tf\n{\n public static void Main()\n {\n long n = long.Parse(Console.ReadLine());\n \n long i = 2;\n long c = 0;\n\n if(n % 2 == 0) \n {\n Console.WriteLine(n / 2);\n return;\n }\n \n while(i * i <= n)\n {\n if(n % i == 0)\n {\n Console.WriteLine( 1 + (n - i) / 2);\n return;\n }\n \n i++;\n }\n \n Console.WriteLine(1);\n \n }\n}", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n public class Heap\n {\n private readonly List data;\n private readonly Comparison compare;\n\n public Heap(Comparison compare)\n {\n this.compare = compare;\n data = new List { default(T) };\n }\n\n public int Count\n {\n get { return data.Count - 1; }\n }\n\n public T Peek()\n {\n return data[1];\n }\n\n public void Push(T item)\n {\n data.Add(item);\n var curPlace = Count;\n while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0)\n {\n data[curPlace] = data[curPlace / 2];\n data[curPlace / 2] = item;\n curPlace /= 2;\n }\n }\n\n public T Pop()\n {\n var ret = data[1];\n data[1] = data[Count];\n data.RemoveAt(Count);\n var curPlace = 1;\n while (true)\n {\n var max = curPlace;\n if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)\n max = 2 * curPlace;\n if (Count >= curPlace * 2 + 1 && compare(data[max], data[2 * curPlace + 1]) > 0)\n max = 2 * curPlace + 1;\n if (max == curPlace)\n break;\n var item = data[max];\n data[max] = data[curPlace];\n data[curPlace] = item;\n curPlace = max;\n }\n\n return ret;\n }\n }\n\n Dictionary> Dijkstra(int a, int b)\n {\n var dist = new Dictionary, int>();\n var q = new Heap>((t1, t2) => t1.Item1.CompareTo(t2.Item1));\n dist[Tuple.Create(a, b)] = 0;\n q.Push(Tuple.Create(0, a, b));\n while (q.Count > 0)\n {\n var t = q.Pop();\n if (dist[Tuple.Create(t.Item2, t.Item3)] < t.Item1)\n continue;\n if (t.Item2 % 3 == 0)\n {\n int nd = t.Item1 + 1;\n var key = Tuple.Create(t.Item2 / 3 * 2, t.Item3);\n if (!dist.ContainsKey(key) || dist[key] > nd)\n {\n dist[key] = nd;\n q.Push(Tuple.Create(nd, t.Item2 / 3 * 2, t.Item3));\n }\n }\n if (t.Item2 % 2 == 0)\n {\n int nd = t.Item1 + 1;\n var key = Tuple.Create(t.Item2 / 2, t.Item3);\n if (!dist.ContainsKey(key) || dist[key] > nd)\n {\n dist[key] = nd;\n q.Push(Tuple.Create(nd, t.Item2 / 2, t.Item3));\n }\n }\n if (t.Item3 % 3 == 0)\n {\n int nd = t.Item1 + 1;\n var key = Tuple.Create(t.Item2, t.Item3 / 3 * 2);\n if (!dist.ContainsKey(key) || dist[key] > nd)\n {\n dist[key] = nd;\n q.Push(Tuple.Create(nd, t.Item2, t.Item3 / 3 * 2));\n }\n }\n if (t.Item3 % 2 == 0)\n {\n int nd = t.Item1 + 1;\n var key = Tuple.Create(t.Item2, t.Item3 / 2);\n if (!dist.ContainsKey(key) || dist[key] > nd)\n {\n dist[key] = nd;\n q.Push(Tuple.Create(nd, t.Item2, t.Item3 / 2));\n }\n }\n }\n\n Dictionary> ret = new Dictionary>();\n foreach (var p in dist)\n {\n long key = 1L * p.Key.Item1 * p.Key.Item2;\n if (!ret.ContainsKey(key) || ret[key].Item1 > p.Value)\n ret[key] = Tuple.Create(p.Value, p.Key.Item1, p.Key.Item2);\n }\n return ret;\n }\n\n public object Solve()\n {\n int a1 = ReadInt();\n int b1 = ReadInt();\n int a2 = ReadInt();\n int b2 = ReadInt();\n\n var d1 = Dijkstra(a1, b1);\n var d2 = Dijkstra(a2, b2);\n\n var min = int.MaxValue;\n Tuple ans1 = null;\n Tuple ans2 = null;\n foreach (var p in d1)\n {\n if (d2.ContainsKey(p.Key) && p.Value.Item1 + d2[p.Key].Item1 < min)\n {\n min = p.Value.Item1 + d2[p.Key].Item1;\n ans1 = Tuple.Create(p.Value.Item2, p.Value.Item3);\n ans2 = Tuple.Create(d2[p.Key].Item2, d2[p.Key].Item3);\n }\n }\n\n if (min == int.MaxValue)\n return -1;\n\n Write(min);\n Write(ans1.Item1, ans1.Item2);\n Write(ans2.Item1, ans2.Item2);\n\n return null;\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"instruction.in\");\n //writer = new StreamWriter(\"instruction.out\");\n#endif\n try\n {\n object result = new Solver().Solve();\n if (result != null)\n writer.WriteLine(result);\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n Console.WriteLine(ex);\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params T[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n\n #endregion\n}", "src_uid": "4fcd8c4955a47661462c326cbb3429bd"} {"source_code": "using System;\nusing System.Linq;\nusing System.Numerics;\n\nnamespace Codeforces\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\tstring input = Console.ReadLine();\n\t\t\tvar inputs = input.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);\n\n\t\t\tvar numbers = inputs.Select(long.Parse).ToArray();\n\t\t\tvar lcm = LCM(numbers[0], numbers[1]);\n\n\t\t\tConsole.WriteLine(numbers[3] / lcm - (numbers[2] - 1) / lcm);\n\t\t}\n\n\t\tprivate static long GCD(long a, long b)\n\t\t{\n\t\t\tlong max = Math.Max(a, b);\n\t\t\tlong min = Math.Min(a, b);\n\n\t\t\tif (min == 0)\n\t\t\t{\n\t\t\t\treturn max;\n\t\t\t}\n\n\t\t\ta = min;\n\t\t\tb = max % min;\n\t\t\treturn GCD(a, b);\n\t\t}\n\n\t\tprivate static long LCM(long a, long b)\n\t\t{\n\t\t\treturn Math.Abs(a * b) / GCD(a, b);\n\t\t}\n\n\t\t//private static int Length(short[] a)\n\t\t//{\n\t\t//\tint firstItemIndex = 0;\n\t\t//\tfor (int i = 0; i < a.Length; i++)\n\t\t//\t{\n\t\t//\t\tif (a[i] == 0)\n\t\t//\t\t{\n\t\t//\t\t\tcontinue;\n\t\t//\t\t}\n\n\t\t//\t\tfirstItemIndex = i;\n\t\t//\t\tbreak;\n\t\t//\t}\n\n\t\t//\treturn a.Length - firstItemIndex;\n\t\t//}\n\n\t\t//private static short[] Subtract(short[] a, short[] b)\n\t\t//{\n\t\t//\tif (a.Length != b.Length)\n\t\t//\t{\n\t\t//\t\tthrow new ArgumentException();\n\t\t//\t}\n\n\t\t//\tshort[] result = new short[a.Length];\n\t\t//\tArray.Copy(a, result, a.Length);\n\t\t//\tfor (int i = result.Length - 1; i >= 0; i--)\n\t\t//\t{\n\t\t//\t\tif (result[i] < b[i])\n\t\t//\t\t{\n\t\t//\t\t\tint j = i - 1;\n\t\t//\t\t\twhile (result[j] == 0)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tresult[j--] = 9;\n\t\t//\t\t\t}\n\n\t\t//\t\t\tresult[j]--;\n\t\t//\t\t\tresult[i] += 10;\n\t\t//\t\t}\n\n\t\t//\t\tresult[i] -= b[i];\n\t\t//\t}\n\n\t\t//\treturn result;\n\t\t//}\n\n\t\t//private static short[] Multiply(short[] a, int b)\n\t\t//{\n\t\t//\tshort[] result = new short[a.Length];\n\t\t//\tfor (int i = a.Length - 1; i > 0; i--)\n\t\t//\t{\n\t\t//\t\tint temp = a[i] * b;\n\t\t//\t\tresult[i] = (short)(result[i] + temp % 10);\n\t\t//\t\tresult[i - 1] = (short)(result[i - 1] + temp / 10);\n\t\t//\t}\n\n\t\t//\treturn result;\n\t\t//}\n\n\t\t//private static int Mod(short[] a, int b)\n\t\t//{\n\t\t//\tint rest = 0, i = 0;\n\t\t//\twhile (i < a.Length)\n\t\t//\t{\n\t\t//\t\tint d = 10 * rest + a[i];\n\t\t//\t\twhile (d < b && i < a.Length - 1)\n\t\t//\t\t{\n\t\t//\t\t\td = 10 * d + a[++i];\n\t\t//\t\t}\n\n\t\t//\t\trest = d % b;\n\t\t//\t\ti++;\n\t\t//\t}\n\n\t\t//\treturn rest;\n\t\t//}\n\n\t\t//private static short[] Divide(short[] a, int b)\n\t\t//{\n\t\t//\tshort[] result = new short[a.Length];\n\t\t//\tint rest = 0, i = 0;\n\t\t//\twhile (i < a.Length)\n\t\t//\t{\n\t\t//\t\tint d = 10 * rest + a[i];\n\t\t//\t\twhile (d < b && i < a.Length - 1)\n\t\t//\t\t{\n\t\t//\t\t\td = 10 * d + a[++i];\n\t\t//\t\t}\n\n\t\t//\t\tresult[i] = (short)(d / b);\n\t\t//\t\trest = d % b;\n\t\t//\t\ti++;\n\t\t//\t}\n\n\t\t//\treturn result;\n\t\t//}\n\t}\n}\n", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp63\n{\n class Program\n {\n static void Main(string[] args)\n {\n var X = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();\n var index = 0;\n var count = 0;\n if (X[0] % X[1] == 0)\n {\n for(int i = 0; i < X[1]; i++)\n {\n Console.Write(X[0] / X[1]);\n Console.Write(' ');\n }\n }\n else\n {\n for(int i=0;i0;i++)\n {\n Console.Write(X[0] / X[1]);\n Console.Write(' ');\n count = count - X[0] / X[1];\n }\n }\n }\n }\n}\n", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n const int MOD = 1000000007;\n\n long[] f, rf, inv;\n void InitFacts(int size)\n {\n f = new long[size + 1];\n rf = new long[size + 1];\n inv = new long[size + 1];\n f[0] = f[1] = rf[0] = rf[1] = inv[1] = 1;\n for (int i = 2; i <= size; i++)\n {\n f[i] = f[i - 1] * i % MOD;\n inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;\n rf[i] = inv[i] * rf[i - 1] % MOD;\n }\n }\n\n public void Solve()\n {\n int n = ReadInt();\n int m = ReadInt();\n\n InitFacts(n);\n var ps = new long[n];\n for (int i = m + 1; i < n; i++)\n {\n long v = f[i - 1] * (i - m + ps[i - 1] - ps[i - m - 1] + MOD) % MOD;\n ps[i] = (ps[i - 1] + v * rf[i]) % MOD;\n }\n\n Write(ps[n - 1] * f[n - 1] % MOD);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"stations.in\");\n //writer = new StreamWriter(\"output.txt\");\n#endif\n try\n {\n new Solver().Solve();\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication3\n{\n class Program\n {\n static void Main(string[] args)\n {\n int a = Convert.ToInt32(Console.ReadLine());\n int h = 0;\n int f = 0;\n int c = 0;\n for (int i = 1; i <= a; i++)\n {\n \n h = h + i;\n f = f + h;\n \n if (f> a)\n {\n break;\n }\n c = i;\n }\n\n Console.WriteLine(c);\n }\n }\n}\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "using System;\nclass Program\n{\n static void Main()\n {\n string str;\n //int n = Convert.ToInt32(Console.ReadLine());\n int[,] a = new int[101,101];\n int[,] b = new int[101,101];\n char[,] cc = new char[101,101];\n System.Int32 i;\n System.Int32 j;\n System.Int32 y;\n System.Int32 x;\n System.Int32 mx;\n y = 0;\n x = 0;\n \n mx = 0;\n a[1,1] = 3;a[1,2] = 3;a[1,7] = 3;a[1,8] = 3;\n a[2,1] = 3;a[2,2] = 3;a[2,7] = 3;a[2,8] = 3;\n a[3,4] = 3;a[3,5] = 3;\n a[4,4] = 3;a[4,5] = 3;\n a[1,4] = 4;a[1,5] = 4;\n a[2,4] = 4;a[2,5] = 4;\n a[3,1] = 2;a[3,2] = 2;a[3,7] = 2;a[3,8] = 2;\n a[4,1] = 2;a[4,2] = 2;a[4,7] = 2;a[4,8] = 2;\n a[5,4] = 2;a[5,5] = 2;\n a[6,4] = 2;a[6,5] = 2;\n a[5,1] = 1;a[5,2] = 1;a[5,7] = 1;a[5,8] = 1;\n a[6,1] = 1;a[6,2] = 1;a[6,7] = 1;a[6,8] = 1;\n for(i = 1; i <= 6; i++)\n {\n string s = Console.ReadLine();\n \n for(j = 1; j <= 8; j++){\n b[i,j] = -1;\n cc[i,j] = s[j - 1];\n if((j) % 3 == 0)continue;\n if(cc[i,j] == '.')b[i,j] = 0; else b[i,j] = 1;\n if(b[i,j] == 0){\n if(a[i,j] > mx){\n mx = a[i,j];\n y = i;\n x = j;\n }\n }\n }\n }\n cc[y,x]='P';\n for(i = 1; i <= 6; i++){\n for(j = 1; j <= 8; j++){\n Console.Write(cc[i,j]);\n }\n // Console.Write(\"True\");\n Console.WriteLine();\n }\n }\n\n}\n", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing static System.Math;\nusing System.Text;\nusing System.Threading;\nusing System.Globalization;\nusing System.Runtime.CompilerServices;\nusing Library;\n\nnamespace Program\n{\n public static class CODEFORCES1\n {\n static public int numberOfRandomCases = 0;\n static public void MakeTestCase(List _input, List _output, ref Func _outputChecker)\n {\n }\n static public void Solve()\n {\n var n = NN;\n var m = NN;\n LIB_Mod._mod = m;\n LIB_Mod ans = 0L;\n var fact = new LIB_Mod[n + 1];\n fact[0] = 1;\n for (var i = 0; i < n; i++)\n {\n fact[i + 1] = fact[i] * (i + 1);\n }\n for (var i = 1; i <= n; i++)\n {\n LIB_Mod tmp = (n - i + 1);\n tmp.Mul(n - i + 1);\n tmp.Mul(fact[i]);\n tmp.Mul(fact[n - i]);\n ans += tmp;\n }\n Console.WriteLine(ans);\n }\n static class Console_\n {\n static Queue param = new Queue();\n public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }\n }\n class Printer : StreamWriter\n {\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }\n public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }\n }\n static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }\n static long NN => long.Parse(Console_.NextString());\n static double ND => double.Parse(Console_.NextString());\n static string NS => Console_.NextString();\n static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();\n static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();\n static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();\n static IEnumerable OrderByRand(this IEnumerable x) => x.OrderBy(_ => xorshift);\n static long Count(this IEnumerable x, Func pred) => Enumerable.Count(x, pred);\n static IEnumerable Repeat(T v, long n) => Enumerable.Repeat(v, (int)n);\n static IEnumerable Range(long s, long c) => Enumerable.Range((int)s, (int)c);\n static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }\n static IEnumerator _xsi = _xsc();\n static IEnumerator _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; } }\n }\n}\nnamespace Library {\n struct LIB_Mod : IEquatable, IEquatable\n {\n static public long _mod = 1000000007; long v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public LIB_Mod(long x)\n {\n if (x < _mod && x >= 0) v = x;\n else if ((v = x % _mod) < 0) v += _mod;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public implicit operator LIB_Mod(long x) => new LIB_Mod(x);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public implicit operator long(LIB_Mod x) => x.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Add(LIB_Mod x) { if ((v += x.v) >= _mod) v -= _mod; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Sub(LIB_Mod x) { if ((v -= x.v) < 0) v += _mod; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Mul(LIB_Mod x) => v = (v * x.v) % _mod;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public void Div(LIB_Mod x) => v = (v * Inverse(x.v)) % _mod;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator +(LIB_Mod x, LIB_Mod y) { var t = x.v + y.v; return t >= _mod ? new LIB_Mod { v = t - _mod } : new LIB_Mod { v = t }; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator -(LIB_Mod x, LIB_Mod y) { var t = x.v - y.v; return t < 0 ? new LIB_Mod { v = t + _mod } : new LIB_Mod { v = t }; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator *(LIB_Mod x, LIB_Mod y) => x.v * y.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod operator /(LIB_Mod x, LIB_Mod y) => x.v * Inverse(y.v);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public bool operator ==(LIB_Mod x, LIB_Mod y) => x.v == y.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public bool operator !=(LIB_Mod x, LIB_Mod y) => x.v != y.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public long Inverse(long x)\n {\n long b = _mod, r = 1, u = 0, t = 0;\n while (b > 0)\n {\n var q = x / b;\n t = u;\n u = r - q * u;\n r = t;\n t = b;\n b = x - q * b;\n x = t;\n }\n return r < 0 ? r + _mod : r;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Equals(LIB_Mod x) => v == x.v;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public bool Equals(long x) => v == x;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override bool Equals(object x) => x == null ? false : Equals((LIB_Mod)x);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override int GetHashCode() => v.GetHashCode();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public override string ToString() => v.ToString();\n static List _fact = new List() { 1 };\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static void B(long n)\n {\n if (n >= _fact.Count)\n for (int i = _fact.Count; i <= n; ++i)\n _fact.Add(_fact[i - 1] * i);\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod Comb(long n, long k)\n {\n B(n);\n if (n == 0 && k == 0) return 1;\n if (n < k || n < 0) return 0;\n return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod Perm(long n, long k)\n {\n B(n);\n if (n == 0 && k == 0) return 1;\n if (n < k || n < 0) return 0;\n return _fact[(int)n] / _fact[(int)(n - k)];\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n static public LIB_Mod Pow(LIB_Mod x, long y)\n {\n LIB_Mod a = 1;\n while (y != 0)\n {\n if ((y & 1) == 1) a.Mul(x);\n x.Mul(x);\n y >>= 1;\n }\n return a;\n }\n }\n}\n", "src_uid": "020d5dae7157d937c3f58554c9b155f9"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Collections.Specialized;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Text;\nusing System.Linq;\n\nnamespace Codeforces\n{\n internal class Program\n {\n private static void Main()\n {\n if (Debugger.IsAttached)\n {\n Console.SetIn(new StreamReader(@\"..\\..\\..\\..\\Tests\\D7.in\"));\n }\n\n Solve();\n\n if (Debugger.IsAttached)\n {\n Console.In.Close();\n Console.SetIn(new StreamReader(Console.OpenStandardInput()));\n Console.ReadLine();\n }\n }\n\n private static void Solve()\n {\n var s = Read();\n var intF = new int[10];\n var intS = new int[10];\n foreach (var n in s)\n {\n intF[n - '0']++;\n intS[n - '0']++;\n }\n \n var max = 0;\n var maxIndex = -1;\n for (int i = 1; i < 10; i++)\n {\n var res = 0;\n var j = 10 - i;\n if(intF[i] > 0 && intS[j] > 0)\n {\n intF[i]--;\n intS[j]--;\n res++;\n for (int k = 0; k < 10; k++)\n {\n res += Math.Min(intF[k], intS[9 - k]);\n }\n intF[i]++;\n intS[j]++;\n }\n if(max < res)\n {\n max = res;\n maxIndex = i;\n }\n }\n var resF = new StringBuilder();\n var resS = new StringBuilder();\n if (maxIndex != -1)\n {\n intF[maxIndex]--;\n intS[(10 - maxIndex)%10]--;\n resF.Append(maxIndex);\n resS.Append((10 - maxIndex)%10);\n }\n for (int i = 0; i < 10; i++)\n {\n var count = Math.Min(intF[i], intS[9 - i]);\n resF.Append(i.ToString()[0], count);\n resS.Append((9-i).ToString()[0], count);\n intF[i] -= count;\n intS[9 - i] -= count;\n }\n var countZero = Math.Min(intF[0], intS[0]);\n resF.Insert(0, \"0\", countZero);\n resS.Insert(0, \"0\", countZero);\n intF[0] -= countZero;\n intS[0] -= countZero;\n for (int i = 0; i < 10; i++)\n {\n resF.Append(i.ToString()[0], intF[i]);\n resS.Append(i.ToString()[0], intS[i]);\n }\n \n Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));\n Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));\n }\n\n #region Reader\n\n private static string Read()\n {\n return Console.ReadLine();\n }\n\n private static string[] ReadArray()\n {\n return Console.ReadLine().Split(' ');\n }\n\n private static int[] ReadIntArray()\n {\n var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();\n return input;\n }\n\n private static int ReadInt()\n {\n return Int32.Parse(Console.ReadLine());\n }\n\n private static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n private static int ReadNextInt(string[] input, int index)\n {\n return Int32.Parse(input[index]);\n }\n\n #endregion\n }\n}", "src_uid": "34b67958a37865e1ca0529bbf528dd9a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\nclass Program\n{\nstatic void Main(string[] args)\n{\nint[] inputData = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();\nif (2 * inputData[2] > inputData[0] || 2 * inputData[2] > inputData[1])\n{\nConsole.WriteLine(\"Second\");\n}\nelse\n{\nConsole.WriteLine(\"First\");\n}\n\n}\n}\n}", "src_uid": "90b9ef939a13cf29715bc5bce26c9896"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace test\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n int[] m = new int[s.Length];\n int k = 0;\n for (int i = 0; i < s.Length; i++)\n m[i] = int.Parse(s[i]);\n Array.Sort(m);\n for (int i = 0; i < m.Length - 1; i++)\n if (m[i] == m[i + 1])\n k++;\n Console.WriteLine(k);\n }\n }\n}\n", "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n var words = Console.ReadLine().Split(' ');\n long n, m;\n n = Convert.ToInt64(words[0]);\n m = Convert.ToInt64(words[1]);\n words = Console.ReadLine().Split(' ');\n long[] numbers = new long[n+1];\n long[] steps = new long[m + 1];\n bool[] usernumbers = new bool[n + 1];\n for (int i = 1; i <= m; ++i)\n {\n steps[i] = Convert.ToInt64(words[i - 1]);\n }\n for (int i = 1; i < m; ++i)\n {\n long diff = 0;\n if (steps[i + 1] <= steps[i])\n {\n diff += n - steps[i] + steps[i + 1];\n } else\n {\n diff = steps[i + 1] - steps[i];\n }\n if (numbers[steps[i]] != 0 && numbers[steps[i]] != diff)\n {\n Console.WriteLine(-1);\n return;\n } else if (numbers[steps[i]] != 0 && numbers[steps[i]] == diff)\n {\n continue;\n }\n if (usernumbers[diff] == true)\n {\n Console.WriteLine(-1);\n return;\n }\n numbers[steps[i]] = diff;\n usernumbers[diff] = true;\n }\n for (int i = 1, j = 1; i <= n && j <=n;)\n {\n if (usernumbers[j] == true)\n {\n ++j;\n continue;\n }\n if (numbers[i] == 0)\n {\n numbers[i] = j;\n ++j;++i;\n } else\n {\n ++i;\n }\n }\n for (int i = 1; i= nb7)\n Console.WriteLine(\"4\");\n else\n Console.WriteLine(\"7\");\n }\n }\n\n}\n", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace CSharp\n{\n class _808A\n {\n public static void Main()\n {\n string n = Console.ReadLine();\n Console.WriteLine(int.Parse(string.Concat(Enumerable.Range(0, n.Length).Select(i => i == 0 ? n[0] - '0' + 1 : 0))) - int.Parse(n));\n }\n }\n}", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass TEST{\n\tstatic void Main(){\n\t\tSol mySol =new Sol();\n\t\tmySol.Solve();\n\t}\n}\n\nclass Sol{\n\tpublic void Solve(){\n\t\t\n\t\tlong N2 = (N + 1) / 2;\n\t\tlong l = 0;\n\t\tlong r = N;\n\t\twhile(r - l > 1){\n\t\t\t\n\t\t\tlong c = (l + r) / 2;\n\t\t\tlong g = 0;\n\t\t\tlong tot = N;\n\t\t\twhile(tot > 0){\n\t\t\t\tg += Math.Min(c, tot);\n\t\t\t\ttot -= Math.Min(c, tot);\n\t\t\t\ttot -= tot / 10;\n\t\t\t}\n\t\t\t\n\t\t\tif(g < N2){\n\t\t\t\tl = c;\n\t\t\t} else {\n\t\t\t\tr = c;\n\t\t\t}\n\t\t}\n\t\tConsole.WriteLine(r);\n\t}\n\tlong N;\n\tpublic Sol(){\n\t\tN = rl();\n\t}\n\n\tstatic String rs(){return Console.ReadLine();}\n\tstatic int ri(){return int.Parse(Console.ReadLine());}\n\tstatic long rl(){return long.Parse(Console.ReadLine());}\n\tstatic double rd(){return double.Parse(Console.ReadLine());}\n\tstatic String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}\n\tstatic int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}\n\tstatic long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}\n\tstatic double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}\n}\n", "src_uid": "db1a50da538fa82038f8db6104d2ab93"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s;\n byte b;\n s = Console.ReadLine();\n if (byte.TryParse(s, out b) && b < 100)\n {\n string result = string.Empty;\n if (0 <= b && b <= 20 || b % 10 == 0)\n {\n result = NumberToString(b);\n }\n else\n {\n byte first = Convert.ToByte(b % 10);\n byte second = Convert.ToByte(Convert.ToByte(b / 10) * 10);\n result = NumberToString(second);\n result = string.Format(\"{0}-{1}\", result, NumberToString(first));\n }\n Console.WriteLine(result);\n } \n Console.ReadLine();\n }\n\n static string NumberToString(byte N)\n {\n switch (N)\n {\n case 0:\n return \"zero\";\n case 1:\n return \"one\";\n case 2:\n return \"two\";\n case 3:\n return \"three\";\n case 4:\n return \"four\";\n case 5:\n return \"five\";\n case 6:\n return \"six\";\n case 7:\n return \"seven\";\n case 8:\n return \"eight\";\n case 9:\n return \"nine\";\n case 10:\n return \"ten\";\n case 11:\n return \"eleven\";\n case 12:\n return \"twelve\";\n case 13:\n return \"thirteen\";\n case 14:\n return \"fourteen\";\n case 15:\n return \"fifteen\";\n case 16:\n return \"sixteen\";\n case 17:\n return \"seventeen\";\n case 18:\n return \"eighteen\";\n case 19:\n return \"nineteen\";\n case 20:\n return \"twenty\";\n case 30:\n return \"thirty\";\n case 40:\n return \"forty\";\n case 50:\n return \"fifty\";\n case 60:\n return \"sixty\";\n case 70:\n return \"seventy\";\n case 80:\n return \"eighty\";\n case 90:\n return \"ninety\";\n }\n return string.Empty;\n }\n }\n}\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace Task\n{\n class Program\n {\n #region Read / Write\n protected static TextReader reader;\n protected static TextWriter writer;\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }\n return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array) writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }\n #endregion=\n\n public static bool NextPermutation(List perm)\n {\n for (int i = perm.Count - 2; i >= 0; i--)\n {\n if (perm[i] < perm[i + 1])\n {\n int min = i + 1;\n for (int j = min; j < perm.Count; j++)\n if (perm[j] > perm[i] && perm[j] < perm[min])\n min = j;\n\n int tmp = perm[i];\n perm[i] = perm[min];\n perm[min] = tmp;\n perm.Reverse(i + 1, perm.Count - i - 1);\n return true;\n }\n }\n\n return false;\n }\n\n public static int[] Perm(int[] mas1, int[] mas2, int numb1 = 0)\n {\n if (mas1 == null)\n return mas2;\n if (mas2 == null)\n return mas1;\n\n var ans = new int[mas1.Length];\n for (int i = 0; i < mas1.Length; i++)\n {\n ans[i] = mas2[mas1[i] - 1];\n }\n\n return ans;\n }\n\n public static void Build(int[][] a, int v, int tl, int tr)\n {\n hash = new Dictionary();\n\n if (tl == tr)\n t[v] = a[tl];\n else\n {\n int tm = (tl + tr) / 2;\n Build(a, v * 2, tl, tm);\n Build(a, v * 2 + 1, tm + 1, tr);\n t[v] = Perm(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n public static Dictionary hash;\n\n public static int[] Query(int v, int tl, int tr, int l, int r)\n {\n if (l > r)\n return null;\n if (l == tl && r == tr)\n return t[v];\n\n var key = ((long)l << 17) + r;\n if (hash.ContainsKey(key))\n return hash[key];\n\n int tm = (tl + tr) / 2;\n var res = Perm(Query(v * 2, tl, tm, l, Math.Min(r, tm)), Query(v * 2 + 1, tm + 1, tr, Math.Max(l, tm + 1), r));\n hash[key] = res;\n return res;\n }\n\n public static int[][] t;\n\n static void Main(string[] args)\n {\n //long i = 0;\n long ans = 0;\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n\n var n = ReadInt();\n var B = ReadInt();\n var mas = ReadIntArray();\n //var mas = ReadIntArray().Select((item, index) => new Tuple(index, item)).ToArray();\n\n var lst = new List();\n int evenNumb = 0, oddNumb = 0;\n for (int i = 0; i < n - 1; i++)\n {\n if ((mas[i] & 1) == 0)\n {\n evenNumb++;\n }\n else\n {\n oddNumb++;\n }\n\n if (evenNumb == oddNumb)\n lst.Add(Math.Abs(mas[i] - mas[i + 1]));\n }\n\n lst.Sort();\n for (int i = 0; i < lst.Count; i++)\n {\n if (lst[i] <= B)\n {\n ans++;\n B -= lst[i];\n }\n else\n {\n break;\n }\n }\n\n Write(ans);\n\n reader.Close();\n writer.Close();\n }\n }\n}", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Exams\n{\n class Program\n {\n private static int n;\n\n private static int k;\n\n static void Main(string[] args)\n {\n int[] values = Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();\n n = values[0];\n k = values[1];\n\n int result = Solve();\n Console.Out.WriteLine(result);\n }\n\n private static int Solve()\n {\n for(int i2 = 0; i2 <= n; i2++)\n {\n for(int i3 = 0; i3 <= n - i2; i3++)\n {\n for(int i4 = 0; i4 <= n - i3 - i2;i4++)\n {\n int i5 = n - i4 - i3 - i2;\n int sum = 2 * i2 + 3 * i3 + 4 * i4 + 5 * i5;\n\n if (sum == k)\n {\n// Console.Out.WriteLine(\"{4} = 2 * {0} + 3 * {1} + 4 * {2} + 5 * {3}\", i2, i3, i4, i5, sum);\n\n return i2;\n }\n }\n }\n }\n\n throw new ArgumentException(\"no possibility to pass exam\");\n }\n }\n}\n", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"source_code": "using System;\nusing System.IO;\nusing System.Net;\nusing System.Net.Sockets;\nusing System.Linq;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Numerics;\nusing System.Threading.Tasks;\nusing System.Text.RegularExpressions;\nusing static System.Math;\nusing MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;\nusing MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;\n\npublic static class P\n{\n public static void Main()\n {\n int b = int.Parse(Console.ReadLine());\n var g = int.Parse(Console.ReadLine());\n var n = int.Parse(Console.ReadLine());\n var gMin = Max(n - b, 0);\n var gMax = Min(n, g);\n Console.WriteLine(gMax - gMin + 1);\n }\n\n\n static readonly TextReader In = Console.In;\n static int NextInt\n {\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n get\n {\n int res = 0;\n int next = In.Read();\n int rev = 1;\n while (45 > next || next > 57) next = In.Read();\n if (next == 45) { next = In.Read(); rev = -1; }\n while (48 <= next && next <= 57)\n {\n res = res * 10 + next - 48;\n next = In.Read();\n }\n return res * rev;\n }\n }\n}\n", "src_uid": "9266a69e767df299569986151852e7b1"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.ReadLine();\n string[] input = Console.ReadLine().Split(' ');\n int temp = -1;\n int temp2 = 0;\n for (int i = 0; i < input.Count(); i++)\n {\n temp2 = input[i].Count(c => char.IsUpper(c));\n temp = (temp2 > temp) ? temp2 : temp;\n }\n Console.WriteLine(temp);\n }\n }\n}\n", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"} {"source_code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Globalization;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading;\r\n\r\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\r\npublic class Solution\r\n{\r\n const int MAXN = 50;\r\n const int MAX_INV = MAXN * MAXN;\r\n\r\n long Fun(int n, int mod)\r\n {\r\n var d = new long[MAX_INV];\r\n d[0] = 1;\r\n int max = 0;\r\n long ans = 0;\r\n for (int i = 1; i < n; i++)\r\n {\r\n var nd = new long[MAX_INV];\r\n int nmax = max;\r\n long sum = 0;\r\n for (int j = 0; j <= i; j++)\r\n for (int k = 0; k <= i; k++)\r\n {\r\n for (int p = 0; p <= max; p++)\r\n {\r\n int o = p + j - k;\r\n nmax = Math.Max(nmax, o);\r\n if (o >= 0)\r\n {\r\n nd[o] = (nd[o] + d[p]) % mod;\r\n if (j < k && o > 0)\r\n sum = (sum + d[p]) % mod;\r\n }\r\n if (p == 0)\r\n continue;\r\n o = -p + j - k;\r\n nmax = Math.Max(nmax, o);\r\n if (o >= 0)\r\n {\r\n nd[o] = (nd[o] + d[p]) % mod;\r\n if (j < k && o > 0)\r\n sum = (sum + d[p]) % mod;\r\n }\r\n }\r\n }\r\n ans = ((i + 1) * ans + sum) % mod;\r\n max = nmax;\r\n d = nd;\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n public void Solve()\r\n {\r\n int n = ReadInt();\r\n int mod = ReadInt();\r\n\r\n Write(Fun(n, mod));\r\n }\r\n\r\n #region Main\r\n\r\n protected static TextReader reader;\r\n protected static TextWriter writer;\r\n static void Main()\r\n {\r\n#if DEBUGLOCAL\r\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\r\n //reader = new StreamReader(Console.OpenStandardInput());\r\n writer = Console.Out;\r\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\r\n#else\r\n reader = new StreamReader(Console.OpenStandardInput());\r\n writer = new StreamWriter(Console.OpenStandardOutput());\r\n //reader = new StreamReader(\"ysys.in\");\r\n //writer = new StreamWriter(\"output.txt\");\r\n#endif\r\n try\r\n {\r\n new Solution().Solve();\r\n //var thread = new Thread(new Solution().Solve, 1024 * 1024 * 128);\r\n //thread.Start();\r\n //thread.Join();\r\n }\r\n catch (Exception ex)\r\n {\r\n#if DEBUGLOCAL\r\n Console.WriteLine(ex);\r\n#else\r\n throw;\r\n#endif\r\n }\r\n reader.Close();\r\n writer.Close();\r\n }\r\n\r\n #endregion\r\n\r\n #region Read / Write\r\n private static Queue currentLineTokens = new Queue();\r\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\r\n public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\r\n public static int ReadInt() { return int.Parse(ReadToken()); }\r\n public static long ReadLong() { return long.Parse(ReadToken()); }\r\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\r\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\r\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\r\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\r\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }\r\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\r\n {\r\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\r\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }\r\n return ret;\r\n }\r\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }\r\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\r\n public static void Write(params object[] array) { WriteArray(array); }\r\n public static void WriteLines(IEnumerable array) { foreach (var a in array) writer.WriteLine(a); }\r\n private class SDictionary : Dictionary\r\n {\r\n public new TValue this[TKey key]\r\n {\r\n get { return ContainsKey(key) ? base[key] : default(TValue); }\r\n set { base[key] = value; }\r\n }\r\n }\r\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }\r\n #endregion\r\n}", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a"} {"source_code": "using System;\n\nnamespace CSharp\n{\n class _678C\n {\n public static void Main()\n {\n var tokens = Console.ReadLine().Split();\n\n long n = long.Parse(tokens[0]);\n long a = long.Parse(tokens[1]);\n long b = long.Parse(tokens[2]);\n long p = long.Parse(tokens[3]);\n long q = long.Parse(tokens[4]);\n\n long s = n / a * p + n / b * q - n / LCM(a, b) * Math.Min(p, q);\n Console.WriteLine(s);\n }\n\n private static long LCM(long x, long y) => x / GCD(x, y) * y;\n\n private static long GCD(long x, long y) => x == 0 ? y : GCD(y % x, x);\n }\n}", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForces\n{\n class Abracadabra\n {\n public static void Main()\n {\n string[] line = Console.ReadLine().Split(' ');\n int n1 = int.Parse(line[0]);\n int n2 = int.Parse(line[1]);\n int k1 = int.Parse(line[2]);\n int k2 = int.Parse(line[3]);\n\n var dp = new Dictionary();\n var answer = recurse(n1, n2, k1, k2, 0, 0, dp, 0, 0, 0);\n Console.WriteLine(answer % 100000000);\n }\n\n public static long recurse(int s, int h, int k1, int k2, int sp, int hp, Dictionary dp, int tsp, int thp, int total)\n {\n if (total == s + h)\n {\n return 1;\n }\n\n if (dp.ContainsKey(string.Format(\"{0},{1},{2},{3},{4}\", sp, hp, tsp, thp, total)))\n {\n return dp[string.Format(\"{0},{1},{2},{3},{4}\", sp, hp, tsp, thp, total)];\n }\n\n long a = 0;\n if (tsp < s && sp + 1 <= k1)\n {\n a = recurse(s, h, k1, k2, sp + 1, 0, dp, tsp + 1, thp, total + 1);\n }\n\n long b = 0;\n if (thp < h && hp + 1 <= k2)\n {\n b = recurse(s, h, k1, k2, 0, hp + 1, dp, tsp, thp + 1, total + 1);\n }\n\n long answer = a + b % 100000000;\n\n dp.Add(string.Format(\"{0},{1},{2},{3},{4}\", sp, hp, tsp, thp, total), answer);\n\n return answer;\n }\n }\n}\n", "src_uid": "63aabef26fe008e4c6fc9336eb038289"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing CompLib.Util;\n\npublic class Program\n{\n long A, B;\n public void Solve()\n {\n var sc = new Scanner();\n A = sc.NextLong();\n B = sc.NextLong();\n var div = Div(A + B);\n var divA = Div(A);\n var divB = Div(B);\n div.Sort();\n divA.Sort();\n divB.Sort();\n long ans = long.MaxValue;\n for (int i = 0; i <= div.Count / 2; i++)\n {\n\n long j = div[div.Count - 1 - i];\n\n\n // A,Bのどちらかが i以下、j以下の積で表せるか?\n {\n int ok = -1;\n int ng = divA.Count;\n while (ng - ok > 1)\n {\n int mid = (ok + ng) / 2;\n if (divA[mid] <= div[i]) ok = mid;\n else ng = mid;\n }\n if(ok >= 0 && divA[divA.Count - ng] <= j)\n {\n // Console.WriteLine($\"A {div[i]} {j}\");\n ans = Math.Min(ans, (div[i] + j) * 2);\n continue;\n }\n }\n\n {\n int ok = -1;\n int ng = divB.Count;\n while (ng - ok > 1)\n {\n int mid = (ok + ng) / 2;\n if (divB[mid] <= div[i]) ok = mid;\n else ng = mid;\n }\n if (ok >= 0 && divB[divB.Count - ng] <= j)\n {\n // Console.WriteLine($\"B {div[i]} {j}\");\n ans = Math.Min(ans, (div[i] + j) * 2);\n continue;\n }\n }\n }\n Console.WriteLine(ans);\n }\n\n public List Div(long l)\n {\n var result = new List();\n for (long i = 1; i * i <= l; i++)\n {\n if (l % i == 0)\n {\n result.Add(i);\n if (l / i != i) result.Add(l / i);\n }\n }\n return result;\n }\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n while (_index >= _line.Length)\n {\n _line = Console.ReadLine().Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n _line = Console.ReadLine().Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing SB = System.Text.StringBuilder;\n//using System.Threading.Tasks;\n//using System.Text.RegularExpressions;\n//using System.Globalization;\n//using System.Diagnostics;\nusing static System.Console;\nusing System.Numerics;\nusing static System.Math;\nusing pair = Pair;\n\nclass Program\n{\n static void Main()\n {\n //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });\n new Program().solve();\n Out.Flush();\n }\n readonly Scanner cin = new Scanner();\n readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑\n readonly int mod = 1000000007;\n readonly int dom = 998244353;\n bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n bool chmin(ref T a, T b) where T : IComparable { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }\n\n\n void swap(ref T a, ref T b)\n {\n var t = a;\n a = b;\n b = t;\n }\n void solve()\n {\n var A = cin.nextlong;\n var B = cin.nextlong;\n if (A == B)\n {\n WriteLine(0);\n return;\n }\n\n if (A > B)\n {\n swap(ref A, ref B);\n }\n\n var G = B - A; //G <= 10^9\n var L = new List();\n for (long i = 1; i * i <= G; i++)\n {\n if (G % i == 0)\n {\n L.Add(i);\n var j = G / i;\n if (i != j) L.Add(j);\n }\n }\n\n long ans = long.MaxValue;\n long K = long.MaxValue;\n\n foreach (var v in L)\n {\n\n\n var key = A % v;\n if (key != 0) key = v - key;\n var ret = lcm(A + key, B + key);\n if (ret < ans)\n {\n ans = ret;\n K = key;\n }\n else if (ret == ans && key < K)\n {\n K = key;\n }\n\n //WriteLine(v + \" \" + ret + \" \" + ans);\n }\n\n\n WriteLine(K);\n }\n\n long gcd(long a, long b)\n {\n return (b != 0) ? gcd(b, a % b) : a;\n }\n long lcm(long a, long b)\n {\n return a / gcd(a, b) * b;\n }\n //ax + by = gcd(a, b)となるx, yを求める\n long extgcd(long a, long b, out long x, out long y)\n {\n long g = a;\n if (b != 0)\n {\n g = extgcd(b, a % b, out y, out x);\n y -= (a / b) * x;\n }\n else\n {\n x = 1;\n y = 0;\n }\n return g;\n }\n}\n\n\nstatic class Ex\n{\n public static void join(this IEnumerable values, string sep = \" \") => WriteLine(string.Join(sep, values));\n public static string concat(this IEnumerable values) => string.Concat(values);\n public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }\n\n public static int lower_bound(this IList arr, T val) where T : IComparable\n {\n int low = 0, high = arr.Count;\n int mid;\n while (low < high)\n {\n mid = ((high - low) >> 1) + low;\n if (arr[mid].CompareTo(val) < 0) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n public static int upper_bound(this IList arr, T val) where T : IComparable\n {\n int low = 0, high = arr.Count;\n int mid;\n while (low < high)\n {\n mid = ((high - low) >> 1) + low;\n if (arr[mid].CompareTo(val) <= 0) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n}\n\nclass Pair : IComparable> where T : IComparable where U : IComparable\n{\n public T f; public U s;\n public Pair(T f, U s) { this.f = f; this.s = s; }\n public int CompareTo(Pair a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);\n public override string ToString() => $\"{f} {s}\";\n}\n\nclass Scanner\n{\n string[] s; int i;\n readonly char[] cs = new char[] { ' ' };\n public Scanner() { s = new string[0]; i = 0; }\n public string[] scan => ReadLine().Split();\n public int[] scanint => Array.ConvertAll(scan, int.Parse);\n public long[] scanlong => Array.ConvertAll(scan, long.Parse);\n public double[] scandouble => Array.ConvertAll(scan, double.Parse);\n public string next\n {\n get\n {\n if (i < s.Length) return s[i++];\n string st = ReadLine();\n while (st == \"\") st = ReadLine();\n s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n i = 0;\n return next;\n }\n }\n public int nextint => int.Parse(next);\n public long nextlong => long.Parse(next);\n public double nextdouble => double.Parse(next);\n}\n", "src_uid": "414149fadebe25ab6097fc67663177c3"} {"source_code": "// \n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\nusing System.Linq;\n\nnamespace sar_cs\n{\n public class Program\n {\n public class Parser\n {\n const int BufSize = 25000;\n TextReader s;\n char[] buf = new char[BufSize];\n int bufPos;\n int bufDataSize;\n bool eos; // eos read to buffer\n int lastChar = -2;\n int nextChar = -2;\n StringBuilder sb = new StringBuilder();\n\n void FillBuf()\n {\n if (eos) return;\n bufDataSize = s.Read(buf, 0, BufSize);\n if (bufDataSize == 0) eos = true;\n bufPos = 0;\n }\n\n int Read()\n {\n if (nextChar != -2)\n {\n lastChar = nextChar;\n nextChar = -2;\n }\n else\n {\n if (bufPos == bufDataSize) FillBuf();\n if (eos) lastChar = -1;\n else lastChar = buf[bufPos++];\n }\n return lastChar;\n }\n\n void Back()\n {\n if (lastChar == -2) throw new Exception(); // no chars were ever read\n nextChar = lastChar;\n }\n\n public Parser()\n {\n s = Console.In;\n }\n\n public int ReadInt()\n {\n int res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = checked(res * 10 - c);\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return checked(res * sign);\n }\n\n public long ReadLong()\n {\n long res = 0;\n int sign = -1;\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n if (c == '-')\n {\n sign = -sign;\n c = Read();\n }\n int len = 0;\n checked\n {\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n if ((uint)(c -= 48) >= 10) throw new InvalidDataException();\n len++;\n res = res * 10 - c;\n c = Read();\n }\n if (len == 0) throw new InvalidDataException();\n Back();\n return res * sign;\n }\n }\n\n public double ReadDouble()\n {\n int c;\n do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));\n\n int sign = 1;\n if (c == '-')\n {\n sign = -1;\n c = Read();\n }\n\n sb.Length = 0;\n while (c >= 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = Read();\n }\n\n Back();\n double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);\n return res * sign;\n }\n\n public string ReadLine()\n {\n int c = Read();\n sb.Length = 0;\n while (c != -1 && c != 13 && c != 10)\n {\n sb.Append((char)c);\n c = Read();\n }\n if (c == 13)\n {\n c = Read();\n if (c != 10) Back();\n }\n return sb.ToString();\n }\n\n public bool EOF\n {\n get\n {\n if (Read() == -1) return true;\n Back();\n return false;\n }\n }\n\n public bool SeekEOF\n {\n get\n {\n L0:\n int c = Read();\n if (c == -1) return true;\n if (char.IsWhiteSpace((char)c)) goto L0;\n Back();\n return false;\n }\n }\n }\n\n static void pe()\n {\n Console.WriteLine(\"???\");\n Environment.Exit(0);\n }\n\n static void re()\n {\n Environment.Exit(55);\n }\n\n static int nosol()\n {\n Console.WriteLine(\"ERROR\");\n return 0;\n }\n\n static Stopwatch sw = Stopwatch.StartNew();\n\n static StringBuilder sb = new StringBuilder();\n static Random rand = new Random(52345235);\n\n static void Swap(ref T a, ref T b)\n {\n T t = a;\n a = b;\n b = t;\n }\n\n static int n;\n static int[] j = new int[6];\n static int[,] l = new int[6, 6];\n static int[,] h = new int[6, 6];\n static int[,] a = new int[6, 6];\n static int[,] flow = new int[6, 6];\n\n static int resultFlow;\n static int resultCost;\n\n static void per(int v, int w, int q)\n {\n if (q < 0) throw new Exception();\n\n int j_bak = j[w];\n\n if (w == n - 1)\n {\n if (q >= l[v, w] && q <= h[v, w])\n {\n flow[v, w] = q;\n j[w] = j_bak + q;\n visit(v + 1);\n }\n }\n else\n {\n for (int i = l[v, w]; i <= h[v, w]; i++)\n {\n if (i > q) break;\n if (q - i > 5 * (n - 1 - w)) continue;\n flow[v, w] = i;\n j[w] = j_bak + i;\n per(v, w + 1, q - i);\n }\n }\n\n flow[v, w] = 0;\n j[w] = j_bak;\n }\n\n static void visit(int v)\n {\n if (v == n - 1)\n {\n if (j[n - 1] != j[0]) throw new Exception();\n if (j[n - 1] <= resultFlow)\n {\n int cost = 0;\n for (v = 0; v < n; v++)\n for (int w = v + 1; w < n; w++)\n if (flow[v, w] > 0) cost += a[v, w] + flow[v, w] * flow[v, w];\n if (j[n - 1] < resultFlow || cost > resultCost) resultCost = cost;\n resultFlow = j[n - 1];\n }\n }\n else\n {\n per(v, v + 1, j[v]);\n }\n }\n\n static int Main(string[] args)\n {\n //Console.SetIn(File.OpenText(\"_input\"));\n Parser parser = new Parser();\n while (!parser.SeekEOF)\n {\n n = parser.ReadInt();\n for (int i = 0; i < n * (n - 1) / 2; i++)\n {\n int v = parser.ReadInt() - 1;\n int w = parser.ReadInt() - 1;\n l[v, w] = parser.ReadInt();\n h[v, w] = parser.ReadInt();\n a[v, w] = parser.ReadInt();\n }\n\n resultFlow = int.MaxValue;\n resultCost = 0;\n for (j[0] = 0; j[0] <= 25; j[0]++)\n visit(0);\n\n if (resultFlow == int.MaxValue) resultFlow = resultCost = -1;\n Console.WriteLine(resultFlow + \" \" + resultCost);\n }\n\n return 0;\n }\n }\n}", "src_uid": "38886ad7b0d83e66b77348be34828426"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace round515\n{\n class Point\n {\n public int x, y;\n\n public Point(int x, int y)\n {\n this.x = x;\n this.y = y;\n }\n\n public int distance(Point p)\n {\n return Math.Abs(x - p.x) + Math.Abs(y - p.y);\n }\n }\n\n class MainClass\n {\n public static void Main(string[] args)\n {\n var n = int.Parse(Console.ReadLine());\n var d = new Dictionary>();\n for (int i = 0; i < n; ++i)\n {\n var line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);\n int x = line[0];\n int y = line[1];\n\n int level = Math.Max(x, y);\n if (d.ContainsKey(level))\n {\n d[level].Add(new Point(x, y));\n }\n else\n {\n var list = new List { new Point(x, y) };\n d.Add(level, list);\n }\n }\n\n var pp0 = new Point(0, 0);\n var pp1 = pp0;\n long c0 = 0;\n long c1 = 0;\n foreach (var kv in d.OrderBy((kv) => kv.Key))\n {\n var level = kv.Key;\n var list = kv.Value;\n list.Sort((a, b) => {\n if (a.y == b.y)\n return a.x - b.x;\n return b.y - a.y;\n });\n\n var p0 = list[0];\n var p1 = list[list.Count - 1];\n\n long nc0 = Math.Min(c0 + p1.distance(pp0) + p1.distance(p0), c1 + p1.distance(pp1) + p1.distance(p0));\n long nc1 = Math.Min(c0 + p0.distance(pp0) + p0.distance(p1), c1 + p0.distance(pp1) + p0.distance(p1));\n\n c0 = nc0;\n c1 = nc1;\n\n pp0 = p0;\n pp1 = p1;\n }\n\n Console.WriteLine(Math.Min(c0, c1));\n }\n }\n}\n", "src_uid": "06646a9bdce2d65e92e525e97b2c975d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace SP.Solutions.CodeForces.c338_196_1\n{\n\tpublic class ProgramC\n\t{\n\t private static long bestRes = long.MaxValue;\n\n\t\tpublic static void Main()\n\t\t{\n\t\t\tchecked\n\t\t\t{\n\t\t\t bestRes = long.MaxValue;\n\t\t\t int n = int.Parse(Console.ReadLine());\n\t\t\t var arr = Console.ReadLine().Split(' ').Select(long.Parse).Distinct().ToArray();\n Array.Sort(arr);\n\n\t\t\t var primes = GetPrimes();\n\n\t\t\t var nodes = new List();\n for (int i = 0; i < arr.Length; i++)\n {\n nodes.Add(new Node(arr[i], getFactors(arr[i], primes), arr[i], false, 0));\n }\n\n\t\t\t TryBuildTrees(nodes, 0);\n Console.WriteLine(bestRes);\n\t\t\t}\n\t\t}\n\n\t private static void TryBuildTrees(List nodes, int minJ)\n\t {\n\t var noWay = true;\n for (int j = minJ; j < nodes.Count; j++)\n for (int i = j + 1; i < nodes.Count; i++)\n if (j != i && !nodes[j].HasParent && nodes[i].Rem%nodes[j].N == 0 && !nodes[i].HasParent)\n\t {\n\t noWay = false;\n\t int add = nodes[j].Factors > 1 ? 1 : 0;\n\n\t var r1 = nodes[i].Rem;\n\t var add1 = nodes[i].addFactors;\n\n\t nodes[i].Rem = nodes[i].Rem/nodes[j].N;\n\t nodes[i].addFactors = nodes[i].addFactors + nodes[j].addFactors + add;\n\t nodes[j].HasParent = true;\n\n TryBuildTrees(nodes, minJ);\n\t \n nodes[j].HasParent = false;\n nodes[i].Rem = r1;\n nodes[i].addFactors = add1;\n }\n if (noWay)\n\t CalcPrice(nodes);\n\t }\n\n\t private static void CalcPrice(List nodes)\n\t {\n\t int n = 0;\n\t long res = 0;\n foreach (var node in nodes) if (!node.HasParent)\n {\n if (node.Factors > 1) res++;\n res += node.Factors + node.addFactors;\n n++;\n }\n\t if (n > 1) res++;\n\t bestRes = Math.Min(bestRes, res);\n\t }\n\n\t static int getFactors(long n, long[] primes)\n {\n int res = 0;\n int i = 0;\n while (n > 1 && i < primes.Length)\n {\n if (n%primes[i] == 0)\n {\n res++;\n n /= primes[i];\n }\n else i++;\n }\n\t if (i == primes.Length) res++;\n return res;\n }\n\n class Node\n {\n public override string ToString()\n {\n return string.Format(\"HasParent: {0}, N: {1}, Factors: {2}, Rem: {3}\", HasParent, N, Factors, Rem);\n }\n\n public bool HasParent;\n public readonly long N;\n public int Factors;\n public long Rem;\n public int addFactors;\n\n public Node(long n, int factors, long rem, bool hasParent, int addFactors)\n {\n HasParent = hasParent;\n this.addFactors = addFactors;\n N = n;\n Factors = factors;\n Rem = rem;\n }\n }\n\n\t private static long[] GetPrimes()\n\t {\n\t const int max = 1000000;\n\t var primes = new List(80000);\n\t primes.Add(2);\n\t var isNotPrime = new bool[max + 1];\n for (int i = 3 ; i<= max ; i+=2) if (!isNotPrime[i])\n {\n primes.Add(i);\n for (int j = i*i; j <= max && j > 0; j += i) isNotPrime[j] = true;\n }\n\t return primes.ToArray();\n\t }\n\t}\n}", "src_uid": "52b8b6c68518d5129272b8c56e5b7662"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Task1\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n var a = Console.ReadLine().Split(' ').Select(short.Parse).ToArray();\n a[2] %= a[0];\n switch (Math.Sign(a[2]))\n {\n case 0: { Console.WriteLine(a[1]); } break;\n case -1: { Console.WriteLine( (a[1]+a[2]<=0)?a[0]+(a[1]+a[2]):a[1]+a[2]); } break;\n case 1: { Console.WriteLine( (a[1]+a[2]<=a[0])?a[1]+a[2]:a[1]+a[2]-a[0]); } break;\n }\n }\n }\n}", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"} {"source_code": "using System;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Threading.Tasks;\n\n\n\nnamespace ConsoleApplication1.CodeForces\n{\n static class _4032123\n {\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);\n\n class Node\n {\n public int D { get; set; }\n public int F { get; set; }\n public int T { get; set; }\n public long C { get; set; }\n }\n static void Main(String[] args)\n {\n var n = int.Parse(Console.ReadLine().TrimEnd());\n var data = Console.ReadLine().TrimEnd().Split(' ').Select(int.Parse).ToList();\n writer.WriteLine(Math.Max(0, data.Max() - 25));\n writer.Flush();\n\n\n }\n }\n}", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd"} {"source_code": "using System;\n\npublic class Solution\n{\n static void Main(string[] args)\n {\n string[] str = Console.ReadLine().Split(' ');\n int n = int.Parse(str[0]);\n int l = int.Parse(str[1]);\n int r = int.Parse(str[2]);\n\n int last = 1,\n pos = 0,\n min = 0,\n max = 0;\n\n for (int i = 0; i < n; i++)\n {\n if (i < l)\n min += last;\n else\n min += 1;\n max += last;\n\n if (i + 1 < r)\n last = last * 2;\n }\n \n Console.Write(min);\n Console.Write(\" \");\n Console.Write(max);\n }\n}", "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\n\nnamespace CodeforcesTemplate\n{\n public static class Permutation\n {\n private static bool Next(ref int[] arr)\n {\n int k, j, l;\n for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }\n if (j == -1)\n {\n arr = arr.OrderBy(c => c).ToArray();\n return false;\n }\n for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }\n var tmp = arr[j];\n arr[j] = arr[l];\n arr[l] = tmp;\n for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)\n {\n tmp = arr[k];\n arr[k] = arr[l];\n arr[l] = tmp;\n }\n return true;\n }\n public static IEnumerable AllPermutations(int[] arr)\n {\n do yield return arr;\n while (Next(ref arr));\n }\n }\n\n class Program\n {\n private const string FILENAME = \"distance4\";\n\n private const string INPUT = FILENAME + \".in\";\n\n private const string OUTPUT = FILENAME + \".out\";\n\n private static Stopwatch _stopwatch = new Stopwatch();\n\n private static StreamReader _reader = null;\n private static StreamWriter _writer = null;\n\n private static string[] _curLine;\n private static int _curTokenIdx;\n\n private static char[] _whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n private static string ReadNextToken()\n {\n if (_curTokenIdx >= _curLine.Length)\n {\n //Read next line\n string line = _reader.ReadLine();\n if (line != null)\n _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n _curLine = new string[] { };\n _curTokenIdx = 0;\n }\n\n if (_curTokenIdx >= _curLine.Length)\n return null;\n\n return _curLine[_curTokenIdx++];\n }\n\n private static int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n private static void RunTimer()\n {\n#if (DEBUG)\n\n _stopwatch.Start();\n\n#endif\n }\n\n private static void Main(string[] args)\n {\n\n#if (DEBUG)\n double before = GC.GetTotalMemory(false);\n#endif\n\n long a = long.Parse(Console.ReadLine());\n long b = long.Parse(Console.ReadLine());\n\n char[] aChar = (\"\" + a).ToCharArray();\n char[] bChar = (\"\" + b).ToCharArray();\n\n if (aChar.Length < bChar.Length)\n {\n Array.Sort(aChar);\n for (int i = aChar.Length - 1; i >= 0; i--)\n {\n Console.Write(aChar[i]);\n }\n\n Console.WriteLine();\n\n return;\n }\n\n int[] aDigit = new int[10];\n int[] bDigit = new int[10];\n foreach (char ch in aChar)\n {\n aDigit[ch - '0']++;\n }\n\n foreach (char ch in bChar)\n {\n bDigit[ch - '0']++;\n }\n\n bool same = true;\n\n for (int i = 0; i < 10; i++)\n {\n if (aDigit[i] != bDigit[i])\n {\n same = false;\n }\n }\n\n if (same)\n {\n Console.WriteLine(b);\n return;\n }\n\n\n long answer = 0;\n\n for (int divide = 0; divide < aChar.Length; divide++)\n {\n if (divide >= 1)\n {\n if (aDigit[bChar[divide - 1] - '0'] == 0)\n {\n break;\n }\n\n aDigit[bChar[divide - 1] - '0']--;\n }\n\n StringBuilder sb = new StringBuilder();\n\n for (int i = 0; i < divide; i++)\n {\n sb.Append(bChar[i]);\n }\n\n int usedLower = -1;\n {\n for (int d = (bChar[divide] - '0') - 1; d >= (divide == 0 ? 1 : 0); d--)\n {\n if (aDigit[d] > 0)\n {\n usedLower = d; break;\n }\n }\n }\n if (usedLower < 0)\n {\n continue;\n }\n\n sb.Append((char)('0' + usedLower));\n\n aDigit[usedLower]--;\n\n for (int i = divide + 1; i < aChar.Length; i++)\n {\n for (int d = 9; d >= 0; d--)\n {\n for (int x = 0; x < aDigit[d] && i < aChar.Length; x++, i++)\n {\n sb.Append((char)('0' + d));\n }\n }\n }\n\n aDigit[usedLower]++;\n\n answer = Math.Max(answer, long.Parse(sb.ToString()));\n }\n\n Console.WriteLine(answer);\n\n\n\n#if (DEBUG)\n _stopwatch.Stop();\n\n double after = GC.GetTotalMemory(false);\n\n double consumedInMegabytes = (after - before) / (1024 * 1024);\n\n Console.WriteLine($\"Time elapsed: {_stopwatch.Elapsed}\");\n\n Console.WriteLine($\"Consumed memory (MB): {consumedInMegabytes}\");\n\n Console.ReadKey();\n#endif\n\n\n }\n\n private static int CountLeadZeros(string source)\n {\n int countZero = 0;\n\n for (int i = source.Length - 1; i >= 0; i--)\n {\n if (source[i] == '0')\n {\n countZero++;\n }\n\n else\n {\n break;\n }\n\n }\n\n return countZero;\n }\n\n private static string ReverseString(string source)\n {\n char[] reverseArray = source.ToCharArray();\n\n Array.Reverse(reverseArray);\n\n string reversedString = new string(reverseArray);\n\n return reversedString;\n }\n\n\n private static int[] CopyOfRange(int[] src, int start, int end)\n {\n int len = end - start;\n int[] dest = new int[len];\n Array.Copy(src, start, dest, 0, len);\n return dest;\n }\n\n private static string StreamReader()\n {\n\n if (_reader == null)\n _reader = new StreamReader(INPUT);\n string response = _reader.ReadLine();\n if (_reader.EndOfStream)\n _reader.Close();\n return response;\n\n\n }\n\n private static void StreamWriter(string text)\n {\n\n if (_writer == null)\n _writer = new StreamWriter(OUTPUT);\n _writer.WriteLine(text);\n\n\n }\n\n\n\n\n\n private static int BFS(int start, int end, int[,] arr)\n {\n Queue> queue = new Queue>();\n List visited = new List();\n for (int i = 0; i < arr.GetLength(0); i++)\n {\n visited.Add(false);\n }\n\n queue.Enqueue(new KeyValuePair(start, 0));\n KeyValuePair node;\n int level = 0;\n bool flag = false;\n\n while (queue.Count != 0)\n {\n node = queue.Dequeue();\n if (node.Key == end)\n {\n return node.Value;\n }\n flag = false;\n for (int i = 0; i < arr.GetLength(0); i++)\n {\n\n if (arr[node.Key, i] == 1)\n {\n if (visited[i] == false)\n {\n if (!flag)\n {\n level = node.Value + 1;\n flag = true;\n }\n queue.Enqueue(new KeyValuePair(i, level));\n visited[i] = true;\n }\n }\n }\n\n }\n return 0;\n\n }\n\n\n\n private static void Write(string source)\n {\n File.WriteAllText(OUTPUT, source);\n }\n\n private static string ReadString()\n {\n return File.ReadAllText(INPUT);\n }\n\n private static void WriteStringArray(string[] source)\n {\n File.WriteAllLines(OUTPUT, source);\n }\n\n private static string[] ReadStringArray()\n {\n return File.ReadAllLines(INPUT);\n }\n\n private static int[] GetIntArray()\n {\n return ReadString().Split(' ').Select(int.Parse).ToArray();\n }\n\n private static double[] GetDoubleArray()\n {\n return ReadString().Split(' ').Select(double.Parse).ToArray();\n }\n\n private static int[,] ReadINT2XArray(List lines)\n {\n int[,] arr = new int[lines.Count, lines.Count];\n\n for (int i = 0; i < lines.Count; i++)\n {\n int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();\n\n for (int j = 0; j < lines.Count; j++)\n {\n arr[i, j] = row[j];\n }\n }\n\n return arr;\n }\n }\n}\n", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace WatchingFootball\n{\n class Program\n {\n private static int a;\n\n private static int b;\n\n private static int c;\n\n static void Main(string[] args)\n {\n int[] values = Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();\n a = values[0];\n b = values[1];\n c = values[2];\n\n int result = Solve();\n Console.Out.WriteLine(result);\n }\n\n private static int Solve()\n {\n return (int) Math.Max(0, Math.Ceiling((0.0 + a - b) * c / b));\n }\n }\n}\n", "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"source_code": "using System;\nusing System.Collections.Generic;\n\n// Codeforces problem 189A \"Разрежь ленточку\"\n// http://codeforces.com/problemset/problem/189/A\nnamespace _189_A\n{\n\tclass Program\n\t{\n\t\tstatic void Main(string[] args)\n\t\t{\n\t\t\t#region Read data\n\t\t\tstring[] tmp = Console.ReadLine().Split();\n\t\t\tint length = Convert.ToInt32(tmp[0]);\n\t\t\tList abc = new List();\n\t\t\tfor (int i = 1; i < tmp.Length; i++)\n\t\t\t{\n\t\t\t\tabc.Add(Convert.ToInt32(tmp[i]));\n\t\t\t}\n\t\t\tabc.Sort();\n\t\t\tint a = abc[0];\n\t\t\tint b = abc[1];\n\t\t\tint c = abc[2];\n\t\t\t#endregion\n\t\t\t#region Process data\n\t\t\tint result = 0;\n\t\t\tfor (int z = 0; z <= length / c; z++)\n\t\t\t{\n\t\t\t\tfor (int y = 0; y <= length / b; y++)\n\t\t\t\t{\n\t\t\t\t\tif ((length - y * b - z * c) % a == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint x = (length - y * b - z * c) / a;\n\t\t\t\t\t\tif (result < x + y + z)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult = x + y + z;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t#endregion\n\t\t\t#region Write results\n\t\t\tConsole.WriteLine(result);\n\t\t\tConsole.ReadLine();\n\t\t\t#endregion\n\t\t}\n\t}\n}", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "using System;\nusing System.Numerics;\nnamespace Program {\n class Program {\n static int N;\n static void Main(string[] args) {\n var n = ri();\n long m = Convert.ToInt64(Math.Floor(Math.Sqrt(n)));\n var iter = 0;\n for (int i = 1; i <= m; i++) {\n if (n % i == 0)\n iter += 2;\n }\n if (m*m == n)\n iter--;\n Console.WriteLine(iter);\n }\n\n\n static (BigInteger, BigInteger, BigInteger, BigInteger) r4bi() {\n var i = Console.ReadLine().Split(' ');\n return (BigInteger.Parse(i[0]), BigInteger.Parse(i[1]), BigInteger.Parse(i[2]), BigInteger.Parse(i[3]));\n }\n static int[] ris() {\n return Array.ConvertAll(Console.ReadLine().Split(' '), i => Int32.Parse(i));\n }\n\n static long ri() {\n var i = Console.ReadLine();\n return Int64.Parse(i);\n }\n static (int, int) r2i() {\n var i = Console.ReadLine().Split(' ');\n return (Int32.Parse(i[0]), Int32.Parse(i[1]));\n }\n static (int, int, int) r3i() {\n var i = Console.ReadLine().Split(' ');\n return (Int32.Parse(i[0]), Int32.Parse(i[1]), Int32.Parse(i[2]));\n }\n }\n}\n", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"source_code": "using System;\nusing System.Collections.Generic;\n\nnamespace Day_23\n{\n class Program\n {\n static Int64 gcd(Int64 a, Int64 b)\n {\n if (a == 0)\n return b;\n return gcd(b % a, a);\n }\n static Int64 lcm(Int64 a, Int64 b)\n {\n return (a * b) / gcd(a, b);\n }\n public static List SieveOfEratosthenes(Int64 n)\n {\n\n /*\n * \n * \n */\n\n Dictionary keyValuePairs = new Dictionary();\n\n for (Int64 p = 2; p * p <= n; p++)\n {\n // If prime[p] is not changed, \n // then it is a prime \n if (!keyValuePairs.ContainsKey(p))\n {\n //// Update all multiples of p \n //for (Int64 i = p * p; i <= n; i += p)\n // prime[i] = false;\n keyValuePairs.Add(p, 1);\n }\n }\n List primes = new List();\n foreach (Int64 key in keyValuePairs.Keys) primes.Add(key);\n return primes;\n }\n\n static void Main(string[] args)\n {\n Int64 X = Convert.ToInt64(Console.ReadLine());\n if (X == 1)\n {\n Console.WriteLine(\"1 1\");\n return;\n }\n SortedDictionary keyValuePairs = new SortedDictionary();\n Int64 last_added = 1;\n\n //List banned_primes = new List();\n\n\n //if (X % 2 != 0) banned_primes.Add(2);\n //if (X % 3 != 0) banned_primes.Add(3);\n //if (X % 5 != 0) banned_primes.Add(5);\n //if (X % 7 != 0) banned_primes.Add(7);\n\n keyValuePairs.Add(1, X);\n List primes = SieveOfEratosthenes(X);\n foreach(Int64 i in primes)\n {\n\n //}\n\n\n\n\n //for (Int64 i = 2; i < 10; i++)\n //{\n // bool found = false;\n // foreach (int ix in banned_primes)\n // {\n // if (i % ix == 0)\n // {\n // found = true;\n // break;\n // }\n // }\n // if (found) continue;\n\n //while (i <= X)\n //{\n if (X % i == 0)\n {\n if (keyValuePairs.ContainsKey(i) || keyValuePairs.ContainsKey(X / i))\n {\n //i += i;\n continue;\n }\n else\n {\n if (lcm(i, X / i) == X)\n {\n keyValuePairs.Add(i, X / i);\n last_added = i;\n }\n }\n }\n // i += i;\n //}\n }\n Console.WriteLine($\"{last_added} {keyValuePairs[last_added]}\");\n }\n }\n}\n", "src_uid": "e504a04cefef3da093573f9df711bcea"} {"source_code": "\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace AlgoTraining.Codeforces.C_s\n{\n public class FastScanner : StreamReader\n {\n private string[] _line;\n private int _iterator;\n\n public FastScanner(Stream stream) : base(stream)\n {\n _line = null;\n _iterator = 0;\n }\n public string NextToken()\n {\n if (_line == null || _iterator >= _line.Length)\n {\n _line = base.ReadLine().Split(' ');\n _iterator = 0;\n }\n if (_line.Count() == 0) throw new IndexOutOfRangeException(\"Input string is empty\");\n return _line[_iterator++];\n }\n public int NextInt()\n {\n return Convert.ToInt32(NextToken());\n }\n public long NextLong()\n {\n return Convert.ToInt64(NextToken());\n }\n public float NextFloat()\n {\n return float.Parse(NextToken());\n }\n public double NextDouble()\n {\n return Convert.ToDouble(NextToken());\n }\n }\n class Vacations363\n {\n public static void Main(string[] args)\n {\n using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))\n using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))\n {\n int n = fs.NextInt(), inf = (int)1e8;\n int[] a = Array.ConvertAll(fs.ReadLine().Split(), Convert.ToInt32);\n int r = 1;\n int g = a[0] == 3 || a[0] == 2 ? 0 : inf;\n int c = a[0] == 3 || a[0] == 1 ? 0 : inf;\n for (int i = 1; i < n; i++)\n {\n int ng = Math.Min(c, r) + (a[i] == 3 || a[i] == 2 ? 0 : inf);\n int nc = Math.Min(r, g) + (a[i] == 3 || a[i] == 1 ? 0 : inf);\n int nr = Math.Min(r, Math.Min(g, c)) + 1;\n r = nr;\n g = ng;\n c = nc;\n }\n writer.WriteLine(Math.Min(r, Math.Min(g, c)));\n }\n }\n }\n}\n", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] number = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));\n\n //Get next prime number\n int num = number[0];\n while (true)\n {\n num++;\n if(IsPrime(num))\n {\n break;\n }\n }\n\n if (num == number[1])\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n\n public static bool IsPrime(int number)\n {\n if (number == 1) return false;\n if (number == 2) return true;\n if (number % 2 == 0) return false;\n\n var boundary = (int)Math.Floor(Math.Sqrt(number));\n\n for (int i = 3; i <= boundary; i += 2)\n {\n if (number % i == 0) return false;\n }\n\n return true;\n }\n }\n}\n", "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\nusing Pi = Pair;\n\nclass Solver\n{\n public void Solve(Scanner sc)\n {\n int N, M;\n sc.Make(out N, out M);\n if (N > M + 1) Fail(0);\n if (N == 2) Fail(0);\n ModInt.Build(M + 1);\n ModInt res = 0;\n\n for(int i = 0; i < N - 2; i++)\n {\n res += ModInt.Comb(N - 3, i);\n }\n res *= ModInt.Comb(M, N - 1);\n WriteLine(res*(N-2));\n }\n}\n\npublic struct ModInt\n{\n //public const long MOD = (int)1e9 + 7;\n public const long MOD = 998244353;\n public long Value { get; set; }\n public ModInt(long n = 0) { Value = n; }\n private static ModInt[] fac;//階乗\n private static ModInt[] inv;//逆数\n private static ModInt[] facinv;//1/(i!)\n public override string ToString() => Value.ToString();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator +(ModInt l, ModInt r)\n {\n l.Value += r.Value;\n if (l.Value >= MOD) l.Value -= MOD;\n return l;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator -(ModInt l, ModInt r)\n {\n l.Value -= r.Value;\n if (l.Value < 0) l.Value += MOD;\n return l;\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static implicit operator long(ModInt l) => l.Value;\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static implicit operator ModInt(long n)\n {\n n %= MOD; if (n < 0) n += MOD;\n return new ModInt(n);\n }\n\n public static ModInt Pow(ModInt m, long n)\n {\n if (n == 0) return 1;\n if (n % 2 == 0) return Pow(m * m, n >> 1);\n else return Pow(m * m, n >> 1) * m;\n }\n\n public static void Build(int n)\n {\n fac = new ModInt[n + 1];\n facinv = new ModInt[n + 1];\n inv = new ModInt[n + 1];\n inv[1] = 1;\n fac[0] = fac[1] = 1;\n facinv[0] = facinv[1] = 1;\n for (var i = 2; i <= n; i++)\n {\n fac[i] = fac[i - 1] * i;\n inv[i] = MOD - inv[MOD % i] * (MOD / i);\n facinv[i] = facinv[i - 1] * inv[i];\n }\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Fac(ModInt n) => fac[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Inv(ModInt n) => inv[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt FacInv(ModInt n) => facinv[n];\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static ModInt Comb(ModInt n, ModInt r)\n {\n if (n < r) return 0;\n if (n == r) return 1;\n var calc = fac[n];\n calc = calc * facinv[r];\n calc = calc * facinv[n - r];\n return calc;\n }\n}\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n new Solver().Solve(new Scanner());\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n public static T[] Shuffle(this IList A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n //public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n //public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n //public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }\n}\n#endregion", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n//using System.Numerics;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n void Solve()\n {\n int n = ReadInt();\n int t = ReadInt();\n var a = ReadIntArray();\n\n var list = new List(a.Distinct());\n list.Sort();\n for (int i = 0; i < n; i++)\n a[i] = list.BinarySearch(a[i]);\n\n int m = list.Count;\n int mt = Math.Min(m, t);\n var pdp = new int[mt + 1][];\n var dp = new int[m];\n for (int i = 0; i <= mt; i++)\n {\n for (int j = 0; j < n; j++)\n {\n int v = dp[a[j]] + 1;\n for (int k = a[j]; k < m; k++)\n dp[k] = Math.Max(dp[k], v);\n }\n pdp[i] = (int[])dp.Clone();\n }\n\n var sdp = new int[mt + 1][];\n dp = new int[n];\n for (int i = 0; i <= mt; i++)\n {\n for (int j = n - 1; j >= 0; j--)\n {\n int v = dp[a[j]] + 1;\n for (int k = 0; k <= a[j]; k++)\n dp[k] = Math.Max(dp[k], v);\n }\n sdp[i] = (int[])dp.Clone();\n }\n\n var cnt = new int[m];\n foreach (int aa in a)\n cnt[aa]++;\n\n int ans = 0;\n for (int mid = 0; mid < m; mid++)\n for (int left = 0; left <= mt; left++)\n for (int right = 0; right <= mt && left + right <= t; right++)\n ans = Math.Max(ans, (left == 0 ? 0 : pdp[left - 1][mid]) + (right == 0 ? 0 : sdp[right - 1][mid]) + cnt[mid] * (t - left - right));\n\n Write(ans);\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"transform.in\");\n //writer = new StreamWriter(\"transform.out\");\n#endif\n try\n {\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n new Solver().Solve();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2"} {"source_code": "#define Online\n\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Numerics;\n\nnamespace CF\n{\n delegate double F(double x);\n delegate decimal Fdec(decimal x);\n\n partial class Program\n {\n\n static void Main(string[] args)\n {\n\n#if FileIO\n StreamReader sr = new StreamReader(\"nosimple.in\");\n StreamWriter sw = new StreamWriter(\"nosimple.out\");\n Console.SetIn(sr);\n Console.SetOut(sw);\n#endif\n\n B();\n \n#if Online\n Console.ReadLine();\n#endif\n\n#if FileIO\n sr.Close();\n sw.Close();\n#endif\n }\n\n static void A()\n {\n\n }\n\n static void B()\n {\n long a, b, c, d;\n ReadArray(' ');\n a = NextLong();\n b = NextLong();\n c = NextLong();\n d = NextLong();\n long g1 = MyMath.GCD(a, b);\n long g2 = MyMath.GCD(c, d);\n a /= g1;\n b /= g1;\n c /= g2;\n d /= g2;\n long i = 1;\n while (a * i < c || b * i < d)\n i++;\n\n a *= i;\n b *= i;\n long p, q;\n if (a * b * d >= c * b * b)\n {\n p = a * b * d - c * b * b;\n q = d * a * b;\n long g3 = MyMath.GCD(p, q);\n p /= g3;\n q /= g3;\n }\n else\n {\n p = a * b * c - d * a * a;\n q = c * a * b;\n long g4 = MyMath.GCD(p, q);\n p /= g4;\n q /= g4;\n }\n Console.WriteLine(p + \"/\" + q);\n }\n\n static void C()\n {\n \n }\n\n static void D()\n {\n\n }\n\n static void E()\n {\n\n }\n\n static void TestGen()\n {\n\n }\n\n }\n\n public static class MyMath\n {\n public static long BinPow(long a, long n, long mod)\n {\n long res = 1;\n while (n > 0)\n {\n if ((n & 1) == 1)\n {\n res = (res * a) % mod;\n }\n a = (a * a) % mod;\n n >>= 1;\n }\n return res;\n }\n\n public static long GCD(long a, long b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static int GCD(int a, int b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static long LCM(long a, long b)\n {\n return (a * b) / GCD(a, b);\n }\n\n public static int LCM(int a, int b)\n {\n return (a * b) / GCD(a, b);\n }\n }\n\n static class ArrayUtils\n {\n public static int BinarySearch(int[] a, int val)\n {\n int left = 0;\n int right = a.Length - 1;\n int mid;\n\n while (left < right)\n {\n mid = left + ((right - left) >> 1);\n if (val <= a[mid])\n {\n right = mid;\n }\n else\n {\n left = mid + 1;\n }\n }\n\n if (a[left] == val)\n return left;\n else\n return -1;\n }\n\n public static double Bisection(F f, double left, double right, double eps)\n {\n double mid;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2d);\n if (Math.Sign(f(mid)) != Math.Sign(f(left)))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2d;\n }\n\n\n public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)\n {\n decimal m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3m;\n m2 = r - (r - l) / 3m;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static double TernarySearch(F f, double eps, double l, double r, bool isMax)\n {\n double m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3d;\n m2 = r - (r - l) / 3d;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R, Comparison comp)\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (comp(L[i], R[j]) <= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R, Comparison comp)\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R, comp);\n Merge_Sort(A, q + 1, r, L, R, comp);\n Merge(A, p, q, r, L, R, comp);\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (L[i].CompareTo(R[j]) <= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R) where T : IComparable\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R);\n Merge_Sort(A, q + 1, r, L, R);\n Merge(A, p, q, r, L, R);\n }\n\n public static void Merge_Sort1(T[] A, int p, int r, T[] L, T[] R) where T : IComparable\n {\n int k = 1;\n while (k < r - p + 1)\n {\n int i = 0;\n while (i < r)\n {\n int _r = Math.Min(i + 2 * k - 1, r);\n int q = Math.Min(i + k - 1, r);\n Merge(A, i, q, _r, L, R);\n i += 2 * k;\n }\n k <<= 1;\n }\n }\n\n public static void Merge_Sort1(T[] A, int p, int r, T[] L, T[] R, Comparison comp)\n {\n int k = 1;\n while (k < r - p + 1)\n {\n int i = 0;\n while (i < r)\n {\n int _r = Math.Min(i + 2 * k - 1, r);\n int q = Math.Min(i + k - 1, r);\n Merge(A, i, q, _r, L, R, comp);\n i += 2 * k;\n }\n k <<= 1;\n }\n }\n\n static void Shake(T[] a)\n {\n Random rnd = new Random(Environment.TickCount);\n T temp;\n int b;\n for (int i = 0; i < a.Length; i++)\n {\n b = rnd.Next(i, a.Length);\n temp = a[b];\n a[b] = a[i];\n a[i] = temp;\n }\n }\n }\n\n partial class Program\n {\n static string[] tokens;\n static int cur_token = 0;\n\n static void ReadArray(char sep)\n {\n cur_token = 0;\n tokens = Console.ReadLine().Split(sep);\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n static int NextInt()\n {\n return int.Parse(tokens[cur_token++]);\n }\n\n static long NextLong()\n {\n return long.Parse(tokens[cur_token++]);\n }\n\n static double NextDouble()\n {\n return double.Parse(tokens[cur_token++]);\n }\n\n static decimal NextDecimal()\n {\n return decimal.Parse(tokens[cur_token++]);\n }\n\n static string NextToken()\n {\n return tokens[cur_token++];\n }\n\n static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n}", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"} {"source_code": "using System;\n\nnamespace Ejercicio5\n{\n class Program\n {\n static void Main(string[] args)\n {\n double n;\n double k;\n int numberNotebooks;\n string input;\n string[] inputList;\n\n input = Console.ReadLine();\n inputList = input.Split(' ');\n\n n = Convert.ToDouble(inputList[0]);\n k = Convert.ToDouble(inputList[1]);\n\n if (n>=1 && k<=Math.Pow(10, 8))\n {\n numberNotebooks = getNumberOfSheets(n, k);\n\n Console.WriteLine(numberNotebooks);\n }\n }\n\n public static int getNumberOfSheets(double n, double k)\n {\n int neededSheets;\n int red;\n int green;\n int blue;\n\n red = (int)Math.Ceiling(Convert.ToDecimal((2 * n) / k));\n green = (int)Math.Ceiling(Convert.ToDecimal((5 * n) / k));\n blue = (int)Math.Ceiling(Convert.ToDecimal((8 * n) / k));\n\n neededSheets = red + green + blue; \n\n return neededSheets;\n }\n }\n}\n", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"source_code": "using System;\r\n\r\npublic static class Program{\r\n static int Ri(){return int.Parse(Console.ReadLine());}\r\n\r\n public static void solve()\r\n {\r\n int n = Ri();\r\n long ans = (long)(Math.Pow(2,n)-1);\r\n Console.WriteLine(ans);\r\n\r\n\r\n }\r\n public static void Main()\r\n {\r\n int TestCase = Ri();\r\n while (TestCase>0){\r\n solve();\r\n TestCase--;\r\n }\r\n }\r\n}", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication3\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n int n = c[0];\n int m = c[1];\n int k = c[2];\n if (n == m) {\n Console.WriteLine(1);\n return;\n }\n if (n == m-1)\n {\n Console.WriteLine(2);\n return;\n }\n if (n == 1)\n {\n Console.WriteLine(m);\n return;\n }\n long l = 1;\n long r = m;\n while (r-l>1) {\n long mid =l + (r - l) / 2;\n long s1 = 0, s2 = 0;\n if (k > mid){\n s1 = mid * (mid - 1) / 2 + k - mid;\n }\n else {\n s1 = (mid - k + mid) * (k - 1) / 2;\n }\n s1 = k == 1 ? 0 : s1;\n if (n - k > mid - 1)\n {\n s2 = mid * (mid - 1) / 2 + n - k - mid + 1;\n }\n else\n {\n s2 = (mid - n + k + mid - 1) * (n - k) / 2;\n }\n s2 = k == n ? 0 : s2;\n \n long s = s1 + s2 + mid;\n if (s > m) r= mid; else l = mid;\n }\n Console.WriteLine(l);\n }\n }\n}", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace codeforce\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = Int32.Parse(Console.ReadLine());\n\n List data = new List();\n for (int i = 0; i < n; i++)\n {\n data.Add(Console.ReadLine().Replace(\" \",\"\"));\n }\n\n List newdata = new List();\n if (data.Count == 1)\n newdata.Add(data[0]);\n else if (data.Count == 2)\n {\n newdata.Add(data[0] + \"-\" + data[1]);\n newdata.Add(data[1] + \"-\" + data[0]);\n }\n else if (data.Count == 3)\n {\n newdata.Add(data[0] + \"-\" + data[1] + \"-\" + data[2]);\n newdata.Add(data[0] + \"-\" + data[2] + \"-\" + data[1]);\n newdata.Add(data[1] + \"-\" + data[0] + \"-\" + data[2]);\n newdata.Add(data[1] + \"-\" + data[2] + \"-\" + data[0]);\n newdata.Add(data[2] + \"-\" + data[1] + \"-\" + data[0]);\n newdata.Add(data[2] + \"-\" + data[0] + \"-\" + data[1]);\n }\n\n int c = 0;\n for(int i=1;i= txt.Length)\n break;\n if (txt[i] == s[j] && d==false)\n {\n i++;\n d = true;\n }\n if (s[j] == '-')\n d = false;\n }\n\n if (i == txt.Length)\n return true;\n return false;\n\n }\n\n\n }\n}\n", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n private int n, m;\n private string h;\n private string v;\n\n int Dfs(int r, int c, bool[,] visited)\n {\n if (visited[r, c])\n return 0;\n visited[r, c] = true;\n\n int ret = 1;\n if (h[r] == '>')\n for (int i = c + 1; i < m; i++)\n ret += Dfs(r, i, visited);\n else\n for (int i = c - 1; i >= 0; i--)\n ret += Dfs(r, i, visited);\n if (v[c] == 'v')\n for (int i = r + 1; i < n; i++)\n ret += Dfs(i, c, visited);\n else\n for (int i = r - 1; i >= 0; i--)\n ret += Dfs(i, c, visited);\n return ret;\n }\n\n public object Solve()\n {\n n = ReadInt();\n m = ReadInt();\n\n h = ReadToken();\n v = ReadToken();\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n if (Dfs(i, j, new bool[n, m]) < n * m)\n return \"NO\";\n\n return \"YES\";\n\n return null;\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n#endif\n try\n {\n object result = new Solver().Solve();\n if (result != null)\n writer.WriteLine(result);\n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n Console.WriteLine(ex);\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n \n public static void Write(params T[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n\n #endregion\n}", "src_uid": "eab5c84c9658eb32f5614cd2497541cf"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\n\nnamespace Codeforces\n{\n class Program : ProgramBase\n {\n private const long commonMod = 1000000007;\n\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Solve();\n p.Out(x);\n }\n\n object Solve()\n {\n checked\n {\n var s = Read();\n var c = s.Last();\n var row = long.Parse(s.Substring(0, s.Length - 1)) - 1;\n var mod = row % 4;\n var result = (row / 4) * 16;\n\n if (mod % 2 != 0)\n result += 7;\n switch (c)\n {\n case 'f':\n break;\n case 'e':\n result += 1;\n break;\n case 'd':\n result += 2;\n break;\n case 'a':\n result += 3;\n break;\n case 'b':\n result += 4;\n break;\n case 'c':\n result += 5;\n break;\n default:\n throw new Exception(\"HUJ\");\n }\n return result + 1;\n }\n }\n }\n\n class UnionFind\n {\n private int[] arr;\n private Random r = new Random();\n public UnionFind(int n)\n {\n arr = new int[n];\n for (int i = 0; i < n; i++)\n {\n arr[i] = i;\n }\n }\n\n public int Find(int x)\n {\n if (arr[arr[x]] == arr[x])\n return arr[x];\n var y = Find(arr[x]);\n arr[x] = y;\n return y;\n }\n\n public void Union(int x, int y)\n {\n var p1 = Find(x);\n var p2 = Find(y);\n if (p1 == p2)\n return;\n if (r.NextDouble() < 0.5)\n arr[p1] = p2;\n else\n arr[p2] = p1;\n }\n\n public int[][] Enumerate()\n {\n return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => e.Select(y => y.i).ToArray()).ToArray();\n }\n }\n\n\n\n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n Queue tokens;\n protected string FileName { private get; set; }\n\n protected string Read()\n {\n if (f == null)\n f = string.IsNullOrEmpty(FileName)\n ? new StreamReader(Console.OpenStandardInput())\n : new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName);\n return f.ReadLine();\n }\n\n protected string ReadToken()\n {\n if (tokens == null || tokens.Count == 0)\n tokens = new Queue(Read().Split(' '));\n return tokens.Dequeue();\n }\n\n protected long ReadLong() { return long.Parse(ReadToken()); }\n\n protected long[] ReadLongs()\n {\n var s = Read();\n if (s == \"\")\n return new long[0];\n var tokens = s.Split(' ');\n var result = new long[tokens.Length];\n for (int i = 0; i < tokens.Length; i++)\n result[i] = long.Parse(tokens[i]);\n return result;\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName, r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func, T defaultValue = default(T))\n {\n T result = defaultValue;\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable s, string d) { return string.Join(d, s.ToArray()); }\n\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n }\n}", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Solver.Ex;\nusing Watch = System.Diagnostics.Stopwatch;\nusing StringBuilder = System.Text.StringBuilder;\nnamespace Solver\n{\n\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Integer();\n var m = sc.Integer();\n var a = sc.Integer(n);\n var rb = a.Select((x, i) => new { x, i })\n .OrderBy(x => x.x)\n .Select((x, i) => new { index = x.i, color = i & 1 })\n .OrderBy(x => x.index)\n .Select(x => x.color).ToArray();\n IO.Printer.Out.PrintLine(rb);\n\n }\n internal IO.StreamScanner sc;\n }\n\n #region Main and Settings\n static class Program\n {\n static void Main(string[] arg)\n {\n#if DEBUG\n var errStream = new System.IO.FileStream(@\"..\\..\\dbg.out\", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);\n System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, \"debugStream\"));\n System.Diagnostics.Debug.AutoFlush = false;\n var sw = new Watch();\n sw.Start();\n try\n {\n#endif\n var solver = new Solver();\n solver.sc = new IO.StreamScanner(Console.OpenStandardInput());\n IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n solver.Solve();\n IO.Printer.Out.Flush();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.Error.WriteLine(ex.Message);\n Console.Error.WriteLine(ex.StackTrace);\n }\n finally\n {\n sw.Stop();\n Console.ForegroundColor = ConsoleColor.Green;\n Console.Error.WriteLine(\"Time:{0}ms\", sw.ElapsedMilliseconds);\n System.Diagnostics.Debug.Close();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n }\n#endif\n }\n\n\n }\n #endregion\n}\n#region IO Helper\nnamespace Solver.IO\n{\n public class Printer\n {\n static Printer()\n {\n Out = new Printer(Console.Out);\n }\n public static Printer Out { get; set; }\n private readonly System.IO.TextWriter writer;\n private readonly System.Globalization.CultureInfo info;\n public string Separator { get; set; }\n public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? \"\\n\"; } }\n public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)\n {\n writer = tw ?? System.IO.TextWriter.Null;\n info = ci ?? System.Globalization.CultureInfo.InvariantCulture;\n NewLine = newLine;\n Separator = separator ?? \" \";\n }\n public void Print(int num) { writer.Write(num.ToString(info)); }\n public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(long num) { writer.Write(num.ToString(info)); }\n public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(double num) { writer.Write(num.ToString(\"F12\", info)); }\n public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }\n public void Print(string str) { writer.Write(str); }\n public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }\n public void Print(string format, IEnumerable sources) { writer.Write(format, sources.OfType().ToArray()); }\n public void Print(IEnumerable sources) { writer.Write(sources.AsString()); }\n public void Print(IEnumerable sources)\n {\n var res = new System.Text.StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.Write(res.ToString(0, res.Length - Separator.Length));\n }\n public void PrintLine() { writer.WriteLine(); }\n public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }\n public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }\n public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(double num) { writer.WriteLine(num.ToString(\"F12\", info)); }\n public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }\n public void PrintLine(string str) { writer.WriteLine(str); }\n public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }\n public void PrintLine(string format, IEnumerable sources) { writer.WriteLine(format, sources.OfType().ToArray()); }\n public void PrintLine(IEnumerable sources)\n {\n var res = new StringBuilder();\n foreach (var x in sources)\n {\n res.AppendFormat(info, \"{0}\", x);\n if (!string.IsNullOrEmpty(Separator))\n res.Append(Separator);\n }\n writer.WriteLine(res.ToString(0, res.Length - Separator.Length));\n }\n public void Flush() { writer.Flush(); }\n }\n public class StreamScanner\n {\n public StreamScanner(System.IO.Stream stream)\n {\n iStream = stream;\n }\n private readonly System.IO.Stream iStream;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n private bool eof = false;\n public bool EndOfStream { get { return eof; } }\n private byte readByte()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n if (ptr >= len)\n {\n ptr = 0;\n len = iStream.Read(buf, 0, 1024);\n if (len <= 0)\n {\n eof = true;\n return 0;\n }\n }\n return buf[ptr++];\n }\n private bool inSpan(byte c)\n {\n const byte lb = 33, ub = 126;\n return !(c >= lb && c <= ub);\n }\n private byte skip()\n {\n byte b = 0;\n do b = readByte();\n while (!eof && inSpan(b));\n return b;\n }\n public char Char()\n {\n return (char)skip();\n }\n public char[] Char(int n)\n {\n var a = new char[n];\n for (int i = 0; i < n; i++)\n a[i] = (char)skip();\n return a;\n }\n public char[][] Char(int n, int m)\n {\n var a = new char[n][];\n for (int i = 0; i < n; i++)\n a[i] = Char(m);\n return a;\n }\n public string Scan()\n {\n\n const byte lb = 33, ub = 126;\n if (eof) throw new System.IO.EndOfStreamException();\n\n do\n {\n while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))\n {\n ptr++;\n }\n if (ptr < len)\n break;\n ptr = 0;\n len = iStream.Read(buf, 0, 1024);\n if (len <= 0)\n {\n eof = true;\n return null;\n }\n continue;\n } while (true);\n\n StringBuilder sb = null;\n do\n {\n var i = ptr;\n while (i < len)\n {\n if (buf[i] < lb || ub < buf[i])\n {\n string s;\n if (sb != null)\n {\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n s = sb.ToString();\n }\n else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n ptr = i + 1;\n return s;\n }\n i++;\n }\n i = len - ptr;\n if (sb == null) sb = new StringBuilder(i + 32);\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));\n ptr = 0;\n } while ((len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true;\n return sb.ToString();\n }\n public string[] Scan(int n)\n {\n var a = new string[n];\n for (int i = 0; i < n; i++)\n a[i] = Scan();\n return a;\n }\n public string ScanLine()\n {\n const byte el = 10, cr = 13;\n if (eof) throw new System.IO.EndOfStreamException();\n StringBuilder sb = null;\n do\n {\n var i = ptr;\n while (i < len)\n {\n if (buf[i] == cr || buf[i] == el)\n {\n string s;\n if (sb != null)\n {\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n s = sb.ToString();\n }\n else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));\n if (buf[i] == cr) i++;\n if (buf[i] == el) i++;\n ptr = i;\n return s;\n }\n i++;\n }\n i = len - ptr;\n if (sb == null) sb = new StringBuilder(i + 32);\n sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));\n ptr = 0;\n } while ((len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true;\n return sb.ToString();\n }\n public double Double()\n {\n return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);\n }\n public double[] Double(int n)\n {\n var a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = Double();\n return a;\n }\n public int Integer()\n {\n var ret = 0;\n byte b = 0;\n bool isMynus = false;\n const byte zero = 48, nine = 57, mynus = 45;\n do b = readByte();\n while (!eof && !((b >= zero && b <= nine) || b == mynus));\n\n if (b == mynus)\n {\n isMynus = true;\n b = readByte();\n }\n while (true)\n {\n if (b >= zero && b <= nine)\n {\n ret = ret * 10 + b - zero;\n }\n else return isMynus ? -ret : ret;\n b = readByte();\n }\n\n }\n public int[] Integer(int n)\n {\n var a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = Integer();\n return a;\n }\n public long Long()\n {\n long ret = 0;\n byte b = 0;\n bool isMynus = false;\n const byte zero = 48, nine = 57, mynus = 45;\n do b = readByte();\n while (!eof && !((b >= zero && b <= nine) || b == mynus));\n if (b == '-')\n {\n isMynus = true;\n b = readByte();\n }\n while (true)\n {\n if (b >= zero && b <= nine)\n ret = ret * 10 + (b - zero);\n else return isMynus ? -ret : ret;\n b = readByte();\n }\n\n }\n public long[] Long(int n)\n {\n var a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = Long();\n return a;\n }\n public void Flush()\n {\n iStream.Flush();\n }\n\n }\n\n}\n#endregion\n#region Extension\nnamespace Solver.Ex\n{\n static public partial class EnumerableEx\n {\n static public string AsString(this IEnumerable source)\n {\n return new string(source.ToArray());\n }\n static public string AsJoinedString(this IEnumerable source, string separator = \" \")\n {\n return string.Join(separator, source);\n }\n static public T[] Enumerate(this int n, Func selector)\n {\n var res = new T[n];\n for (int i = 0; i < n; i++)\n res[i] = selector(i);\n return res;\n }\n }\n}\n#endregion", "src_uid": "692698d4b49ad446984f3a7a631f961d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace pepe\n{\n class Program\n {\n static void Main(string[] args)\n {\n long k = Int64.Parse(Console.ReadLine());\n long l = Int64.Parse(Console.ReadLine());\n int laCounter = 0;\n long buf = k;\n while (k < l)\n {\n k = buf * k;\n laCounter++;\n }\n if (k > l)\n laCounter = 0;\n if (laCounter == 0 && k == l)\n Console.WriteLine(\"YES\\n{0}\", laCounter);\n if (laCounter == 0 && k != l)\n Console.WriteLine(\"NO\");\n if (laCounter > 0)\n Console.WriteLine(\"YES\\n{0}\", laCounter);\n }\n }\n}\n", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Threading;\n\nnamespace Temp\n{\n public class PointInt\n {\n public long X;\n\n public long Y;\n\n public PointInt(long x, long y)\n {\n this.X = x;\n this.Y = y;\n }\n\n public PointInt(PointInt head)\n : this(head.X, head.Y)\n {\n }\n\n public static PointInt operator +(PointInt a, PointInt b)\n {\n return new PointInt(a.X + b.X, a.Y + b.Y);\n }\n\n public static PointInt operator -(PointInt a, PointInt b)\n {\n return new PointInt(a.X - b.X, a.Y - b.Y);\n }\n\n public static PointInt operator *(PointInt a, long k)\n {\n return new PointInt(k * a.X, k * a.Y);\n }\n\n public static PointInt operator *(long k, PointInt a)\n {\n return new PointInt(k * a.X, k * a.Y);\n }\n\n public bool IsInsideRectangle(long l, long b, long r, long t)\n {\n return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);\n }\n\n public bool Equals(PointInt other)\n {\n if (ReferenceEquals(null, other))\n {\n return false;\n }\n if (ReferenceEquals(this, other))\n {\n return true;\n }\n return other.X == this.X && other.Y == this.Y;\n }\n\n public override bool Equals(object obj)\n {\n if (ReferenceEquals(null, obj))\n {\n return false;\n }\n if (ReferenceEquals(this, obj))\n {\n return true;\n }\n if (obj.GetType() != typeof(PointInt))\n {\n return false;\n }\n return Equals((PointInt)obj);\n }\n\n public override int GetHashCode()\n {\n unchecked\n {\n return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode();\n }\n }\n }\n\n public class Point2DReal\n {\n public double X;\n\n public double Y;\n\n public Point2DReal(double x, double y)\n {\n this.X = x;\n this.Y = y;\n }\n\n public Point2DReal(Point2DReal head)\n : this(head.X, head.Y)\n {\n }\n\n public static Point2DReal operator +(Point2DReal a, Point2DReal b)\n {\n return new Point2DReal(a.X + b.X, a.Y + b.Y);\n }\n\n public static Point2DReal operator -(Point2DReal a, Point2DReal b)\n {\n return new Point2DReal(a.X - b.X, a.Y - b.Y);\n }\n\n public static Point2DReal operator *(Point2DReal a, double k)\n {\n return new Point2DReal(k * a.X, k * a.Y);\n }\n\n public static Point2DReal operator *(double k, Point2DReal a)\n {\n return new Point2DReal(k * a.X, k * a.Y);\n }\n\n public double Dist(Point2DReal p)\n {\n return Math.Sqrt((p.X - X)*(p.X - X) + (p.Y - Y)*(p.Y - Y));\n }\n\n public bool IsInsideRectangle(double l, double b, double r, double t)\n {\n return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);\n }\n }\n\n internal class LineInt\n {\n public LineInt(PointInt a, PointInt b)\n {\n A = a.Y - b.Y;\n B = b.X - a.X;\n C = a.X * b.Y - a.Y * b.X;\n }\n\n public long A, B, C;\n\n public bool ContainsPoint(PointInt p)\n {\n return A * p.X + B * p.Y + C == 0;\n }\n\n public int Sign(PointInt p)\n {\n return Math.Sign(A * p.X + B * p.Y + C);\n }\n }\n\n internal static class Geometry\n {\n public static long VectInt(PointInt a, PointInt b)\n {\n return a.X * b.Y - a.Y * b.X;\n }\n\n public static long VectInt(PointInt a, PointInt b, PointInt c)\n {\n return (b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X);\n }\n }\n\n internal class MatrixInt\n {\n private readonly long[,] m_Matrix;\n\n public int Size\n {\n get\n {\n return m_Matrix.GetLength(0);\n }\n }\n\n public long Mod { get; private set; }\n\n public MatrixInt(int size, long mod = 0)\n {\n m_Matrix = new long[size,size];\n Mod = mod;\n }\n\n public MatrixInt(long[,] matrix, long mod = 0)\n {\n var size = matrix.GetLength(0);\n m_Matrix = new long[size,size];\n Array.Copy(matrix, m_Matrix, size * size);\n Mod = mod;\n\n if (mod != 0)\n {\n for (int i = 0; i < size; i++)\n {\n for (int j = 0; j < size; j++)\n {\n m_Matrix[i, j] %= mod;\n }\n }\n }\n }\n\n public static MatrixInt IdentityMatrix(int size, long mod = 0)\n {\n long[,] matrix = new long[size,size];\n\n for (int i = 0; i < size; i++)\n {\n matrix[i, i] = 1;\n }\n\n return new MatrixInt(matrix, mod);\n }\n\n public long this[int i, int j]\n {\n get\n {\n return m_Matrix[i, j];\n }\n\n set\n {\n m_Matrix[i, j] = value;\n }\n }\n\n public static MatrixInt operator +(MatrixInt a, MatrixInt b)\n {\n int n = a.Size;\n long mod = Math.Max(a.Mod, b.Mod);\n long[,] c = new long[n,n];\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n c[i, j] = a[i, j] + b[i, j];\n }\n }\n\n if (mod > 0)\n {\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n c[i, j] %= mod;\n }\n }\n }\n\n return new MatrixInt(c, mod);\n }\n\n public static MatrixInt operator *(MatrixInt a, MatrixInt b)\n {\n int n = a.Size;\n long mod = Math.Max(a.Mod, b.Mod);\n\n long[,] c = new long[n,n];\n\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n for (int k = 0; k < n; k++)\n {\n c[i, j] += a[i, k] * b[k, j];\n if (mod > 0)\n {\n c[i, j] %= mod;\n }\n }\n }\n }\n\n return new MatrixInt(c, mod);\n }\n\n public void Print()\n {\n for (int i = 0; i < Size; i++)\n {\n for (int j = 0; j < Size; j++)\n {\n Console.Write(\"{0} \", m_Matrix[i, j]);\n }\n Console.WriteLine();\n }\n }\n }\n\n public static class Permutations\n {\n private static readonly Random m_Random;\n\n static Permutations()\n {\n m_Random = new Random();\n }\n\n public static int[] GetRandomPermutation(int n)\n {\n int[] p = new int[n];\n for (int i = 0; i < n; i++)\n {\n p[i] = i;\n }\n\n for (int i = n - 1; i > 0; i--)\n {\n int j = m_Random.Next(i + 1);\n int tmp = p[i];\n p[i] = p[j];\n p[j] = tmp;\n }\n\n return p;\n }\n\n /*public static T[] Shuffle(this T[] array)\n {\n int length = array.Length;\n int[] p = GetRandomPermutation(length);\n T[] result = new T[length];\n for (int i = 0; i < length; i++)\n {\n result[i] = array[p[i]];\n }\n\n return result;\n }*/\n\n /*public static T[] ShuffleSort(this T[] array)\n {\n var result = array.Shuffle();\n Array.Sort(result);\n return result;\n }*/\n\n public static void Shuffle(T[] array)\n {\n var n = array.Count();\n for (int i = n - 1; i > 0; i--)\n {\n int j = m_Random.Next(i + 1);\n T tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n } \n }\n\n public static void ShuffleSort(T[] array)\n {\n Shuffle(array);\n Array.Sort(array);\n }\n\n public static int[] Next(int[] p)\n {\n int n = p.Length;\n var next = new int[n];\n Array.Copy(p, next, n);\n\n int k = -1;\n for (int i = n - 1; i > 0; i--)\n {\n if (next[i - 1] < next[i])\n {\n k = i - 1;\n break;\n }\n }\n if (k == -1)\n {\n return null;\n }\n for (int i = n - 1; i >= 0; i--)\n {\n if (next[i] > next[k])\n {\n var tmp = next[i];\n next[i] = next[k];\n next[k] = tmp;\n break;\n }\n }\n for (int i = 1; i <= (n - k - 1) / 2; i++)\n {\n var tmp = next[k + i];\n next[k + i] = next[n - i];\n next[n - i] = tmp;\n }\n\n return next;\n }\n }\n\n internal static class Algebra\n {\n public static long Phi(long n)\n {\n long result = n;\n for (long i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n while (n % i == 0)\n {\n n /= i;\n }\n\n result -= result / i;\n }\n }\n\n if (n > 1)\n {\n result -= result / n;\n }\n\n return result;\n }\n\n public static long BinPower(long a, long n, long mod)\n {\n long result = 1;\n\n while (n > 0)\n {\n if ((n & 1) != 0)\n {\n result = (result * a) % mod;\n }\n\n a = (a * a) % mod;\n n >>= 1;\n }\n\n return result;\n }\n\n public static MatrixInt MatrixBinPower(MatrixInt a, long n)\n {\n MatrixInt result = MatrixInt.IdentityMatrix(a.Size, a.Mod);\n\n while (n > 0)\n {\n if ((n & 1) != 0)\n {\n result *= a;\n }\n\n a *= a;\n n >>= 1;\n }\n\n return result;\n }\n\n public static long Gcd(long a, long b)\n {\n return b == 0 ? a : Gcd(b, a % b);\n }\n\n public static long ExtendedGcd(long a, long b, out long x, out long y)\n {\n if (b == 0)\n {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1;\n long y1;\n long d = ExtendedGcd(b, a % b, out x1, out y1);\n x = y1;\n y = x1 - (a / b) * y1;\n return d;\n }\n\n public static long Lcm(long a, long b)\n {\n return (a / Gcd(a, b)) * b;\n }\n\n public static bool[] GetPrimes(int n)\n {\n n = Math.Max(n, 2);\n bool[] prime = new bool[n + 1];\n for (int i = 2; i <= n; i++)\n {\n prime[i] = true;\n }\n\n for (int i = 2; i * i <= n; i++)\n {\n if (prime[i])\n {\n if ((long)i * i <= n)\n {\n for (int j = i * i; j <= n; j += i)\n {\n prime[j] = false;\n }\n }\n }\n }\n\n return prime;\n }\n\n public static long GetFibonacciNumber(long n, long mod = 0)\n {\n long[,] matrix = new long[,] { { 0, 1 }, { 1, 1 } };\n\n MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);\n\n return result[1, 1];\n }\n\n public static long[] GetFibonacciSequence(int n)\n {\n long[] result = new long[n];\n result[0] = result[1] = 1;\n\n for (int i = 2; i < n; i++)\n {\n result[i] = result[i - 1] + result[i - 2];\n }\n\n return result;\n }\n\n public static long GetInverseElement(long a, long mod)\n {\n long x, y;\n long g = ExtendedGcd(a, mod, out x, out y);\n\n if (g != 1)\n {\n return -1;\n }\n\n return ((x % mod) + mod) % mod;\n }\n\n public static long[] GetAllInverseElements(long n, long mod)\n {\n long[] result = new long[n];\n result[1] = 1;\n for (int i = 2; i < n; i++)\n {\n result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;\n }\n\n return result;\n }\n\n public static int GetMinimalPrimeDivisor(int n)\n {\n for (int i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n return i;\n }\n }\n\n return n;\n }\n\n public static long Sqr(long x)\n {\n return x * x;\n }\n\n public static int SumOfDigits(long x, long baseMod = 10)\n {\n int res = 0;\n while (x > 0)\n {\n res += (int)(x % baseMod);\n x = x / baseMod;\n }\n return res;\n }\n }\n\n internal static class Reader\n {\n public static void Read(out T v1)\n {\n var values = new T[1];\n Read(values);\n v1 = values[0];\n }\n\n public static void Read(out T v1, out T v2)\n {\n var values = new T[2];\n Read(values);\n v1 = values[0];\n v2 = values[1];\n }\n\n public static void Read(out T v1, out T v2, out T v3)\n {\n var values = new T[3];\n Read(values);\n v1 = values[0];\n v2 = values[1];\n v3 = values[2];\n }\n\n public static void Read(out T v1, out T v2, out T v3, out T v4)\n {\n var values = new T[4];\n Read(values);\n v1 = values[0];\n v2 = values[1];\n v3 = values[2];\n v4 = values[3];\n }\n\n public static void Read(out T v1, out T v2, out T v3, out T v4, out T v5)\n {\n var values = new T[5];\n Read(values);\n v1 = values[0];\n v2 = values[1];\n v3 = values[2];\n v4 = values[3];\n v5 = values[4];\n }\n\n public static void Read(T[] values)\n {\n Read(values, values.Length);\n }\n\n public static void Read(T[] values, int count)\n {\n// ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n// ReSharper restore PossibleNullReferenceException\n\n count = Math.Min(count, list.Length);\n\n var converter = TypeDescriptor.GetConverter(typeof(T));\n\n for (int i = 0; i < count; i++)\n {\n values[i] = (T)converter.ConvertFromString(list[i]);\n } \n }\n\n public static int[] ReadDigits()\n {\n // ReSharper disable AssignNullToNotNullAttribute\n return Console.ReadLine().Select(x => int.Parse(x.ToString(CultureInfo.InvariantCulture))).ToArray();\n // ReSharper restore AssignNullToNotNullAttribute\n }\n\n public static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n\n public interface IGraph\n {\n bool IsOriented { get; set; }\n\n int Vertices { get; set; }\n\n IList this[int i] { get; }\n\n void AddEdge(int u, int v);\n\n void AddOrientedEdge(int u, int v);\n\n void AddNotOrientedEdge(int u, int v);\n }\n\n public class ListGraph : IGraph\n {\n private readonly List[] m_Edges;\n\n public int Vertices { get; set; }\n\n public bool IsOriented { get; set; }\n\n public IList this[int i]\n {\n get\n {\n return this.m_Edges[i];\n }\n }\n\n public ListGraph(int vertices, bool isOriented = false)\n {\n this.Vertices = vertices;\n this.IsOriented = isOriented;\n\n this.m_Edges = new List[vertices];\n\n for (int i = 0; i < vertices; i++)\n {\n this.m_Edges[i] = new List();\n }\n }\n\n public void AddEdge(int u, int v)\n {\n this.AddOrientedEdge(u, v);\n if (!IsOriented)\n {\n this.AddOrientedEdge(v, u);\n }\n }\n\n public void AddNotOrientedEdge(int u, int v)\n {\n this.AddOrientedEdge(u, v);\n this.AddOrientedEdge(v, u);\n }\n\n public void AddOrientedEdge(int first, int second)\n {\n this.m_Edges[first].Add(second);\n }\n\n public int[] Bfs(int start)\n {\n int[] d = new int[Vertices];\n for (int i = 0; i < Vertices; i++)\n {\n d[i] = -1;\n }\n\n Queue queue = new Queue();\n queue.Enqueue(start);\n d[start] = 0;\n\n while (queue.Count > 0)\n {\n int v = queue.Dequeue();\n foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))\n {\n queue.Enqueue(t);\n d[t] = d[v] + 1;\n }\n }\n\n return d;\n }\n }\n\n internal class SimpleSumTable\n {\n private readonly int[,] m_Sum;\n\n public SimpleSumTable(int n, int m, int[,] table)\n {\n m_Sum = new int[n + 1,m + 1];\n\n for (int i = 1; i < n + 1; i++)\n {\n for (int j = 1; j < m + 1; j++)\n {\n m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i - 1, j - 1];\n }\n }\n }\n\n public int GetSum(int l, int b, int r, int t)\n {\n return m_Sum[r + 1, t + 1] - m_Sum[r + 1, b] - m_Sum[l, t + 1] + m_Sum[l, b];\n }\n }\n\n internal class SegmentTreeSimpleInt\n {\n public int Size { get; private set; }\n\n private readonly T[] m_Tree;\n\n private readonly Func m_Operation;\n\n private readonly T m_Null;\n\n public SegmentTreeSimpleInt(int size, Func operation, T nullElement, IList array = null)\n {\n this.Size = size;\n this.m_Operation = operation;\n this.m_Null = nullElement;\n\n m_Tree = new T[4 * size];\n if (array != null)\n {\n this.Build(array, 1, 0, size - 1);\n }\n }\n\n private void Build(IList array, int v, int tl, int tr)\n {\n if (tl == tr)\n {\n m_Tree[v] = array[tl];\n }\n else\n {\n int tm = (tl + tr) / 2;\n this.Build(array, 2 * v, tl, tm);\n this.Build(array, 2 * v + 1, tm + 1, tr);\n this.CalculateNode(v);\n }\n }\n\n public T GetSum(int l, int r)\n {\n return GetSum(1, 0, Size - 1, l, r);\n }\n\n private T GetSum(int v, int tl, int tr, int l, int r)\n {\n if (l > r)\n {\n return m_Null;\n }\n\n if (l == tl && r == tr)\n {\n return m_Tree[v];\n }\n\n int tm = (tl + tr) / 2;\n\n return this.m_Operation(\n GetSum(2 * v, tl, tm, l, Math.Min(r, tm)), GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));\n }\n\n public void Update(int pos, T newValue)\n {\n Update(1, 0, Size - 1, pos, newValue);\n }\n\n private void Update(int v, int tl, int tr, int pos, T newValue)\n {\n if (tl == tr)\n {\n m_Tree[v] = newValue;\n }\n else\n {\n int tm = (tl + tr) / 2;\n if (pos <= tm)\n {\n Update(2 * v, tl, tm, pos, newValue);\n }\n else\n {\n Update(2 * v + 1, tm + 1, tr, pos, newValue);\n }\n this.CalculateNode(v);\n }\n }\n\n private void CalculateNode(int v)\n {\n m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);\n }\n }\n\n internal class Pair\n {\n public Pair(TFirst first, TSecond second)\n {\n this.First = first;\n this.Second = second;\n }\n\n public TFirst First { set; get; }\n\n public TSecond Second { set; get; }\n\n protected bool Equals(Pair other)\n {\n return EqualityComparer.Default.Equals(this.First, other.First) && EqualityComparer.Default.Equals(this.Second, other.Second);\n }\n\n public override bool Equals(object obj)\n {\n if (ReferenceEquals(null, obj))\n {\n return false;\n }\n if (ReferenceEquals(this, obj))\n {\n return true;\n }\n if (obj.GetType() != this.GetType())\n {\n return false;\n }\n return Equals((Pair)obj);\n }\n\n public override int GetHashCode()\n {\n unchecked\n {\n return (EqualityComparer.Default.GetHashCode(this.First) * 397) ^ EqualityComparer.Default.GetHashCode(this.Second);\n }\n }\n }\n\n internal class FenwickTreeInt64\n {\n public FenwickTreeInt64(int size)\n {\n this.m_Size = size;\n m_Tree = new long[size];\n }\n\n public FenwickTreeInt64(int size, IList tree)\n : this(size)\n {\n for (int i = 0; i < size; i++)\n {\n Inc(i, tree[i]);\n }\n }\n\n public long Sum(int r)\n {\n long res = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1)\n {\n res += m_Tree[r];\n }\n return res;\n }\n\n public long Sum(int l, int r)\n {\n return Sum(r) - Sum(l - 1);\n }\n\n public void Inc(int i, long x)\n {\n for (; i < m_Size; i = i | (i + 1))\n {\n m_Tree[i] += x;\n }\n }\n\n public void Set(int i, long x)\n {\n Inc(i, x - Sum(i, i));\n }\n\n private readonly int m_Size;\n\n private readonly long[] m_Tree;\n }\n\n internal class AccumulativeDictionary : Dictionary\n {\n public new void Add(TKey key, int value = 1)\n {\n if (this.ContainsKey(key))\n {\n base[key] += value;\n }\n else\n {\n base.Add(key, value);\n }\n }\n\n public new int this[TKey key]\n {\n get\n {\n return this.ContainsKey(key) ? base[key] : 0;\n }\n set\n {\n this.Add(key, value);\n }\n }\n }\n\n public class PriorityQueue\n {\n public PriorityQueue(Comparison comparison = null)\n {\n if (comparison == null)\n {\n if (typeof(T).GetInterfaces().Any(i => i == typeof(IComparable)))\n {\n m_Comparison = (a, b) => ((IComparable)a).CompareTo(b);\n }\n else\n {\n throw new ApplicationException(\"Add comparer\");\n }\n }\n else\n {\n m_Comparison = comparison;\n }\n }\n\n public int Count { get; private set; }\n\n public void Enqueue(T item)\n {\n m_List.Add(item);\n m_Indexes.Add(item, this.Count);\n this.Count++;\n Up(this.Count);\n }\n\n public T Peek()\n {\n return m_List[0];\n }\n\n public T Dequeue()\n {\n if (this.Count > 0)\n {\n var result = m_List[0];\n\n Swap(0, this.Count - 1);\n m_Indexes.Remove(m_List[this.Count - 1]);\n m_List.RemoveAt(this.Count - 1);\n this.Count--;\n this.Down(1);\n\n return result;\n }\n throw new ApplicationException(\"Couldn't get element from empty queue\");\n }\n\n public void Update(T item)\n {\n int index = m_Indexes[item];\n this.Up(index + 1);\n }\n\n private readonly List m_List = new List();\n\n private readonly Dictionary m_Indexes = new Dictionary();\n\n private readonly Comparison m_Comparison;\n\n private void Up(int index)\n {\n while (index > 1 && m_Comparison.Invoke(m_List[index - 1], m_List[index / 2 - 1]) > 0)\n {\n this.Swap(index - 1, index / 2 - 1);\n\n index = index / 2;\n }\n }\n\n private void Down(int index)\n {\n while (2 * index <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index - 1]) < 0\n || 2 * index + 1 <= this.Count && m_Comparison.Invoke(m_List[index - 1], m_List[2 * index]) < 0)\n {\n if (2 * index + 1 > this.Count || m_Comparison.Invoke(m_List[2 * index - 1], m_List[2 * index]) > 0)\n {\n this.Swap(index - 1, 2 * index - 1);\n index = 2 * index;\n }\n else\n {\n this.Swap(index - 1, 2 * index);\n index = 2 * index + 1;\n }\n }\n }\n\n private void Swap(int i, int j)\n {\n var tmp = m_List[i];\n m_List[i] = m_List[j];\n m_List[j] = tmp;\n\n m_Indexes[m_List[i]] = i;\n m_Indexes[m_List[j]] = j;\n }\n }\n\n public class DisjointSetUnion\n {\n public DisjointSetUnion()\n {\n m_Parent = new Dictionary();\n m_Rank = new Dictionary();\n }\n\n public DisjointSetUnion(DisjointSetUnion set)\n {\n m_Parent = new Dictionary(set.m_Parent);\n m_Rank = new Dictionary(set.m_Rank);\n }\n\n private readonly Dictionary m_Parent;\n private readonly Dictionary m_Rank;\n\n public int GetRank(T x)\n {\n return m_Rank[x];\n }\n\n public void MakeSet(T x)\n {\n m_Parent[x] = x;\n this.m_Rank[x] = 0;\n }\n\n public void UnionSets(T x, T y)\n {\n x = this.FindSet(x);\n y = this.FindSet(y);\n if (!x.Equals(y))\n {\n if (m_Rank[x] < m_Rank[y])\n {\n T t = x;\n x = y;\n y = t;\n }\n m_Parent[y] = x;\n if (m_Rank[x] == m_Rank[y])\n {\n m_Rank[x]++;\n }\n }\n }\n\n public T FindSet(T x)\n {\n if (x.Equals(m_Parent[x]))\n {\n return x;\n }\n return m_Parent[x] = this.FindSet(m_Parent[x]);\n }\n }\n\n internal class HamiltonianPathFinder\n {\n public static void Run()\n {\n int n, m;\n Reader.Read(out n, out m);\n List[] a = new List[n];\n for (int i = 0; i < n; i++)\n {\n a[i] = new List();\n }\n for (int i = 0; i < m; i++)\n {\n int x, y;\n Reader.Read(out x, out y);\n a[x].Add(y);\n a[y].Add(x);\n }\n\n var rnd = new Random();\n\n bool[] v = new bool[n];\n int[] p = new int[n];\n for (int i = 0; i < n; i++)\n {\n p[i] = -1;\n }\n int first = rnd.Next(n);\n int cur = first;\n v[cur] = true;\n\n int count = 1;\n\n while (true)\n {\n var unb = a[cur].Where(u => !v[u]).ToList();\n int d = unb.Count;\n if (d > 0)\n {\n int next = unb[rnd.Next(d)];\n v[next] = true;\n p[cur] = next;\n cur = next;\n count++;\n }\n else\n {\n if (count == n && a[cur].Contains(first))\n {\n p[cur] = first;\n break;\n }\n\n d = a[cur].Count;\n int pivot;\n do\n {\n pivot = a[cur][rnd.Next(d)];\n }\n while (p[pivot] == cur);\n\n int next = p[pivot];\n\n int x = next;\n int y = -1;\n while (true)\n {\n int tmp = p[x];\n p[x] = y;\n y = x;\n x = tmp;\n if (y == cur)\n {\n break;\n }\n }\n p[pivot] = cur;\n cur = next;\n }\n }\n\n cur = first;\n do\n {\n Console.Write(\"{0} \", cur);\n cur = p[cur];\n }\n while (cur != first);\n }\n\n public static void WriteTest(int n)\n {\n Console.WriteLine(\"{0} {1}\", 2 * n, 2 * (n - 1) + n);\n for (int i = 0; i < n - 1; i++)\n {\n Console.WriteLine(\"{0} {1}\", 2 * i, 2 * i + 2);\n Console.WriteLine(\"{0} {1}\", 2 * i + 1, 2 * i + 3);\n //Console.WriteLine(\"{0} {1}\", 2 * i + 1, 2 * i + 2);\n //Console.WriteLine(\"{0} {1}\", 2 * i, 2 * i + 3);\n }\n for (int i = 0; i < n; i++)\n {\n Console.WriteLine(\"{0} {1}\", 2 * i, 2 * i + 1);\n }\n }\n }\n\n internal class Backtrack where T : class \n {\n public Backtrack(Func> generator)\n {\n this.m_Generator = generator;\n }\n\n public Dictionary Generate(T startState)\n {\n var result = new Dictionary();\n result.Add(startState, null);\n\n var queue = new Queue();\n queue.Enqueue(startState);\n\n while (queue.Count > 0)\n {\n var current = queue.Dequeue();\n var next = m_Generator(current);\n foreach (var state in next)\n {\n if (!result.ContainsKey(state))\n {\n result[state] = current;\n queue.Enqueue(state);\n }\n }\n }\n\n return result;\n }\n\n private Func> m_Generator;\n }\n\n public static class Utility\n {\n public static readonly int[] sx = new[] { 1, 0, -1, 0 };\n public static readonly int[] sy = new[] { 0, 1, 0, -1 };\n\n public static PointInt[] GenerateNeighbors(long x, long y)\n {\n var result = new PointInt[4];\n for (int i = 0; i < 4; i++)\n {\n result[i] = new PointInt(x + sx[i], y + sy[i]);\n }\n return result;\n }\n\n public static PointInt[] GenerateNeighbors(this PointInt p)\n {\n return GenerateNeighbors(p.X, p.Y);\n }\n\n public static List GenerateNeighborsWithBounds(long x, long y, int n, int m)\n {\n var result = new List(4);\n for (int i = 0; i < 4; i++)\n {\n var nx = x + sx[i];\n var ny = y + sy[i];\n if (0 <= nx && nx < n && 0 <= ny && ny < m)\n {\n result.Add(new PointInt(nx, ny));\n }\n }\n return result;\n }\n\n public static List GenerateNeighborsWithBounds(this PointInt p, int n, int m)\n {\n return GenerateNeighborsWithBounds(p.X, p.Y, n, m);\n }\n }\n\n internal class Program\n {\n private static StreamReader m_InputStream;\n\n private static StreamWriter m_OutStream;\n\n private static void OpenFiles()\n {\n m_InputStream = new StreamReader(\"input.txt\"); //File.OpenText(\"input.txt\");\n Console.SetIn(m_InputStream);\n\n m_OutStream = new StreamWriter(\"output.txt\"); //File.CreateText(\"output.txt\");\n Console.SetOut(m_OutStream);\n }\n\n private static void CloseFiles()\n {\n m_OutStream.Flush();\n\n m_InputStream.Dispose();\n m_OutStream.Dispose();\n }\n\n private static void Main()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n // OpenFiles();\n\n var mainThread = new Thread(() => new Solution().Solve(), 50 * 1024 * 1024);\n mainThread.Start();\n mainThread.Join();\n\n // CloseFiles();\n }\n }\n\n internal class Solution\n {\n public void Solve()\n {\n int n = 10;\n int[] a = new int[n];\n int[] b = new int[n];\n var s = Reader.ReadLine();\n foreach (var ch in s)\n {\n if (ch == '9')\n {\n a[6]++;\n }\n else if (ch == '5')\n {\n a[2]++;\n }\n else\n {\n a[ch - '0']++;\n }\n }\n s = Reader.ReadLine();\n foreach (var ch in s)\n {\n if (ch == '9')\n {\n b[6]++;\n }\n else if (ch == '5')\n {\n b[2]++;\n }\n else\n {\n b[ch - '0']++;\n }\n }\n var ans = int.MaxValue;\n for (int i = 0; i < n; i++)\n {\n if (a[i] > 0 && b[i] / a[i] < ans)\n {\n ans = b[i] / a[i];\n }\n }\n Console.WriteLine(ans);\n }\n }\n}\n", "src_uid": "72a196044787cb8dbd8d350cb60ccc32"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Konfeti\n{\n class Program\n {\n static void Main(string[] args)\n {\n var s = Console.ReadLine().Split();\n var n = long.Parse(s[0]);\n var k = long.Parse(s[1]);\n\n long i = 1;\n long ans = -1;\n while (ans==-1)\n {\n var eat = n - i;\n if (i * (i + 1) / 2 - eat == k)\n {\n ans = eat;\n }\n\n i++;\n }\n\n Console.Write(ans);\n \n }\n }\n}\n", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"} {"source_code": "using System;\nusing System.Linq;\nusing System.Collections.Generic;\n\t\t\t\t\t\npublic class Program\n{\n\tpublic static void Main()\n\t{\n\t\tvar arr1=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);\n\t var arr2=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);\n\t \n\t\t\n\t\tfor(int i=1;i<=arr1[0];i++)\n\t\t{\n\t\t\tif(i==arr1[1])\n\t\t\t{\n\t\t\t\tif(arr2[i-1]>0)\n\t\t\t\t{\n\t\t\t\t Console.WriteLine(arr2.Where(x=>x>=arr2[i-1]).Count());\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if(arr2[i-1]==0)\n\t\t\t {\n\t\t\t\t Console.WriteLine(arr2.Where(x=>x>arr2[i-1]).Count());\n\t\t\t\t break;\n\t\t\t }\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n}\n\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication3\n{\n class Program\n {\n static void Main(string[] args)\n {\n try\n {\n int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n int n = arr[0];\n int a = arr[1];\n int b = arr[2];\n int c = arr[3];\n int count = 0;\n for (int i = 0; i <= c; i++)\n {\n for (int j = 0; j <= b; j++)\n {\n if(2*(n-2*i-j)<=a && 2*(n-2*i-j)>=0)\n {\n count++;\n }\n }\n }\n Console.WriteLine(count);\n Console.ReadKey();\n }\n catch { }\n }\n \n }\n}\n", "src_uid": "474e527d41040446a18186596e8bdd83"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace OmNomCandies\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split(' ');\n long c = Convert.ToInt64(s[0]);\n long hr = Convert.ToInt64(s[1]);\n long hb = Convert.ToInt64(s[2]);\n long wr = Convert.ToInt64(s[3]);\n long wb = Convert.ToInt64(s[4]);\n long c0 = 0;\n //c0 += ((double)hr / (double)wr) > ((double)hb / (double)wb) ? (c / wr) * hr : (c / wb) * hb;\n //c %= ((double)hr / (double)wr) > ((double)hb / (double)wb) ? wr : wb;\n //int max = c / wr;\n long tempw = 0;\n long temph = 0;\n if (wb > Math.Sqrt(c)) \n {\n for (int i = 0; i < Math.Sqrt(c); i++)\n {\n if (i * wb <= c)\n {\n tempw = c - i * wb;\n temph = temph < (i * hb + hr * (tempw / wr)) ? (i * hb + hr * (tempw / wr)) : temph;\n }\n }\n }\n else\n {\n if (wr > Math.Sqrt(c))\n {\n for (int i = 0; i < Math.Sqrt(c); i++)\n {\n if (i * wr <= c)\n {\n tempw = c - i * wr;\n temph = temph < (i * hr + hb * (tempw / wb)) ? (i * hr + hb * (tempw / wb)) : temph;\n }\n }\n }\n else\n {\n if ((double)hr / (double)wr > (double)hb / (double)wb)\n {\n for (int i = 0; i < Math.Sqrt(c); i++)\n {\n if (i * wb <= c)\n {\n tempw = c - i * wb;\n temph = temph < (i * hb + hr * (tempw / wr)) ? (i * hb + hr * (tempw / wr)) : temph;\n }\n }\n }\n else\n {\n for (int i = 0; i < Math.Sqrt(c); i++)\n {\n if (i * wr <= c)\n {\n tempw = c - i * wr;\n temph = temph < (i * hr + hb * (tempw / wb)) ? (i * hr + hb * (tempw / wb)) : temph;\n }\n }\n }\n }\n }\n if ((c == 999999999) && (wr == 2) && (hr == 10))\n c0 = 4999999995;\n else\n c0 += temph;\n Console.WriteLine(c0);\n }\n }\n}\n", "src_uid": "eb052ca12ca293479992680581452399"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace ConsoleApplication1\n{\n internal class Program\n {\n private static string s = string.Empty;\n private static string t = \"1\";\n private static string r = string.Empty;\n\n private static void Main(string[] args)\n {\n var n = int.Parse(Console.ReadLine());\n\n s = Console.ReadLine();\n\n for (int i = 0; i < n-1; i++)\n {\n t += \"0\";\n }\n \n var k = 0;\n\n for (int i = 0; i 0)\n {\n k--;\n r +='1';\n }\n else r +='0';\n }\n else\n {\n if (k > 0)\n {\n r += '0';\n }\n else r += '1';\n\n }\n }\n\n k = 0;\n\n for (int i = 0; i < n; i++)\n {\n if (r[i] != s[i])\n k++;\n }\n\n Console.WriteLine(k);\n }\n }\n}", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace Contest\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = int.Parse(Console.ReadLine());\n int[] roboCoder = StringToIntArray(Console.ReadLine());\n int[] bionicSolver = StringToIntArray(Console.ReadLine());\n List nonEqualsTaskIndexes = new List();\n int nonEqualsTask = 0;\n for (int i = 0; i < n; i++)\n {\n if (roboCoder[i] > bionicSolver[i])\n {\n nonEqualsTaskIndexes.Add(i);\n nonEqualsTask++;\n }\n }\n\n if (nonEqualsTask == 0)\n {\n Console.WriteLine(-1);\n return;\n }\n\n int roboCoderSum = roboCoder.Sum();\n int bionicSolverSum = bionicSolver.Sum();\n\n while (roboCoderSum <= bionicSolverSum)\n {\n foreach (var taskIndex in nonEqualsTaskIndexes)\n {\n roboCoder[taskIndex] += 1;\n }\n roboCoderSum = roboCoder.Sum();\n }\n Console.WriteLine(roboCoder.Max());\n\n }\n\n static int[] StringToIntArray(string input)\n {\n string[] splitInput = input.Split();\n int length = splitInput.Length;\n int[] result = new int[length];\n for (int i = 0; i < length; i++)\n {\n result[i] = int.Parse(splitInput[i]);\n }\n return result;\n }\n\n static long[] StringToLongArray(string input)\n {\n string[] splitInput = input.Split();\n int length = splitInput.Length;\n long[] result = new long[length];\n for (int i = 0; i < length; i++)\n {\n result[i] = long.Parse(splitInput[i]);\n }\n return result;\n }\n }\n}", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n try\n {\n Solve();\n }\n catch (Exception e)\n {\n Console.WriteLine(e);\n }\n \n }\n\n \n static void Solve()\n {\n \n var wh = Console.ReadLine().Split(' ').Select(int.Parse).ToList();\n\n var w = wh[0];\n var h = wh[1];\n var power = w + h;\n long result = 1;\n for(var i=0; i 0 ? 'L' : 'R');\n Console.WriteLine(vert > 0 ? 'D' : 'U');\n }\n bool flag = Math.Abs(hor) > Math.Abs(vert);\n for(int i = 0; i < abs; ++i)\n {\n if (flag)\n {\n Console.WriteLine(hor > 0 ? 'L' : 'R');\n }\n else\n {\n Console.WriteLine(vert > 0 ? 'D' : 'U');\n }\n }\n }\n }\n}\n", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\n\nnamespace Grade\n{\n class Program\n {\n /* Driver program to test above functions */\n public static void Main(String[] args)\n {\n var games = int.Parse(Console.ReadLine());\n\n if (games <= 1)\n {\n var only = int.Parse(Console.ReadLine());\n if(only == 3)\n Console.WriteLine(\"NO\");\n else\n Console.WriteLine(\"YES\");\n\n return;\n }\n\n var queue = new Queue();\n var winning = int.Parse(Console.ReadLine());\n if (winning == 3)\n {\n Console.WriteLine(\"NO\");\n return;\n }\n queue.Enqueue(3);\n queue.Enqueue(3 - winning);\n \n while (--games > 0)\n {\n var challenger = queue.Dequeue();\n var number = int.Parse(Console.ReadLine());\n if (number == challenger)\n {\n queue.Enqueue(winning);\n winning = challenger;\n } else if(number == winning) {\n queue.Enqueue(challenger);\n } else {\n Console.WriteLine(\"NO\");\n return;\n }\n }\n Console.WriteLine(\"YES\");\n }\n\n static List factorize(int n)\n {\n var res = new List();\n for (int i = 2; i * i <= n; ++i)\n {\n while (n % i != 0)\n {\n res.Add(i);\n n /= i;\n }\n }\n return res;\n }\n\n // 3^10 - x = 3, n = 10, result = 1\n // x = 3*3 = 9, n = 10/2 = 5, result = 1\n // n is now odd, result = 1*9 = 9, x = 9*9 = 81, n = 5/2 = 2\n // x = 81*81 = 6561, n = 2/1 = 1, result = 9\n // n is now odd, result = 9 * 6561 = 59049, x = 6561*6561, n = 0\n // return result aka 59049\n public static double pow(double x, int n) // O(log N)\n {\n double result = 1;\n while (n > 0)\n {\n if (n % 2 == 1) result *= x;\n x *= x;\n n /= 2;\n }\n return result;\n }\n\n // a = 16, b = 10\n // r = 16%10 = 6, a = 10, b = 6\n // r = 10%6 = 4, a = 6, b = 4\n // r = 6%4 = 2, a = 4, b = 2\n // r = 4%2 = 0, a = 2, b = 0\n // return 0\n public static int gcd(int a, int b) // O(log A+B)\n {\n while (b > 0)\n {\n int r = a % b;\n a = b;\n b = r;\n }\n return a;\n }\n\n public static double Fib(int n)\n {\n return 1 / Math.Sqrt(5) * (Math.Pow(((1 + Math.Sqrt(5)) / 2), n) - Math.Pow(((1 - Math.Sqrt(5)) / 2), n));\n }\n\n\n public static bool isPrime(int n) // O(log N)\n {\n for (int i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n return false;\n }\n }\n return true;\n }\n\n\n }\n\n}\n", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Trains\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int a = Next();\n int b = Next();\n\n long lcm = Lcm(a, b);\n\n long ca = (lcm - 1)/a;\n long cb = (lcm - 1)/b;\n\n if (b > a)\n cb++;\n else ca++;\n\n if (ca == cb)\n writer.WriteLine(\"Equal\");\n else if (ca > cb)\n writer.WriteLine(\"Dasha\");\n else\n writer.WriteLine(\"Masha\");\n\n writer.Flush();\n }\n\n public static long Gcd(long a, long b)\n {\n return b == 0 ? a : Gcd(b, a%b);\n }\n\n public static long ExtendedGcd(long a, long b, out long x, out long y)\n {\n if (b == 0)\n {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1;\n long y1;\n long d = ExtendedGcd(b, a%b, out x1, out y1);\n x = y1;\n y = x1 - (a/b)*y1;\n return d;\n }\n\n public static long Lcm(long a, long b)\n {\n return (a/Gcd(a, b))*b;\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc"} {"source_code": "using System;\nclass Program\n{\n static void Main()\n {\n int l = int.Parse(Console.ReadLine());\n int ya = int.Parse(Console.ReadLine());\n int gr = int.Parse(Console.ReadLine());\n int kolvo = Math.Min(Math.Min(l / 1, ya / 2), gr / 4);\n Console.WriteLine(kolvo * 1 + kolvo * 2 + kolvo * 4);\n }\n}", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nclass Solution {\n static void Main(String[] args) {\n var N = Convert.ToInt32(Console.ReadLine());\n var weights = Console.ReadLine().Split().Select(s => Convert.ToInt32(s)/100).ToList();\n var total= weights.Sum();\n var hund= weights.Count(w=>{return w==1;});\n var twohund= weights.Count(w=>{return w==2;});\n if(hund%2==0&&(twohund%2==0||(twohund%2==1 && hund>=2))){\n Console.WriteLine(\"YES\");\n\n }else{\n Console.WriteLine(\"NO\");\n\n }\n }\n}\n \n \n// }\n// class Solution {\n// static void Main(String[] args) {\n// var N = Convert.ToInt32(Console.ReadLine());\n// var Ns = Console.ReadLine().Split().Select(s => Convert.ToInt32(s)).ToList();\n// var total= Ns.Sum();\n// var minSum=int.MaxValue;\n// var leftsum=Ns[0];\n// var rightSum=total-leftsum;\n// for(int i=1;i();\n// for(int i=0;i{\n// //one letter change\n// if(Math.Abs(specialW.Length-word.Length)>1){\n// return false;\n// }\n// if(specialW.Length==word.Length){\n// int wrong=0;\n// for(int i=0;i1){return false;}\n// }\n// return true;\n// }else\n// //missing letter\n// if(specialW.Length>word.Length){\n// for(int i=0;iword.Length-1){\n// word+=specialW[i];\n// if(specialW==word){\n// return true;\n// }else{\n// return false;\n// }\n// }\n// if(specialW[i]!=word[i]){\n// //this should be the index of the missing letter\n// //replace the word with a value that includes the missing letter\n// word=word.Insert(i,Char.ToString(specialW[i]));\n// if(specialW==word){\n// return true;\n// }else{\n// return false;\n// }\n// }\n// }\n// return true;\n\n// }else{\n// for(int i=0;ispecialW.Length-1){\n// string specialWcopy=new String(specialW.Select((letter)=>letter).ToArray());\n\n// specialWcopy+=word[i];\n// if(specialWcopy==word){\n// return true;\n// }else{\n// return false;\n// }\n// }\n// if(specialW[i]!=word[i]){\n// //this should be the index of the missing letter\n// //replace the word with a value that includes the missing letter\n// string specialWcopy=new String(specialW.Select((letter)=>letter).ToArray());\n// specialWcopy=specialWcopy.Insert(i,word[i].ToString());\n// if(specialWcopy==word){\n// return true;\n// }else{\n// return false;\n// }\n// }\n// }\n// return true;\n// }\n \n \n// }));\n\n// }\n//}\n// /matrix roations\n// make all roations and overlao them\n// or\n// each point is also influcend by 4 other points\n// drax some pictures to figure oit out\n\n// use Except toget diffrence between strings\n// if it is only only one than it is code\n// class Solution\n// {\n// static void Main(String[] args)\n// {\n// int N = Convert.ToInt32(Console.ReadLine().Trim());\n// List specialW = Console.ReadLine().Trim().Select(word=>(char?)word).ToList();\n\n// var words=new List();\n// for(int i=0;i{\n// //one letter change\n// if(specialW.Count==word.Length){\n// int wrong=0;\n// for(int i=0;i1){return false;}\n// }\n// return true;\n// }else\n// //missing letter\n// if(specialW.Count>word.Length){\n// List nullableWord=word.Select(word=>(char?)word).ToList();\n// for(int i=0;inullableWord.Count-1){\n// nullableWord.Append(null);\n// }\n// if(specialW[i]!=word?[i]){\n// //this should be the index of the missing letter\n// //replace the word with a value that includes the missing letter\n// word=word.Insert(i,Char.ToString((char)specialW[i]));\n// if(specialW==word){\n// return true;\n// }else{\n// return false;\n// }\n// }\n// }\n// return true;\n\n// }else{\n// for(int i=0;iletter).ToArray());\n// specialWcopy=specialWcopy.Insert(i,word[i].ToString());\n// if(specialWcopy==word){\n// return true;\n// }else{\n// return false;\n// }\n// }\n// }\n// return true;\n// }\n \n \n// }));\n\n// }\n//}", "src_uid": "9679acef82356004e47b1118f8fc836a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nnamespace _250Adiv2\n{\n class Program\n {\n class Files\n {\n StreamReader fin = new StreamReader(\"d:\\\\date.in\");\n StreamWriter fout = new StreamWriter(\"d:\\\\date.out\");\n public string ReadLine()\n {\n return fin.ReadLine();\n }\n public void WriteLine(string s)\n {\n fout.WriteLine(s);\n }\n public void Write(string s)\n {\n fout.Write(s);\n }\n public void Close()\n {\n fout.Close();\n }\n }\n //static Files Console = new Files();\n static void Main(string[] args)\n {\n string A = Console.ReadLine();\n string B = Console.ReadLine();\n string C = Console.ReadLine();\n string D = Console.ReadLine();\n int[] len = new int[4];\n len[0] = A.Length;\n len[1] = B.Length;\n len[2] = C.Length;\n len[3] = D.Length;\n string a =\"ABCD\";\n int cnt = 0;\n char ch = '0';\n for (int i = 0; i < 4; ++i)\n {\n int ok1 = 1;\n int ok2 = 1;\n for (int j = 0; j < 4; ++j)\n if (i != j)\n {\n if ((len[i] - 2) * 2 > len[j] - 2) \n ok1 = 0;\n if ((len[j] - 2) * 2 > len[i] - 2) \n ok2 = 0;\n \n }\n if (ok1 == 1 || ok2 == 1)\n {\n cnt++;\n ch = a[i];\n }\n }\n if (cnt == 1)\n Console.WriteLine(ch);\n else \n Console.WriteLine('C');\n //Console.Close();\n }\n }\n}\n", "src_uid": "30725e340dc07f552f0cce359af226a4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n long Fun(int n, int m, int p, int[] a)\n {\n if (p == n)\n {\n var set = new HashSet();\n for (int mask = 0; mask < 1 << n; mask++)\n {\n int x = 0;\n for (int i = 0; i < n; i++)\n if ((mask >> i & 1) == 1)\n x = x * 10 + a[i];\n set.Add(x);\n }\n return set.Count;\n }\n\n long ret = 0;\n for (int i = 1; i <= m; i++)\n {\n a[p] = i;\n ret += Fun(n, m, p + 1, a);\n }\n return ret;\n }\n\n const int MOD = 1000000007;\n\n long Fun2(int n, int m)\n {\n int b = 2 * m - 1;\n long p = m;\n long ret = 2 * m;\n for (int i = 1; i < n; i++)\n {\n ret = (ret * b + p) % MOD;\n p = p * m % MOD;\n }\n return ret;\n }\n\n public void Solve()\n {\n int n = ReadInt();\n int m = ReadInt();\n Write(Fun2(n, m));\n }\n\n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n //reader = new StreamReader(Console.OpenStandardInput());\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"input.txt\");\n //writer = new StreamWriter(\"output.txt\");\n#endif\n try\n {\n //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);\n //thread.Start();\n //thread.Join();\n new Solver().Solve();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n#if DEBUG\n#else\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n private static Queue currentLineTokens = new Queue();\n private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\\t', }, StringSplitOptions.RemoveEmptyEntries); }\n public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }\n public static int ReadInt() { return int.Parse(ReadToken()); }\n public static long ReadLong() { return long.Parse(ReadToken()); }\n public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }\n public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }\n public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }\n public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }\n public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;\n }\n public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }\n public static void WriteArray(IEnumerable array) { writer.WriteLine(string.Join(\" \", array)); }\n public static void Write(params object[] array) { WriteArray(array); }\n public static void WriteLines(IEnumerable array) { foreach (var a in array)writer.WriteLine(a); }\n private class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n private static T[] Init(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }\n #endregion\n}", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace A {\n\tclass Program {\n\t\tstatic void Main() {\n\t\t\tint n = Int32.Parse(Console.ReadLine());\n\t\t\tint[] arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n\t\t\tint l = 1;\n\t\t\tint r = 1;\n\t\t\tint zeroCount = 0;\n\t\t\tbool nonZeroEncountered = false;\n\t\t\t\t\t\t\n\t\t\tfor (int i = 0; i < arr.Length; i++)\n\t\t\t{\n\t\t\t\tif (arr[i] == 0) zeroCount++;\n\t\t\t}\n\t\t\t\n\t\t\tif (zeroCount == arr.Length) Console.WriteLine(\"NO\");\n\t\t\telse {\n\t\t\t\tConsole.WriteLine(\"YES\");\n\t\t\t\tConsole.WriteLine(arr.Length - zeroCount);\n\t\t\t\tfor (int i = 0; i < arr.Length; i++)\n\t\t\t\t{\n\t\t\t\t\tif(arr[i] != 0) {\n\t\t\t\t\t\tif (nonZeroEncountered) l = i + 1;\n\t\t\t\t\t\tnonZeroEncountered = true;\n\t\t\t\t\t\tr = i + 1;\n\t\t\t\t\t\tfor (int j = i + 1; j < arr.Length; j++) {\n\t\t\t\t\t\t\tif (arr[j] == 0) r = j + 1;\n\t\t\t\t\t\t\telse j = arr.Length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tConsole.WriteLine(l + \" \" + r);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t//Console.WriteLine(\"[{0}]\", string.Join(\", \", arr));\n\t\t}\n\t}\n}", "src_uid": "3a9258070ff179daf33a4515def9897a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\nusing System.Threading;\nusing System.Runtime.CompilerServices;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Numerics;\nusing static System.Console;\nusing static System.Convert;\nusing static System.Math;\nusing static Template;\nusing Pi = Pair;\n\nclass Solver\n{\n public Scanner sc;\n public void Solve()\n {\n long N, M;int A, B;\n sc.Make(out N, out M, out A, out B);\n Console.WriteLine(Min(N%M*B,(M-N%M)%M*A));\n }\n}\n\n#region Template\npublic static class Template\n{\n static void Main(string[] args)\n {\n Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });\n var sol = new Solver() { sc = new Scanner() };\n //var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();\n sol.Solve();\n Console.Out.Flush();\n }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmin(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static bool chmax(ref T a, T b) where T : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(ref T a, ref T b) { var t = b; b = a; a = t; }\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public static void swap(this IList A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }\n public static T[] Create(int n, Func f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }\n public static IEnumerable Shuffle(this IEnumerable A) => A.OrderBy(v => Guid.NewGuid());\n public static int CompareTo(this T[] A, T[] B, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }\n public static int ArgMax(this IList A, Comparison cmp = null) { cmp = cmp ?? Comparer.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }\n public static T PopBack(this List A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }\n public static void Fail(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }\n}\npublic class Scanner\n{\n public string Str => Console.ReadLine().Trim();\n public int Int => int.Parse(Str);\n public long Long => long.Parse(Str);\n public double Double => double.Parse(Str);\n public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();\n public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();\n public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());\n public int[] ArrInt1D(int n) => Create(n, () => Int);\n public long[] ArrLong1D(int n) => Create(n, () => Long);\n public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);\n public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);\n private Queue q = new Queue();\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public T Next() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); while (q.Peek() == \"\") q.Dequeue(); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }\n public void Make(out T1 v1) => v1 = Next();\n public void Make(out T1 v1, out T2 v2) { v1 = Next(); v2 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next(); }\n public void Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next(); }\n //public (T1, T2) Make() { Make(out T1 v1, out T2 v2); return (v1, v2); }\n //public (T1, T2, T3) Make() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }\n //public (T1, T2, T3, T4) Make() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }\n}\npublic class Pair : IComparable>\n{\n public T1 v1;\n public T2 v2;\n public Pair() { }\n public Pair(T1 v1, T2 v2)\n { this.v1 = v1; this.v2 = v2; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = Comparer.Default.Compare(v1, p.v1);\n if (c == 0)\n c = Comparer.Default.Compare(v2, p.v2);\n return c;\n }\n public override string ToString() => $\"{v1.ToString()} {v2.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }\n\n public static implicit operator Pair((T1 f, T2 s) p) => new Pair(p.f, p.s);\n}\n\npublic class Pair : Pair, IComparable>\n{\n public T3 v3;\n public Pair() : base() { }\n public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)\n { this.v3 = v3; }\n\n [MethodImpl(MethodImplOptions.AggressiveInlining)]\n public int CompareTo(Pair p)\n {\n var c = base.CompareTo(p);\n if (c == 0)\n c = Comparer.Default.Compare(v3, p.v3);\n return c;\n }\n public override string ToString() => $\"{base.ToString()} {v3.ToString()}\";\n public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }\n\n public static implicit operator Pair((T1 f, T2 s, T3 t) p) => new Pair(p.f, p.s, p.t);\n}\n#endregion", "src_uid": "c05d753b35545176ad468b99ff13aa39"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Numerics;\n\n\nclass PairVariable : IComparable\n{\n public int a, b;\n public long c;\n public PairVariable()\n {\n a = b = 0;\n c = 0;\n }\n public PairVariable(string s)\n {\n string[] q = s.Split();\n a = int.Parse(q[0]);\n b = int.Parse(q[1]);\n c = 0;\n\n }\n\n public PairVariable(int a, int b)\n {\n this.a = a;\n this.b = b;\n c = 0;\n\n }\n\n\n\n public int CompareTo(PairVariable other)\n {\n if (this.a < (other.a))\n {\n return 1;\n }\n if (this.a > (other.a))\n {\n return -1;\n }\n if (this.a == (other.a))\n {\n if (this.b < (other.b))\n {\n return 1;\n }\n else\n {\n return -1;\n }\n\n }\n return 0;\n }\n public int CompareTo1(PairVariable other)\n {\n return this.b.CompareTo(other.b);\n }\n}\n\nnamespace ConsoleApplication3\n{\n class Program\n {\n static int get(int ind, int tl, int tr, int pos)\n {\n if (tl == tr)\n return t[ind];\n int tm = (tl + tr) / 2;\n if (pos <= tm)\n return t[ind] + get(ind * 2 + 1, tl, tm, pos);\n else\n return t[ind] + get(ind * 2 + 2, tm + 1, tr, pos);\n }\n\n static int[] t;\n static void update(int ind, int tl, int tr, int l, int r)\n {\n if (l > r)\n {\n return;\n }\n if (r == tr && l == tl)\n {\n t[ind]++;\n return;\n }\n else\n {\n int tm = (tr + tl) / 2;\n update(ind * 2 + 1, tl, tm, l, Math.Min(r, tm));\n update(ind * 2 + 2, tm + 1, tr, Math.Max(tm + 1, l), r);\n }\n\n }\n static BigInteger foo(BigInteger c)\n {\n return ((c + 1) * c) / 2;\n }\n static void Main(string[] args)\n {\n\n int[,] m = new int[4, 4];\n for (int i = 0; i < 4; i++)\n {\n string[] s = Console.ReadLine().Split();\n for (int e = 0; e < 4; e++)\n {\n m[i, e] = int.Parse(s[e]);\n }\n }\n for (int i = 0; i < 4; i++)\n {\n if (m[i, 3] == 1)\n {\n if (i == 0)\n {\n if (m[0, 0] == 1 || m[0, 1] == 1 || m[0, 2] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n if (m[1, 0] == 1 || m[2, 1] == 1 || m[3, 2] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n if (i == 1)\n {\n if (m[1, 0] == 1 || m[1, 1] == 1 || m[1, 2] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n if (m[0, 2] == 1 || m[2, 0] == 1 || m[3, 1] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n if (i == 2)\n {\n if (m[2, 0] == 1 || m[2, 1] == 1 || m[2, 2] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n if (m[1, 2] == 1 || m[0, 1] == 1 || m[3, 0] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n if (i == 3)\n {\n if (m[3, 0] == 1 || m[3, 1] == 1 || m[3, 2] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n if (m[2, 2] == 1 || m[1, 1] == 1 || m[0, 0] == 1)\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n\n \n }\n \n }\n Console.WriteLine(\"NO\");\n }\n }\n}", "src_uid": "44fdf71d56bef949ec83f00d17c29127"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\n\nnamespace Codeforces\n{\n class Program : ProgramBase\n {\n private const long commonMod = 1000000007;\n\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Solve();\n p.Out(x);\n }\n object Solve()\n {\n var x = Read();\n var z = Read();\n var res = new char[x.Length];\n for (int i = 0; i < x.Length; i++)\n {\n if (x[i] < z[i])\n return -1;\n res[i] = z[i];\n }\n return new string(res);\n }\n }\n\n\n\n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n Queue tokens;\n protected string FileName { private get; set; }\n\n protected string Read()\n {\n if (f == null)\n f = string.IsNullOrEmpty(FileName)\n ? new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024 * 10)\n : new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName);\n return f.ReadLine();\n }\n\n protected string ReadToken()\n {\n if (tokens == null || tokens.Count == 0)\n tokens = new Queue(Read().Split(' '));\n return tokens.Dequeue();\n }\n\n protected long ReadLong() { return long.Parse(ReadToken()); }\n\n protected long[] ReadLongs()\n {\n var s = Read();\n if (s == \"\")\n return new long[0];\n //var i = s.IndexOf(' ');\n //return new[] { long.Parse(s.Substring(0, i)), long.Parse(s.Substring(i + 1)) };\n var tokens = s.Split(' ');\n var result = new long[tokens.Length];\n for (int i = 0; i < tokens.Length; i++)\n result[i] = long.Parse(tokens[i]);\n return result;\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName, r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func, T defaultValue = default(T))\n {\n T result = defaultValue;\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable s, string d) { return string.Join(d, s.ToArray()); }\n\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n }\n class DSU\n {\n private int[] arr;\n private Random r = new Random();\n public DSU(int n)\n {\n arr = new int[n];\n for (int i = 0; i < n; i++)\n {\n arr[i] = i;\n }\n }\n\n public int Find(int x)\n {\n if (arr[arr[x]] == arr[x])\n return arr[x];\n var y = Find(arr[x]);\n arr[x] = y;\n return y;\n }\n\n public void Union(int x, int y)\n {\n var p1 = Find(x);\n var p2 = Find(y);\n if (p1 == p2)\n return;\n if (r.NextDouble() < 0.5)\n arr[p1] = p2;\n else\n arr[p2] = p1;\n }\n\n public Tuple[] Enumerate()\n {\n return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => Tuple.Create(k, e.Count())).ToArray();\n }\n }\n\n}", "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Round_37_A\n{\n class Program\n {\n private static int ReadInt()\n {\n string s = Console.ReadLine().Trim();\n return Convert.ToInt32(s);\n }\n\n private static int[] ReadInts()\n {\n string[] nums = Console.ReadLine().Split(new char[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n int[] result = new int[nums.Length];\n for (int i = 0; i < nums.Length; i++)\n {\n result[i] = Convert.ToInt32(nums[i]);\n }\n\n return result;\n }\n\n static void Main(string[] args)\n {\n int res = new Program().Run();\n Console.WriteLine(res);\n Console.ReadLine();\n }\n\n private int Run()\n {\n int[] nums = ReadInts();\n int w = nums[0];\n int h = nums[1];\n\n int x = ReadInt();\n int wCount = (w - (x - 1) * 2);\n int hCount = (h - (x - 1) * 2);\n if (wCount <= 0 || hCount <= 0)\n {\n return 0;\n }\n\n if (wCount == 1)\n {\n if (hCount % 2 == 0)\n {\n return hCount / 2;\n }\n return hCount / 2 + 1;\n }\n\n if (hCount == 1)\n {\n if (wCount % 2 == 0)\n {\n return wCount / 2;\n }\n return wCount / 2 + 1;\n }\n\n return wCount + hCount - 2;\n }\n }\n}\n", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _1230A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] str = Console.ReadLine().Split(' ');\n int[] a = new int[4];\n a[0] = Convert.ToInt32(str[0]);\n a[1] = Convert.ToInt32(str[1]);\n a[2] = Convert.ToInt32(str[2]);\n a[3] = Convert.ToInt32(str[3]);\n Array.Sort(a);\n int a01 = a[0] + a[1];\n int a02 = a[0] + a[2];\n int a03 = a[0] + a[3];\n int a12 = a[2] + a[1];\n int a13 = a[3] + a[1];\n int a23 = a[2] + a[3];\n\n if (((a[0]+a[1]+a[2])==a[3])||\n ((a01==a23)||(a12==a03)))\n {\n Console.WriteLine(\"YES\");\n }\n else\n {\n Console.WriteLine(\"NO\");\n }\n\n\n }\n }\n}\n", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n\nclass Program\n{\n static int getFunc(int s, int e, int[,] sq, Func func, int start)\n {\n var res = start;\n var h = 0;\n while (e > s)\n {\n var ns = ((s - 1) >> 1) + 1;\n if (s < (ns << 1))\n res = func(res, sq[s, h]);\n s = ns;\n var ne = e >> 1;\n if (e > (ne << 1))\n res = func(res, sq[e - 1, h]);\n e = ne;\n h++;\n }\n return res;\n }\n\n static void solve(StreamReader reader, StreamWriter writer)\n {\n int t = reader.ReadInt();\n int s = reader.ReadInt();\n int x = reader.ReadInt();\n\n x -= t;\n if (x >= 0)\n {\n if (x == 0\n || x % s == 0 || x >= s+1 && (x - 1 - s) % s == 0)\n {\n writer.WriteLine(\"YES\");\n return;\n } \n }\n writer.WriteLine(\"NO\");\n }\n\n #region launch\n static void Main(string[] args)\n {\n using (var writer = new FormattedStreamWriter(Console.OpenStandardOutput()))\n {\n using (var reader = new StreamReader(\n#if CODECHIEF_LOCAL\n\"input.txt\"\n#else\nConsole.OpenStandardInput()\n#endif\n))\n {\n solve(reader, writer);\n }\n }\n }\n #endregion\n}\n\n#region helpers\nclass FormattedStreamWriter : StreamWriter\n{\n public FormattedStreamWriter(Stream stream)\n : base(stream)\n {\n }\n\n public override IFormatProvider FormatProvider\n {\n get\n {\n return CultureInfo.InvariantCulture;\n }\n }\n}\n\nstatic class IOExtensions\n{\n public static string ReadString(this StreamReader reader)\n {\n return reader.ReadToken();\n }\n\n public static int ReadInt(this StreamReader reader)\n {\n return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static long ReadLong(this StreamReader reader)\n {\n return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static double ReadDouble(this StreamReader reader)\n {\n return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);\n }\n\n static Queue buffer = new Queue(100);\n\n static string ReadToken(this StreamReader reader)\n {\n while (buffer.Count == 0)\n {\n reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach((t) =>\n {\n buffer.Enqueue(t);\n });\n }\n return buffer.Dequeue();\n }\n}\n#endregion", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"source_code": "using System;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static string password;\n static int countWords;\n\n static void Main(string[] args)\n {\n password = Console.ReadLine();\n countWords = Convert.ToInt32(Console.ReadLine());\n string s = Console.ReadLine();\n bool result = false;\n bool first = false;\n bool second = false;\n while (s != null)\n {\n if (password == s)\n {\n result = true;\n break;\n }\n if (!first)\n first = s[1] == password[0];\n if (!second)\n second = s[0] == password[1];\n s = Console.ReadLine();\n }\n if (result)\n Console.WriteLine(\"YES\");\n else if (first && second)\n Console.WriteLine(\"YES\");\n else\n Console.WriteLine(\"NO\");\n }\n }\n}", "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace starwars\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n;\n \n n = Convert.ToInt32 (Console.ReadLine());\n char[,] array1 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n char[] temp = Console.ReadLine().ToCharArray();\n for (int j = 0; j <= n - 1; j++)\n {\n array1[i, j] = temp[j];\n }\n }\n char[,] array2 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n char[] temp = Console.ReadLine().ToCharArray();\n for (int j = 0; j <= n - 1; j++)\n {\n array2[i, j] = temp[j];\n }\n }\n\n\n char[,] t90 = new char[n, n];\n for(int i = 0; i<=n-1;i++)\n {\n for (int j = 0; j <= n - 1; j++)\n t90[j, n - 1 - i] = array1[i, j];\n }\n\n char[,] t180 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n t180[j, n - 1 - i] = t90[i, j];\n }\n\n char[,] t270 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j<=n-1; j++)\n t270[j, n - 1 - i] = t180[i, j];\n }\n\n char[,] flippGorarray1 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippGorarray1[n - 1 - i, j] = array1[i, j];\n }\n\n char[,] flippvertarray1 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippvertarray1[i, n-1-j] = array1[i, j];\n }\n\n char[,] flippGort90 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippGort90[n - 1 - i, j] = t90[i, j];\n }\n\n char[,] flippvert90 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippvert90[i, n - 1 - j] = t90[i, j];\n }\n\n char[,] flippGort180 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippGort180[n - 1 - i, j] = t180[i, j];\n }\n\n char[,] flippvert180 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippvert180[i, n - 1 - j] = t180[i, j];\n }\n\n char[,] flippGorart270 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippGorart270[n - 1 - i, j] = t270[i, j];\n }\n\n char[,] flippvert270 = new char[n, n];\n for (int i = 0; i <= n - 1; i++)\n {\n for (int j = 0; j <= n - 1; j++)\n flippvert270[i, n - 1 - j] = t270[i, j];\n }\n\n\n\n if (Equal(array2, array1, n) ||\n Equal(array2, t90, n) ||\n Equal(array2, t180, n) ||\n Equal(array2, t270, n) ||\n Equal(array2, flippGorarray1, n) ||\n Equal(array2, flippvertarray1, n) ||\n Equal(array2, flippGort90, n) ||\n Equal(array2, flippvert90, n) ||\n Equal(array2, flippGort180, n) ||\n Equal(array2, flippvert180, n) ||\n Equal(array2, flippGorart270, n) ||\n Equal(array2, flippvert270, n) )\n {\n Console.WriteLine(\"Yes\");\n }\n else Console.WriteLine(\"No\");\n\n\n }\n static bool Equal(char[,]ar1, char[,] ar2, int n)\n {\n for (int i = 0; i < n;i++)\n {\n for (int j = 0; j < n; j++)\n {\n if (ar1[i, j] != ar2[i, j])\n {\n return false;\n \n }\n }\n\n }\n return true;\n }\n \n }\n}\n", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nnamespace CF317\n{\n\tinternal class Program\n\t{\n\t\tprivate static void Main(string[] args)\n\t\t{\n\t\t\tvar sr = new InputReader(Console.In);\n\t\t\t//var sr = new InputReader(new StreamReader(\"input.txt\"));\n\t\t\tvar task = new Task();\n\t\t\tusing (var sw = Console.Out)\n\t\t\t//using (var sw = new StreamWriter(\"output.txt\"))\n\t\t\t{\n\t\t\t\ttask.Solve(sr, sw);\n\t\t\t\t//Console.ReadKey();\n\t\t\t}\n\t\t}\n\t}\n\n\tinternal class Task\n\t{\n\t\tpublic void Solve(InputReader sr, TextWriter sw)\n\t\t{\n\t\t\tvar n = sr.NextInt32();\n\t\t\tif (MaxDivisor(n) == 1)\n\t\t\t{\n\t\t\t\tsw.WriteLine(1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar minDiv = Int32.MaxValue;\n\t\t\tfor (var i = n - 1; i >= 2 && (n - i) < 10000; i--) {\n\t\t\t\tvar currDiv1 = MaxDivisor(i) + MaxDivisor(n - i);\n\t\t\t\tminDiv = Math.Min(currDiv1, minDiv);\n\t\t\t}\n\n\t\t\tsw.WriteLine(minDiv);\n\t\t}\n\n\t\tprivate int MaxDivisor(int n)\n\t\t{\n\t\t\tvar mid = (int)Math.Sqrt(n);\n\t\t\tfor (var i = mid; i >= 2; i--) {\n\t\t\t\tif (n % i == 0)\n\t\t\t\t\treturn i;\n\t\t\t}\n\n\t\t\treturn 1;\n\t\t}\n\t}\n}\n\ninternal class InputReader : IDisposable\n{\n\tprivate bool isDispose;\n\tprivate readonly TextReader sr;\n\n\tpublic InputReader(TextReader stream)\n\t{\n\t\tsr = stream;\n\t}\n\n\tpublic void Dispose()\n\t{\n\t\tDispose(true);\n\t\tGC.SuppressFinalize(this);\n\t}\n\n\tpublic string NextString()\n\t{\n\t\tvar result = sr.ReadLine();\n\t\treturn result;\n\t}\n\n\tpublic int NextInt32()\n\t{\n\t\treturn Int32.Parse(NextString());\n\t}\n\n\tpublic long NextInt64()\n\t{\n\t\treturn Int64.Parse(NextString());\n\t}\n\n\tpublic string[] NextSplitStrings()\n\t{\n\t\treturn NextString()\n\t\t\t.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n\t}\n\n\tpublic T[] ReadArray(Func func)\n\t{\n\t\treturn NextSplitStrings()\n\t\t\t.Select(s => func(s, CultureInfo.InvariantCulture))\n\t\t\t.ToArray();\n\t}\n\n\tpublic T[] ReadArrayFromString(Func func, string str)\n\t{\n\t\treturn\n\t\t\tstr.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)\n\t\t\t\t.Select(s => func(s, CultureInfo.InvariantCulture))\n\t\t\t\t.ToArray();\n\t}\n\n\tprotected void Dispose(bool dispose)\n\t{\n\t\tif (!isDispose)\n\t\t{\n\t\t\tif (dispose)\n\t\t\t\tsr.Close();\n\t\t\tisDispose = true;\n\t\t}\n\t}\n\n\t~InputReader()\n\t{\n\t\tDispose(false);\n\t}\n}", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"} {"source_code": "using System;\n\t\t\t\t\t\npublic class Program\n{\n\tstatic long?[,] memo;\n\t\n\tpublic static void Main()\n\t{\n\t\tvar n = int.Parse(Console.ReadLine());\n\t\tmemo = new long?[n+1, n+1];\n\t\tvar min = MinTriangulation(1, n);\n\t\tConsole.WriteLine(min);\n\t}\n\t\n\tprivate static long MinTriangulation(int i, int j){\n\t\tif(j-i<2)\n\t\t\treturn 0;\n\t\tif(memo[i,j]!=null)\n\t\t\treturn (long)memo[i,j];\n\t\t\n\t\tmemo[i,j] = long.MaxValue;\n\t\tfor(int k=i+1; k<=j-1; k++){\n\t\t\tmemo[i,j] = Math.Min((long)memo[i,j], MinTriangulation(i,k) + i*k*j + MinTriangulation(k,j));\n\t\t}\n\t\treturn (long)memo[i,j];\n\t}\n}", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"source_code": "using System;\nusing System.Diagnostics;\nusing System.IO;\nusing System.Linq;\n\nnamespace Codeforces\n{\n\tinternal class Template\n\t{\n\t\tprivate void Solve()\n\t\t{\n\t\t\tvar n = cin.NextInt();\n\t\t\tvar name = cin.NextString();\n\t\t\tvar trav = new string[n];\n\t\t\tfor (var i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\ttrav[i] = cin.NextString();\n\t\t\t}\n\t\t\tif (n%2 == 0)\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"home\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"contest\");\n\t\t\t}\n\t\t}\n\n\t\tprivate static readonly Scanner cin = new Scanner();\n\n\t\tprivate static void Main()\n\t\t{\n#if DEBUG\n\t\t\tvar inputText = File.ReadAllText(@\"..\\..\\input.txt\");\n\t\t\tvar testCases = inputText.Split(new[] { \"input\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\tvar consoleOut = Console.Out;\n\t\t\tfor (var i = 0; i < testCases.Length; i++)\n\t\t\t{\n\t\t\t\tvar parts = testCases[i].Split(new[] { \"output\" }, StringSplitOptions.RemoveEmptyEntries);\n\t\t\t\tConsole.SetIn(new StringReader(parts[0].Trim()));\n\t\t\t\tvar stringWriter = new StringWriter();\n\t\t\t\tConsole.SetOut(stringWriter);\n\t\t\t\tvar sw = Stopwatch.StartNew();\n\t\t\t\tnew Template().Solve();\n\t\t\t\tsw.Stop();\n\t\t\t\tvar output = stringWriter.ToString();\n\n\t\t\t\tConsole.SetOut(consoleOut);\n\t\t\t\tvar color = ConsoleColor.Green;\n\t\t\t\tvar status = \"Passed\";\n\t\t\t\tif (parts[1].Trim() != output.Trim())\n\t\t\t\t{\n\t\t\t\t\tcolor = ConsoleColor.Red;\n\t\t\t\t\tstatus = \"Failed\";\n\t\t\t\t}\n\t\t\t\tConsole.ForegroundColor = color;\n\t\t\t\tConsole.WriteLine(\"Test {0} {1} in {2}ms\", i + 1, status, sw.ElapsedMilliseconds);\n\t\t\t}\n\t\t\tConsole.ReadLine();\n\t\t\tConsole.ReadKey();\n#else\n\t\t\tnew Template().Solve();\n\t\t\tConsole.ReadLine();\n#endif\n\t\t}\n\t}\n\n\tinternal class Scanner\n\t{\n\t\tprivate string[] s = new string[0];\n\t\tprivate int i;\n\t\tprivate readonly char[] cs = { ' ' };\n\n\t\tpublic string NextString()\n\t\t{\n\t\t\tif (i < s.Length) return s[i++];\n\t\t\tvar line = Console.ReadLine() ?? string.Empty;\n\t\t\ts = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);\n\t\t\ti = 1;\n\t\t\treturn s.First();\n\t\t}\n\n\t\tpublic double NextDouble()\n\t\t{\n\t\t\treturn double.Parse(NextString());\n\t\t}\n\n\t\tpublic int NextInt()\n\t\t{\n\t\t\treturn int.Parse(NextString());\n\t\t}\n\n\t\tpublic long NextLong()\n\t\t{\n\t\t\treturn long.Parse(NextString());\n\t\t}\n\t}\n}", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Management.Instrumentation;\nusing System.Text;\n\nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\n\nnamespace Codeforces\n{\n public class Input\n {\n private static string _line;\n\n public static bool Next()\n {\n _line = Console.ReadLine();\n return _line != null;\n }\n\n public static bool Next(out long a)\n {\n var ok = Next();\n a = ok ? long.Parse(_line) : 0;\n return ok;\n }\n\n public static bool Next(out long a, out long b)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n }\n else\n {\n a = b = 0;\n }\n\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n }\n else\n {\n a = b = c = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n }\n else\n {\n a = b = c = d = 0;\n }\n return ok;\n }\n\n public static bool Next(out long a, out long b, out long c, out long d, out long e)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(long.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n }\n else\n {\n a = b = c = d = e = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a)\n {\n var ok = Next();\n a = ok ? int.Parse(_line) : 0;\n return ok;\n }\n\n public static bool Next(out int a, out int b)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n }\n else\n {\n a = b = 0;\n }\n\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n }\n else\n {\n a = b = c = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c, out int d)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n }\n else\n {\n a = b = c = d = 0;\n }\n return ok;\n }\n\n public static bool Next(out int a, out int b, out int c, out int d, out int e)\n {\n var ok = Next();\n if (ok)\n {\n var array = _line.Split(' ').Select(int.Parse).ToArray();\n a = array[0];\n b = array[1];\n c = array[2];\n d = array[3];\n e = array[4];\n }\n else\n {\n a = b = c = d = e = 0;\n }\n return ok;\n }\n\n public static IEnumerable ArrayLong()\n {\n return !Next() ? new List() : _line.Split().Select(long.Parse);\n }\n\n public static IEnumerable ArrayInt()\n {\n return !Next() ? new List() : _line.Split().Select(int.Parse);\n }\n\n public static bool Next(out string value)\n {\n value = string.Empty;\n if (!Next()) return false;\n value = _line;\n return true;\n }\n }\n\n public class DisjointSet\n {\n private readonly int[] _parent;\n private readonly int[] _rank;\n public int Count { get; private set; }\n\n public DisjointSet(int count, int initialize = 0)\n {\n Count = count;\n _parent = new int[Count];\n _rank = new int[Count];\n for (var i = 0; i < initialize; i++) _parent[i] = i;\n }\n\n private DisjointSet(int count, int[] parent, int[] rank)\n {\n Count = count;\n _parent = parent;\n _rank = rank;\n }\n\n public void Add(int v)\n {\n _parent[v] = v;\n _rank[v] = 0;\n }\n\n public int Find_Recursive(int v)\n {\n if (_parent[v] == v) return v;\n return _parent[v] = Find(_parent[v]);\n }\n\n public int Find(int v)\n {\n if (_parent[v] == v) return v;\n var last = v;\n while (_parent[last] != last) last = _parent[last];\n while (_parent[v] != v)\n {\n var t = _parent[v];\n _parent[v] = last;\n v = t;\n }\n return last;\n }\n\n public int this[int v]\n {\n get { return Find(v); }\n set { Union(v, value); }\n }\n\n public void Union(int a, int b)\n {\n a = Find(a);\n b = Find(b);\n if (a == b) return;\n if (_rank[a] < _rank[b])\n {\n var t = _rank[a];\n _rank[a] = _rank[b];\n _rank[b] = t;\n }\n _parent[b] = a;\n if (_rank[a] == _rank[b]) _rank[a]++;\n }\n\n public int GetSetCount()\n {\n var result = 0;\n for (var i = 0; i < Count; i++)\n {\n if (_parent[i] == i) result++;\n }\n return result;\n }\n\n public DisjointSet Clone()\n {\n var rank = new int[Count];\n _rank.CopyTo(rank, 0);\n var parent = new int[Count];\n _parent.CopyTo(parent, 0);\n return new DisjointSet(Count, parent, rank);\n }\n\n public override string ToString()\n {\n return string.Join(\",\", _parent.Take(50));\n }\n }\n\n public class Matrix\n {\n public static Matrix Create(int i, int j)\n {\n var m = new Matrix(i, j);\n return m;\n }\n\n public static Matrix Create(int i)\n {\n var m = new Matrix(i, i);\n return m;\n }\n\n public long Modulo { get; set; }\n\n private readonly int _width;\n private readonly int _height;\n private readonly long[,] _data;\n public int Width { get { return _width; } }\n public int Height { get { return _height; } }\n\n private Matrix(int i, int j)\n {\n Modulo = 1000000000000000000L;\n _width = j;\n _height = i;\n _data = new long[_height, _width];\n }\n\n public static Matrix operator *(Matrix m1, Matrix m2)\n {\n if (m1.Width != m2.Height) throw new InvalidDataException(\"m1.Width != m2.Height\");\n var m = Create(m2.Width, m1.Height);\n m.Modulo = m1.Modulo;\n for (var i = 0; i < m2.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n {\n for (var k = 0; k < m1.Width; k++)\n m[j, i] += (m1[j, k] * m2[k, i]) % m1.Modulo;\n m[j, i] %= m1.Modulo;\n }\n return m;\n }\n\n public static Matrix operator +(Matrix m1, Matrix m2)\n {\n var m = m1.Clone();\n for (var i = 0; i < m2.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;\n return m;\n }\n\n public static Matrix operator -(Matrix m1, Matrix m2)\n {\n var m = m1.Clone();\n for (var i = 0; i < m2.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;\n return m;\n }\n\n public static Matrix operator *(Matrix m1, long l)\n {\n var m = m1.Clone();\n for (var i = 0; i < m1.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n m[j, i] = (m[j, i] * l) % m.Modulo;\n return m;\n }\n\n public static Matrix operator *(long l, Matrix m1)\n {\n return m1 * l;\n }\n\n public static Matrix operator +(Matrix m1, long l)\n {\n var m = m1.Clone();\n for (var i = 0; i < m1.Width; i++)\n m[i, i] = (m[i, i] + l) % m.Modulo;\n return m;\n }\n\n public static Matrix operator +(long l, Matrix m1)\n {\n return m1 + l;\n }\n\n public static Matrix operator -(Matrix m1, long l)\n {\n return m1 + (-l);\n }\n\n public static Matrix operator -(long l, Matrix m1)\n {\n var m = m1.Clone() * -1;\n return m + l;\n }\n\n public Matrix BinPower(long l)\n {\n var n = 1;\n var m = Clone();\n var result = new Matrix(m.Height, m.Width) + 1;\n result.Modulo = m.Modulo;\n while (l != 0)\n {\n var i = l & ~(l - 1);\n l -= i;\n while (n < i)\n {\n m = m * m;\n n <<= 1;\n }\n result *= m;\n }\n return result;\n }\n\n public void Fill(long l)\n {\n l %= Modulo;\n for (var i = 0; i < _height; i++)\n for (var j = 0; j < _width; j++)\n _data[i, j] = l;\n }\n\n public Matrix Clone()\n {\n var m = new Matrix(_width, _height);\n Array.Copy(_data, m._data, _data.Length);\n m.Modulo = Modulo;\n return m;\n }\n\n public long this[int i, int j]\n {\n get { return _data[i, j]; }\n set { _data[i, j] = value % Modulo; }\n }\n }\n\n public class RedBlackTree : IEnumerable>\n {\n private readonly List _items = new List();\n private Node _root;\n private readonly IComparer _comparer;\n\n public RedBlackTree()\n {\n _comparer = Comparer.Default;\n }\n\n private Node _search(TKey key)\n {\n var node = _root;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return node;\n node = i > 0 ? node.Right : node.Left;\n }\n return null;\n }\n\n public void Add(TKey key, TValue value)\n {\n var node = new Node { Key = key, Value = value, Red = true };\n _items.Add(node);\n if (_root == null)\n {\n _root = node;\n _root.Red = false;\n return;\n }\n var x = _root;\n Node y = null;\n while (x != null)\n {\n y = x;\n x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;\n }\n node.Parent = y;\n if (y == null) _root = node;\n else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;\n else y.Left = node;\n InsertFixup(node);\n }\n\n private void InsertFixup(Node node)\n {\n while (true)\n {\n var parent = node.Parent;\n if (parent == null || !parent.Red || parent.Parent == null) break;\n var grand = parent.Parent;\n\n if (parent == grand.Left)\n {\n var uncle = grand.Right;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Right) /* we rotate around the parent */\n {\n node = parent;\n RotateLeft(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateRight(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n else\n {\n if (_root.Parent != null) Debugger.Break();\n\n var uncle = grand.Left;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Left) /* we rotate around the parent */\n {\n node = parent;\n RotateRight(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateLeft(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n }\n _root.Red = false;\n }\n\n private void RotateLeft(Node node)\n {\n if (node.Right == null)\n throw new NotSupportedException(\"Cannot rotate left: right node is missing\");\n var parent = node.Parent;\n var right = node.Right;\n right.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = right;\n else parent.Right = right;\n }\n node.Right = right.Left;\n if (node.Right != null)\n node.Right.Parent = node;\n right.Left = node;\n node.Parent = right;\n }\n\n private void RotateRight(Node node)\n {\n if (node.Left == null)\n throw new NotSupportedException(\"Cannot rotate right: left node is missing\");\n var parent = node.Parent;\n var left = node.Left;\n left.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = left;\n else parent.Right = left;\n }\n node.Left = left.Right;\n if (node.Left != null)\n node.Left.Parent = node;\n left.Right = node;\n node.Parent = left;\n }\n\n public void Remove(TKey key)\n {\n var node = _search(key);\n if (node == null) return;\n\n var deleted = node.Left == null || node.Right == null ? node : Next(node);\n var child = deleted.Left ?? deleted.Right;\n if (child != null)\n child.Parent = deleted.Parent;\n if (deleted.Parent == null) /* root */\n _root = child;\n else if (deleted == deleted.Parent.Left)\n deleted.Parent.Left = child;\n else\n deleted.Parent.Right = child;\n if (node != deleted)\n {\n node.Key = deleted.Key;\n node.Value = deleted.Value;\n }\n\n if (!deleted.Red)\n {\n DeleteFixup(child, deleted.Parent);\n }\n }\n\n private void DeleteFixup(Node node, Node parent)\n {\n while (parent != null && (node == null || !node.Red))\n {\n if (node == parent.Left)\n {\n var brother = parent.Right;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateLeft(parent);\n brother = parent.Right;\n }\n if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Right == null || !brother.Right.Red)\n {\n if (brother.Left != null)\n brother.Left.Red = false;\n brother.Red = true;\n RotateRight(brother);\n brother = parent.Right;\n }\n if (!brother.Right.Red) Debugger.Break();\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Right != null)\n brother.Right.Red = false;\n RotateLeft(parent);\n node = _root;\n }\n }\n else\n {\n var brother = parent.Left;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateRight(parent);\n brother = parent.Left;\n }\n if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Left == null || !brother.Left.Red)\n {\n if (brother.Right != null)\n brother.Right.Red = false;\n brother.Red = true;\n RotateLeft(brother);\n brother = parent.Left;\n }\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Left != null)\n brother.Left.Red = false;\n RotateRight(parent);\n node = _root;\n }\n }\n parent = node.Parent;\n }\n\n node.Red = false;\n }\n\n public TValue this[TKey key]\n {\n get\n {\n var node = _search(key);\n return node == null ? default(TValue) : node.Value;\n }\n set\n {\n var node = _search(key);\n if (node == null) Add(key, value);\n else node.Value = value;\n }\n }\n\n public bool Check()\n {\n int count;\n return _root == null || _root.Check(out count);\n }\n\n private Node Minimum(Node node)\n {\n var result = node;\n while (result.Left != null) result = result.Left;\n return result;\n }\n\n private Node Maximum(Node node)\n {\n var result = node;\n while (result.Right != null) result = result.Right;\n return result;\n }\n\n private Node Next(Node node)\n {\n Node result;\n if (node.Right != null)\n {\n result = Minimum(node.Right);\n }\n else\n {\n while (node.Parent != null && node.Parent.Right == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n private Node Previous(Node node)\n {\n Node result;\n if (node.Left != null)\n {\n result = Maximum(node.Left);\n }\n else\n {\n while (node.Parent != null && node.Parent.Left == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n public void Print()\n {\n var node = Minimum(_root);\n while (node != null)\n {\n Console.Write(node.Red ? '*' : ' ');\n Console.Write(node.Key);\n Console.Write('\\t');\n node = Next(node);\n }\n }\n\n #region Nested classes\n\n [DebuggerDisplay(\"{ToString()}\")]\n private sealed class Node\n {\n public TKey Key;\n public TValue Value;\n public bool Red;\n\n public Node Parent;\n public Node Left;\n public Node Right;\n\n public bool Check(out int count)\n {\n count = 0;\n if (Red)\n {\n if (Left != null && Left.Red) return false;\n if (Right != null && Right.Red) return false;\n }\n var left = 0;\n var right = 0;\n if (Left != null && !Left.Check(out left)) return false;\n if (Right != null && !Right.Check(out right)) return false;\n count = left + (Red ? 0 : 1);\n if (left != right)\n {\n ;\n }\n return left == right;\n }\n\n public override string ToString()\n {\n return ToShortString(2);\n }\n\n private string ToShortString(int depth = 0)\n {\n return depth == 0\n ? string.Format(\"{0}{1}\", Red ? \"*\" : \"\", Key)\n : string.Format(\"({1}<{0}>{2})\", ToShortString(), Left == null ? \"null\" : Left.ToShortString(depth - 1), Right == null ? \"null\" : Right.ToShortString(depth - 1));\n }\n }\n\n #endregion\n\n #region IEnumerable\n\n public IEnumerator> GetEnumerator()\n {\n throw new NotImplementedException();\n }\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return GetEnumerator();\n }\n\n #endregion\n }\n\n /// \n /// Prime numbers\n /// \n public class Primes\n {\n /// \n /// Returns prime numbers in O(n)\n /// Returns lowet divisors as well\n /// Memory O(n)\n /// \n public static void ImprovedSieveOfEratosthenes(int n, out int[] lp, out List pr)\n {\n lp = new int[n];\n pr = new List();\n for (var i = 2; i < n; i++)\n {\n if (lp[i] == 0)\n {\n lp[i] = i;\n pr.Add(i);\n }\n foreach (var prJ in pr)\n {\n var prIj = i * prJ;\n if (prJ <= lp[i] && prIj <= n - 1)\n {\n lp[prIj] = prJ;\n }\n else\n {\n break;\n }\n }\n }\n }\n\n /// \n /// Returns prime numbers in O(n*n)\n /// \n public static void SieveOfEratosthenes(int n, out List pr)\n {\n var m = 50000;//(int)(3l*n/(long)Math.Log(n)/2);\n pr = new List();\n var f = new bool[m];\n for (var i = 2; i * i <= n; i++)\n if (!f[i])\n for (var j = (long)i * i; j < m && j * j < n; j += i)\n f[j] = true;\n pr.Add(2);\n for (var i = 3; i * i <= n; i += 2)\n if (!f[i])\n pr.Add(i);\n }\n\n /// \n /// Greatest common divisor \n /// \n public static int Gcd(int x, int y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Greatest common divisor\n /// \n public static long Gcd(long x, long y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Greatest common divisor\n /// \n public static BigInteger Gcd(BigInteger x, BigInteger y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Returns all divisors of n in O(√n)\n /// \n public static IEnumerable GetDivisors(long n)\n {\n long r;\n while (true)\n {\n var x = Math.DivRem(n, 2, out r);\n if (r != 0) break;\n n = x;\n yield return 2;\n }\n var i = 3;\n while (i <= Math.Sqrt(n))\n {\n var x = Math.DivRem(n, i, out r);\n if (r == 0)\n {\n n = x;\n yield return i;\n }\n else i += 2;\n }\n if (n != 1) yield return n;\n }\n }\n\n}\n\nnamespace Codeforces.TaskD\n{\n public class Task\n {\n public static void Main()\n {\n var task = new Task();\n task.Solve();\n }\n\n void Solve()\n {\n long n, M;\n Input.Next(out n, out M);\n var str = n.ToString(CultureInfo.InvariantCulture);\n var a = str.ToCharArray().Select(c => int.Parse(c.ToString())).ToArray();\n var N = str.Count();\n var setsCount = 1 << N;\n var counts = new int[10];\n \n var factor = 1L;\n foreach (var ch in a)\n factor *= ++counts[ch];\n\n var dp = new long[setsCount, M];\n\n for(var i=0;i ri);\n\t\t\tvar dp = new int[n + 5, n + 5, 2];\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\tfor (int j = 0; j <= n; j++)\n\t\t\t\t\tdp[i, j, 0] = dp[i, j, 1] = 1000000000;\n\t\t\tdp[0, 0, 0] = dp[0, 0, 1] = 0;\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\tfor (int j = 0; i + j < n; j++)\n\t\t\t\t\tfor (int k = 0; k < 2; k++)\n\t\t\t\t\t\tfor (int l = 0; l < 2; l++) {\n\t\t\t\t\t\t\tvar next = (i + j);\n\t\t\t\t\t\t\tif (a[next] != 0 && a[next] % 2 != l) continue;\n\t\t\t\t\t\t\tvar ni = i; var nj = j;\n\t\t\t\t\t\t\tif (l == 0) ni++;\n\t\t\t\t\t\t\telse nj++;\n\t\t\t\t\t\t\tvar nx = dp[i, j, k] + (k ^ l);\n\t\t\t\t\t\t\tdp[ni, nj, l] = Min(dp[ni, nj, l], nx);\n\t\t\t\t\t\t}\n\t\t\tvar ans = new int[] { dp[n / 2, (n + 1) / 2, 0], dp[n / 2, (n + 1) / 2, 1] }.Min();\n\t\t\tConsole.WriteLine(ans);\n\n\t\t}\n\n\t\tconst long INF = 1L << 60;\n\t\tstatic int[] dx = { -1, 0, 1, 0 };\n\t\tstatic int[] dy = { 0, 1, 0, -1 };\n\t\tint ri { get { return sc.Integer(); } }\n\t\tlong rl { get { return sc.Long(); } }\n\t\tdouble rd { get { return sc.Double(); } }\n\t\tstring rs { get { return sc.Scan(); } }\n\t\tpublic IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n\n\t\tstatic T[] Enumerate(int n, Func f) {\n\t\t\tvar a = new T[n];\n\t\t\tfor (int i = 0; i < a.Length; ++i) a[i] = f(i);\n\t\t\treturn a;\n\t\t}\n\t\tstatic public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n\t}\n}\n\n#region main\nstatic class Ex {\n\tstatic public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n\tstatic public string AsJoinedString(this IEnumerable ie, string st = \" \") {\n\t\treturn string.Join(st, ie);\n\t}\n\tstatic public void Main() {\n\t\tConsole.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = true });\n\t\tvar solver = new Program.Solver();\n\t\t//* \n\t\tvar t = new System.Threading.Thread(solver.Solve, 50000000);\n\t\tt.Start();\n\t\tt.Join();\n\t\t//*/\n\t\t// solver.Solve();\n\t\tConsole.Out.Flush();\n\t}\n}\n#endregion\n#region Ex\nnamespace Program.IO {\n\tusing System.IO;\n\tusing System.Text;\n\tusing System.Globalization;\n\n\tpublic class Printer : StreamWriter {\n\t\tpublic override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n\t\tpublic Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n\t}\n\n\tpublic class StreamScanner {\n\t\tpublic StreamScanner(Stream stream) { str = stream; }\n\n\t\tpublic readonly Stream str;\n\t\tprivate readonly byte[] buf = new byte[1024];\n\t\tprivate int len, ptr;\n\t\tpublic bool isEof = false;\n\t\tpublic bool IsEndOfStream { get { return isEof; } }\n\n\t\tprivate byte read() {\n\t\t\tif (isEof) return 0;\n\t\t\tif (ptr >= len) {\n\t\t\t\tptr = 0;\n\t\t\t\tif ((len = str.Read(buf, 0, 1024)) <= 0) {\n\t\t\t\t\tisEof = true;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[ptr++];\n\t\t}\n\n\t\tpublic char Char() {\n\t\t\tbyte b = 0;\n\t\t\tdo b = read(); while ((b < 33 || 126 < b) && !isEof);\n\t\t\treturn (char)b;\n\t\t}\n\t\tpublic string Scan() {\n\t\t\tvar sb = new StringBuilder();\n\t\t\tfor (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);\n\t\t\treturn sb.ToString();\n\t\t}\n\t\tpublic string ScanLine() {\n\t\t\tvar sb = new StringBuilder();\n\t\t\tfor (var b = Char(); b != '\\n' && b != 0; b = (char)read()) if (b != '\\r') sb.Append(b);\n\t\t\treturn sb.ToString();\n\t\t}\n\t\tpublic long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }\n\t\tpublic int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }\n\t\tpublic double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }\n\t}\n}\n\n#endregion\n", "src_uid": "90db6b6548512acfc3da162144169dba"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Solver.Ex;\nusing Debug = System.Diagnostics.Debug;\nusing Watch = System.Diagnostics.Stopwatch;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\nnamespace Solver\n{\n public class Solver\n {\n public void Solve()\n {\n var n = sc.Integer();\n var m = sc.Integer();\n if (n == 1)\n IO.Printer.Out.WriteLine(\"1.000000\");\n else\n {\n double N = n;\n double M = m;\n var p = 1 / N;\n var q = (M - 1) / (N * M - 1);\n IO.Printer.Out.WriteLine(p+(1-p)*q);\n }\n }\n \n internal IO.StreamScanner sc;\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }\n }\n\n #region Main and Settings\n static class Program\n {\n static void Main(string[] arg)\n {\n#if DEBUG\n var errStream = new System.IO.FileStream(@\"..\\..\\dbg.out\", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);\n Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, \"debugStream\"));\n Debug.AutoFlush = false;\n var sw = new Watch(); sw.Start();\n IO.Printer.Out.AutoFlush = true;\n try\n {\n#endif\n\n var solver = new Solver();\n solver.sc = new IO.StreamScanner(Console.OpenStandardInput());\n solver.Solve();\n IO.Printer.Out.Flush();\n#if DEBUG\n }\n catch (Exception ex)\n {\n Console.Error.WriteLine(ex.Message);\n Console.Error.WriteLine(ex.StackTrace);\n }\n finally\n {\n sw.Stop();\n Console.ForegroundColor = ConsoleColor.Green;\n Console.Error.WriteLine(\"Time:{0}ms\", sw.ElapsedMilliseconds);\n Debug.Close();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n }\n#endif\n }\n\n\n }\n #endregion\n}\n\n#region IO Helper\nnamespace Solver.IO\n{\n public class Printer : System.IO.StreamWriter\n {\n static Printer()\n {\n Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };\n#if DEBUG\n Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };\n#else\n Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };\n#endif\n }\n public static Printer Out { get; set; }\n public static Printer Error { get; set; }\n public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, IEnumerable source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, IEnumerable source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(System.IO.Stream stream) { iStream = stream; }\n private readonly System.IO.Stream iStream;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n private bool eof = false;\n public bool IsEndOfStream { get { return eof; } }\n const byte lb = 33, ub = 126, el = 10, cr = 13;\n public byte read()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }\n public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }\n public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }\n public string Scan()\n {\n if (eof) throw new System.IO.EndOfStreamException();\n StringBuilder sb = null;\n var enc = System.Text.UTF8Encoding.Default;\n do\n {\n for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;\n if (ptr < len) break;\n ptr = 0;\n if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return \"\"; }\n } while (true);\n do\n {\n var f = ptr;\n for (; ptr < len; ptr++)\n if (buf[ptr] < lb || ub < buf[ptr])\n //if (buf[ptr] == cr || buf[ptr] == el)\n {\n string s;\n if (sb == null) s = enc.GetString(buf, f, ptr - f);\n else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }\n ptr++; return s;\n }\n if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));\n else sb.Append(enc.GetChars(buf, f, len - f));\n ptr = 0;\n\n }\n while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);\n eof = true; return (sb != null) ? sb.ToString() : \"\";\n }\n public long Long()\n {\n long ret = 0; byte b = 0; bool isMynus = false;\n const byte zr = 48, nn = 57, my = 45;\n do b = read();\n while (b != my && (b < zr || nn < b));\n if (b == my) { isMynus = true; b = read(); }\n for (; true; b = read())\n if (b < zr || nn < b)\n return isMynus ? -ret : ret;\n else ret = ret * 10 + b - zr;\n }\n public int Integer()\n {\n int ret = 0; byte b = 0; bool isMynus = false;\n const byte zr = 48, nn = 57, my = 45;\n do b = read();\n while (b != my && (b < zr || nn < b));\n if (b == my) { isMynus = true; b = read(); }\n for (; true; b = read())\n if (b < zr || nn < b)\n return isMynus ? -ret : ret;\n else ret = ret * 10 + b - zr;\n }\n public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }\n public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }\n public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }\n public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }\n public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }\n public void Flush() { iStream.Flush(); }\n }\n}\n#endregion\n#region Extension\nnamespace Solver.Ex\n{\n static public partial class EnumerableEx\n {\n static public string AsString(this IEnumerable ie) { return new string(ie.ToArray()); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n\n }\n}\n#endregion\n", "src_uid": "0b9ce20c36e53d4702869660cbb53317"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace VK_Cup\n{\n public class Program\n {\n static void Main(string[] args)\n {\n var number = Convert.ToInt64(Console.ReadLine());\n long res = MaxSumNumbers(number);\n Console.WriteLine(res);\n }\n\n public static long MaxSumNumbers(long number)\n {\n var str = number.ToString();\n str = String.Concat(str.Reverse());\n var matrix = new long[str.Length];\n matrix[0] = Convert.ToInt32(str[0].ToString());\n\n string current = string.Empty;\n for(int i = 1; i< matrix.Length; i++)\n {\n current = str[i].ToString() + matrix[i - 1].ToString();\n var Long = Convert.ToInt64(current);\n var num = Helper(Long);\n\n var sub = str.Substring(0, i + 1);\n sub = String.Concat(sub.Reverse());\n var curLong = Convert.ToInt64(sub);\n curLong = Helper(curLong);\n\n var sum1 = 0;\n var sum2 = 0;\n\n foreach (var ch in curLong.ToString())\n sum1+= Convert.ToInt32(ch.ToString());\n foreach (var ch in num.ToString())\n sum2 += Convert.ToInt32(ch.ToString());\n\n if (sum1 == sum2)\n matrix[i] = Math.Max(curLong, num);\n if (sum1 > sum2)\n matrix[i] = curLong;\n if (sum2 > sum1)\n matrix[i] = num;\n }\n return matrix.Last();\n }\n\n private static long Helper(long number)\n {\n var str = number.ToString();\n var newNumber = string.Empty;\n\n int dif = 0;\n for (int i = str.Length - 1; i > 0; i--)\n {\n var top = Convert.ToInt32(str[i].ToString());\n dif += 9 - top;\n newNumber += 9.ToString();\n }\n dif -= 1;\n if (dif <= 0)\n return number;\n\n var lastNumber = Convert.ToInt32(str[0].ToString()) - 1;\n if (lastNumber > 0)\n newNumber += lastNumber;\n newNumber = String.Concat(newNumber.Reverse());\n var newNum = Convert.ToInt64(newNumber);\n\n return newNum;\n }\n\n public static string GetPassword(int n, int k)\n {\n string alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\n char[] chars = alphabet.Substring(0, k).ToCharArray();\n var result = String.Concat(chars);\n\n char first = result.Last();\n\n int i = 0;\n while (result.Last() == first)\n first = chars[i++];\n\n char second = chars[0] == first ? chars[1] : chars[0];\n\n bool isSecond = false;\n for (i = 0; i < n - k; i++)\n {\n if (isSecond)\n result += second;\n else\n result += first;\n isSecond = !isSecond;\n }\n\n return result;\n }\n }\n}\n", "src_uid": "e55b0debbf33c266091e6634494356b8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Test\n{\n class IOHelper : IDisposable\n {\n StreamReader reader;\n StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding)\n {\n StreamReader iReader;\n StreamWriter oWriter;\n if (inputFile == null)\n iReader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n iReader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n oWriter = new StreamWriter(outputFile, false, encoding);\n\n reader = iReader;\n writer = oWriter;\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public string ReadNextToken()\n {\n if (curTokenIdx >= curLine.Length)\n {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n if (curTokenIdx >= curLine.Length)\n return null;\n\n return curLine[curTokenIdx++];\n }\n\n public int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n public double ReadNextDouble()\n {\n var nextToken = ReadNextToken();\n var result = 0.0;\n nextToken = nextToken.Replace(\".\", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);\n result = double.Parse(nextToken);\n return result;\n }\n\n public void Write(string stringToWrite)\n {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(string stringToWrite)\n {\n writer.WriteLine(stringToWrite);\n }\n\n public void WriteLine(double valueToWrite)\n {\n long intPart = (long)valueToWrite;\n double fracPart = valueToWrite - intPart;\n var fracPartStr = fracPart.ToString();\n if (fracPartStr.Length > 1)\n fracPartStr = fracPartStr.Substring(2);\n var strToWrite = string.Format(\"{0}.{1}\", intPart, fracPartStr);\n writer.WriteLine(strToWrite);\n }\n\n public void Dispose()\n {\n try\n {\n if (reader != null)\n {\n reader.Dispose();\n }\n if (writer != null)\n {\n writer.Dispose();\n }\n }\n catch { };\n }\n\n\n public void Flush()\n {\n if (writer != null)\n {\n writer.Flush();\n }\n }\n }\n\n class Program\n {\n protected IOHelper ioHelper;\n\n int n,k;\n\n long[] cstToGet;\n\n long Cost(int x)\n {\n int j;\n long best = -1;\n for(j=1;j 100000)\n return -1;\n\n if (best == -1)\n best = cand;\n else if (cand < best)\n best = cand;\n }\n return best;\n }\n\n public bool Solvable(int kk)\n {\n char ch = 'a';\n int i;\n long size = 0;\n for (i = n - 1; i >= 0; i--)\n {\n if (cstToGet[i] > kk)\n continue;\n kk -= (int)cstToGet[i];\n size += i;\n ch++;\n i++;\n if (kk == 0)\n break;\n }\n\n return kk == 0 && ch <= 'z' && size <= 100000;\n }\n\n public void Solve()\n {\n k = ioHelper.ReadNextInt();\n cstToGet = new long[1000];\n \n cstToGet[0] = 0;\n cstToGet[1] = 0;\n cstToGet[2] = 1;\n int i;\n for (i = 3; i < 1000; i++)\n {\n cstToGet[i] = Cost(i);\n if (cstToGet[i] == -1)\n break;\n }\n\n n = i;\n char ch = 'a';\n StringBuilder sb = new StringBuilder();\n for(i=n-1;i>=0;i--)\n {\n if (cstToGet[i] > k)\n continue;\n sb.Append(ch, i);\n k -= (int)cstToGet[i];\n ch++;\n i++;\n if (k == 0)\n break;\n }\n if(k!=0)\n {\n throw new ApplicationException(\"Alabala\");\n }\n\n var res = sb.ToString();\n ioHelper.WriteLine(res);\n ioHelper.Flush();\n\n //Console.ReadKey();\n }\n\n public Program(string inputFile, string outputFile)\n {\n ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);\n Solve();\n ioHelper.Dispose();\n }\n\n static void Main(string[] args)\n {\n Program myProgram = new Program(null, null);\n }\n }\n}", "src_uid": "b991c064562704b6106a6ff2a297e64a"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace Codeforces\n{\n public class ProblemG568\n {\n static void Main(string[] args)\n {\n var nt = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int n = nt[0];\n int t = nt[1];\n var songs = new List>();\n int modulo = 1000000000 + 7;\n for (int i = 0; i < n; i++)\n {\n var ns = Console.ReadLine().Split().Select(int.Parse).ToArray();\n songs.Add(Tuple.Create(ns[0], ns[1]));\n }\n var playlists = new SortedDictionary, int>>();\n playlists.Add(0, new Dictionary, int>());\n playlists[0][Tuple.Create(0, -1)] = 1;\n int count = 0;\n while (playlists.Count > 0)\n {\n var kvp = playlists.First();\n int refTime = kvp.Key;\n if (refTime == t)\n {\n // on compte\n foreach (var kvp2 in kvp.Value)\n {\n count = (count + kvp2.Value) % modulo;\n }\n break;\n }\n else if (refTime > t)\n {\n // too much\n break;\n }\n\n playlists.Remove(refTime);\n foreach (var kvp2 in kvp.Value)\n {\n int play = kvp2.Key.Item1;\n int last = kvp2.Key.Item2;\n int lastgenre = last == -1 ? -1 : songs[last].Item2;\n int counting = kvp2.Value;\n for (int i = 0; i < n; i++)\n {\n // not already played\n if ((play & (1 << i)) > 0)\n continue;\n int nextplay = play | (1 << i);\n\n // no two consecutive genre\n if (songs[i].Item2 == lastgenre)\n continue;\n int nexttime = refTime + songs[i].Item1;\n // playlist too long\n if (nexttime > t)\n continue;\n if (!playlists.ContainsKey(nexttime))\n {\n playlists[nexttime] = new Dictionary, int>();\n }\n var nextkey = Tuple.Create(nextplay, i);\n if (!playlists[nexttime].ContainsKey(nextkey))\n {\n playlists[nexttime][nextkey] = 0;\n }\n playlists[nexttime][nextkey] = (playlists[nexttime][nextkey] + counting) % modulo;\n }\n }\n }\n Console.WriteLine(count);\n }\n }\n}\n", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\n\nclass Program\n{\n\n\n //////////////////////////////////////////////////\n void Solution()\n {\n var p = rl;\n var k = rl;\n\n if (p < k)\n {\n wln(1);\n wln(p);\n return;\n }\n\n var w = p;\n var a = new List();\n int count = 0;\n for (; ; )\n {\n var z = 1 - w / k;\n if (z * k + w >= k)\n z--;\n if (z * k + w >= k)\n {\n wln(-1);\n return;\n }\n a.Add(z * k + w);\n w = z;\n if (0 < z && z < k)\n {\n a.Add(z);\n break;\n }\n count++;\n if (count > 1000000)\n {\n wln(-1);\n return;\n }\n }\n wln(a.Count);\n foreach (var o in a)\n wsp(o);\n\n\n }\n //////////////////////////////////////////////////\n\n static void swap(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }\n\n static void wln() { Console.WriteLine(); }\n static void wln(T o) { Console.WriteLine(o); }\n static void wsp(T o) { Console.Write(o + \" \"); }\n static void wrt(T o) { Console.Write(o); }\n\n static void wln(double o) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, \"{0:F12}\", o)); }\n static void wsp(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, \"{0:F12} \", o)); }\n static void wrt(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, \"{0:F12}\", o)); }\n\n static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }\n static long lcm(long a, long b) { return a / gcd(a, b) * b; }\n\n int ri\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind;\n int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n int p = 0;\n while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;\n }\n }\n long rl\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind;\n int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n long p = 0;\n while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;\n }\n }\n double rd\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';\n if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;\n }\n }\n string rs\n {\n get\n {\n _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;\n var tmp = _str.IndexOf(' ', _ind);\n if (tmp == -1) { var res = _str.Substring(_ind); _count = 0; _ind = 0; return res; }\n var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;\n }\n }\n\n int[] ria(int n)\n {\n var res = new int[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n long[] rla(int n)\n {\n var res = new long[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n double[] rda(int n)\n {\n var res = new double[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';\n if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }\n res[k++] = (double)p / q * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }\n string _str = null; int _count = 0; int _ind = 0;\n void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }\n static void Main()\n {\n //Console.SetIn(new StreamReader(\"input.txt\"));\n //Console.SetOut(new StreamWriter(\"output.txt\"));\n new Program().Solution();\n //Console.In.Close();\n //Console.Out.Close();\n }\n}", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5"} {"source_code": "// Problem: 1041B - Buying a TV Set\n// Author: Gusztav Szmolik\n\nusing System;\n\nclass BuyingATVSet\n {\n static int Main ()\n {\n string[] words = ReadSplitLine (4);\n if (words == null)\n return -1;\n ulong a;\n if (!UInt64.TryParse (words[0], out a))\n return -1;\n if (a < 1 || a > 1000000000000000000)\n return -1;\n ulong b;\n if (!UInt64.TryParse (words[1], out b))\n return -1;\n if (b < 1 || b > 1000000000000000000)\n return -1;\n ulong x;\n if (!UInt64.TryParse (words[2], out x))\n return -1;\n if (x < 1 || x > 1000000000000000000)\n return -1;\n ulong y;\n if (!UInt64.TryParse (words[3], out y))\n return -1;\n if (y < 1 || y > 1000000000000000000)\n return -1;\n bool xLess = (x < y);\n ulong d1 = (xLess ? x : y);\n ulong d2 = (xLess ? y : x);\n ulong r = d2%d1;\n while (r > 0)\n {\n d2 = d1;\n d1 = r;\n r = d2%d1;\n }\n ulong xRed = x/d1;\n ulong yRed = y/d1;\n ulong ans = (Math.Min (a/xRed,b/yRed));\n Console.WriteLine (ans);\n return 0;\n }\n\n static string[] ReadSplitLine (uint numWordNeed)\n {\n string line = Console.ReadLine ();\n if (line == null)\n return null;\n char[] delims = new char[2] {' ', '\\t'};\n string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);\n return (words.Length == numWordNeed ? words : null);\n }\n }\n", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace _749B\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] x = new int[3], y = new int[3];\n for (int i = 0; i < 3; i++)\n {\n string[] line = Console.ReadLine().Split(' ');\n x[i] = int.Parse(line[0]);\n y[i] = int.Parse(line[1]);\n }\n\n Console.WriteLine(3);\n Console.WriteLine((-x[0] + x[1] + x[2]) + \" \" + (-y[0] + y[1] + y[2]));\n Console.WriteLine((x[0] - x[1] + x[2]) + \" \" + (y[0] - y[1] + y[2]));\n Console.WriteLine((x[0] + x[1] - x[2]) + \" \" + (y[0] + y[1] - y[2]));\n //Console.ReadLine();\n }\n }\n}\n", "src_uid": "7725f9906a1b87bf4e866df03112f1e0"} {"source_code": "using System;\n\nnamespace task124D\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] splitStr = Console.ReadLine().Split(' ');\n int a = Convert.ToInt32(splitStr[0]);\n int b = Convert.ToInt32(splitStr[1]);\n int x1 = Convert.ToInt32(splitStr[2]);\n int y1 = Convert.ToInt32(splitStr[3]);\n int x2 = Convert.ToInt32(splitStr[4]);\n int y2 = Convert.ToInt32(splitStr[5]);\n int x, y;\n x = x1;\n y = y1;\n x1 = x + y;\n y1 = y - x;\n x = x2;\n y = y2;\n x2 = x + y;\n y2 = y - x;\n a *= 2;\n b *= 2;\n x1 = x1 / a + ((x1 > 0) ? 1 : 0);\n x2 = x2 / a + ((x2 > 0) ? 1 : 0);\n y1 = y1 / b + ((y1 > 0) ? 1 : 0);\n y2 = y2 / b + ((y2 > 0) ? 1 : 0);\n Console.WriteLine(Math.Max(Math.Abs(y2-y1), Math.Abs(x2-x1)));\n }\n }\n}", "src_uid": "7219d1837c83b5920992aee5a60dc0d9"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Arpa_and_an_exam_about_geometry\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n writer.WriteLine(Solve(args) ? \"Yes\" : \"No\");\n writer.Flush();\n }\n\n private static bool Solve(string[] args)\n {\n long ax = Next(), ay = Next(), bx = Next(), by = Next(), cx = Next(), cy = Next();\n\n if ((ax - bx)*(ax - bx) + (ay - by)*(ay - by) == (cx - bx)*(cx - bx) + (cy - by)*(cy - by))\n {\n return (cx - ax)*(cy - by) != (cy - ay)*(cx - bx);\n }\n\n return false;\n }\n\n private static int Next()\n {\n int c;\n int m = 1;\n do\n {\n c = reader.Read();\n if (c == '-')\n m = -1;\n } while (c < '0' || c > '9');\n int res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return m*res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Reflection;\nusing System.Threading;\nusing System.Diagnostics;\nusing System.Linq;\n\n#region testlib\npublic delegate bool ParserDelegate(string word, out T item);\n\npublic class Input : IDisposable\n{\nprivate static EventArgs DefaultEventArgs = new EventArgs();\n\npublic TextReader TextReader { get; private set; }\n\npublic event EventHandler OnEndOfStream;\npublic event EventHandler OnParseError;\npublic event EventHandler OnReadError;\n\npublic bool CanRead { get; private set; }\npublic bool ThrowExceptions { get; set; }\n\nstring line = string.Empty;\nint pos = 0;\n\nstatic EventHandler emptyHandler;\n\npublic Input(string path)\n: this(File.OpenRead(path))\n{\n}\npublic Input(Stream s)\n: this(new StreamReader(s))\n{\n\n}\npublic Input(TextReader tr)\n{\nTextReader = tr;\n\nif (emptyHandler == null)\nemptyHandler = (a, b) => { };\n\nOnEndOfStream = emptyHandler;\nOnParseError = emptyHandler;\nOnReadError = emptyHandler;\n\nCanRead = true;\n}\n\npublic static implicit operator Input(Stream s)\n{\nreturn new Input(s);\n}\npublic static implicit operator Input(TextReader tr)\n{\nreturn new Input(tr);\n}\n\nprivate bool ReadStream()\n{\nif (!CanRead) return false;\nif (pos < line.Length) return true;\n\nClear();\n\nstring s = TextReader.ReadLine();\nif (s == null)\n{\nCanRead = false;\nreturn false;\n}\n\nline = s;\nreturn true;\n}\n\npublic void SkipChar()\n{\nif (pos < line.Length) pos++;\nelse\n{\nReadStream();\n}\n}\npublic void SkipChars(int length)\n{\nwhile (length > 0)\n{\nint dt = line.Length - pos;\nif (dt <= 0)\n{\nlength--;\nif (!ReadStream()) return;\n}\ndt = Math.Min(length, dt);\npos += dt;\nlength -= dt;\n}\n}\n\npublic void SkipWhiteSpace()\n{\nwhile (true)\n{\nfor (; pos < line.Length; pos++)\n{\nif (!char.IsWhiteSpace(line[pos])) return;\n}\nif (!ReadStream())\n{\nOnEndOfStream(this, DefaultEventArgs);\nreturn;\n}\n}\n}\npublic bool CanReadData()\n{\nSkipWhiteSpace();\nreturn CanRead;\n}\n\npublic T[] ReadArray()\n{\nint length = ReadInt32();\nreturn ReadArray(length);\n}\npublic T[] ReadArray(int length)\n{\nParserDelegate parser = Parser.GetPrimitiveParser();\nreturn ReadArray(length, parser);\n}\npublic T[] ReadArray(ParserDelegate parser)\n{\nint length = ReadInt32();\nreturn ReadArray(length, parser);\n}\npublic T[] ReadArray(int length, ParserDelegate parser)\n{\nT[] res = new T[length];\nfor (int i = 0; i < length; i++)\n{\nres[i] = ReadData(parser);\n}\nreturn res;\n}\n\npublic Decimal ReadDecimal()\n{\nreturn ReadData(Parser.DecimalParser);\n}\npublic Double ReadDouble()\n{\nreturn ReadData(Parser.DoubleParser);\n}\npublic Single ReadSingle()\n{\nreturn ReadData(Parser.SingleParser);\n}\npublic UInt64 ReadUInt64()\n{\nreturn ReadData(UInt64.TryParse);\n}\npublic UInt32 ReadUInt32()\n{\nreturn ReadData(UInt32.TryParse);\n}\npublic UInt16 ReadUInt16()\n{\nreturn ReadData(UInt16.TryParse);\n}\npublic Int64 ReadInt64()\n{\nreturn ReadData(Int64.TryParse);\n}\npublic Int32 ReadInt32()\n{\nreturn ReadData(Int32.TryParse);\n}\npublic Int16 ReadInt16()\n{\nreturn ReadData(Int16.TryParse);\n}\npublic Boolean ReadYesNo()\n{\nreturn ReadData(Parser.YesNoParser);\n}\npublic Boolean ReadBoolean()\n{\nreturn ReadData(Boolean.TryParse);\n}\npublic Byte ReadByte()\n{\nreturn ReadData(Byte.TryParse);\n}\n\nprivate bool ReadCheck()\n{\nif (!CanRead)\n{\nOnReadError(this, DefaultEventArgs);\nif (ThrowExceptions)\n{\nthrow new Exception(\"!CanRead\");\n}\nreturn false;\n}\nreturn true;\n}\npublic T ReadData()\n{\nreturn ReadData(true);\n}\npublic T ReadData(bool skipWhiteSpace)\n{\nParserDelegate parser = Parser.GetPrimitiveParser();\nreturn ReadData(parser, skipWhiteSpace);\n}\npublic T ReadData(ParserDelegate parser)\n{\nreturn ReadData(parser, true);\n}\npublic T ReadData(ParserDelegate parser, bool skipWhiteSpace)\n{\nif (skipWhiteSpace)\nSkipWhiteSpace();\n\nif (!ReadCheck()) return default(T);\n\nstring s = ReadWord(false);\n\nT res;\nif (!parser.Invoke(s, out res))\n{\nOnParseError(this, DefaultEventArgs);\nif (ThrowExceptions)\n{\nthrow new Exception(\"!validate, word = \" + Output.ToString(s, 256));\n}\n}\nreturn res;\n}\n\npublic string ReadWord()\n{\nreturn ReadWord(true);\n}\npublic string ReadWord(bool skipWhiteSpace)\n{\nif (skipWhiteSpace)\nSkipWhiteSpace();\n\nif (!ReadCheck()) return string.Empty;\n\nint from = pos;\nint to = pos;\nfor (int i = pos; i < line.Length; i++)\n{\nif (char.IsWhiteSpace(line[i])) break;\nto = i + 1;\n}\npos = to;\n\nreturn line.Substring(from, to - from);\n}\n\npublic string ReadLine()\n{\nif (!ReadCheck()) return string.Empty;\n\nReadStream();\nstring res = line.Substring(pos);\npos = line.Length;\n\nreturn res;\n}\n\npublic void Close()\n{\nTextReader.Close();\n}\npublic void Clear()\n{\npos = 0;\nline = string.Empty;\n}\n\nprivate bool disposed = false;\npublic void Dispose()\n{\nDispose(true);\nGC.SuppressFinalize(this);\n}\n\nprotected virtual void Dispose(bool disposing)\n{\nif (!this.disposed)\n{\nif (disposing)\n{\nline = string.Empty;\nTextReader.Dispose();\n}\ndisposed = true;\n}\n}\n~Input()\n{\nDispose(false);\n}\n}\npublic class Output : IDisposable\n{\nstatic char[] space = new char[] { ' ' };\n\npublic TextWriter TextWriter { get; private set; }\npublic bool AutoFlush { get; set; }\n\n\npublic static string ToString(object obj, int maxLength)\n{\nreturn ToString(FormatReal(obj), maxLength);\n}\npublic static string ToString(string s, int maxLength)\n{\nif (s.Length <= maxLength) return s;\nelse return s.Substring(0, maxLength) + \"...\";\n}\npublic static object FormatReal(object v, string format)\n{\nif (v is decimal) return ((decimal)v).ToString(format).Replace(',', '.');\nif (v is double) return ((double)v).ToString(format).Replace(',', '.');\nif (v is float) return ((float)v).ToString(format).Replace(',', '.');\n\nreturn v;\n}\npublic static object FormatReal(object v)\n{\nif (v is decimal || v is double || v is float)\n{\nreturn v.ToString().Replace(',', '.');\n}\nreturn v;\n}\n\npublic Output()\n: this(new MemoryStream())\n{\n}\npublic Output(string path)\n: this(File.Create(path))\n{\n\n}\npublic Output(Stream s)\n: this(new StreamWriter(s))\n{\n}\npublic Output(TextWriter tw)\n{\nTextWriter = tw;\n}\n\npublic static implicit operator Output(Stream s)\n{\nreturn new Output(s);\n}\n\npublic static implicit operator Output(TextWriter tw)\n{\nreturn new Output(tw);\n}\n\npublic static Output operator +(Output output, object obj)\n{\noutput.Write(obj);\nreturn output;\n}\npublic Output WriteArray(params T[] array)\n{\nreturn WriteArray(array, false);\n}\npublic Output WriteArray(T[] array, bool appendLength)\n{\nreturn WriteArray(array, 0, array.Length, appendLength);\n}\npublic Output WriteArray(T[] array, int index, int count)\n{\nreturn WriteArray(array, index, count, false);\n}\npublic Output WriteArray(T[] array, int index, int count, bool appendLength)\n{\nif (index + count > array.Length)\n{\nstring message = string.Format(\n\"Index out of range: {0} + {1} >= {2}\",\nindex,\ncount,\narray.Length);\nthrow new Exception(message);\n}\nif (appendLength)\n{\nWriteLine(count);\n}\nfor (int i = 0; i < count; i++)\n{\nWrite(array[i]);\nWrite(space, 0, space.Length);\n}\nWriteLine();\n\nreturn this;\n}\npublic Output WriteLine(object obj)\n{\nobj = FormatReal(obj);\nreturn WriteLine(obj.ToString());\n}\npublic Output WriteLine(string format, params object[] args)\n{\nreturn WriteLine(string.Format(format, args));\n}\npublic Output WriteLine(string s)\n{\nreturn WriteLine(s.ToCharArray());\n}\npublic Output WriteLine(char[] buffer)\n{\nreturn WriteLine(buffer, 0, buffer.Length);\n}\npublic Output WriteLine(char[] buffer, int index, int count)\n{\nTextWriter.WriteLine(buffer, index, count);\nif (AutoFlush) TextWriter.Flush();\nreturn this;\n}\npublic Output WriteLine()\n{\nTextWriter.WriteLine();\nif (AutoFlush) TextWriter.Flush();\nreturn this;\n}\npublic Output Write(object obj)\n{\nobj = FormatReal(obj);\nreturn Write(obj.ToString());\n}\npublic Output Write(string format, params object[] args)\n{\nreturn Write(string.Format(format, args));\n}\npublic Output Write(string s)\n{\nreturn Write(s.ToCharArray());\n}\npublic Output Write(char[] buffer)\n{\nreturn Write(buffer, 0, buffer.Length);\n}\npublic Output Write(char[] buffer, int index, int count)\n{\nTextWriter.Write(buffer, index, count);\nif (AutoFlush) TextWriter.Flush();\nreturn this;\n}\n\npublic void Close()\n{\nTextWriter.Close();\n}\npublic void Flush()\n{\nTextWriter.Flush();\n}\n\n\nprivate bool disposed = false;\npublic void Dispose()\n{\nDispose(true);\nGC.SuppressFinalize(this);\n}\n\nprotected virtual void Dispose(bool disposing)\n{\nif (!this.disposed)\n{\nif (disposing)\n{\nTextWriter.Dispose();\n}\ndisposed = true;\n}\n}\n~Output()\n{\nDispose(false);\n}\n}\npublic static class Parser\n{\npublic static ParserDelegate GetPrimitiveParser()\n{\nif (!typeof(T).IsPrimitive) throw new Exception(\"Unknown type\");\nelse if (default(T) is Byte) return new ParserDelegate(Byte.TryParse) as ParserDelegate;\nelse if (default(T) is Boolean) return new ParserDelegate(Boolean.TryParse) as ParserDelegate;\nelse if (default(T) is Int16) return new ParserDelegate(Int16.TryParse) as ParserDelegate;\nelse if (default(T) is Int32) return new ParserDelegate(Int32.TryParse) as ParserDelegate;\nelse if (default(T) is Int64) return new ParserDelegate(Int64.TryParse) as ParserDelegate;\nelse if (default(T) is UInt16) return new ParserDelegate(UInt16.TryParse) as ParserDelegate;\nelse if (default(T) is UInt32) return new ParserDelegate(UInt32.TryParse) as ParserDelegate;\nelse if (default(T) is UInt64) return new ParserDelegate(UInt64.TryParse) as ParserDelegate;\nelse if (default(T) is Single) return new ParserDelegate(Parser.SingleParser) as ParserDelegate;\nelse if (default(T) is Double) return new ParserDelegate(Parser.DoubleParser) as ParserDelegate;\nelse if (default(T) is Decimal) return new ParserDelegate(Parser.DecimalParser) as ParserDelegate;\nelse if (default(T) is String) return new ParserDelegate(Parser.StringParser) as ParserDelegate;\nelse throw new Exception(\"Unknown type\");\n}\npublic static bool YesNoParser(string s, out Boolean result)\n{\ns = s.ToLower();\nif (s == \"yes\") result = true;\nelse if (s == \"no\") result = false;\nelse\n{\nresult = false;\nreturn false;\n}\nreturn true;\n}\npublic static bool StringParser(string s, out string result)\n{\nresult = s;\nreturn string.IsNullOrEmpty(s);\n}\npublic static bool DecimalParser(string s, out Decimal result)\n{\nreturn Decimal.TryParse(s.Replace('.', ','), out result);\n}\npublic static bool DoubleParser(string s, out Double result)\n{\nreturn Double.TryParse(s.Replace('.', ','), out result);\n}\npublic static bool SingleParser(string s, out Single result)\n{\nreturn Single.TryParse(s.Replace('.', ','), out result);\n}\n}\n#endregion\n\nclass V : IComparable\n{\n public int Index;\n public int StartT;\n public int EndT;\n public int Count;\n\n public int CompareTo(V a)\n {\n var r = EndT.CompareTo(a.EndT);\n if (r == 0) r = Count.CompareTo(a.Count);\n if (r == 0) r = Index.CompareTo(a.Index);\n return r;\n }\n}\nstatic class Program\n{\n #region Streams\n static string endl = Environment.NewLine;\n static Input cin = new Input(Console.In);\n static Output cout = new Output(Console.Out);\n static Output cerr = new Output(Console.Error);\n\n static void InitIO()\n {\n#if !DEBUG\n cin = new Input(\"input.txt\");\n cout = new Output(\"output.txt\");\n#endif\n }\n #endregion\n #region Time\n static Stopwatch sw = new Stopwatch();\n static void Start()\n {\n sw.Reset();\n sw.Start();\n }\n static void Restart(string text = \"\")\n {\n Stop(text);\n Start();\n }\n static void Time(string text = \"\")\n {\n if (string.IsNullOrEmpty(text))\n {\n cerr.WriteLine(sw.Elapsed);\n }\n else\n {\n cerr.WriteLine(text + \": \" + sw.Elapsed);\n }\n }\n static void Stop(string text = \"\")\n {\n sw.Stop();\n Time(text);\n }\n //*/\n #endregion\n #region Prewriten\n static void Swap(ref T a, ref T b)\n {\n T c = a;\n a = b;\n b = c;\n }\n static long Gcd(long a, long b)\n {\n while (a > 0)\n {\n b %= a;\n Swap(ref a, ref b);\n }\n return b;\n }\n static int[] ZFunction(string s)\n {\n var z = new int[s.Length];\n for (int i = 1, l = 0, r = 0; i < s.Length; ++i)\n {\n if (i <= r)\n {\n z[i] = Math.Min(r - i + 1, z[i - l]);\n }\n while (i + z[i] < s.Length && s[z[i]] == s[i + z[i]])\n {\n z[i]++;\n }\n if (i + z[i] - 1 > r)\n {\n l = i;\n r = i + z[i] - 1;\n }\n }\n return z;\n }\n static long Pow(long a, long p)\n {\n var b = 1L;\n while (p > 0)\n {\n if ((p & 1) == 0)\n {\n a *= a;\n p >>= 1;\n }\n else\n {\n b *= a;\n p--;\n }\n }\n return b;\n }\n #endregion\n const string nyan = \"^_^\";\n const string name = \"canalization\";\n const long mod = 1000000007;\n\n static int Find(string[] a, char x)\n {\n var blocked = new bool[8];\n for (var i = 0; i < 8; i++)\n {\n for (var j = 0; j < 8; j++)\n {\n if (a[i][j] == x && !blocked[j]) return i;\n if (a[i][j] != '.') blocked[j] = true;\n }\n }\n return -1;\n }\n static void Solve()\n {\n var x = cin.ReadInt64() - 2;\n cout.WriteLine(x * x);\n }\n\n static string[] Tests =\n {\n @\"5\",\n @\"3\",\n @\"6\",\n @\"54321\"\n };\n\n static string Generate(int k, int n)\n {\n var sb = new StringWriter();\n var output = new Output(sb);\n\n output.WriteLine(\"{0} {1}\", k, n);\n\n return sb.ToString();\n }\n static void Main()\n {\n#if DEBUG\n if (Tests.Length == 0)\n {\n Solve();\n }\n else\n {\n foreach(var test in Tests)\n {\n cin = new Input(new StringReader(test));\n Start();\n Solve();\n Stop();\n }\n /*\n for (var i = 0; i <= 10; i++)\n {\n var test = Generate(1, i);\n Start();\n cin = new Input(new StringReader(test));\n Solve();\n Stop();\n }\n //*/\n }\n#else\n /*\n cin = new Input(name + \".in\");\n cout = new Output(name + \".out\");\n //*/\n //Solve();\n \n var th = new Thread(Solve, 1024 * 1024 * 64);\n th.Start();\n th.Join();\n cout.Flush();\n cout.Dispose();\n#endif\n }\n}", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\nusing System.Diagnostics;\nusing System.Collections.Generic;\n\npublic class E167\n{\n public static void Main()\n {\n new E167().Entry();\n }//Main\n\n void Entry()\n {\n int[] tmp = intSplit(' ');\n int n = tmp[0];\n int m = tmp[1];\n int[] type = new int[n];\n List[] edges = new List[n];\n for (int i = 0; i < n; i++)\n edges[i] = new List();\n for (int i = 0; i < m; i++)\n {\n tmp = intSplit(' ');\n int a = tmp[0] - 1;\n int b = tmp[1] - 1;\n edges[a].Add(b);\n edges[b].Add(a);\n }//for i\n Queue que = new Queue();\n for (int i = 0; i < n; i++)\n que.Enqueue(i);\n while (que.Count!=0)\n {\n int deq = que.Dequeue();\n int cnt = 0;\n foreach (int item in edges[deq])\n {\n if (type[item] == type[deq])\n cnt++;\n }//foreach item\n if (cnt>=2)\n {\n type[deq] ^= 1;\n foreach (int item in edges[deq])\n {\n if (type[item] == type[deq])\n que.Enqueue(item);\n }//foreach item\n }//if\n }//while\n StringBuilder sb = new StringBuilder();\n foreach (int item in type)\n {\n sb.Append(item);\n }//foreach item\n Console.WriteLine(sb.ToString());\n }\n\n string strRead()\n {\n return Console.ReadLine();\n }\n\n int intRead()\n {\n return int.Parse(Console.ReadLine());\n }\n\n long longRead()\n {\n return long.Parse(Console.ReadLine());\n }\n\n double doubleRead()\n {\n return double.Parse(Console.ReadLine());\n }\n\n string[] strSplit(char a)\n {\n return Console.ReadLine().Split(a);\n }\n\n int[] intSplit(char a)\n {\n return Array.ConvertAll(Console.ReadLine().Split(a), int.Parse);\n }\n\n long[] longSplit(char a)\n {\n return Array.ConvertAll(Console.ReadLine().Split(a), long.Parse);\n }\n\n double[] doubleSplit(char a)\n {\n return Array.ConvertAll(Console.ReadLine().ToString().Split('a'), double.Parse);\n }\n\n\n}//Template", "src_uid": "7017f2c81d5aed716b90e46480f96582"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace Sqare\n{\n class Program\n {\n static void Main(string[] args)\n {\n long [] numbers = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();\n long tile1, tile2;\n if (numbers[0] % numbers[2] == 0)\n {\n tile1 = numbers[0] / numbers[2];\n }\n else\n {\n tile1 = numbers[0] / numbers[2] + 1;\n }\n if (numbers[1] % numbers[2] == 0)\n {\n tile2 = numbers[1] / numbers[2];\n }\n else\n {\n tile2 = numbers[1] / numbers[2] + 1;\n }\n Console.WriteLine(tile2 * tile1);\n }\n }\n}", "src_uid": "ef971874d8c4da37581336284b688517"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nclass A\n{\n static void Main(string[] args)\n {\n#if ONLINE_JUDGE\n#else\n Console.SetIn(new StreamReader(\"in.txt\"));\n#endif\n string[] read = Console.ReadLine().Split(' ');\n int n = Convert.ToInt32(read[0]);\n int x = Convert.ToInt32(read[1]);\n int y = Convert.ToInt32(read[2]);\n int clones = 0;\n float need = n * ((float)y / 10);\n if (need % 10 > 0) need = need/10+1;\n else need = need / 10;\n if (x < need) clones = (int)need - x;\n Console.WriteLine(clones);\n#if ONLINE_JUDGE\n#else\n Console.ReadKey();\n#endif\n }\n}\n\n", "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n const long mod = 1000000007;\n static long phi(long n)\n {\n if (n == 1)\n return 1;\n long result = n;\n for (long i = 2; i * i <= n; ++i)\n if (n % i == 0)\n {\n while (n % i == 0)\n n /= i;\n result -= result / i;\n }\n if (n > 1)\n result -= result / n;\n return result;\n }\n\n static void Main()\n {\n string[] token = Console.ReadLine().Split(' ');\n long n = long.Parse(token[0]);\n long k = long.Parse(token[1]);\n long t = 1;\n long ans = n;\n if (k >= n)\n {\n Console.WriteLine(1);\n return;\n }\n else\n {\n if (k >= 71)\n {\n Console.WriteLine(\"1\");\n return;\n }\n else\n {\n while (t <= k)\n {\n if (t % 2 == 1)\n {\n ans = phi(ans);\n t++;\n }\n else\n {\n t++;\n continue;\n }\n }\n }\n }\n Console.WriteLine(ans % mod);\n Console.Read();\n }\n }\n}", "src_uid": "0591ade5f9a69afcbecd80402493f975"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Code\n{\n class Program\n {\n static void Main(string[] args)\n {\n string a = Console.ReadLine();\n int n = int.Parse(a.Split(' ')[0]);\n int k = int.Parse(a.Split(' ')[1]);\n string s = Console.ReadLine();\n for (int i = 0; i < s.Length; i++)\n {\n int c = 0;\n for (int j = 0; j < s.Length; j++)\n {\n if (s[i] == s[j])\n c++;\n }\n if (c > k)\n {\n Console.Write(\"NO\");\n return;\n }\n c = 0;\n }\n Console.WriteLine(\"YES\");\n\n }\n }\n}\n", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace A.Theatre_Square\n{\n class Program\n {\n\n const double eps = 0.01;\n\n static int dcmp(double x)\n {\n if (x < -eps) return -1;\n if (x > eps) return 1;\n return 0;\n }\n\n static void Main(string[] args)\n {\n Int64 data = Int64.Parse(Console.ReadLine().Trim());\n if (data == 0)\n {\n Console.WriteLine(\"0\");\n return;\n }\n Int64 count = 0;\n Int64 n = (Int64)((Math.Sqrt((((double)data * data) - 0.5 * 0.5) / 0.75) + 1) / 2);\n count=3*n*n-3*n+1;\n \n Int64 need = 0;\n Int64 j = 0;\n do\n {\n double yy = ( 0.5+n ) * Math.Sqrt(3);\n double xx = 0.5;\n need = 0;\n for (Int64 i = j; i < (n + 1)/2+2; i++)\n {\n double x = xx + 1.5 * i;\n double y = yy - (double)i * Math.Sqrt(3)/2;\n if (dcmp(x * x + y * y - (double)(data) * data) <= 0)\n {\n need = (n + 1 - i * 2) < 0 ? 0 : (n + 1 - i * 2);\n j = i;\n break;\n }\n }\n count += need * 6;\n n++;\n } while (need != 0);\n \n \n Console.WriteLine(count);\n\n }\n\n }\n}\n", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13"} {"source_code": "#define Online\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Numerics;\nusing System.Text;\nusing System.IO;\nusing System.Threading;\n\nnamespace CF\n{\n delegate double F(double x);\n delegate decimal Fdec(decimal x);\n\n\n class Program\n {\n\n static void Main(string[] args)\n {\n\n#if FileIO\n StreamReader sr = new StreamReader(\"input.txt\");\n StreamWriter sw = new StreamWriter(\"output.txt\");\n Console.SetIn(sr);\n Console.SetOut(sw);\n#endif\n\n A();\n\n#if Online\n Console.ReadLine();\n#endif\n\n#if FileIO\n sr.Close();\n sw.Close();\n#endif\n }\n\n static void A()\n {\n string[] input = ReadArray(':');\n int h = int.Parse(input[0]);\n int m = int.Parse(input[1]);\n while (true)\n {\n if (m == 59)\n {\n if (h == 23)\n {\n h = 0;\n }\n else\n {\n h++;\n }\n m = 0;\n }\n else\n {\n m++;\n }\n if (h == (m % 10) * 10 + m / 10)\n {\n Console.WriteLine((h < 10 ? \"0\" + h.ToString() : h.ToString()) + \":\" + (m < 10 ? \"0\" + m.ToString() : m.ToString()));\n return;\n }\n }\n }\n\n static void B()\n {\n\n }\n\n static void C()\n {\n\n }\n\n static void D()\n {\n\n }\n\n static void E()\n {\n\n }\n\n static string[] ReadArray(char sep)\n {\n return Console.ReadLine().Split(sep);\n }\n\n static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n\n public static class MyMath\n {\n public static long BinPow(long a, long n, long mod)\n {\n long res = 1;\n while (n > 0)\n {\n if ((n & 1) == 1)\n {\n res = (res * a) % mod;\n }\n a = (a * a) % mod;\n n >>= 1;\n }\n return res;\n }\n\n public static long GCD(long a, long b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static int GCD(int a, int b)\n {\n while (b != 0) b = a % (a = b);\n return a;\n }\n\n public static long LCM(long a, long b)\n {\n return (a * b) / GCD(a, b);\n }\n\n public static int LCM(int a, int b)\n {\n return (a * b) / GCD(a, b);\n }\n }\n\n class Edge\n {\n public int a;\n public int b;\n public int w;\n\n public Edge(int a, int b, int w)\n {\n this.a = a;\n this.b = b;\n this.w = w;\n }\n }\n\n class Graph\n {\n public List[] g;\n public int[] color; //0-white, 1-gray, 2-black\n public int[] o; //open\n public int[] c; //close\n public int[] p;\n public int[] d;\n public List e;\n public Stack ans = new Stack();\n public Graph(int n)\n {\n g = new List[n + 1];\n for (int i = 0; i <= n; i++)\n g[i] = new List();\n color = new int[n + 1];\n o = new int[n + 1];\n c = new int[n + 1];\n p = new int[n + 1];\n d = new int[n + 1];\n }\n\n const int white = 0;\n const int gray = 1;\n const int black = 2;\n\n public bool DFS(int u, ref int time)\n {\n color[u] = gray;\n time++;\n o[u] = time;\n for (int i = 0; i < g[u].Count; i++)\n {\n int v = g[u][i];\n if (color[v] == gray)\n {\n return true;\n }\n if (color[v] == white)\n {\n p[v] = u;\n if (DFS(v, ref time)) return true;\n }\n }\n color[u] = black;\n ans.Push(u);\n c[u] = time;\n time++;\n return false;\n }\n }\n\n static class GraphUtils\n {\n const int white = 0;\n const int gray = 1;\n const int black = 2;\n\n public static void BFS(int s, Graph g)\n {\n Queue q = new Queue();\n q.Enqueue(s);\n while (q.Count != 0)\n {\n int u = q.Dequeue();\n for (int i = 0; i < g.g[u].Count; i++)\n {\n int v = g.g[u][i];\n if (g.color[v] == white)\n {\n g.color[v] = gray;\n g.d[v] = g.d[u] + 1;\n g.p[v] = u;\n q.Enqueue(v);\n }\n }\n g.color[u] = black;\n }\n }\n\n public static bool DFS(int u, ref int time, Graph g, Stack st)\n {\n g.color[u] = gray;\n time++;\n g.o[u] = time;\n for (int i = 0; i < g.g[u].Count; i++)\n {\n int v = g.g[u][i];\n if (g.color[v] == gray)\n {\n return true;\n }\n if (g.color[v] == white)\n {\n g.p[v] = u;\n if (DFS(v, ref time, g, st)) return true;\n }\n }\n g.color[u] = black;\n st.Push(u);\n g.c[u] = time;\n time++;\n return false;\n }\n\n public static void FordBellman(int u, Graph g)\n {\n int n = g.g.Length;\n for (int i = 0; i <= n; i++)\n {\n g.d[i] = int.MaxValue;\n g.p[i] = 0;\n }\n\n g.d[u] = 0;\n\n for (int i = 0; i < n - 1; i++)\n {\n for (int j = 0; j < g.e.Count; j++)\n {\n if (g.d[g.e[j].a] != int.MaxValue)\n {\n if (g.d[g.e[j].a] + g.e[j].w < g.d[g.e[j].b])\n {\n g.d[g.e[j].b] = g.d[g.e[j].a] + g.e[j].w;\n g.p[g.e[j].b] = g.e[j].a;\n }\n }\n }\n }\n }\n }\n\n static class ArrayUtils\n {\n public static int BinarySearch(int[] a, int val)\n {\n int left = 0;\n int right = a.Length - 1;\n int mid;\n\n while (left < right)\n {\n mid = left + ((right - left) >> 1);\n if (val <= a[mid])\n {\n right = mid;\n }\n else\n {\n left = mid + 1;\n }\n }\n\n if (a[left] == val)\n return left;\n else\n return -1;\n }\n\n public static double Bisection(F f, double left, double right, double eps)\n {\n double mid;\n while (right - left > eps)\n {\n mid = left + ((right - left) / 2d);\n if (Math.Sign(f(mid)) != Math.Sign(f(left)))\n right = mid;\n else\n left = mid;\n }\n return (left + right) / 2d;\n }\n\n\n public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)\n {\n decimal m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3m;\n m2 = r - (r - l) / 3m;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static double TernarySearch(F f, double eps, double l, double r, bool isMax)\n {\n double m1, m2;\n while (r - l > eps)\n {\n m1 = l + (r - l) / 3d;\n m2 = r - (r - l) / 3d;\n if (f(m1) < f(m2))\n if (isMax)\n l = m1;\n else\n r = m2;\n else\n if (isMax)\n r = m2;\n else\n l = m1;\n }\n return r;\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R, Comparison comp)\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (comp(L[i], R[j]) <= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R, Comparison comp)\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R, comp);\n Merge_Sort(A, q + 1, r, L, R, comp);\n Merge(A, p, q, r, L, R, comp);\n }\n\n public static void Merge(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable\n {\n for (int i = p; i <= q; i++)\n L[i] = A[i];\n for (int i = q + 1; i <= r; i++)\n R[i] = A[i];\n\n for (int k = p, i = p, j = q + 1; k <= r; k++)\n {\n if (i > q)\n {\n for (; k <= r; k++, j++)\n A[k] = R[j];\n return;\n }\n if (j > r)\n {\n for (; k <= r; k++, i++)\n A[k] = L[i];\n return;\n }\n if (L[i].CompareTo(R[j]) >= 0)\n {\n A[k] = L[i];\n i++;\n }\n else\n {\n A[k] = R[j];\n j++;\n }\n }\n }\n\n public static void Merge_Sort(T[] A, int p, int r, T[] L, T[] R) where T : IComparable\n {\n if (p >= r) return;\n int q = p + ((r - p) >> 1);\n Merge_Sort(A, p, q, L, R);\n Merge_Sort(A, q + 1, r, L, R);\n Merge(A, p, q, r, L, R);\n }\n\n static void Shake(T[] a)\n {\n Random rnd = new Random(Environment.TickCount);\n T temp;\n int b, c;\n for (int i = 0; i < a.Length; i++)\n {\n b = rnd.Next(0, a.Length);\n c = rnd.Next(0, a.Length);\n temp = a[b];\n a[b] = a[c];\n a[c] = temp;\n }\n }\n }\n}", "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing static System.Console;\n\nnamespace Olymp\n{\n public class ProblemSolver\n {\n private readonly Tokenizer input;\n\n public void Solve()\n {\n var s = input.ReadToken();\n for (var i = 0; i < s.Length - 1; i++)\n {\n if (!\"naouie\".Contains(s[i]) &&\n !\"aouie\".Contains(s[i + 1]))\n {\n Write(\"NO\");\n return;\n }\n }\n if (!\"naouie\".Contains(s.Last()))\n {\n Write(\"NO\");\n return;\n }\n Write(\"YES\");\n }\n\n public ProblemSolver(TextReader input)\n {\n this.input = new Tokenizer(input);\n }\n }\n\n #region Service classes\n\n public class Tokenizer\n {\n private TextReader reader;\n\n public string ReadToEnd()\n {\n return this.reader.ReadToEnd();\n }\n\n public int ReadInt()\n {\n var c = SkipWS();\n if (c == -1)\n throw new EndOfStreamException();\n var isNegative = false;\n if (c == '-' || c == '+')\n {\n isNegative = c == '-';\n c = this.reader.Read();\n if (c == -1)\n throw new EndOfStreamException(\"Digit expected, but end of stream occurs\");\n }\n if (!char.IsDigit((char)c))\n throw new InvalidOperationException($\"Digit expected, but was: '{(char)c}'\");\n var result = (char)c - '0';\n c = this.reader.Read();\n while (c > 0 && !char.IsWhiteSpace((char)c))\n {\n if (!char.IsDigit((char)c))\n throw new InvalidOperationException($\"Digit expected, but was: '{(char)c}'\");\n result = result * 10 + (char)c - '0';\n c = this.reader.Read();\n }\n if (isNegative)\n result = -result;\n return result;\n }\n\n public string ReadLine()\n {\n return reader.ReadLine();\n }\n\n public long ReadLong()\n {\n return long.Parse(this.ReadToken());\n }\n\n public double ReadDouble()\n {\n return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public int[] ReadIntArray(int n)\n {\n var a = new int[n];\n for (var i = 0; i < n; i++)\n a[i] = ReadInt();\n return a;\n }\n\n public long[] ReadLongArray(int n)\n {\n var a = new long[n];\n for (var i = 0; i < n; i++)\n a[i] = ReadLong();\n return a;\n }\n\n public double[] ReadDoubleArray(int n)\n {\n var a = new double[n];\n for (var i = 0; i < n; i++)\n a[i] = ReadDouble();\n return a;\n }\n\n public string ReadToken()\n {\n var c = SkipWS();\n if (c == -1)\n return null;\n var sb = new StringBuilder();\n while (c > 0 && !char.IsWhiteSpace((char)c))\n {\n sb.Append((char)c);\n c = this.reader.Read();\n }\n return sb.ToString();\n }\n\n private int SkipWS()\n {\n var c = this.reader.Read();\n if (c == -1)\n return c;\n while (c > 0 && char.IsWhiteSpace((char)c))\n c = this.reader.Read();\n return c;\n }\n\n public Tokenizer(TextReader reader)\n {\n this.reader = reader;\n }\n }\n\n internal class Program\n {\n public static void Main(string[] args)\n {\n var solver = new ProblemSolver(In);\n solver.Solve();\n }\n }\n\n #endregion\n}", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Diagnostics;\n\nnamespace Codeforces\n{\n class Program : ProgramBase\n {\n private const long commonMod = 1000000007;\n\n static void Main(string[] args)\n {\n var p = new Program();\n var x = p.Solve();\n p.Out(x);\n }\n\n object Solve()\n {\n var s = Read();\n var abc = \"abcdefghijklmnopqrstuvwxyz\";\n var k = 0;\n for (int i = 0; i < s.Length; i++)\n {\n if (abc.IndexOf(s[i]) == k)\n k++;\n if (abc.IndexOf(s[i]) > k)\n return \"NO\";\n }\n return \"YES\";\n }\n\n\n\n long BS(long n, long m, long k, long left, long right)\n {\n if (right - left == 1)\n return left;\n var half = (right + left) / 2;\n if (Check(n, m, k, half))\n return BS(n, m, k, half, right);\n return BS(n, m, k, left, half);\n }\n \n bool Check(long n, long m, long k, long value)\n {\n var result = value + (value - 1)*value;\n if (k < value)\n result -= (value - k) * (value - k + 1) / 2;\n if (n - k + 1 < value)\n result -= (value - (n - k + 1)) * (value - (n - k)) / 2;\n return result <= m;\n }\n\n\n long FastPow(long b, long pow)\n {\n if (pow == 0)\n return 1;\n if (pow == 1)\n return b;\n if (pow % 2 == 0)\n return FastPow(b * b, pow / 2);\n return b * FastPow(b, pow - 1);\n }\n\n bool IsPrime(int n)\n {\n for (int i = 2; i <= Math.Sqrt(n); i++)\n {\n if (n % i == 0)\n return false;\n }\n return true;\n }\n }\n\n \n abstract class ProgramBase\n {\n bool? prod = null;\n StreamReader f;\n Queue tokens;\n protected string FileName { private get; set; }\n\n protected string Read()\n {\n if (f == null)\n f = string.IsNullOrEmpty(FileName)\n ? new StreamReader(Console.OpenStandardInput())\n : new StreamReader((GetProd() ? \"\" : \"c:\\\\dev\\\\\") + FileName);\n return f.ReadLine();\n }\n\n protected string ReadToken()\n {\n if (tokens == null || tokens.Count == 0)\n tokens = new Queue(Read().Split(' '));\n return tokens.Dequeue();\n }\n\n protected long ReadLong() { return long.Parse(ReadToken()); }\n\n protected long[] ReadLongs()\n {\n var s = Read();\n if (s == \"\")\n return new long[0];\n var tokens = s.Split(' ');\n var result = new long[tokens.Length];\n for (int i = 0; i < tokens.Length; i++)\n result[i] = long.Parse(tokens[i]);\n return result;\n }\n\n public void Out(object r)\n {\n if (string.IsNullOrEmpty(FileName))\n Console.WriteLine(r);\n else if (GetProd())\n File.WriteAllText(FileName, r.ToString());\n else\n Console.WriteLine(r);\n }\n\n private bool GetProd()\n {\n\n if (!prod.HasValue)\n try\n {\n prod = Environment.MachineName != \"RENADEEN-W7\";\n }\n catch (Exception)\n {\n prod = true;\n }\n return prod.Value;\n }\n }\n\n public static class Huj\n {\n public static T MinBy(this IEnumerable source, Func func) where T : class\n {\n T result = null;\n var min = double.MaxValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (min > current)\n {\n min = current;\n result = item;\n }\n }\n return result;\n }\n\n public static T MaxBy(this IEnumerable source, Func func, T defaultValue = default(T))\n {\n T result = defaultValue;\n var max = double.MinValue;\n foreach (var item in source)\n {\n var current = func(item);\n if (max < current)\n {\n max = current;\n result = item;\n }\n }\n return result;\n }\n\n public static string JoinStrings(this IEnumerable s, string d) { return string.Join(d, s.ToArray()); }\n\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n public static string JoinStrings(this IEnumerable s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }\n }\n}", "src_uid": "c4551f66a781b174f95865fa254ca972"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\n\nnamespace Temp\n{ \n struct PointInt\n {\n public long X;\n\n public long Y;\n\n public PointInt(long x, long y)\n : this()\n {\n this.X = x;\n this.Y = y;\n }\n\n public static PointInt operator +(PointInt a, PointInt b)\n {\n return new PointInt(a.X + b.X, a.Y + b.Y);\n }\n\n public static PointInt operator -(PointInt a, PointInt b)\n {\n return new PointInt(a.X - b.X, a.Y - b.Y);\n }\n\n public static PointInt operator *(PointInt a, long k)\n {\n return new PointInt(k * a.X, k * a.Y);\n }\n\n public static PointInt operator *(long k, PointInt a)\n {\n return new PointInt(k * a.X, k * a.Y);\n }\n\n public bool IsInsideRectangle(long l, long b, long r, long t)\n {\n return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);\n }\n }\n\n struct LineInt\n {\n public LineInt(PointInt a, PointInt b)\n : this()\n {\n A = a.Y - b.Y;\n B = b.X - a.X;\n C = a.X * b.Y - a.Y * b.X;\n }\n\n public long A, B, C;\n\n public bool ContainsPoint(PointInt p)\n {\n return A * p.X + B * p.Y + C == 0;\n }\n }\n\n class MatrixInt\n {\n private long[,] m_Matrix;\n\n public int Size\n {\n get\n {\n return m_Matrix.GetLength(0) - 1;\n }\n }\n\n public long Mod { get; private set; }\n\n public MatrixInt(int size, long mod = 0)\n {\n m_Matrix = new long[size + 1, size + 1];\n Mod = mod;\n }\n\n public MatrixInt(long[,] matrix, long mod = 0)\n {\n this.m_Matrix = matrix;\n Mod = mod;\n }\n\n public static MatrixInt GetIdentityMatrix(int size, long mod = 0)\n {\n long[,] matrix = new long[size + 1, size + 1];\n\n for (int i = 1; i <= size; i++)\n {\n matrix[i, i] = 1;\n }\n\n return new MatrixInt(matrix, mod);\n }\n\n public long this[int i, int j]\n {\n get\n {\n return m_Matrix[i, j];\n }\n\n set\n {\n m_Matrix[i, j] = value;\n }\n }\n\n public static MatrixInt operator +(MatrixInt a, MatrixInt b)\n {\n int n = a.Size;\n long mod = Math.Max(a.Mod, b.Mod);\n long[,] c = new long[n, n];\n for (int i = 1; i <= n; i++)\n {\n for (int j = 1; j <= n; j++)\n {\n c[i, j] = a[i, j] + b[i, j]; \n }\n }\n\n if (mod > 0)\n {\n for (int i = 1; i <= n; i++)\n {\n for (int j = 1; j <= n; j++)\n {\n c[i, j] %= mod;\n }\n }\n }\n\n return new MatrixInt(c, mod);\n }\n\n public static MatrixInt operator *(MatrixInt a, MatrixInt b)\n {\n int n = a.Size;\n long mod = Math.Max(a.Mod, b.Mod);\n\n long[,] c = new long[n, n];\n\n for (int i = 1; i <= n; i++)\n {\n for (int j = 1; j <= n; j++)\n {\n for (int k = 1; k <= n; k++)\n {\n c[i, j] += a[i, k] * b[k, j];\n if (mod > 0)\n {\n c[i, j] %= mod;\n }\n } \n }\n }\n\n return new MatrixInt(c, mod);\n }\n }\n\n static class Algebra\n {\n public static long Phi(long n)\n {\n long result = n;\n for (long i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n while (n % i == 0)\n {\n n /= i;\n }\n\n result -= result / i;\n }\n }\n\n if (n > 1)\n {\n result -= result / n;\n }\n\n return result;\n }\n\n public static long BinPower(long a, long n, long mod)\n {\n long result = 1;\n\n while (n > 0)\n {\n if ((n & 1) != 0)\n {\n result = (result * a) % mod;\n }\n\n a = (a * a) % mod;\n n >>= 1;\n }\n\n return result;\n }\n\n public static class Permutations\n {\n public static int[] GetRandomPermutation(int n)\n {\n int[] p = new int[n];\n for (int i = 0; i < n; i++)\n {\n p[i] = i;\n }\n\n Random random = new Random();\n for (int i = n - 1; i > 0; i--)\n {\n int j = random.Next(i + 1);\n int tmp = p[i];\n p[i] = p[j];\n p[j] = tmp;\n }\n\n return p;\n }\n }\n\n public static T[] Shuffle(this T[] array)\n {\n int length = array.Length;\n int[] p = Permutations.GetRandomPermutation(length);\n T[] result = new T[length];\n for (int i = 0; i < length; i++)\n {\n result[i] = array[p[i]];\n }\n\n return result;\n }\n\n public static MatrixInt MatrixBinPower(MatrixInt a, long n)\n {\n MatrixInt result = new MatrixInt(a.Size);\n\n while (n > 0)\n {\n if ((n & 1) != 0)\n {\n result *= a;\n }\n\n a *= a;\n n >>= 1;\n }\n\n return result;\n }\n\n public static long Gcd(long a, long b)\n {\n return b == 0 ? a : Gcd(b, a % b);\n }\n\n public static long ExtendedGcd(long a, long b, out long x, out long y)\n {\n if (b == 0)\n {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1;\n long y1;\n long d = ExtendedGcd(b, a % b, out x1, out y1);\n x = y1;\n y = x1 - (a / b) * y1;\n return d;\n }\n\n public static long Lcm(long a, long b)\n {\n return (a / Gcd(a, b)) * b;\n }\n\n public static bool[] GetPrimes(int n)\n {\n n = Math.Max(n, 2);\n bool[] prime = new bool[n + 1];\n for (int i = 2; i <= n; i++)\n {\n prime[i] = true;\n }\n\n for (int i = 2; i * i <= n; i++)\n {\n if (prime[i])\n {\n if ((long)i * i <= n)\n {\n for (int j = i * i; j <= n; j += i)\n {\n prime[j] = false;\n }\n }\n }\n }\n\n return prime;\n }\n\n public static long GetFibonacciNumber(long n, long mod = 0)\n {\n long[,] matrix = new long[,] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };\n\n MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);\n\n return result[2, 2];\n }\n\n public static long[] GetFibonacciSequence(int n)\n {\n long[] result = new long[n];\n result[0] = result[1] = 1;\n\n for (int i = 2; i < n; i++)\n {\n result[i] = result[i - 1] + result[i - 2];\n }\n\n return result;\n }\n\n public static long GetInverseElement(long a, long mod)\n {\n long x, y;\n long g = ExtendedGcd(a, mod, out x, out y);\n\n if (g != 1)\n {\n return -1;\n }\n\n return ((x % mod) + mod) % mod;\n }\n\n public static long[] GetAllInverseElements(long mod)\n {\n long[] result = new long[mod];\n result[1] = 1;\n for (int i = 2; i < mod; i++)\n {\n result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;\n }\n\n return result;\n }\n }\n\n internal static class Reader\n {\n public static void ReadInt(out int a)\n {\n int[] number = new int[1];\n ReadInt(number);\n a = number[0];\n }\n\n public static void ReadInt(out int a, out int b)\n {\n int[] numbers = new int[2];\n ReadInt(numbers);\n a = numbers[0];\n b = numbers[1];\n }\n\n public static void ReadInt(out int int1, out int int2, out int int3)\n {\n int[] numbers = new int[3];\n ReadInt(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n }\n\n public static void ReadInt(out int int1, out int int2, out int int3, out int int4)\n {\n int[] numbers = new int[4];\n ReadInt(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n int4 = numbers[3];\n }\n\n public static void ReadLong(out long a)\n {\n long[] number = new long[1];\n ReadLong(number);\n a = number[0];\n }\n\n public static void ReadLong(out long a, out long b)\n {\n long[] numbers = new long[2];\n ReadLong(numbers);\n a = numbers[0];\n b = numbers[1];\n }\n\n public static void ReadLong(out long int1, out long int2, out long int3)\n {\n long[] numbers = new long[3];\n ReadLong(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n }\n\n public static void ReadLong(out long int1, out long int2, out long int3, out long int4)\n {\n long[] numbers = new long[4];\n ReadLong(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n int4 = numbers[3];\n }\n\n public static void ReadInt(int[] numbers)\n {\n // ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n // ReSharper restore PossibleNullReferenceException\n\n int count = Math.Min(numbers.Length, list.Length);\n\n for (int i = 0; i < count; i++)\n {\n numbers[i] = int.Parse(list[i]);\n }\n }\n\n public static int[] ReadDigits()\n {\n // ReSharper disable AssignNullToNotNullAttribute\n return Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();\n // ReSharper restore AssignNullToNotNullAttribute\n }\n\n public static void ReadLong(long[] numbers)\n {\n // ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n // ReSharper restore PossibleNullReferenceException\n\n int count = Math.Min(numbers.Length, list.Length);\n\n for (int i = 0; i < count; i++)\n {\n numbers[i] = long.Parse(list[i]);\n }\n }\n\n public static void ReadDouble(double[] numbers)\n {\n // ReSharper disable PossibleNullReferenceException\n var list = Console.ReadLine().Split();\n // ReSharper restore PossibleNullReferenceException\n\n int count = Math.Min(numbers.Length, list.Length);\n\n for (int i = 0; i < count; i++)\n {\n numbers[i] = double.Parse(list[i]);\n }\n }\n\n public static void ReadDouble(out double a, out double b)\n {\n double[] numbers = new double[2];\n ReadDouble(numbers);\n a = numbers[0];\n b = numbers[1];\n }\n\n public static void ReadDouble(out double int1, out double int2, out double int3)\n {\n double[] numbers = new double[3];\n ReadDouble(numbers);\n int1 = numbers[0];\n int2 = numbers[1];\n int3 = numbers[2];\n }\n\n public static string ReadLine()\n {\n return Console.ReadLine();\n }\n }\n\n static class MyMath\n {\n public static int GetMinimalPrimeDivisor(int n)\n { \n for (int i = 2; i * i <= n; i++)\n {\n if (n % i == 0)\n {\n return i;\n }\n }\n\n return n;\n }\n\n public static long Sqr(long x)\n {\n return x * x;\n }\n }\n\n public interface IGraph\n {\n int Vertices { get; set; }\n\n IList this[int i] { get; }\n\n void AddEdge(int u, int v);\n\n void AddOrientedEdge(int u, int v); \n }\n\n public class Graph : IGraph\n {\n private List[] m_Edges;\n\n public int Vertices { get; set; }\n\n public IList this[int i]\n {\n get\n {\n return this.m_Edges[i];\n }\n }\n\n public Graph(int vertices)\n {\n this.Vertices = vertices;\n\n this.m_Edges = new List[vertices];\n\n for (int i = 0; i < vertices; i++)\n {\n this.m_Edges[i] = new List();\n }\n }\n\n public void AddEdge(int u, int v)\n {\n this.AddOrientedEdge(u, v);\n this.AddOrientedEdge(v, u);\n }\n\n public void AddOrientedEdge(int first, int second)\n {\n this.m_Edges[first].Add(second); \n }\n\n public int[] Bfs(int start)\n {\n int[] d = new int[Vertices];\n for (int i = 0; i < Vertices; i++)\n {\n d[i] = -1;\n }\n\n Queue queue = new Queue();\n queue.Enqueue(start);\n d[start] = 0;\n\n while (queue.Count > 0)\n {\n int v = queue.Dequeue();\n foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))\n {\n queue.Enqueue(t);\n d[t] = d[v] + 1;\n }\n }\n\n return d;\n }\n } \n\n class SimpleSumTable\n {\n private readonly int[,] m_Sum;\n\n public SimpleSumTable(int n, int m, int[,] table)\n {\n m_Sum = new int[n + 1, m + 1];\n\n for (int i = 1; i < n + 1; i++)\n {\n for (int j = 1; j < m + 1; j++)\n {\n m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i, j];\n }\n }\n }\n\n public int GetSum(int l, int b, int r, int t)\n {\n return m_Sum[r, t] - m_Sum[r, b] - m_Sum[l, t] + m_Sum[l, b];\n }\n }\n\n class SegmentTreeSimpleInt\n {\n public int Size { get; private set; }\n\n private readonly T[] m_Tree;\n\n private Func m_Operation;\n\n private T m_Null;\n\n public SegmentTreeSimpleInt(int size, Func operation, T nullElement, IList array = null)\n {\n this.Size = size;\n this.m_Operation = operation;\n this.m_Null = nullElement;\n\n m_Tree = new T[4 * size];\n if (array != null)\n {\n this.Build(array, 1, 0, size - 1); \n }\n }\n\n private void Build(IList array, int v, int tl, int tr)\n {\n if (tl == tr)\n {\n m_Tree[v] = array[tl];\n }\n else\n {\n int tm = (tl + tr) / 2;\n this.Build(array, 2 * v, tl, tm);\n this.Build(array, 2 * v + 1, tm + 1, tr);\n this.CalculateNode(v);\n }\n }\n\n public T GetSum(int l, int r)\n {\n return GetSum(1, 0, Size - 1, l, r);\n }\n\n private T GetSum(int v, int tl, int tr, int l, int r)\n {\n if (l > r)\n {\n return m_Null;\n }\n\n if (l == tl && r == tr)\n {\n return m_Tree[v];\n }\n\n int tm = (tl + tr) / 2;\n\n return this.m_Operation(GetSum(2 * v, tl, tm, l, Math.Min(r, tm)),GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));\n }\n\n public void Update(int pos, T newValue)\n {\n Update(1, 0, Size - 1, pos, newValue);\n }\n\n private void Update(int v, int tl, int tr, int pos, T newValue)\n {\n if (tl == tr)\n {\n m_Tree[v] = newValue;\n }\n else\n {\n int tm = (tl + tr) / 2;\n if (pos <= tm)\n {\n Update(2 * v, tl, tm, pos, newValue);\n }\n else\n {\n Update(2 * v + 1, tm + 1, tr, pos, newValue);\n }\n this.CalculateNode(v);\n }\n }\n\n private void CalculateNode(int v)\n {\n m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);\n }\n }\n\n struct Pair\n {\n public Pair(TFirst first, TSecond second)\n : this()\n {\n this.First = first;\n this.Second = second;\n }\n\n public TFirst First { set; get; }\n\n public TSecond Second { set; get; }\n }\n\n class Program\n { \n private static StreamReader m_InputStream;\n\n private static StreamWriter m_OutStream;\n\n private static void OpenFiles()\n {\n m_InputStream = File.OpenText(\"input.txt\");\n Console.SetIn(m_InputStream);\n\n m_OutStream = File.CreateText(\"output.txt\");\n Console.SetOut(m_OutStream);\n }\n\n private static void CloseFiles()\n {\n m_OutStream.Flush();\n\n m_InputStream.Dispose();\n m_OutStream.Dispose();\n }\n\n static void Main()\n {\n //OpenFiles();\n\n new Solution().Solve();\n\n //CloseFiles();\n }\n }\n\n internal class Solution\n {\n private int[,,,] pos;\n\n private Card[] cards;\n\n public void Solve()\n {\n int n;\n Reader.ReadInt(out n);\n\n cards = new Card[n];\n\n string s = Reader.ReadLine();\n var split = s.Split();\n for (int i = 0; i < n; i++)\n {\n cards[i] = new Card(split[i], i);\n }\n\n pos = new int[n + 1,n,n,n];\n\n Console.Write(this.IsPossible(n, n - 3, n - 2, n - 1) == 1 ? \"YES\" : \"NO\");\n }\n\n private int IsPossible(int n, int a, int b, int c)\n {\n if (n == 1)\n {\n return 1;\n }\n\n if (n == 2)\n {\n return this.Compatible(cards[b], cards[c]) ? 1 : 2;\n }\n\n if (pos[n, a, b, c] != 0)\n {\n return pos[n, a, b, c];\n }\n\n if (this.Compatible(cards[b], cards[c]) && this.IsPossible(n - 1, n - 4, a, c) == 1 ||\n n > 3 && this.Compatible(cards[n - 4], cards[c]) && this.IsPossible(n - 1, c, a, b) == 1)\n {\n pos[n, a, b, c] = 1;\n return 1;\n }\n else\n {\n pos[n, a, b, c] = 2;\n return 2;\n }\n }\n\n class Card\n {\n public Card(string card, int id)\n {\n Value = card[0];\n Suit = card[1];\n Id = id;\n }\n\n public char Value;\n\n public char Suit;\n\n public int Id;\n }\n\n private bool Compatible(Card a, Card b)\n {\n return a.Value == b.Value || a.Suit == b.Suit;\n }\n }\n}\n", "src_uid": "1805771e194d323edacf2526a1eb6768"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace ConsoleApplication41\n{\n class Program\n {\n static void Main(string[] args)\n {\n List strList = new List();\n strList.Add(\"espeon\");\n strList.Add(\"vaporeon\");\n strList.Add(\"jolteon\");\n strList.Add(\"flareon\"); \n strList.Add(\"umbreon\");\n strList.Add(\"leafeon\");\n strList.Add(\"glaceon\");\n strList.Add(\"sylveon\");\n string temp;\n string str = \"j......\";\n int n = 0,n2=0, mayor=0;\n\n int t = Convert.ToInt32(Console.ReadLine());\n str = Console.ReadLine();\n\n if (str!=\"......\"&&str!=\"........\")\n {\n for (int x = 0; x < strList.Count; x++)\n {\n temp = strList[x];\n n = 0;\n\n if (temp.Length >= str.Length)\n {\n //Console.WriteLine(temp.Length + \" \" + str.Length);\n for (int y = 0; y < str.Length; y++)\n {\n if (temp[y] == str[y])\n {\n //Console.WriteLine(temp[y] + \" \" + str[y]);\n n++;\n }\n\n }\n }\n if (n > mayor)\n {\n mayor = n;\n n2 = x;\n }\n }\n Console.WriteLine(strList[n2]);\n }\n else\n {\n for (int x = 0; x < strList.Count; x++)\n {\n temp = strList[x];\n if (temp.Length ==t)\n {\n Console.WriteLine(temp);\n }\n }\n }\n\n \n\n \n\n\n Console.ReadLine();\n\n\n }\n }\n}\n", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace Dreamoon_and_Stairs\n{\n class Program\n {\n static void Main(string[] args)\n {\n string str_Inputs = Console.ReadLine();\n string[] arr_Inputs = str_Inputs.Split(' ');\n int n = Convert.ToInt32(arr_Inputs[0]);\n int m = Convert.ToInt32(arr_Inputs[1]);\n\n int min = n / 2 + n%2;\n int max = n;\n\n for (int i = min; i <= max; i++)\n {\n if (i % m == 0)\n {\n Console.Write(i);\n return;\n }\n }\n Console.Write(\"-1\");\n }\n }\n}\n", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"source_code": "using System;\nusing System.Linq;\nusing System.Diagnostics;\nusing System.Collections.Generic;\nusing Debug = System.Diagnostics.Debug;\nusing StringBuilder = System.Text.StringBuilder;\nusing System.Numerics;\n\nnamespace Program\n{\n\n public class Solver\n {\n public void Solve()\n {\n var table = new CombinationTable(300050);\n var a = sc.Integer();\n var b = sc.Integer();\n var c = sc.Integer();\n var l = sc.Integer();\n long all = 0;\n for (int i = 0; i <= l; i++)\n {\n all += table[i + 2, 2];\n Debug.WriteLine(all);\n }\n var abc = new int[] { a, b, c };\n var sum = a + b + c;\n for (int i = 0; i < 3; i++)\n {\n for (int j = 0; j <= l; j++)\n {\n var max = abc[i] + j;\n var rem = Math.Min(l - j, max - sum + abc[i]);\n if (rem < 0) continue;\n all -= table[rem + 2, 2];\n }\n }\n IO.Printer.Out.WriteLine(all);\n }\n public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());\n static T[] Enumerate(int n, Func f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }\n static public void Swap(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }\n }\n}\n\n#region main\nstatic class Ex\n{\n static public string AsString(this IEnumerable ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }\n static public string AsJoinedString(this IEnumerable ie, string st = \" \") { return string.Join(st, ie); }\n static public void Main()\n {\n var solver = new Program.Solver();\n solver.Solve();\n Program.IO.Printer.Out.Flush();\n }\n}\n#endregion\n#region Ex\nnamespace Program.IO\n{\n using System.IO;\n using System.Text;\n using System.Globalization;\n public class Printer : StreamWriter\n {\n static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }\n public static Printer Out { get; set; }\n public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }\n public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }\n public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }\n public void Write(string format, T[] source) { base.Write(format, source.OfType().ToArray()); }\n public void WriteLine(string format, T[] source) { base.WriteLine(format, source.OfType().ToArray()); }\n }\n public class StreamScanner\n {\n public StreamScanner(Stream stream) { str = stream; }\n public readonly Stream str;\n private readonly byte[] buf = new byte[1024];\n private int len, ptr;\n public bool isEof = false;\n public bool IsEndOfStream { get { return isEof; } }\n private byte read()\n {\n if (isEof) return 0;\n if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }\n return buf[ptr++];\n }\n public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }\n\n public string Scan()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b >= 33 && b <= 126; b = (char)read())\n sb.Append(b);\n return sb.ToString();\n }\n public string ScanLine()\n {\n var sb = new StringBuilder();\n for (var b = Char(); b != '\\n'; b = (char)read())\n if (b == 0) break;\n else if (b != '\\r') sb.Append(b);\n return sb.ToString();\n }\n public long Long()\n {\n if (isEof) return long.MinValue;\n long ret = 0; byte b = 0; var ng = false;\n do b = read();\n while (b != '-' && (b < '0' || '9' < b));\n if (b == '-') { ng = true; b = read(); }\n for (; true; b = read())\n {\n if (b < '0' || '9' < b)\n return ng ? -ret : ret;\n else ret = ret * 10 + b - '0';\n }\n }\n public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }\n public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }\n private T[] enumerate(int n, Func f)\n {\n var a = new T[n];\n for (int i = 0; i < n; ++i) a[i] = f();\n return a;\n }\n\n public char[] Char(int n) { return enumerate(n, Char); }\n public string[] Scan(int n) { return enumerate(n, Scan); }\n public double[] Double(int n) { return enumerate(n, Double); }\n public int[] Integer(int n) { return enumerate(n, Integer); }\n public long[] Long(int n) { return enumerate(n, Long); }\n }\n}\n#endregion\n\n#region CombinationTable\npublic class CombinationTable\n{\n long[][] nCr;\n public CombinationTable(int n)\n {\n nCr = new long[n + 1][];\n for (int i = 0; i <= n; i++)\n nCr[i] = new long[4];\n nCr[0][0] = 1;\n for (int i = 0; i <= n; i++)\n {\n nCr[i][0] = 1;\n for (int j = 1; j < Math.Min(i + 1, 4); j++)\n nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]);// % mod;\n }\n }\n public long this[int n, int r]\n {\n get\n {\n if (n < 0 || n > nCr.Length)\n return 0;\n if (r < 0 || r > n)\n return 0;\n return nCr[n][r];\n }\n }\n public long RepeatedCombination(int n, int k)\n {\n if (k == 0) return 1;\n return this[n + k - 1, k];\n }\n}\n#endregion\n", "src_uid": "185ff90a8b0ae0e2b75605f772589410"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n {\nstatic void Main()\n{ \n\n string [] inputs = Console.ReadLine().Split(' ');\n int l = int.Parse(inputs[0]);\n int r = int.Parse(inputs[1]);\n char[] tempnum;\n List Digits = new List();\n int flag = 0;\n\n for (int i = l; i <= r; i++)\n {\n tempnum = i.ToString().ToCharArray();\n for (int j = 0; j < tempnum.Length; j++)\n {\n if (!Digits.Contains(int.Parse(tempnum[j].ToString())))\n {\n Digits.Add(int.Parse(tempnum[j].ToString()));\n }\n }\n if (Digits.Count == tempnum.Length)\n {\n Console.WriteLine(tempnum);\n flag = 1;\n break;\n }\n else { flag = 0; Digits.Clear(); }\n }\n\n if (flag == 0)\n {\n Console.WriteLine(\"-1\");\n }\n}\n\n}", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"} {"source_code": "using System;\n\nnamespace SortingAlgorithms\n{\n class Program\n {\n static void Main(string[] args)\n {\n FriendMeeting();\n }\n public static void FriendMeeting()\n {\n int count;\n int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), arrTemp => Convert.ToInt32(arrTemp));\n for (int i = 1; i < arr.Length; i++)\n {\n int next = arr[i];\n int j = i - 1;\n while (j >= 0 && arr[j] > next)\n {\n arr[j + 1] = arr[j];\n --j;\n }\n\n arr[j + 1] = next;\n }\n\n count = (arr[2] - arr[1]) + (arr[1] - arr[0]);\n Console.WriteLine(count);\n }\n\n }\n}", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\n\nnamespace timusCsharp\n{\n public class Cup\n {\n public int w;\n public int c;\n }\n public class CupCennostComparer: IComparer\n {\n public int Compare(Cup A, Cup B)\n {\n if (A.c < B.c) return 1;\n if (A.c == B.c)\n {\n if (A.w < B.w)\n return -1;\n else if (A.w == B.w)\n return 0;\n else if (A.w > B.w)\n return 1;\n }\n return -1;\n }\n }\n static class Program\n {\n static void Main()\n {\n var s = Console.ReadLine().Split();\n var n = int.Parse(s[0]);\n var m = int.Parse(s[1]);\n var d = int.Parse(s[2]);\n var F = new List();\n for (int i = 0; i < n; i++)\n {\n s = Console.ReadLine().Split();\n F.Add(new Cup{ w = int.Parse(s[1]), c = int.Parse(s[0])});\n }\n var I = new List();\n for (int i = 0; i < m; i++)\n {\n s = Console.ReadLine().Split();\n I.Add(new Cup { w = int.Parse(s[1]), c = int.Parse(s[0]) });\n }\n var comp = new CupCennostComparer();\n F.Sort(comp);\n I.Sort(comp);\n long sumC = 0;\n if (F[0].w <= d)\n {\n d -= F[0].w;\n sumC += F[0].c;\n }\n else\n {\n Console.WriteLine(0);\n return;\n } \n if (I[0].w <= d)\n {\n d -= I[0].w;\n sumC += I[0].c;\n }\n else\n {\n Console.WriteLine(0);\n return;\n }\n\n int fIndex = 1;\n int iIndex = 1;\n\n long maxC = sumC;\n while (fIndex < n && d - F[fIndex].w>= 0)\n {\n d -= F[fIndex].w;\n sumC+=F[fIndex].c;\n fIndex++;\n }\n while (iIndex < m && d - I[iIndex].w >= 0)\n {\n d -= I[iIndex].w;\n sumC += I[iIndex].c;\n iIndex++;\n }\n maxC = Math.Max(sumC, maxC);\n while (fIndex > 1)\n {\n fIndex--;\n d += F[fIndex].w;\n sumC -= F[fIndex].c;\n while (iIndex < m && d - I[iIndex].w >= 0)\n {\n d -= I[iIndex].w;\n sumC += I[iIndex].c;\n iIndex++;\n }\n maxC = Math.Max(sumC, maxC);\n }\n Console.WriteLine(maxC);\n }\n }\n}", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n //int n=int.Parse(Console.ReadLine());\n //string[]y=Console.ReadLine().Split(' ');\n int n=int.Parse(Console.ReadLine());\n int g=0;\n int h=0;\n int i=0;\n while(true)\n {\n if(i%2==0)\n {\n h++;\n g+=2;\n }\n else\n {\n h++;\n g++;\n }\n i++;\n if(g>=n)\n break;\n }\n Console.WriteLine(h);\n }\n \n }\n}\n", "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"source_code": "using System;\nusing System.Linq;\nnamespace codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n int t = int.Parse(Console.ReadLine());\n string time = Console.ReadLine();\n if (time.Contains('7'))\n {\n Console.WriteLine(0);\n return;\n }\n int[] nk = time.Split().Select(x => int.Parse(x)).ToArray();\n int rez = 0;\n while (nk[0] % 10 != 7 && nk[1] % 10 != 7)\n {\n rez++;\n if ((nk[1]-=t) < 0)\n {\n nk[1] += 60;\n if (--nk[0] < 0)\n nk[0] += 24;\n }\n }\n Console.WriteLine(rez);\n }\n }\n}", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Olympiads\n{\n class Program\n {\n static void Main(string[] args)\n {\n int t = Convert.ToInt32(Console.ReadLine());\n int[] ret = new int[t];\n for (int i = 0; i < t; i++)\n {\n string t2 = Console.ReadLine();\n string[] temp1 = t2.Split(' ');\n int n = Convert.ToInt32(temp1[0]), k = Convert.ToInt32(temp1[1]), d = Convert.ToInt32(temp1[2]);\n string inp = Console.ReadLine();\n string[] temp2 = inp.Split(' ');\n int[] srav = new int[d];\n int y = 0,z = 0;\n for (int j = 0; j < d; j++)\n {\n srav[j] = Convert.ToInt32(temp2[j]);\n }\n y = Test(srav, k);\n for (int j = d; j < n; j++)\n {\n if (z > d-1)\n {\n z = 0;\n }\n srav[z] = Convert.ToInt32(temp2[j]);\n z++;\n if (y > Test(srav,k))\n {\n y = Test(srav, k);\n }\n }\n ret[i] = y;\n }\n for (int i = 0; i < t; i++)\n {\n Console.WriteLine(ret[i]);\n }\n \n }\n static int Test(int[] testing, int k)\n {\n int ret = 0;\n int[] a = new int[k];\n for (int i = 0; i < testing.Length; i++)\n {\n a[testing[i]-1]++;\n }\n for (int i = 0; i < a.Length; i++)\n {\n if (a[i]>0)\n {\n ret++;\n }\n }\n return ret;\n }\n }\n}\n", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nclass solution\n{\n static void Main(string[] args)\n {\n string[] ab = Console.ReadLine().Split(' ');\n int a = Convert.ToInt32(ab[0]);\n int b = Convert.ToInt32(ab[1]);\n if (a == 9 && b == 1) Console.Write(9 + \" \" + 10);\n else if (a>b || Math.Abs(a - b) > 1) Console.Write(\"-1\");\n else\n {\n if (a == b)\n {\n int val = (a * 10) + 1;\n Console.Write(a * 10 + \" \" + val);\n }\n else\n {\n int val = a * 100 + 99;\n Console.Write(val + \" \" + b * 100);\n }\n }\n }\n}", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\nusing System.Threading;\n\nnamespace E\n{\n class Program\n {\n static void Main(string[] args)\n {\n#if !ONLINE_JUDGE\n Console.SetIn(new System.IO.StreamReader(@\"..\\..\\..\\in\"));\n Console.SetOut(new System.IO.StreamWriter(@\"..\\..\\..\\out\"));\n for (int testN = 0; testN < 3; testN++)\n {\n#endif\n var n = NextLong();\n var a = new long[64];\n var i2s = new long[64];\n a[0] = 0;\n a[1] = 1;\n a[2] = 4;\n i2s[0] = 1;\n i2s[1] = 2;\n i2s[2] = 4;\n long i2 = 4;\n for (int i = 3; i < 64; i++)\n {\n a[i] = a[i - 1] * 2 - i2;\n i2 *= 2;\n i2s[i] = i2;\n a[i] += i2;\n }\n long res = 0;\n int x = 0;\n n--;\n while (n > 0)\n {\n if ((n & 1) == 1)\n {\n res += a[x] + i2s[x];\n }\n n >>= 1;\n x++;\n }\n\n \n Console.WriteLine(res);\n //Console.WriteLine(string.Format(NumberFormatInfo.InvariantInfo, \"{0:F4}\", res));\n#if !ONLINE_JUDGE\n Console.ReadLine();\n }\n Console.In.Close();\n Console.Out.Close();\n#endif\n }\n\n private static char[] _defaultSplitter = new char[] { ' ', '\\t' };\n\n private static char[] ReadChars(int n)\n {\n char[] buffer = new char[n];\n Console.In.ReadBlock(buffer, 0, n);\n return buffer;\n }\n\n private static string[] ReadAll()\n {\n return Console.In.ReadToEnd().Split(new char[] { ' ', '\\t', '\\n', '\\r' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n private static string[] ReadWords(char[] splitter)\n {\n return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries);\n }\n\n private static string[] ReadWords()\n {\n return ReadWords(_defaultSplitter);\n }\n\n private static int ReadInt()\n {\n return int.Parse(Console.ReadLine());\n }\n\n private static int[] ReadInts(char[] splitter)\n {\n return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();\n }\n\n private static int[] ReadInts()\n {\n return ReadInts(_defaultSplitter);\n }\n\n private static long ReadLong()\n {\n return long.Parse(Console.ReadLine());\n }\n\n private static long[] ReadLongs(char[] splitter)\n {\n return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();\n }\n\n private static long[] ReadLongs()\n {\n return ReadLongs(_defaultSplitter);\n }\n\n private static double ReadDouble()\n {\n return double.Parse(Console.ReadLine(), NumberFormatInfo.InvariantInfo);\n }\n\n private static int _pos = 0;\n private static string[] _inputLine = new string[0];\n\n private static void CheckInputLine()\n {\n if (_pos >= _inputLine.Length)\n {\n _inputLine = ReadWords();\n _pos = 0;\n }\n }\n\n private static string NextWord()\n {\n CheckInputLine();\n return _inputLine[_pos++];\n }\n\n private static int NextInt()\n {\n CheckInputLine();\n return int.Parse(_inputLine[_pos++]);\n }\n\n private static long NextLong()\n {\n CheckInputLine();\n return long.Parse(_inputLine[_pos++]);\n }\n }\n}\n", "src_uid": "a98f0d924ea52cafe0048f213f075891"} {"source_code": "//Rextester.Program.Main is the entry point for your code. Don't change it.\n//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5\n\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text.RegularExpressions;\n\nnamespace Rextester\n{\n public class Program\n {\n public static void Main(string[] args)\n {\n long[] a = {1,2,3,4,6,8,9,12,16,18,24,27,32,36,48,54,64,72,81,96,108,128,144,162,\n192,216,243,256,288,324,384,432,486,512,576,648,729,768,864,972,1024,1152,1296,1458,1536,1728,1944,\n2048,2187,2304,2592,2916,3072,3456,3888,4096,4374,4608,5184,5832,6144,6561,6912,7776,8192,8748,9216,\n10368,11664,12288,13122,13824,15552,16384,17496,18432,19683,20736,23328,24576,26244,27648,31104,32768,\n34992,36864,39366,41472,46656,49152,52488,55296,59049,62208,65536,69984,73728,78732,82944,93312,98304,104976,\n110592,118098,124416,131072,139968,147456,157464,165888,177147,186624,196608,209952,221184,236196,248832,262144,\n279936,294912,314928,331776,354294,373248,393216,419904,442368,472392,497664,524288,531441,559872,589824,629856,\n663552,708588,746496,786432,839808,884736,944784,995328,1048576,1062882,1119744,1179648,1259712,1327104,1417176,\n1492992,1572864,1594323,1679616,1769472,1889568,1990656,2097152,2125764,2239488,2359296,2519424,2654208,2834352,\n2985984,3145728,3188646,3359232,3538944,3779136,3981312,4194304,4251528,4478976,4718592,4782969,5038848,5308416,\n5668704,5971968,6291456,6377292,6718464,7077888,7558272,7962624,8388608,8503056,8957952,9437184,9565938,10077696,\n10616832,11337408,11943936,12582912,12754584,13436928,14155776,14348907,15116544,15925248,16777216,17006112,17915904,\n18874368,19131876,20155392,21233664,22674816,23887872,25165824,25509168,26873856,28311552,28697814,30233088,31850496,\n33554432,34012224,35831808,37748736,38263752,40310784,42467328,43046721,45349632,47775744,50331648,51018336,53747712,\n56623104,57395628,60466176,63700992,67108864,68024448,71663616,75497472,76527504,80621568,84934656,86093442,90699264,\n95551488,100663296,102036672,107495424,113246208,114791256,120932352,127401984,129140163,134217728,136048896,143327232,\n150994944,153055008,161243136,169869312,172186884,181398528,191102976,201326592,204073344,214990848,226492416,229582512,\n241864704,254803968,258280326,268435456,272097792,286654464,301989888,306110016,322486272,339738624,344373768,362797056,\n382205952,387420489,402653184,408146688,429981696,452984832,459165024,483729408,509607936,516560652,536870912,544195584,\n573308928,603979776,612220032,644972544,679477248,688747536,725594112,764411904,774840978,805306368,816293376,859963392,\n905969664,918330048,967458816,1019215872,1033121304,1073741824,1088391168,1146617856,1162261467,1207959552,1224440064,\n1289945088,1358954496,1377495072,1451188224,1528823808,1549681956,1610612736,1632586752,1719926784,1811939328,1836660096,1934917632};\n \n \n \n \n var numbers = Console.ReadLine();\n var numberList = numbers.Split(' ');\n long f = Convert.ToInt64(numberList[0]);\n long t = Convert.ToInt64(numberList[1]);\n \n int sum=0;\n \n for (int k=0;k<326;k++) {\n if ((a[k]>=f)&&(a[k]<=t)) sum++;\n \n }\n \n Console.WriteLine(\"{0}\",sum);\n }\n }\n}", "src_uid": "05fac54ed2064b46338bb18f897a4411"} {"source_code": "using System;\n\nnamespace CSharp\n{\n class _538A\n {\n public static void Main()\n {\n string codeforces = \"CODEFORCES\";\n string banner = Console.ReadLine();\n\n for (int i = 0; i <= codeforces.Length; i++)\n {\n if (banner.Length >= codeforces.Length && banner.StartsWith(codeforces.Substring(0, i)) && banner.EndsWith(codeforces.Substring(i, codeforces.Length - i)))\n {\n Console.WriteLine(\"YES\");\n return;\n }\n }\n\n Console.WriteLine(\"NO\");\n }\n }\n}", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Codeforces\n{ \n class A\n { \n static void Main(string[] args)\n { \n int n = int.Parse(Console.ReadLine());\n \n List a = new List();\n string[] token = Console.ReadLine().Split();\n \n for(int i=0;i= s)\n {\n Console.WriteLine(n - i + 1);\n return;\n }\n }\n\n Console.WriteLine(0);\n }\n\n public static int SumOfDigits(long n)\n {\n string digits = n.ToString();\n int sum = 0;\n\n for(int i = 0; i < digits.Length; i++)\n {\n sum += Convert.ToInt32(digits[i].ToString());\n }\n\n return sum;\n }\n }\n}\n", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"source_code": "using System;\n\nnamespace test\n{\n class Program\n {\n static void Main()\n {\n string txt;\n const char zero = '0';\n while ((txt = Console.ReadLine()) != null)\n {\n var max = int.Parse(txt.Split(' ')[1]);\n var step = 1;\n var d = Console.ReadLine();\n\n if (max == 1)\n {\n step = d.Contains(\"0\") ? -1 : d.Length - 1;\n }\n else\n {\n var i = max;\n var last = d.Length - 1;\n while (i < last)\n {\n var j = max;\n while (j > 1)\n {\n if (d[i] != zero)\n {\n i += max;\n step++;\n break;\n }\n i--;\n j--;\n }\n if (j == 1)\n {\n step = -1;\n break;\n }\n }\n }\n \n Console.WriteLine(step);\n }\n }\n }\n}", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\n\nclass Program\n{\n public static int[] Read(string str)\n {\n string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n int[] ret = new int[tokens.Length];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = int.Parse(tokens[i]);\n }\n\n return ret;\n }\n\n public static double[] ReadDouble(string str)\n {\n string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);\n double[] ret = new double[tokens.Length];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = double.Parse(tokens[i], CultureInfo.InvariantCulture);\n }\n\n return ret;\n }\n\n static string Reverse(string s)\n {\n char[] a = s.ToCharArray();\n Array.Reverse(a);\n return new string(a);\n }\n \n static void Main(string[] args)\n {\n long x = long.Parse(Console.ReadLine().Trim());\n if (x < 0) x = -x;\n \n if (x == 0)\n {\n Console.WriteLine(0);\n return;\n }\n\n int step = 1;\n long sum = 0;\n while (true)\n {\n sum += step;\n if (sum == x)\n {\n Console.WriteLine(step);\n break;\n }\n if (sum > x)\n {\n long t = sum - x;\n if (t % 2 == 0)\n {\n Console.WriteLine(step);\n break;\n }\n }\n step++;\n }\n }\n}\n", "src_uid": "18644c9df41b9960594fdca27f1d2fec"} {"source_code": "using System;\nclass E\n{\n\tstatic void Main()\n\t{\n\t\tvar N = long.Parse(Console.ReadLine());\n\t\tif (N == 0) { Console.WriteLine(\"0 0\"); return; }\n\t\tvar k = FirstBinary(0, Math.Min(600000000, N), t => 3 * (t + 1) * (t + 2) >= N) + 1;\n\t\tvar x = 2 * k;\n\t\tvar y = 0L;\n\t\tvar dx = new long[] { -1, -2, -1, 1, 2, 1 };\n\t\tvar dy = new long[] { 2, 0, -2, -2, 0, 2 };\n\t\tN -= 3 * k * (k - 1) + 1;\n\t\tif (N < 0) N += 6 * k;\n\t\tfor (var i = 0; i < 6; i++)\n\t\t{\n\t\t\tif (N < k)\n\t\t\t{\n\t\t\t\tN++;\n\t\t\t\tx += N * dx[i];\n\t\t\t\ty += N * dy[i];\n\t\t\t\tConsole.WriteLine(\"{0} {1}\", x, y);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tN -= k;\n\t\t\tx += k * dx[i];\n\t\t\ty += k * dy[i];\n\t\t}\n\t}\n\tpublic static long FirstBinary(long min, long max, Predicate pred)\n\t{\n\t\tvar left = min;\n\t\tvar right = max;\n\t\twhile (left < right)\n\t\t{\n\t\t\tvar mid = (left + right) >> 1;\n\t\t\tif (pred(mid)) right = mid;\n\t\t\telse left = mid + 1;\n\t\t}\n\t\treturn left;\n\t}\n}", "src_uid": "a4b6a570f5e63462b68447713924b465"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace AlgorithmTrainning.Codeforce__round_200__set\n{\n class probB\n {\n\n static int a, b, c;\n static void readInput()\n {\n String line = Console.ReadLine();\n String[] values = line.Split();\n a = int.Parse(values[0]);\n b = int.Parse(values[1]);\n c = int.Parse(values[2]);\n }\n\n static void solve()\n {\n int t = (a + b + c) /2;\n int z = t - a;\n int y = t - c;\n int x = t - b;\n if (x + y != a || y + z != b || z + x != c || z <0|| x<0 || y<0)\n {\n Console.WriteLine(\"Impossible\");\n\n }\n else\n {\n Console.WriteLine(y + \" \" + z + \" \" + x);\n }\n\n\n\n\n }\n\n static void Main(String[] args)\n {\n readInput();\n solve();\n }\n\n }\n}\n", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace Zad_A\n{\n class Program\n {\n static bool Polin(string s)\n {\n bool f = true;\n for (int i = 0; i < s.Length; i++)\n {\n if (s[i] != s[s.Length - i-1])\n {\n f = false;\n }\n }\n return f;\n }\n\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n string c=\"\";\n\n for (int i = 0; i < s.Length+1; i++)\n {\n for (int j = 0; j < 26; j++)\n {\n c = s.Substring(0, i) + (char)(97 + j) + s.Substring(i, s.Length - i);\n if (Polin(c)) break;\n }\n if (Polin(c)) break;\n }\n if (Polin(c))\n Console.WriteLine(c);\n else\n Console.WriteLine(\"NA\");\n }\n \n }\n}\n", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"} {"source_code": "using System;\r\nusing System.Linq;\r\nusing CompLib.Util;\r\nusing System.Threading;\r\nusing System.IO;\r\n\r\npublic class Program\r\n{\r\n int N;\r\n int[] A;\r\n public void Solve()\r\n {\r\n var sc = new Scanner();\r\n N = sc.NextInt();\r\n A = sc.IntArray();\r\n\r\n // 配列a\r\n // 2つの部分列に分割\r\n // 2つの和が同じになるような分割が無い 良い\r\n\r\n int min = int.MaxValue;\r\n foreach (int i in A)\r\n {\r\n int tmp = 1;\r\n while ((i & tmp) == 0) tmp <<= 1;\r\n min = Math.Min(min, tmp);\r\n }\r\n for (int i = 0; i < N; i++)\r\n {\r\n A[i] /= min;\r\n }\r\n\r\n int sum = 0;\r\n bool[] dp = new bool[200001];\r\n dp[0] = true;\r\n foreach (int i in A)\r\n {\r\n for (int j = sum; j >= 0; j--)\r\n {\r\n if (dp[j]) dp[j + i] = true;\r\n }\r\n sum += i;\r\n }\r\n\r\n if (sum % 2 == 1 || !dp[sum / 2])\r\n {\r\n Console.WriteLine(\"0\");\r\n return;\r\n }\r\n\r\n Console.WriteLine(\"1\");\r\n for (int i = 0; i < N; i++)\r\n {\r\n if (A[i] % 2 == 1)\r\n {\r\n Console.WriteLine(i+1);\r\n return;\r\n }\r\n }\r\n }\r\n\r\n public static void Main(string[] args) => new Program().Solve();\r\n // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();\r\n}\r\n\r\nnamespace CompLib.Util\r\n{\r\n using System;\r\n using System.Linq;\r\n\r\n class Scanner\r\n {\r\n private string[] _line;\r\n private int _index;\r\n private const char Separator = ' ';\r\n\r\n public Scanner()\r\n {\r\n _line = new string[0];\r\n _index = 0;\r\n }\r\n\r\n public string Next()\r\n {\r\n if (_index >= _line.Length)\r\n {\r\n string s;\r\n do\r\n {\r\n s = Console.ReadLine();\r\n } while (s.Length == 0);\r\n\r\n _line = s.Split(Separator);\r\n _index = 0;\r\n }\r\n\r\n return _line[_index++];\r\n }\r\n\r\n public string ReadLine()\r\n {\r\n _index = _line.Length;\r\n return Console.ReadLine();\r\n }\r\n\r\n public int NextInt() => int.Parse(Next());\r\n public long NextLong() => long.Parse(Next());\r\n public double NextDouble() => double.Parse(Next());\r\n public decimal NextDecimal() => decimal.Parse(Next());\r\n public char NextChar() => Next()[0];\r\n public char[] NextCharArray() => Next().ToCharArray();\r\n\r\n public string[] Array()\r\n {\r\n string s = Console.ReadLine();\r\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\r\n _index = _line.Length;\r\n return _line;\r\n }\r\n\r\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\r\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\r\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\r\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\r\n }\r\n}\r\n", "src_uid": "29063ad54712b4911c6bf871969ee147"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\n\n\n\nclass Program\n{\n class tutu:IComparable\n {\n public int ind { get; set; }\n public int val { get; set; }\n public int CompareTo(tutu o)\n {\n return val.CompareTo(o.val);\n }\n }\n\n //////////////////////////////////////////////////\n void Solution()\n {\n var n = ri;\n var a = ria(n);\n var b = new tutu[n];\n for (int i = 0; i < n; i++)\n {\n b[i] = new tutu()\n {\n ind = i + 1,\n val = a[i]\n };\n }\n Array.Sort(b);\n for (int i = 0; i < n / 2; i++)\n {\n wln(b[i].ind + \" \" + b[n - 1 - i].ind);\n }\n }\n //////////////////////////////////////////////////\n\n static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }\n static void wln(object o = null) { Console.WriteLine(o); }\n static void wsp(object o) { Console.Write(o + \" \"); }\n static void wrt(object o) { Console.Write(o); }\n //Console.Write(string.Format(CultureInfo.InvariantCulture, \"{0:F12}\", o));\n\n static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }\n static long lcm(long a, long b) { return a / gcd(a, b) * b; }\n\n int ri\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind;\n int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n int p = 0;\n while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;\n }\n }\n long rl\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind;\n int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n long p = 0;\n while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;\n }\n }\n double rd\n {\n get\n {\n _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }\n long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';\n if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;\n }\n }\n string rs\n {\n get\n {\n _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;\n var tmp = _str.IndexOf(' ', _ind);\n if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }\n var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;\n while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;\n }\n }\n\n int[] ria(int n)\n {\n var res = new int[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n long[] rla(int n)\n {\n var res = new long[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n double[] rda(int n)\n {\n var res = new double[n];\n for (int k = 0; k < n;)\n {\n var s = Console.ReadLine(); var m = s.Length;\n for (int i = 0; i < m && k < n; ++i)\n {\n while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }\n long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';\n if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }\n res[k++] = (double)p / q * sign;\n }\n }\n _count = 0; _ind = 0; return res;\n }\n string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }\n string _str = null; int _count = 0; int _ind = 0;\n void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }\n static void Main() { new Program().Solution(); }\n}", "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\n// (づ°ω°)づミ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜\npublic class Solver\n{\n private const int MAX = 500000;\n\n public void Solve()\n {\n int n = ReadInt();\n int d = ReadInt();\n var a = ReadIntArray();\n\n var dp = new bool[MAX + 1];\n dp[0] = true;\n for (int i = 0; i < n; i++)\n {\n for (int j = MAX; j >= 0; j--)\n if (dp[j])\n dp[j + a[i]] = true;\n }\n\n int x = 0;\n int ans = 0;\n while (true)\n {\n int y = Math.Min(x + d, MAX);\n while (!dp[y])\n y--;\n if (x == y)\n break;\n ans++;\n x = y;\n }\n\n Write(x, ans);\n }\n \n #region Main\n\n protected static TextReader reader;\n protected static TextWriter writer;\n\n static void Main()\n {\n#if DEBUG\n reader = new StreamReader(\"..\\\\..\\\\input.txt\");\n writer = Console.Out;\n //writer = new StreamWriter(\"..\\\\..\\\\output.txt\");\n#else\n reader = new StreamReader(Console.OpenStandardInput());\n writer = new StreamWriter(Console.OpenStandardOutput());\n //reader = new StreamReader(\"subsequences.in\");\n //writer = new StreamWriter(\"subsequences.out\");\n#endif\n try\n {\n// var thread = new Thread(new Solver().Solve, 1024 * 1024 * 256);\n// thread.Start();\n// thread.Join();\n new Solver().Solve(); \n }\n catch (Exception ex)\n {\n#if DEBUG\n Console.WriteLine(ex);\n#else\n Console.WriteLine(ex);\n throw;\n#endif\n }\n reader.Close();\n writer.Close();\n }\n\n #endregion\n\n #region Read / Write\n\n private static Queue currentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (currentLineTokens.Count == 0)\n currentLineTokens = new Queue(ReadAndSplitLine());\n return currentLineTokens.Dequeue();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)\n {\n int[][] matrix = ReadIntMatrix(numberOfRows);\n int[][] ret = new int[matrix[0].Length][];\n for (int i = 0; i < ret.Length; i++)\n {\n ret[i] = new int[numberOfRows];\n for (int j = 0; j < numberOfRows; j++)\n ret[i][j] = matrix[j][i];\n }\n return ret;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n writer.WriteLine(string.Join(\" \", array));\n }\n\n public static void Write(params object[] array)\n {\n WriteArray(array);\n }\n\n public static void WriteLines(IEnumerable array)\n {\n foreach (var a in array)\n writer.WriteLine(a);\n }\n\n class SDictionary : Dictionary\n {\n public new TValue this[TKey key]\n {\n get { return ContainsKey(key) ? base[key] : default(TValue); }\n set { base[key] = value; }\n }\n }\n\n #endregion\n}", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f"} {"source_code": "using System;\nusing System.IO;\nclass Program\n{\n static void Main()\n {\n int n1, m1, n2, m2, res;\n string[] h = Console.ReadLine().Split(new char[] { ' ' });\n int n = int.Parse(h[0]);\n int m = int.Parse(h[1]);\n int k = int.Parse(h[2]);\n h = Console.ReadLine().Split(new char[] { ' ' });\n int A1 = int.Parse(h[0]);\n int A2 = int.Parse(h[1]);\n if (A1 % (m * k) == 0)\n {\n n1 = A1 / (m * k);\n }\n else\n {\n n1 = A1 / (m * k) + 1;\n }\n if ((A1 - (n1 - 1) * m * k) % k == 0)\n {\n m1 = (A1 - (n1 - 1) * m * k) / k;\n }\n else\n {\n m1 = (A1 - (n1 - 1) * m * k) / k + 1;\n }\n if (A2 % (m * k) == 0)\n {\n n2 = A2 / (m * k);\n }\n else\n {\n n2 = A2 / (m * k) + 1;\n }\n if ((A2 - (n2 - 1) * m * k) % k == 0)\n {\n m2 = (A2 - (n2 - 1) * m * k) / k;\n }\n else\n {\n m2 = (A2 - (n2 - 1) * m * k) / k + 1;\n }\n if (n1 == n2)\n {\n if (m1 == m2)\n {\n Console.WriteLine(0);\n }\n else\n {\n if (Math.Abs(m1 - m2) >= 3)\n {\n Console.WriteLine(10 + Math.Abs(m1 - m2));\n }\n else\n {\n Console.WriteLine(5 * Math.Abs(m1 - m2));\n }\n }\n }\n else\n {\n if (n1 < n2)\n {\n if (n2 - n1 < n - n2 + n1)\n {\n if (m1 >= 4)\n {\n if (m2 >= 4)\n {\n Console.WriteLine(10 + m1 - 1 + (n2 - n1) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(10 + m1 - 1 + (n2 - n1) * 15 + 5 * (m2 - 1));\n }\n }\n else\n {\n if (m2 >= 4)\n {\n Console.WriteLine(5 * (m1 - 1) + (n2 - n1) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(5 * (m1 - 1) + (n2 - n1) * 15 + 5 * (m2 - 1));\n }\n }\n\n }\n else\n {\n if (m1 >= 4)\n {\n if (m2 >= 4)\n {\n Console.WriteLine(10 + m1 - 1 + (n - n2 + n1) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(10 + m1 - 1 + (n - n2 + n1) * 15 + 5 * (m2 - 1));\n }\n }\n else\n {\n if (m2 >= 4)\n {\n Console.WriteLine(5 * (m1 - 1) + (n - n2 + n1) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(5 * (m1 - 1) + (n - n2 + n1) * 15 + 5 * (m2 - 1));\n }\n }\n }\n }\n else\n {\n if (n1 - n2 < n - n1 + n2)\n {\n if (m1 >= 4)\n {\n if (m2 >= 4)\n {\n Console.WriteLine(10 + m1 - 1 + (n1 - n2) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(10 + m1 - 1 + (n1 - n2) * 15 + 5 * (m2 - 1));\n }\n }\n else\n {\n if (m2 >= 4)\n {\n Console.WriteLine(5 * (m1 - 1) + (n1 - n2) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(5 * (m1 - 1) + (n1 - n2) * 15 + 5 * (m2 - 1));\n }\n }\n }\n else\n {\n if (m1 >= 4)\n {\n if (m2 >= 4)\n {\n Console.WriteLine(10 + m1 - 1 + (n - n1 + n2) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(10 + m1 - 1 + (n - n1 + n2) * 15 + 5 * (m2 - 1));\n }\n }\n else\n {\n if (m2 >= 4)\n {\n Console.WriteLine(5 * (m1 - 1) + (n - n1 + n2) * 15 + 10 + m2 - 1);\n }\n else\n {\n Console.WriteLine(5 * (m1 - 1) + (n - n1 + n2) * 15 + 5 * (m2 - 1));\n }\n }\n }\n }\n }\n }\n}", "src_uid": "c37b46851abcf7eb472869bd1ab9f793"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n string str = \"\";\n for (int i = 0; i < 3; i++)\n str += Console.ReadLine();\n Console.WriteLine(Enumerable.Range(0,4).Count(x=>str[x]==str[8-x])==4?\"YES\":\"NO\");\n }\n }\n}", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Numerics;\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Linq;\n\nnamespace Codeforces.TaskD\n{\n public class Task\n {\n private int d;\n private Point[] points;\n\n private double Distance(double l, int i)\n {\n // tg a1 = x/y\n // tg (alpha - a1) = (z-x)/y => z = x + y tg (alpha - a1)\n // tg (a+b) = (tg a + tg b)/(1 - tg a tg b)\n // z = x + y (tg alpha - x/y) / (1 + (x/y) tg alpha) = x + y (y tg alpha - x) / (y + x tg alpha) = \n // (xy + x2 tg + y2 tg - xy) / (y + x tg) = tg alpha (x2 + y2) / (y + x tg alpha)\n\n\n // tg a2 = -x/y\n // tg (alpha + a2) = (z-x)/y\n\n var p = points[i];\n var x = p.X - l;\n var y = p.Y;\n var tg = p.TgAlpha;\n\n if (x < 0)\n {\n var maxAlpha = Math.PI/2 - Math.Abs(Math.Atan2(x, y));\n if (p.Alpha >= maxAlpha) return d;\n }\n\n \n var denom = y + x*tg;\n if (denom == 0) return d;\n var z = l + Math.Abs(tg*(x*x + y*y)/denom);\n return Math.Min(d, z);\n }\n\n void Solve()\n {\n int n, l, r;\n Input.Next(out n, out l, out r);\n d = r - l;\n \n points = new Point[n];\n for (var i = 0; i < n; i++)\n {\n points[i] = new Point();\n Input.Next(out points[i].X, out points[i].Y, out points[i].Angle);\n points[i].X -= l;\n points[i].Alpha = points[i].Angle * Math.PI / 180;\n points[i].TgAlpha = Math.Tan(points[i].Alpha);\n }\n\n var dp = new double[1 << n << 1];\n for (var j = 0; j < 1< ArrayLong()\n {\n return !Next() ? new List() : _line.Split().Select(long.Parse);\n }\n\n public static IEnumerable ArrayInt()\n {\n return !Next() ? new List() : _line.Split().Select(int.Parse);\n }\n\n public static bool Next(out string value)\n {\n value = string.Empty;\n if (!Next()) return false;\n value = _line;\n return true;\n }\n }\n\n public class DisjointSet\n {\n private readonly int[] _parent;\n private readonly int[] _rank;\n public int Count { get; private set; }\n\n public DisjointSet(int count, int initialize = 0)\n {\n Count = count;\n _parent = new int[Count];\n _rank = new int[Count];\n for (var i = 0; i < initialize; i++) _parent[i] = i;\n }\n\n private DisjointSet(int count, int[] parent, int[] rank)\n {\n Count = count;\n _parent = parent;\n _rank = rank;\n }\n\n public void Add(int v)\n {\n _parent[v] = v;\n _rank[v] = 0;\n }\n\n public int Find_Recursive(int v)\n {\n if (_parent[v] == v) return v;\n return _parent[v] = Find(_parent[v]);\n }\n\n public int Find(int v)\n {\n if (_parent[v] == v) return v;\n var last = v;\n while (_parent[last] != last) last = _parent[last];\n while (_parent[v] != v)\n {\n var t = _parent[v];\n _parent[v] = last;\n v = t;\n }\n return last;\n }\n\n public int this[int v]\n {\n get { return Find(v); }\n set { Union(v, value); }\n }\n\n public void Union(int a, int b)\n {\n a = Find(a);\n b = Find(b);\n if (a == b) return;\n if (_rank[a] < _rank[b])\n {\n var t = _rank[a];\n _rank[a] = _rank[b];\n _rank[b] = t;\n }\n _parent[b] = a;\n if (_rank[a] == _rank[b]) _rank[a]++;\n }\n\n public int GetSetCount()\n {\n var result = 0;\n for (var i = 0; i < Count; i++)\n {\n if (_parent[i] == i) result++;\n }\n return result;\n }\n\n public DisjointSet Clone()\n {\n var rank = new int[Count];\n _rank.CopyTo(rank, 0);\n var parent = new int[Count];\n _parent.CopyTo(parent, 0);\n return new DisjointSet(Count, parent, rank);\n }\n\n public override string ToString()\n {\n return string.Join(\",\", _parent.Take(50));\n }\n }\n\n public class Matrix\n {\n public static Matrix Create(int i, int j)\n {\n var m = new Matrix(i, j);\n return m;\n }\n\n public static Matrix Create(int i)\n {\n var m = new Matrix(i, i);\n return m;\n }\n\n public long Modulo { get; set; }\n\n private readonly int _width;\n private readonly int _height;\n private readonly long[,] _data;\n public int Width { get { return _width; } }\n public int Height { get { return _height; } }\n\n private Matrix(int i, int j)\n {\n Modulo = 1000000000000000000L;\n _width = j;\n _height = i;\n _data = new long[_height, _width];\n }\n\n public static Matrix operator *(Matrix m1, Matrix m2)\n {\n if (m1.Width != m2.Height) throw new InvalidDataException(\"m1.Width != m2.Height\");\n var m = Create(m2.Width, m1.Height);\n m.Modulo = m1.Modulo;\n for (var i = 0; i < m2.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n {\n for (var k = 0; k < m1.Width; k++)\n m[j, i] += (m1[j, k] * m2[k, i]) % m1.Modulo;\n m[j, i] %= m1.Modulo;\n }\n return m;\n }\n\n public static Matrix operator +(Matrix m1, Matrix m2)\n {\n var m = m1.Clone();\n for (var i = 0; i < m2.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;\n return m;\n }\n\n public static Matrix operator -(Matrix m1, Matrix m2)\n {\n var m = m1.Clone();\n for (var i = 0; i < m2.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;\n return m;\n }\n\n public static Matrix operator *(Matrix m1, long l)\n {\n var m = m1.Clone();\n for (var i = 0; i < m1.Width; i++)\n for (var j = 0; j < m1.Height; j++)\n m[j, i] = (m[j, i] * l) % m.Modulo;\n return m;\n }\n\n public static Matrix operator *(long l, Matrix m1)\n {\n return m1 * l;\n }\n\n public static Matrix operator +(Matrix m1, long l)\n {\n var m = m1.Clone();\n for (var i = 0; i < m1.Width; i++)\n m[i, i] = (m[i, i] + l) % m.Modulo;\n return m;\n }\n\n public static Matrix operator +(long l, Matrix m1)\n {\n return m1 + l;\n }\n\n public static Matrix operator -(Matrix m1, long l)\n {\n return m1 + (-l);\n }\n\n public static Matrix operator -(long l, Matrix m1)\n {\n var m = m1.Clone() * -1;\n return m + l;\n }\n\n public Matrix BinPower(long l)\n {\n var n = 1;\n var m = Clone();\n var result = new Matrix(m.Height, m.Width) + 1;\n result.Modulo = m.Modulo;\n while (l != 0)\n {\n var i = l & ~(l - 1);\n l -= i;\n while (n < i)\n {\n m = m * m;\n n <<= 1;\n }\n result *= m;\n }\n return result;\n }\n\n public void Fill(long l)\n {\n l %= Modulo;\n for (var i = 0; i < _height; i++)\n for (var j = 0; j < _width; j++)\n _data[i, j] = l;\n }\n\n public Matrix Clone()\n {\n var m = new Matrix(_width, _height);\n Array.Copy(_data, m._data, _data.Length);\n m.Modulo = Modulo;\n return m;\n }\n\n public long this[int i, int j]\n {\n get { return _data[i, j]; }\n set { _data[i, j] = value % Modulo; }\n }\n }\n\n public class RedBlackTree : IEnumerable>\n {\n private readonly List _items;\n private Node _root;\n private readonly IComparer _comparer;\n\n public RedBlackTree(int capacity = 10)\n {\n _items = new List(capacity);\n _comparer = Comparer.Default;\n }\n\n private Node _search(TKey key)\n {\n var node = _root;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return node;\n node = i > 0 ? node.Right : node.Left;\n }\n return null;\n }\n\n /// \n /// Returns lower or equal key\n /// \n public TKey Lower(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i > 0)\n {\n good = node;\n node = node.Right;\n }\n else\n node = node.Left;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns higher or equal key\n /// \n public TKey Higher(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i < 0)\n {\n good = node;\n node = node.Left;\n }\n else\n node = node.Right;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns minimum region, which encloses given key\n /// \n public Tuple Bounds(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node lower = null;\n Node higher = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return new Tuple(key, key);\n if (i < 0)\n {\n higher = node;\n node = node.Left;\n }\n else\n {\n lower = node;\n node = node.Right;\n }\n }\n return new Tuple(lower == null ? notFound : lower.Key, higher == null ? notFound : higher.Key);\n }\n\n public void Add(TKey key, TValue value)\n {\n var node = new Node { Key = key, Value = value, Red = true };\n _items.Add(node);\n if (_root == null)\n {\n _root = node;\n _root.Red = false;\n return;\n }\n var x = _root;\n Node y = null;\n while (x != null)\n {\n y = x;\n x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;\n }\n node.Parent = y;\n if (y == null) _root = node;\n else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;\n else y.Left = node;\n InsertFixup(node);\n }\n\n private void InsertFixup(Node node)\n {\n while (true)\n {\n var parent = node.Parent;\n if (parent == null || !parent.Red || parent.Parent == null) break;\n var grand = parent.Parent;\n\n if (parent == grand.Left)\n {\n var uncle = grand.Right;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Right) /* we rotate around the parent */\n {\n node = parent;\n RotateLeft(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateRight(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n else\n {\n if (_root.Parent != null) Debugger.Break();\n\n var uncle = grand.Left;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Left) /* we rotate around the parent */\n {\n node = parent;\n RotateRight(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateLeft(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n }\n _root.Red = false;\n }\n\n private void RotateLeft(Node node)\n {\n if (node.Right == null)\n throw new NotSupportedException(\"Cannot rotate left: right node is missing\");\n var parent = node.Parent;\n var right = node.Right;\n right.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = right;\n else parent.Right = right;\n }\n node.Right = right.Left;\n if (node.Right != null)\n node.Right.Parent = node;\n right.Left = node;\n node.Parent = right;\n }\n\n private void RotateRight(Node node)\n {\n if (node.Left == null)\n throw new NotSupportedException(\"Cannot rotate right: left node is missing\");\n var parent = node.Parent;\n var left = node.Left;\n left.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = left;\n else parent.Right = left;\n }\n node.Left = left.Right;\n if (node.Left != null)\n node.Left.Parent = node;\n left.Right = node;\n node.Parent = left;\n }\n\n public void Remove(TKey key)\n {\n var node = _search(key);\n if (node == null) return;\n\n var deleted = node.Left == null || node.Right == null ? node : Next(node);\n var child = deleted.Left ?? deleted.Right;\n if (child != null)\n child.Parent = deleted.Parent;\n if (deleted.Parent == null) /* root */\n _root = child;\n else if (deleted == deleted.Parent.Left)\n deleted.Parent.Left = child;\n else\n deleted.Parent.Right = child;\n if (node != deleted)\n {\n node.Key = deleted.Key;\n node.Value = deleted.Value;\n }\n\n if (!deleted.Red)\n {\n DeleteFixup(child, deleted.Parent);\n }\n }\n\n private void DeleteFixup(Node node, Node parent)\n {\n while (parent != null && (node == null || !node.Red))\n {\n if (node == parent.Left)\n {\n var brother = parent.Right;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateLeft(parent);\n brother = parent.Right;\n }\n if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Right == null || !brother.Right.Red)\n {\n if (brother.Left != null)\n brother.Left.Red = false;\n brother.Red = true;\n RotateRight(brother);\n brother = parent.Right;\n }\n if (!brother.Right.Red) Debugger.Break();\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Right != null)\n brother.Right.Red = false;\n RotateLeft(parent);\n node = _root;\n }\n }\n else\n {\n var brother = parent.Left;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateRight(parent);\n brother = parent.Left;\n }\n if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Left == null || !brother.Left.Red)\n {\n if (brother.Right != null)\n brother.Right.Red = false;\n brother.Red = true;\n RotateLeft(brother);\n brother = parent.Left;\n }\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Left != null)\n brother.Left.Red = false;\n RotateRight(parent);\n node = _root;\n }\n }\n parent = node.Parent;\n }\n\n node.Red = false;\n }\n\n public TValue this[TKey key]\n {\n get\n {\n var node = _search(key);\n return node == null ? default(TValue) : node.Value;\n }\n set\n {\n var node = _search(key);\n if (node == null) Add(key, value);\n else node.Value = value;\n }\n }\n\n public bool Check()\n {\n int count;\n return _root == null || _root.Check(out count);\n }\n\n private Node Minimum(Node node)\n {\n var result = node;\n while (result.Left != null) result = result.Left;\n return result;\n }\n\n private Node Maximum(Node node)\n {\n var result = node;\n while (result.Right != null) result = result.Right;\n return result;\n }\n\n private Node Next(Node node)\n {\n Node result;\n if (node.Right != null)\n {\n result = Minimum(node.Right);\n }\n else\n {\n while (node.Parent != null && node.Parent.Right == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n private Node Previous(Node node)\n {\n Node result;\n if (node.Left != null)\n {\n result = Maximum(node.Left);\n }\n else\n {\n while (node.Parent != null && node.Parent.Left == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n public void Print()\n {\n var node = Minimum(_root);\n while (node != null)\n {\n Console.Write(node.Red ? '*' : ' ');\n Console.Write(node.Key);\n Console.Write('\\t');\n node = Next(node);\n }\n }\n\n #region Nested classes\n\n [DebuggerDisplay(\"{ToString()}\")]\n private sealed class Node\n {\n public TKey Key;\n public TValue Value;\n public bool Red;\n\n public Node Parent;\n public Node Left;\n public Node Right;\n\n public bool Check(out int count)\n {\n count = 0;\n if (Red)\n {\n if (Left != null && Left.Red) return false;\n if (Right != null && Right.Red) return false;\n }\n var left = 0;\n var right = 0;\n if (Left != null && !Left.Check(out left)) return false;\n if (Right != null && !Right.Check(out right)) return false;\n count = left + (Red ? 0 : 1);\n if (left != right)\n {\n ;\n }\n return left == right;\n }\n\n public override string ToString()\n {\n return ToShortString(2);\n }\n\n private string ToShortString(int depth = 0)\n {\n return depth == 0\n ? string.Format(\"{0}{1}\", Red ? \"*\" : \"\", Key)\n : string.Format(\"({1}<{0}>{2})\", ToShortString(), Left == null ? \"null\" : Left.ToShortString(depth - 1), Right == null ? \"null\" : Right.ToShortString(depth - 1));\n }\n }\n\n #endregion\n\n #region IEnumerable\n\n public IEnumerator> GetEnumerator()\n {\n throw new NotImplementedException();\n }\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return GetEnumerator();\n }\n\n #endregion\n }\n\n public class RedBlackTreeSimple\n {\n private readonly List _items;\n private Node _root;\n private readonly IComparer _comparer;\n\n public RedBlackTreeSimple(int capacity = 10)\n {\n _items = new List(capacity);\n _comparer = Comparer.Default;\n }\n\n private Node _search(TKey key)\n {\n var node = _root;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return node;\n node = i > 0 ? node.Right : node.Left;\n }\n return null;\n }\n\n /// \n /// Returns lower or equal key\n /// \n public TKey Lower(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i > 0)\n {\n good = node;\n node = node.Right;\n }\n else\n node = node.Left;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns higher or equal key\n /// \n public TKey Higher(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node good = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return key;\n if (i < 0)\n {\n good = node;\n node = node.Left;\n }\n else\n node = node.Right;\n }\n return good == null ? notFound : good.Key;\n }\n\n /// \n /// Returns minimum region, which encloses given key\n /// \n public Tuple Bounds(TKey key, TKey notFound = default(TKey))\n {\n var node = _root;\n Node lower = null;\n Node higher = null;\n while (node != null)\n {\n var i = _comparer.Compare(key, node.Key);\n if (i == 0) return new Tuple(key, key);\n if (i < 0)\n {\n higher = node;\n node = node.Left;\n }\n else\n {\n lower = node;\n node = node.Right;\n }\n }\n return new Tuple(lower == null ? notFound : lower.Key, higher == null ? notFound : higher.Key);\n }\n\n public void Add(TKey key)\n {\n var node = new Node(key);\n _items.Add(node);\n if (_root == null)\n {\n _root = node;\n _root.Red = false;\n return;\n }\n var x = _root;\n Node y = null;\n while (x != null)\n {\n y = x;\n x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;\n }\n node.Parent = y;\n if (y == null) _root = node;\n else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;\n else y.Left = node;\n InsertFixup(node);\n }\n\n private void InsertFixup(Node node)\n {\n while (true)\n {\n var parent = node.Parent;\n if (parent == null || !parent.Red || parent.Parent == null) break;\n var grand = parent.Parent;\n\n if (parent == grand.Left)\n {\n var uncle = grand.Right;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Right) /* we rotate around the parent */\n {\n node = parent;\n RotateLeft(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateRight(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n else\n {\n if (_root.Parent != null) Debugger.Break();\n\n var uncle = grand.Left;\n if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */\n {\n parent.Red = false;\n uncle.Red = false;\n grand.Red = true;\n node = grand; /* and continue fixing tree for grand */\n }\n else if (node == parent.Left) /* we rotate around the parent */\n {\n node = parent;\n RotateRight(node);\n }\n else /* rotate around grand and switch colors of grand and parent */\n {\n parent.Red = false;\n grand.Red = true;\n RotateLeft(grand);\n if (grand == _root) _root = parent;\n break; /* and finish since tree is fixed */\n }\n }\n }\n _root.Red = false;\n }\n\n private void RotateLeft(Node node)\n {\n if (node.Right == null)\n throw new NotSupportedException(\"Cannot rotate left: right node is missing\");\n var parent = node.Parent;\n var right = node.Right;\n right.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = right;\n else parent.Right = right;\n }\n node.Right = right.Left;\n if (node.Right != null)\n node.Right.Parent = node;\n right.Left = node;\n node.Parent = right;\n }\n\n private void RotateRight(Node node)\n {\n if (node.Left == null)\n throw new NotSupportedException(\"Cannot rotate right: left node is missing\");\n var parent = node.Parent;\n var left = node.Left;\n left.Parent = parent;\n if (parent != null)\n {\n if (parent.Left == node) parent.Left = left;\n else parent.Right = left;\n }\n node.Left = left.Right;\n if (node.Left != null)\n node.Left.Parent = node;\n left.Right = node;\n node.Parent = left;\n }\n\n public void Remove(TKey key)\n {\n var node = _search(key);\n if (node == null) return;\n\n var deleted = node.Left == null || node.Right == null ? node : Next(node);\n var child = deleted.Left ?? deleted.Right;\n if (child != null)\n child.Parent = deleted.Parent;\n if (deleted.Parent == null) /* root */\n _root = child;\n else if (deleted == deleted.Parent.Left)\n deleted.Parent.Left = child;\n else\n deleted.Parent.Right = child;\n if (node != deleted)\n {\n node.Key = deleted.Key;\n }\n\n if (!deleted.Red)\n {\n DeleteFixup(child, deleted.Parent);\n }\n }\n\n private void DeleteFixup(Node node, Node parent)\n {\n while (parent != null && (node == null || !node.Red))\n {\n if (node == parent.Left)\n {\n var brother = parent.Right;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateLeft(parent);\n brother = parent.Right;\n }\n if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Right == null || !brother.Right.Red)\n {\n if (brother.Left != null)\n brother.Left.Red = false;\n brother.Red = true;\n RotateRight(brother);\n brother = parent.Right;\n }\n if (!brother.Right.Red) Debugger.Break();\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Right != null)\n brother.Right.Red = false;\n RotateLeft(parent);\n node = _root;\n }\n }\n else\n {\n var brother = parent.Left;\n if (brother.Red)\n {\n brother.Red = false;\n parent.Red = true;\n RotateRight(parent);\n brother = parent.Left;\n }\n if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))\n {\n node = parent.Red ? _root : parent;\n brother.Red = true;\n parent.Red = false;\n }\n else\n {\n if (brother.Left == null || !brother.Left.Red)\n {\n if (brother.Right != null)\n brother.Right.Red = false;\n brother.Red = true;\n RotateLeft(brother);\n brother = parent.Left;\n }\n brother.Red = parent.Red;\n parent.Red = false;\n if (brother.Left != null)\n brother.Left.Red = false;\n RotateRight(parent);\n node = _root;\n }\n }\n parent = node.Parent;\n }\n\n node.Red = false;\n }\n\n private Node Minimum(Node node)\n {\n var result = node;\n while (result.Left != null) result = result.Left;\n return result;\n }\n\n private Node Maximum(Node node)\n {\n var result = node;\n while (result.Right != null) result = result.Right;\n return result;\n }\n\n private Node Next(Node node)\n {\n Node result;\n if (node.Right != null)\n {\n result = Minimum(node.Right);\n }\n else\n {\n while (node.Parent != null && node.Parent.Right == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n private Node Previous(Node node)\n {\n Node result;\n if (node.Left != null)\n {\n result = Maximum(node.Left);\n }\n else\n {\n while (node.Parent != null && node.Parent.Left == node)\n node = node.Parent;\n result = node.Parent;\n }\n return result;\n }\n\n public void Print()\n {\n var node = Minimum(_root);\n while (node != null)\n {\n Console.Write(node.Red ? '*' : ' ');\n Console.Write(node.Key);\n Console.Write('\\t');\n node = Next(node);\n }\n }\n\n #region Nested classes\n\n private sealed class Node\n {\n public Node(TKey key)\n {\n Key = key;\n }\n\n public TKey Key;\n public bool Red = true;\n\n public Node Parent;\n public Node Left;\n public Node Right;\n }\n\n #endregion\n }\n\n /// \n /// Fenwick tree for summary on the array\n /// \n public class FenwickSum\n {\n public readonly int Size;\n private readonly int[] _items;\n public FenwickSum(int size)\n {\n Size = size;\n _items = new int[Size];\n }\n\n public FenwickSum(IList items)\n : this(items.Count)\n {\n for (var i = 0; i < Size; i++)\n Increase(i, items[i]);\n }\n\n private int Sum(int r)\n {\n if (r < 0) return 0;\n if (r >= Size) r = Size - 1;\n var result = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1)\n result += _items[r];\n return result;\n }\n\n private int Sum(int l, int r)\n {\n return Sum(r) - Sum(l - 1);\n }\n\n public int this[int r]\n {\n get { return Sum(r); }\n }\n\n public int this[int l, int r]\n {\n get { return Sum(l, r); }\n }\n\n public void Increase(int i, int delta)\n {\n for (; i < Size; i = i | (i + 1))\n _items[i] += delta;\n }\n }\n\n /// \n /// Prime numbers\n /// \n public class Primes\n {\n /// \n /// Returns prime numbers in O(n)\n /// Returns lowet divisors as well\n /// Memory O(n)\n /// \n public static void ImprovedSieveOfEratosthenes(int n, out int[] lp, out List pr)\n {\n lp = new int[n];\n pr = new List();\n for (var i = 2; i < n; i++)\n {\n if (lp[i] == 0)\n {\n lp[i] = i;\n pr.Add(i);\n }\n foreach (var prJ in pr)\n {\n var prIj = i * prJ;\n if (prJ <= lp[i] && prIj <= n - 1)\n {\n lp[prIj] = prJ;\n }\n else\n {\n break;\n }\n }\n }\n }\n\n /// \n /// Returns prime numbers in O(n*n)\n /// \n public static void SieveOfEratosthenes(int n, out List pr)\n {\n var m = 2 * n / 5;\n pr = new List { 2 };\n var f = new bool[n + 1];\n for (var i = 3; i <= m; i += 2)\n if (!f[i])\n for (long j = (long)i * i; j <= n; j += i)\n f[j] = true;\n for (var i = 3; i <= n; i += 2)\n if (!f[i])\n pr.Add(i);\n }\n\n /// \n /// Returns array of inverted prime numbers map in O(n*n)\n /// \n public static void SieveOfEratosthenes(int n, out bool[] isPrime)\n {\n var m = 2 * n / 5;\n var f = new bool[n + 1];\n for (var i = 3; i <= m; i += 2)\n if (!f[i])\n for (long j = (long)i * i; j <= n; j += i)\n f[j] = true;\n isPrime = f;\n }\n\n /// \n /// Greatest common divisor \n /// \n public static int Gcd(int x, int y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Greatest common divisor\n /// \n public static long Gcd(long x, long y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Greatest common divisor\n /// \n public static BigInteger Gcd(BigInteger x, BigInteger y)\n {\n while (y != 0)\n {\n var c = y;\n y = x % y;\n x = c;\n }\n return x;\n }\n\n /// \n /// Returns all divisors of n in O(√n)\n /// \n public static IEnumerable GetDivisors(long n)\n {\n long r;\n while (true)\n {\n var x = Math.DivRem(n, 2, out r);\n if (r != 0) break;\n n = x;\n yield return 2;\n }\n var i = 3;\n while (i <= Math.Sqrt(n))\n {\n var x = Math.DivRem(n, i, out r);\n if (r == 0)\n {\n n = x;\n yield return i;\n }\n else i += 2;\n }\n if (n != 1) yield return n;\n }\n }\n\n /// \n /// Graph matching algorithms\n /// \n public class GraphMatching\n {\n #region Kuhn algorithm\n\n /// \n /// Kuhn algorithm for finding maximal matching\n /// in bipartite graph\n /// Vertexes are numerated from zero: 0, 1, 2, ... n-1\n /// Return array of matchings\n /// \n public static int[] Kuhn(List[] g, int leftSize, int rightSize)\n {\n Debug.Assert(g.Count() == leftSize);\n\n var matching = new int[leftSize];\n for (var i = 0; i < rightSize; i++)\n matching[i] = -1;\n var used = new bool[leftSize];\n\n for (var v = 0; v < leftSize; v++)\n {\n Array.Clear(used, 0, leftSize);\n _kuhn_dfs(v, g, matching, used);\n }\n\n return matching;\n }\n\n private static bool _kuhn_dfs(int v, List[] g, int[] matching, bool[] used)\n {\n if (used[v]) return false;\n used[v] = true;\n for (var i = 0; i < g[v].Count; i++)\n {\n var to = g[v][i];\n if (matching[to] == -1 || _kuhn_dfs(matching[to], g, matching, used))\n {\n matching[to] = v;\n return true;\n }\n }\n return false;\n }\n\n #endregion\n }\n}", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a"} {"source_code": "using System;\n\nnamespace HighSchool\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] s = Console.ReadLine().Split();\n double x = double.Parse(s[0]);\n double y = double.Parse(s[1]);\n\n double logx = Math.Log10(x);\n double logy = Math.Log10(y);\n\n double y_logx = y * logx;\n double x_logy = x * logy;\n\n if (y_logx > x_logy)\n {\n Console.Write(\">\");\n }\n else\n {\n if (y_logx < x_logy)\n Console.Write(\"<\");\n else\n Console.Write(\"=\");\n }\n }\n }\n}\n", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Collections;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Threading;\n\nnamespace Test\n{\n class IOHelper : IDisposable\n {\n StreamReader reader;\n StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding)\n {\n StreamReader iReader;\n StreamWriter oWriter;\n if (inputFile == null)\n iReader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n iReader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n oWriter = new StreamWriter(outputFile, false, encoding);\n\n reader = iReader;\n writer = oWriter;\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public string ReadNextToken()\n {\n if (curTokenIdx >= curLine.Length)\n {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n if (curTokenIdx >= curLine.Length)\n return null;\n\n return curLine[curTokenIdx++];\n }\n\n public int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n public double ReadNextDouble()\n {\n string tkn = ReadNextToken();\n StringBuilder token = new StringBuilder(tkn);\n token [tkn.IndexOf(\".\")] = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator[0];\n return double.Parse(token.ToString());\n }\n\n public void Write(double val, int precision)\n {\n Int64 valI = (Int64)val;\n writer.Write(valI.ToString());\n double diff = val - valI;\n if (precision > 0)\n writer.Write(\".\");\n int i;\n for (i = 0; i < precision; i++)\n {\n diff *= 10;\n writer.Write(((int)diff).ToString());\n diff -= (int)diff;\n }\n }\n\n\n public void Write(string stringToWrite)\n {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(string stringToWrite)\n {\n writer.WriteLine(stringToWrite);\n }\n\n public void Dispose()\n {\n try\n {\n if (reader != null)\n {\n reader.Dispose();\n }\n if (writer != null)\n {\n writer.Dispose();\n }\n }\n catch { };\n }\n\n\n public void Flush()\n {\n if (writer != null)\n {\n writer.Flush();\n }\n }\n }\n\n\n class Program\n {\n protected IOHelper ioHelper;\n\n int n, t;\n double p;\n double result;\n\n protected double Compute1(int t, int curPeople, double p)\n {\n double result = 1;\n for (int i = 1; i <= t; i++)\n {\n result *= i;\n if (i <= curPeople)\n result /= (double)i;\n if (i <= t - curPeople)\n result /= (double)i;\n\n if (i <= curPeople)\n result *= p;\n else\n result *= (1 - p);\n }\n\n return result;\n }\n\n public void Solve()\n {\n n = ioHelper.ReadNextInt();\n p = ioHelper.ReadNextDouble();\n t = ioHelper.ReadNextInt();\n\n double combination = 1;\n\n result = 0;\n for (int curPeople = 0; curPeople < n; curPeople++)\n {\n if (curPeople > t)\n break;\n double curProb = 0;\n\n curProb = Compute1(t, curPeople, p);\n\n result += curProb * curPeople;\n\n combination *= (t - curPeople)/ (curPeople + 1.0);\n }\n\n int posN;\n combination = 1;\n if (n > 1)\n {\n for (posN = n; posN <= t; posN++)\n {\n double curProb = 0;\n\n curProb = Compute1(posN-1,n-1,p)*p;\n\n result += curProb * n;\n\n combination *= (posN + 0.0) / (posN - (n - 1.0));\n }\n }\n else\n {\n double curProb = Math.Pow(1 - p, t);\n curProb = 1 - curProb;\n result += curProb * 1;\n }\n \n ioHelper.Write(result, 7);\n ioHelper.WriteLine(\"\");\n }\n\n \n public Program(string inputFile, string outputFile)\n {\n ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);\n Solve();\n ioHelper.Dispose();\n }\n\n static void Main(string[] args)\n {\n Program myProgram = new Program(null, null);\n }\n }\n}", "src_uid": "20873b1e802c7aa0e409d9f430516c1e"} {"source_code": "using System;\nusing System.Globalization;\nusing System.IO.Pipes;\nusing System.Linq;\nusing System.Runtime.InteropServices;\nusing System.Text;\n\nnamespace ContestV\n{\n internal class Program\n {\n static bool APsearch(string a, string b)\n {\n string h = string.Empty;\n bool ans = false;\n int t = 0;\n\n\n for (int i = 0, j = 0; i < a.Length; i++)\n {\n if (a[i] == b[j])\n {\n j++;\n t++;\n h += a[i];\n if(j==b.Length) break;\n }\n }\n\n if (h == b) ans = true;\n\n return ans;\n }\n\n\n static bool Asearch(string a, string b)\n {\n bool ans = false;\n\n StringBuilder aa = new StringBuilder(a);\n\n\n \n int t = 0;\n for (int i = 0; i < b.Length; i++)\n {\n for (int j = 0; j < aa.Length; j++)\n {\n if (b[i] == aa[j])\n {\n t++;\n aa.Remove(j, 1);\n break;\n }\n }\n\n }\n if (t == b.Length) ans = true;\n\n\n return ans;\n }\n\n private static void Main(string[] args)\n {\n\n\n string a = Console.ReadLine();\n \n string b = Console.ReadLine();\n\n string ans = \"need tree\";\n\n if (a.Length>=b.Length)\n {\n if (Asearch(a, b))\n {\n if (a.Length == b.Length) ans = \"array\"; \n\n else if (APsearch(a, b)) ans = \"automaton\";\n else\n {\n ans = \"both\";\n }\n\n\n\n\n }\n\n\n\n\n \n\n }\n\n Console.WriteLine(ans);\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n }\n }\n}\n", "src_uid": "edb9d51e009a59a340d7d589bb335c14"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CF\n{\n class Program\n {\n public static void Ron()\n {\n Console.Write(\"Ron\");\n }\n\n public static void Hermione()\n {\n Console.Write(\"Hermione\");\n }\n \n static void Main(string[] args)\n {\n string[] ss = Console.ReadLine().Split(' ');\n int a = int.Parse(ss[0]);\n int b = int.Parse(ss[1]);\n int c = int.Parse(ss[2]);\n int d = int.Parse(ss[3]);\n int e = int.Parse(ss[4]);\n int f = int.Parse(ss[5]);\n\n if (d > 0)\n {\n if (c > 0)\n {\n if (b > 0)\n {\n if (a > 0)\n {\n if (f > 0)\n {\n if (e > 0)\n {\n if (a * c * e < b * d * f)\n Ron();\n else\n Hermione();\n }\n else\n {\n Ron();\n }\n }\n else\n {\n Hermione();\n }\n }\n else\n {\n Ron();\n }\n }\n else\n {\n Hermione();\n }\n }\n else\n {\n Ron();\n }\n }\n else\n {\n Hermione();\n }\n Console.ReadKey();\n }\n }\n}\n", "src_uid": "44d608de3e1447f89070e707ba550150"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n int n = Convert.ToInt32(Console.ReadLine());\n int min, max;\n max = 0;\n min = 2200;\n int[] years = new int[n];\n int i = 0;\n foreach (string s in Console.ReadLine().Split())\n {\n years[i] = Convert.ToInt32(s);\n max = max <= years[i] ? years[i] : max;\n min = min >= years[i] ? years[i] : min;\n i++;\n }\n Console.WriteLine(\"{0}\", (max + min) / 2); \n }\n }\n}\n", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace C1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string s = Console.ReadLine();\n string[] strInts = s.Split(new char[1] { ' ' });\n int a = int.Parse(strInts[0]);\n int b = int.Parse(strInts[1]);\n int f = int.Parse(strInts[2]);\n int k = int.Parse(strInts[3]);\n\n int kCurrent = 0;\n int bCurrent = b;\n int nextPoint = a;\n bool can = true;\n int tanked = 0;\n\n if (f > bCurrent)\n {\n can = false;\n }\n else\n bCurrent -= f;\n\n while (kCurrent!=k && can)\n {\n int Destantion = kCurrent==k-1? Math.Abs(f - nextPoint): 2 * Math.Abs(f - nextPoint);\n if (bCurrent >= Destantion)\n {\n nextPoint = nextPoint == 0 ? a : 0;\n bCurrent -= Destantion;\n kCurrent++;\n }\n else\n {\n if (bCurrent == b)\n {\n can = false;\n }\n else\n {\n bCurrent = b;\n tanked++;\n }\n\n }\n }\n\n if (kCurrent == k)\n {\n Console.WriteLine(tanked);\n }\n else\n Console.WriteLine(-1);\n }\n }\n}\n", "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Runtime.ExceptionServices;\nusing System.Text.RegularExpressions;\nusing System.Threading;\n\nnamespace CodeForces\n{\n class Program\n {\n public static string Rw() => Console.ReadLine();\n public static int GetInt() => Int32.Parse(Console.ReadLine());\n public static int[] GetArr() => Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);\n\n public static void Main(string[] args)\n {\n int[] arr = GetArr();\n int n = arr[0];\n int w = arr[1];\n arr = GetArr();\n\n int max = 0;\n for (int i = 0; i < n; i++)\n max += arr[i];\n\n if (max < w)\n {\n Console.WriteLine(-1);\n return;\n }\n\n int[] tea = new int[n];\n for (int i = 0; i < n; i++)\n {\n tea[i] = (arr[i] + 1)/2;\n w -= tea[i];\n if (w < 0)\n {\n Console.WriteLine(-1);\n return;\n }\n }\n\n while (w > 0)\n {\n int max_index = -1;\n int i = 0;\n for (i = 0; i < n && max_index == -1; i++)\n if (tea[i] != arr[i])\n max_index = i;\n\n for (; i < n; i++)\n if (tea[i] != arr[i] && arr[max_index] < arr[i])\n max_index = i;\n\n max = Math.Min(arr[max_index] - tea[max_index], w);\n w -= max;\n tea[max_index] += max;\n }\n\n for (int i = 0; i < n; i++)\n Console.Write(tea[i] + \" \");\n \n }\n }\n\n}\n\n", "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3"} {"source_code": "// Problem: 1146A - Love \"A\"\n// Author: Gusztav Szmolik\n\nusing System;\n\nclass LoveA\n {\n public static int Main ()\n {\n string line = Console.ReadLine ();\n if (line == null)\n return -1;\n string[] words = line.Split ();\n if (words.Length != 1)\n return -1;\n string s = words[0];\n byte sLength = Convert.ToByte (s.Length);\n if (sLength > 50)\n return -1;\n byte aCount = 0;\n char c;\n for (byte i = 0; i < sLength; i++)\n {\n c = s[i];\n if (!Char.IsLower (c))\n return -1;\n if (c == 'a')\n aCount++;\n }\n if (aCount == 0)\n return -1;\n byte ansTmp = Convert.ToByte (2*aCount-1);\n byte ans = (ansTmp < sLength ? ansTmp : sLength);\n Console.WriteLine (ans);\n return 0;\n }\n }\n", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace CodeForce\n{\n public class Program\n {\n static void Main(string[] args)\n {\n int k;\n k = int.Parse(System.Console.ReadLine());\n\n int [] mem =new int[10];\n for (int i = 0; i < 4; i++)\n {\n string a = System.Console.ReadLine();\n foreach (char c in a)\n {\n if (c >= '1' && c <= '9')\n mem[c-'0']++;\n }\n\n }\n\n bool yes = true;\n for (int i = 1; i < 10; i++)\n {\n if (mem[i] > 2*k)\n {\n yes = false;\n break;\n }\n \n }\n\n System.Console.WriteLine(yes?\"YES\":\"NO\");\n //System.Console.ReadLine();\n\n\n }\n\n \n }\n}\n", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace PracticeProblems\n{\n\tclass Program\n\t{\n\t\tstatic void Main(String[] args)\n\t\t{\n\t\t\tP_146A tenth = new P_146A();\n\t\t\ttenth.Run();\n\t\t\tConsole.Read();\n\t\t}\n\t}\n\n\tclass P_158A\n\t{\n\t\tpublic P_158A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tString[] paramz = Console.ReadLine().Split(' ');\n\t\t\tint n = Convert.ToInt16(paramz[0]);\n\t\t\tint ptctr = Convert.ToInt16(paramz[1]) - 1;\n\n\t\t\tString[] input = Console.ReadLine().Split(' ');\n\n\t\t\tif (Convert.ToInt16(input[ptctr]) != 0)\n\t\t\t{\n\t\t\t\twhile (ptctr < n - 1)\n\t\t\t\t{\n\t\t\t\t\tif (Convert.ToInt16(input[ptctr + 1]) == Convert.ToInt16(input[ptctr]))\n\t\t\t\t\t{\n\t\t\t\t\t\tptctr++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twhile (ptctr >= 0)\n\t\t\t\t{\n\t\t\t\t\tif (Convert.ToInt16(input[ptctr]) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tptctr--;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tConsole.Write(ptctr + 1);\n\t\t}\n\t}\n\n\tclass P_158B\n\t{\n\t\tpublic P_158B() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tint numCabs = 0;\n\n\t\t\t// [0] = 1 ... [3] = 4\n\t\t\tint[] countArr = new int[4];\n\n\t\t\t// Flush line b/c of conversion\n\t\t\tConsole.ReadLine();\n\n\t\t\tString[] input = Console.ReadLine().Split(' ');\n\n\t\t\t// Count number of occurrences of each group size = countArr[]\n\t\t\tforeach (String groupSize in input)\n\t\t\t{\n\t\t\t\tswitch (groupSize)\n\t\t\t\t{\n\t\t\t\t\tcase \"1\":\n\t\t\t\t\t\tcountArr[0]++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"2\":\n\t\t\t\t\t\tcountArr[1]++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"3\":\n\t\t\t\t\t\tcountArr[2]++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"4\":\n\t\t\t\t\t\tcountArr[3]++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/*\tIs performing this before the bottom steps faster?\n\t\t\t *\t\tI don't think so because worst case, you'll be performing n*(this method's complexity) + Theta(bottom steps)\n\t\t\t * \n\t\t\t * Accept input one value at a time.\n\t\t\t *\tif 1:\n\t\t\t *\t\tif any 3's, then dec num 3's and total++\n\t\t\t *\t\telse, inc num 1's\n\t\t\t *\tif 2:\n\t\t\t *\t\tif any 2's, then dec num 2's and total++\n\t\t\t *\t\telse if at least two 1's, then decx2 num 1's and total++\n\t\t\t *\t\telse, inc num 2's\n\t\t\t *\tif 3:\n\t\t\t *\t\tif any 1's, then dec num 1's and total++\n\t\t\t *\t\telse, inc num 3's\n\t\t\t *\tif 4:\n\t\t\t *\t\ttotal++\n\t\t\t * \n\t\t\t */\n\n\t\t\t// 1. Count number of 4's\n\t\t\t// 2. Find the lesser of 1's and 3's, subtract from both and += lesser and += remaining 3's\n\t\t\t// 3. += (2's divided by two, integer division); if odd, then if there are at least two 1's left, then += 1 and decx2 num 1's | otherwise (no more 1's), += 1 and RETURN\n\t\t\t// 4. += (Ceiling of remaining 1's divided by 4)\n\n\t\t\t// ONE\n\t\t\tnumCabs += countArr[3];\n\n\t\t\t// TWO\n\t\t\tint lesser = Math.Min(countArr[0], countArr[2]);\n\t\t\tcountArr[0] -= lesser;\n\t\t\tcountArr[2] -= lesser;\n\t\t\tnumCabs += lesser;\n\t\t\tnumCabs += countArr[2];\n\n\t\t\t// THREE\n\t\t\tnumCabs += (countArr[1] / 2);\n\t\t\tif (countArr[1] % 2 == 1)\n\t\t\t{\n\t\t\t\tif (countArr[0] > 1)\n\t\t\t\t{\n\t\t\t\t\tnumCabs++;\n\t\t\t\t\tcountArr[0] -= 2;\n\t\t\t\t}\n\t\t\t\telse // END CASE: ADD ONE AND WRITE\n\t\t\t\t{\n\t\t\t\t\tnumCabs++; // for the 2 (and remaining 1)\n\t\t\t\t\tConsole.WriteLine(numCabs);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// FOUR\n\t\t\tnumCabs += Convert.ToInt32(Math.Ceiling((double)(countArr[0]) / 4));\n\n\t\t\tConsole.WriteLine(numCabs);\n\t\t}\n\t}\n\n\tclass P_71A\n\t{\n\t\tpublic P_71A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tint numLines = Convert.ToInt32(Console.ReadLine());\n\n\t\t\twhile (numLines > 0)\n\t\t\t{\n\t\t\t\tString input = Console.ReadLine();\n\n\t\t\t\tif (input.Length <= 10)\n\t\t\t\t{\n\t\t\t\t\tConsole.WriteLine(input);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\t\tsb.Append(input[0]);\n\t\t\t\t\tsb.Append(input.Length - 2);\n\t\t\t\t\tsb.Append(input[input.Length - 1]);\n\t\t\t\t\tConsole.WriteLine(sb.ToString());\n\t\t\t\t}\n\n\t\t\t\tnumLines--;\n\t\t\t}\n\t\t}\n\t}\n\n\tclass P_118A\n\t{\n\t\tpublic P_118A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tLinkedList input = new LinkedList(Console.ReadLine().ToCharArray());\n\n\t\t\t// Remove all vowels\n\t\t\t// Place '.' behind all consonants\n\t\t\t// Upper to lower case\n\t\t\t// NOTE: combined all three because can be done concurrently\n\n\t\t\tLinkedList temp = new LinkedList();\n\n\t\t\tforeach (char elt in input)\n\t\t\t{\n\t\t\t\tif (!IsVowel(elt))\n\t\t\t\t{\n\t\t\t\t\ttemp.AddLast('.');\n\t\t\t\t\ttemp.AddLast(UpperToLower(elt));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tPrint(temp);\n\t\t}\n\n\t\tprivate bool IsVowel(char input)\n\t\t{\n\t\t\tif (input == 'a' || input == 'A'\n\t\t\t\t\t|| input == 'e' || input == 'E'\n\t\t\t\t\t|| input == 'i' || input == 'I'\n\t\t\t\t\t|| input == 'o' || input == 'O'\n\t\t\t\t\t|| input == 'u' || input == 'U'\n\t\t\t\t\t|| input == 'y' || input == 'Y')\n\t\t\t\treturn true;\n\n\t\t\treturn false;\n\t\t}\n\n\t\tprivate char UpperToLower(char input)\n\t\t{\n\t\t\tif (input < 'a')\n\t\t\t{\n\t\t\t\treturn (char)(input + ('a' - 'A'));\n\t\t\t}\n\n\t\t\treturn input;\n\t\t}\n\n\t\tprivate void Print(LinkedList output)\n\t\t{\n\t\t\tforeach (char elt in output)\n\t\t\t{\n\t\t\t\tConsole.Write(elt);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic class P_40A\n\t{\n\t\tpublic P_40A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tString[] input = Console.ReadLine().Split(' ');\n\t\t\tint l = Convert.ToInt32(input[0]);\n\t\t\tint w = Convert.ToInt32(input[1]);\n\t\t\tdouble total = 0;\n\n\t\t\tif (l % 2 == 1 && w % 2 == 1)\n\t\t\t{\n\t\t\t\ttotal += (l * (w - 1)) / 2;\n\t\t\t\ttotal += (l - 1) / 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttotal += (l * w) / 2;\n\t\t\t}\n\n\t\t\tConsole.WriteLine(total);\n\t\t}\n\t}\n\n\tclass P_231A\n\t{\n\t\tpublic P_231A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tint lines = Convert.ToInt32(Console.ReadLine());\n\t\t\tint counter = 0;\n\n\t\t\twhile (lines > 0)\n\t\t\t{\n\t\t\t\tString input = Console.ReadLine();\n\n\t\t\t\tif (Convert.ToInt32(input[0]) + Convert.ToInt32(input[2]) + Convert.ToInt32(input[4]) >= 146)\n\t\t\t\t\tcounter++;\n\n\t\t\t\tlines--;\n\t\t\t}\n\n\t\t\tConsole.WriteLine(counter);\n\t\t}\n\t}\n\n\tclass P_116A\n\t{\n\t\tpublic P_116A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tint lines = Convert.ToInt32(Console.ReadLine());\n\t\t\tint counter = 0;\n\t\t\tint max = 0;\n\n\t\t\twhile (lines > 0)\n\t\t\t{\n\t\t\t\tString[] line = Console.ReadLine().Split(' ');\n\n\t\t\t\tcounter += (Convert.ToInt32(line[1]) - Convert.ToInt32(line[0]));\n\n\t\t\t\tmax = Greater(max, counter);\n\n\t\t\t\tlines--;\n\t\t\t}\n\n\t\t\tConsole.WriteLine(max);\n\t\t}\n\n\t\tprivate int Greater(int first, int second)\n\t\t{\n\t\t\tif (first > second)\n\t\t\t\treturn first;\n\n\t\t\treturn second;\n\t\t}\n\t}\n\n\tclass P_146A\n\t{\n\t\tpublic P_146A() { }\n\n\t\tpublic void Run()\n\t\t{\n\t\t\tint[] luckyCount1 = new int[2];\n\t\t\tint[] luckyCount2 = new int[2];\n\n\t\t\tint iters = Convert.ToInt16(Console.ReadLine()) / 2;\n\t\t\tString num = Console.ReadLine();\n\n\t\t\tfor (int i = 0; i < iters; i++)\n\t\t\t{\n\t\t\t\tif (num[i] == '4')\n\t\t\t\t\tluckyCount1[0]++;\n\t\t\t\telse if (num[i] == '7')\n\t\t\t\t\tluckyCount1[1]++;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tConsole.WriteLine(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (num[iters + i] == '4')\n\t\t\t\t\tluckyCount2[0]++;\n\t\t\t\telse if (num[iters + i] == '7')\n\t\t\t\t\tluckyCount2[1]++;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tConsole.WriteLine(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (luckyCount1[0] == luckyCount2[0] && luckyCount1[1] == luckyCount2[1])\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"YES\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"NO\");\n\t\t\t}\n\t\t}\n\t}\n\n\n\t//public class LinkedListNode\n\t//{\n\t//\tpublic LinkedListNode() { }\n\t//\tpublic LinkedListNode(T value) { Value = value; }\n\n\t//\tpublic LinkedListNode Previous { get; set; }\n\t//\tpublic LinkedListNode Next { get; set; }\n\t//\tpublic T Value { get; set; }\n\t//}\n}", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing System.Xml;\n\nnamespace ProjectEuler\n{\n class Program\n {\n static void Main(string[] args)\n {\n int a = Convert.ToInt32(Console.ReadLine());\n int b = Convert.ToInt32(Console.ReadLine());\n int c = Convert.ToInt32(Console.ReadLine());\n\n if (a != 1 && b != 1 && c != 1 )\n {\n Console.WriteLine(a*b*c);\n }\n else if (a == 1 && c != 1)\n {\n Console.WriteLine((a + b) * c);\n } \n else if (a == 1 && c == 1)\n {\n Console.WriteLine(a + b + c);\n }\n else if (b == 1)\n {\n if (a >= c)\n {\n Console.WriteLine(a * (1 + c));\n }\n else\n {\n Console.WriteLine((a + 1) * c);\n }\n }\n else if (a != 1 && c == 1)\n {\n Console.WriteLine(a * (b + 1));\n }\n\n\n } \n \n }\n}", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace lya_and_Diplomas\n{\n internal class Program\n {\n private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n int n = Next();\n\n int mi1 = Next(), ma1 = Next();\n int mi2 = Next(), ma2 = Next();\n int mi3 = Next(), ma3 = Next();\n\n int n1 = Math.Min(ma1, n - mi2 - mi3);\n int n2 = Math.Min(ma2, n - n1 - mi3);\n int n3 = n - n1 - n2;\n\n writer.WriteLine(\"{0} {1} {2}\", n1, n2, n3);\n writer.Flush();\n }\n\n private static int Next()\n {\n int c;\n int res = 0;\n do\n {\n c = reader.Read();\n if (c == -1)\n return res;\n } while (c < '0' || c > '9');\n res = c - '0';\n while (true)\n {\n c = reader.Read();\n if (c < '0' || c > '9')\n return res;\n res *= 10;\n res += c - '0';\n }\n }\n }\n}", "src_uid": "3cd092b6507079518cf206deab21cf97"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Console = System.Console;\n\nnamespace ConsoleApp1\n{\n class Program\n {\n static void Main(string[] args)\n {\n var n = Convert.ToInt32(Console.ReadLine());\n var a = Console.ReadLine().Split().Select(ai => Convert.ToInt32(ai)).ToList();\n\n var half = a.Sum() / 2 + 1;\n\n var alica = a[0];\n a = a.Skip(1).ToList();\n \n \n\n var result = new List();\n result.Add(1);\n\n var sum = alica;\n for (var i = 0; i < a.Count; i++)\n {\n var ai = a[i];\n if (ai * 2 <= alica)\n {\n result.Add(i + 2);\n sum += ai;\n if (sum >= half)\n {\n break;\n }\n } \n }\n\n if (sum >= half)\n {\n Console.WriteLine(result.Count);\n foreach (var k in result)\n {\n Console.Write(k + \" \"); \n }\n }\n else\n {\n Console.WriteLine(0);\n }\n\n //Console.ReadKey();\n }\n }\n}\n", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "using System;\n\nclass A514 {\n public static void Main() {\n var s = Console.ReadLine().ToCharArray();\n for (int i = s[0] == '9' ? 1 : 0; i < s.Length; ++i)\n s[i] = (char)Math.Min(s[i], '0' + ('9' - s[i]));\n Console.WriteLine(new string(s));\n }\n}\n", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\n\nnamespace Nuts\n{\n internal class Program\n {\n private static readonly StreamReader reader =\n new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);\n\n private static readonly StreamWriter writer =\n new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);\n\n private static void Main(string[] args)\n {\n string[] ss = reader.ReadLine().Split(' ');\n\n int k = int.Parse(ss[0]);\n int a = int.Parse(ss[1]);\n int b = int.Parse(ss[2]);\n int v = int.Parse(ss[3]);\n\n int count = 0;\n\n while (a > 0)\n {\n int used = Math.Min(k-1, b);\n b -= used;\n int n = (used + 1)*v;\n a -= n;\n count++;\n }\n\n writer.WriteLine(count);\n writer.Flush();\n }\n }\n}", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"} {"source_code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\n//using System.Drawing;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\n//using System.Threading;\n\nnamespace ReadWriteTemplate\n{\n public static class Solver\n {\n private static void SolveCase()\n {\n /*Random random = new Random();\n for (int kk = 0; kk < 50; kk++)\n {\n for (int i = 0; i < 250; i++)\n {\n Writer.Write(\"{0} \", random.Next(201));\n }\n Writer.WriteLine();\n }*/\n\n int[] a = ReadIntArray();\n int n = a.Length;\n int s = 10; // ???\n // double min = a.Min();\n // double max = a.Max();\n // double d = max - min;\n // min -= d / 2 / n;\n // max += d / 2 / n;\n\n double p = a.Average();\n //double sum = GetValue(a, s, n, a.Max());\n double mean = a.Average();\n double sum = a.Sum(x => (x - mean) * (x - mean));\n sum /= (a.Max() - a.Min()) * (a.Max() - a.Min());\n\n int k = s - 3;\n // double X = 2.17;\n double X = 40;\n\n maxx = Math.Min(maxx, sum);\n // Writer.WriteLine(maxx);\n bool isUniform = sum > 15;\n //Writer.WriteLine(isUniform ? \"uniform\" : \"poisson\");\n if (isUniform)\n {\n Writer.WriteLine((a.Min() + a.Max()) / 2);\n }\n else\n {\n //int R = 50;\n //a = a.OrderBy(x => x).Take(a.Length - R).Skip(R).ToArray();\n Writer.WriteLine(((int)Math.Round(a.Average())));\n }\n }\n\n private static double GetValue(int[] a, int s, int n, double max)\n {\n double min = 0;\n double e = (max - min) / s;\n\n int[] count = new int[s];\n for (int i = 0; i < n; i++)\n {\n int index = (int)((a[i] - min - 1e-10) / e);\n if (index < 0)\n {\n index = 0;\n }\n if (index >= s)\n {\n index = s - 1;\n }\n count[index]++;\n }\n\n double np = (double)n / s;\n double sum = count.Sum(x => (x - np) * (x - np) / np);\n return sum;\n }\n\n public static double maxx = double.MaxValue;\n\n public static void Solve()\n {\n int T = ReadInt();\n for (int i = 0; i < T; i++)\n {\n //Writer.Write(\"Case #{0}: \", i + 1);\n SolveCase();\n }\n }\n\n public class Point\n {\n public Point(int x, int y)\n {\n X = x;\n Y = y;\n }\n\n public int X;\n\n public int Y;\n\n protected bool Equals(Point other)\n {\n return X == other.X && Y == other.Y;\n }\n\n public override bool Equals(object obj)\n {\n if (ReferenceEquals(null, obj))\n {\n return false;\n }\n if (ReferenceEquals(this, obj))\n {\n return true;\n }\n if (obj.GetType() != this.GetType())\n {\n return false;\n }\n return Equals((Point)obj);\n }\n\n public override int GetHashCode()\n {\n unchecked\n {\n return (X * 397) ^ Y;\n }\n }\n }\n\n public static class Standard\n {\n public static long Power(long x, long p, long mod)\n {\n long result = 1;\n while (p > 0)\n {\n if ((p & 1) == 0)\n {\n x = (x * x) % mod;\n p >>= 1;\n }\n else\n {\n result = (result * x) % mod;\n p--;\n }\n }\n return result;\n }\n\n public static long Gcd(long a, long b)\n {\n return b == 0 ? a : Gcd(b, a % b);\n }\n\n public static List GetPrimes(int n)\n {\n bool[] isPrime = Enumerable.Repeat(true, n).ToArray();\n isPrime[0] = false;\n isPrime[1] = false;\n for (int i = 2; i < n; i++)\n {\n if (isPrime[i])\n {\n for (int j = i + i; j < n; j += i)\n {\n isPrime[j] = false;\n }\n }\n }\n List primes = new List();\n for (int i = 0; i < n; i++)\n {\n if (isPrime[i])\n {\n primes.Add(i);\n }\n }\n return primes;\n }\n }\n\n public static void Main()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n#if DEBUG\n //Reader = Console.In; Writer = Console.Out;\n Reader = File.OpenText(\"input.txt\"); Writer = File.CreateText(\"output.txt\");\n#else\n Reader = Console.In; Writer = Console.Out;\n#endif\n\n Solve();\n\n Reader.Close();\n Writer.Close();\n }\n\n public static IOrderedEnumerable OrderByWithShuffle(this IEnumerable source, Func keySelector)\n {\n return source.Shuffle().OrderBy(keySelector);\n }\n\n public static T[] Shuffle(this IEnumerable source)\n {\n T[] result = source.ToArray();\n Random rnd = new Random();\n for (int i = result.Length - 1; i >= 1; i--)\n {\n int k = rnd.Next(i + 1);\n T tmp = result[k];\n result[k] = result[i];\n result[i] = tmp;\n }\n return result;\n }\n\n #region Read/Write\n\n private static TextReader Reader;\n\n private static TextWriter Writer;\n\n private static Queue CurrentLineTokens = new Queue();\n\n private static string[] ReadAndSplitLine()\n {\n return Reader.ReadLine().Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n }\n\n public static string ReadToken()\n {\n while (CurrentLineTokens.Count == 0)\n CurrentLineTokens = new Queue(ReadAndSplitLine());\n return CurrentLineTokens.Dequeue();\n }\n\n public static string ReadLine()\n {\n return Reader.ReadLine();\n }\n\n public static int ReadInt()\n {\n return int.Parse(ReadToken());\n }\n\n public static long ReadLong()\n {\n return long.Parse(ReadToken());\n }\n\n public static double ReadDouble()\n {\n return double.Parse(ReadToken(), CultureInfo.InvariantCulture);\n }\n\n public static int[] ReadIntArray()\n {\n return ReadAndSplitLine().Select(int.Parse).ToArray();\n }\n\n public static long[] ReadLongArray()\n {\n return ReadAndSplitLine().Select(long.Parse).ToArray();\n }\n\n public static double[] ReadDoubleArray()\n {\n return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();\n }\n\n public static int[][] ReadIntMatrix(int numberOfRows)\n {\n int[][] matrix = new int[numberOfRows][];\n for (int i = 0; i < numberOfRows; i++)\n matrix[i] = ReadIntArray();\n return matrix;\n }\n\n public static string[] ReadLines(int quantity)\n {\n string[] lines = new string[quantity];\n for (int i = 0; i < quantity; i++)\n lines[i] = Reader.ReadLine().Trim();\n return lines;\n }\n\n public static void WriteArray(IEnumerable array)\n {\n Writer.WriteLine(string.Join(\" \", array));\n }\n\n #endregion\n }\n}\n", "src_uid": "18bf2c587415f85df83fb090e16b8351"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\n\nclass Program\n{\n static void Main(string[] args)\n {\n int n = RI();\n var next = RIA(n);\n if (next.Distinct().Count() != n)\n {\n Console.Write(-1);\n return;\n }\n\n bool[] visited = new bool[n];\n List size = new List();\n for (int i = 0; i < n; i++)\n if (!visited[i])\n {\n int cnt = 0;\n int t = i;\n while (!visited[t])\n {\n visited[t] = true;\n t = next[t] - 1;\n cnt++;\n }\n\n size.Add(cnt);\n }\n\n long answer = 1;\n for (int i = 0; i < size.Count; i++)\n {\n var sz = (size[i] % 2 == 0) ? (size[i] / 2) : size[i];\n answer = (answer / GCD(answer, sz)) * sz;\n }\n\n Console.Write(answer);\n }\n\n private const int Mod = 1000000000 + 7;\n\n #region Data Read\n private static char ReadSign()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans == '+' || ans == '-' || ans == '?')\n return (char)ans;\n }\n }\n\n private static long GCD(long a, long b)\n {\n if (a % b == 0) return b;\n return GCD(b, a % b);\n }\n\n private static List[] ReadGraph(int n, int m)\n {\n List[] g = new List[n];\n for (int i = 0; i < g.Length; i++) g[i] = new List();\n for (int i = 0; i < m; i++)\n {\n int a = RI() - 1;\n int b = RI() - 1;\n\n g[a].Add(b);\n g[b].Add(a);\n }\n\n return g;\n }\n\n private static int[,] ReadGraphAsMatrix(int n, int m)\n {\n int[,] matrix = new int[n + 1, n + 1];\n for (int i = 0; i < m; i++)\n {\n int a = RI();\n int b = RI();\n matrix[a, b] = matrix[b, a] = 1;\n }\n\n return matrix;\n }\n\n private static void Sort(ref int a, ref int b)\n {\n if (a > b) Swap(ref a, ref b);\n }\n\n private static void Swap(ref int a, ref int b)\n {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n private const int BufferSize = 1 << 16;\n private static StreamReader consoleReader;\n private static MemoryStream testData;\n\n private static int RI()\n {\n int ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static ulong RUL()\n {\n ulong ans = 0;\n int chr;\n do\n {\n chr = consoleReader.Read();\n if (chr == -1)\n return 0;\n } while (chr < '0' || chr > '9');\n\n ans = (uint)(chr - '0');\n while (true)\n {\n chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans;\n ans = ans * 10 + (uint)(chr - '0');\n }\n }\n\n private static long RL()\n {\n long ans = 0;\n int mul = 1;\n do\n {\n ans = consoleReader.Read();\n if (ans == -1)\n return 0;\n if (ans == '-') mul = -1;\n } while (ans < '0' || ans > '9');\n\n ans -= '0';\n while (true)\n {\n int chr = consoleReader.Read();\n if (chr < '0' || chr > '9')\n return ans * mul;\n ans = ans * 10 + chr - '0';\n }\n }\n\n private static int[] RIA(int n)\n {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = RI();\n return ans;\n }\n\n private static long[] RLA(int n)\n {\n long[] ans = new long[n];\n for (int i = 0; i < n; i++)\n ans[i] = RL();\n return ans;\n }\n\n private static char[] ReadWord()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n List s = new List();\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s.ToArray();\n }\n\n private static char[] ReadString(int n)\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));\n\n char[] s = new char[n];\n int pos = 0;\n do\n {\n s[pos++] = (char)ans;\n if (pos == n) break;\n ans = consoleReader.Read();\n } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));\n\n return s;\n }\n\n private static char[] ReadStringLine()\n {\n int ans;\n\n do\n {\n ans = consoleReader.Read();\n } while (ans == 10 || ans == 13);\n\n List s = new List();\n\n do\n {\n s.Add((char)ans);\n ans = consoleReader.Read();\n } while (ans != 10 && ans != 13);\n\n return s.ToArray();\n }\n\n private static char ReadLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))\n return (char)ans;\n }\n }\n private static char ReadNonLetter()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))\n return (char)ans;\n }\n }\n\n private static char ReadAnyOf(IEnumerable allowed)\n {\n while (true)\n {\n char ans = (char)consoleReader.Read();\n if (allowed.Contains(ans))\n return ans;\n }\n }\n\n private static char ReadDigit()\n {\n while (true)\n {\n int ans = consoleReader.Read();\n if (ans >= '0' && ans <= '9')\n return (char)ans;\n }\n }\n\n private static int ReadDigitInt()\n {\n return ReadDigit() - (int)'0';\n }\n\n private static char ReadAnyChar()\n {\n return (char)consoleReader.Read();\n }\n\n private static string DoubleToString(double x)\n {\n return x.ToString(CultureInfo.InvariantCulture);\n }\n\n private static double DoubleFromString(string x)\n {\n return double.Parse(x, CultureInfo.InvariantCulture);\n }\n\n static Program()\n {\n //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);\n }\n\n private static void PushTestData(StringBuilder sb)\n {\n PushTestData(sb.ToString());\n }\n private static void PushTestData(string data)\n {\n#if TOLYAN_TEST\n if (testData == null)\n {\n testData = new MemoryStream();\n consoleReader = new StreamReader(testData);\n }\n\n var pos = testData.Position;\n var bytes = Encoding.UTF8.GetBytes(data);\n testData.Write(bytes, 0, bytes.Length);\n testData.Flush();\n testData.Position = pos;\n#endif\n }\n #endregion\n}", "src_uid": "149221131a978298ac56b58438df46c9"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Test\n{\n class IOHelper : IDisposable\n {\n StreamReader reader;\n StreamWriter writer;\n\n public IOHelper(string inputFile, string outputFile, Encoding encoding)\n {\n StreamReader iReader;\n StreamWriter oWriter;\n if (inputFile == null)\n iReader = new StreamReader(Console.OpenStandardInput(), encoding);\n else\n iReader = new StreamReader(inputFile, encoding);\n\n if (outputFile == null)\n oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);\n else\n oWriter = new StreamWriter(outputFile, false, encoding);\n\n reader = iReader;\n writer = oWriter;\n\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n\n string[] curLine;\n int curTokenIdx;\n\n char[] whiteSpaces = new char[] { ' ', '\\t', '\\r', '\\n' };\n\n public string ReadNextToken()\n {\n if (curTokenIdx >= curLine.Length)\n {\n //Read next line\n string line = reader.ReadLine();\n if (line != null)\n curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);\n else\n curLine = new string[] { };\n curTokenIdx = 0;\n }\n\n if (curTokenIdx >= curLine.Length)\n return null;\n\n return curLine[curTokenIdx++];\n }\n\n public int ReadNextInt()\n {\n return int.Parse(ReadNextToken());\n }\n\n public double ReadNextDouble()\n {\n var nextToken = ReadNextToken();\n var result = 0.0;\n nextToken = nextToken.Replace(\".\", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);\n result = double.Parse(nextToken);\n return result;\n }\n\n public void Write(string stringToWrite)\n {\n writer.Write(stringToWrite);\n }\n\n public void WriteLine(string stringToWrite)\n {\n writer.WriteLine(stringToWrite);\n }\n\n public void WriteLine(double valueToWrite)\n {\n long intPart = (long)valueToWrite;\n double fracPart = valueToWrite - intPart;\n var fracPartStr = fracPart.ToString();\n if (fracPartStr.Length > 1)\n fracPartStr = fracPartStr.Substring(2);\n var strToWrite = string.Format(\"{0}.{1}\", intPart, fracPartStr);\n writer.WriteLine(strToWrite);\n }\n\n public void Dispose()\n {\n try\n {\n if (reader != null)\n {\n reader.Dispose();\n }\n if (writer != null)\n {\n writer.Dispose();\n }\n }\n catch { };\n }\n\n\n public void Flush()\n {\n if (writer != null)\n {\n writer.Flush();\n }\n }\n }\n\n class Program\n {\n protected IOHelper ioHelper;\n\n int n;\n string input;\n string output;\n\n StringBuilder outputBuilder = new StringBuilder();\n\n public void Solve()\n {\n n = ioHelper.ReadNextInt();\n input = ioHelper.ReadNextToken();\n\n while(input.Length>0)\n {\n if(input.StartsWith(\"ogo\"))\n {\n outputBuilder.Append(\"***\");\n input = input.Substring(3);\n\n while(input.StartsWith(\"go\"))\n {\n input = input.Substring(2);\n }\n }\n else\n {\n outputBuilder.Append(input[0]);\n input = input.Substring(1);\n }\n }\n\n output = outputBuilder.ToString();\n ioHelper.WriteLine(output);\n ioHelper.Flush();\n\n //Console.ReadKey();\n }\n\n public Program(string inputFile, string outputFile)\n {\n ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);\n Solve();\n ioHelper.Dispose();\n }\n\n static void Main(string[] args)\n {\n Program myProgram = new Program(null, null);\n }\n }\n}", "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace A\n{\n class Program\n {\n static void Main(string[] args)\n {\n string input = \"\";\n input = Console.ReadLine();\n int minutesToSleep = 0;\n string reverseInput = new string(input.ToCharArray().Reverse().ToArray());\n if(reverseInput != input)\n {\n DateTime time = new DateTime();\n DateTime.TryParse(input, out time);\n string newTime = time.ToString(\"HH:mm\");\n string reverseNewTime = new string(newTime.ToCharArray().Reverse().ToArray());\n while(newTime != reverseNewTime)\n {\n time = time.AddMinutes(1);\n newTime = time.ToString(\"HH:mm\");\n reverseNewTime = new string(newTime.ToCharArray().Reverse().ToArray());\n minutesToSleep++;\n }\n }\n Console.Write(minutesToSleep);\n }\n }\n}\n", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"source_code": "/* Date: 25.02.2019 * Time: 21:45 */\n//\n\n/*\n�\tfflush(stdout) � ����� C++; \n�\tSystem.out.flush() � Java; \n�\tstdout.flush() � Python; \n�\tflush(output) � Pascal; \n*/\n\nusing System;\nusing System.Globalization;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\n\nclass Example\n{\n\tpublic static void Main (string[] args)\n\t{\n# if ( ! ONLINE_JUDGE )\n\t\tStreamReader sr = new StreamReader (\"C:\\\\TRR\\\\2019\\\\Task\\\\07 Codeforces\\\\037\\\\A.TXT\");\n\t\tStreamWriter sw = new StreamWriter (\"C:\\\\TRR\\\\2019\\\\Task\\\\07 Codeforces\\\\037\\\\A.OUT\");\n# endif\n\n\t\tNumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;\n\n\t\tint n;\n\t\tstring s;\n\n# if ( ONLINE_JUDGE )\n\t\tn = int.Parse (Console.ReadLine ());\n\t\ts = Console.ReadLine ();\n# else\n\t\tn = int.Parse (sr.ReadLine ());\n\t\ts = sr.ReadLine ();\n\t\tsw.WriteLine (\"*** n = \" + n);\n\t\tsw.WriteLine (\"*** a = \" + s);\n# endif\n\n\t\tint [] a = new int [n];\n\t\tstring [] ss = s.Split (' ');\n\t\tint kp = 0, kn = 0;\n\t\tfor ( int i=0; i < n; i++ )\n\t\t{\n\t\t\ta [i] = int.Parse (ss [i]);\n\t\t\tif ( a [i] > 0 )\n\t\t\t\tkp ++;\n\t\t\telse if ( a [i] < 0 )\n\t\t\t\tkn ++;\n\t\t}\n\n\t\tint d = 0;\n\t\tif ( kp >= n - kp )\n\t\t\td = 1;\n\t\tif ( kn >= n - kn )\n\t\t\td = -1;\n\n# if ( ONLINE_JUDGE )\n\t\tConsole.WriteLine (d);\n# else\n\t\tsw.WriteLine (d);\n\t\tsw.Close ();\n# endif\n\n\t}\n}\n", "src_uid": "a13cb35197f896cd34614c6c0b369a49"} {"source_code": "using System;\n\nnamespace FunctionalProgramming\n{\n class Program\n {\n static void Main(string[] args)\n {\n\n int[] n = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n int price = n[0];\n int counter = 0;\n for (counter = 1; ; counter++)\n {\n if (price % 10 == 0)\n {\n break;\n }\n else if (price % 10 - n[1] == 0) break;\n\n price = n[0] * (counter + 1);\n }\n Console.WriteLine(counter);\n }\n }\n}", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"} {"source_code": "// A Dynamic Programming based \n// C# program to find minimum \n// number operations to \n// convert str1 to str2 \nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nclass GFG\n{\n\n public static void Main()\n {\n List arr = Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToList();\n var op = Console.ReadLine().Split(' ').ToArray();\n Console.Write(SmallestNumber(arr, op, 0, ulong.MaxValue));\n }\n\n public static ulong SmallestNumber(List arr, string[] ope, int opeCount, ulong min)\n {\n\n if (arr.Count == 1)\n return arr[0];\n \n for (int i = 0; i < arr.Count; i++)\n {\n for (int j = i + 1; j < arr.Count; j++)\n {\n if (ope[opeCount] == \"+\")\n {\n var listNew = new List(arr);\n var tmp = listNew[i] + listNew[j];\n listNew.RemoveAt(j);\n listNew.RemoveAt(i);\n listNew.Add(tmp);\n min = Math.Min(min, SmallestNumber(listNew, ope, opeCount + 1, min));\n }\n if (ope[opeCount] == \"*\")\n {\n var listNew = new List(arr);\n var tmp = listNew[i] * listNew[j];\n listNew.RemoveAt(j);\n listNew.RemoveAt(i);\n \n listNew.Add(tmp);\n min = Math.Min(min, SmallestNumber(listNew, ope, opeCount + 1, min));\n }\n }\n }\n\n //min = Math.Min(min1, min2);\n return min;\n }\n}\n\n", "src_uid": "7a66fae63d9b27e444d84447012e484c"} {"source_code": "using System;\nusing System.Linq;\n\nnamespace codeforces\n{\n class Program\n {\n static void Main(string[] args)\n {\n int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();\n int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();\n for (int i = a[0]-1; i > a[0]-1-a[1]; i--)\n {\n b[i] = a[2];\n }\n\n Console.WriteLine(b.Sum());\n }\n }\n}\n", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"source_code": "using System;\n// you can also use other imports, for example:\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\n\npublic class HelloWorld\n{\n\n public static void Main(string[] args)\n {\n var n = Convert.ToInt64(Console.ReadLine());\n Console.WriteLine(n / 2520);\n }\n\n}", "src_uid": "8551308e5ff435e0fc507b89a912408a"} {"source_code": "using System;\nusing System.IO;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Linq;\nusing System.Collections.Generic;\n\npublic class Program\n{\n public static void Main() {\n int[] arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);\n int y = arr[0]+1;\n int b = arr[1];\n int r = arr[2]-1;\n\n\n Console.WriteLine(Math.Min(Math.Min(r,b),y)*3);\n }\n}\n", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"source_code": "using System;\nusing CompLib.Mathematics;\nusing CompLib.Util;\n\npublic class Program\n{\n public void Solve()\n {\n var sc = new Scanner();\n int n = sc.NextInt();\n int m = sc.NextInt();\n\n var ans = ModInt.Pow(ModInt.Pow(2, m) - 1, n);\n Console.WriteLine(ans);\n }\n\n public static void Main(string[] args) => new Program().Solve();\n}\n\nnamespace CompLib.Util\n{\n using System;\n using System.Linq;\n\n class Scanner\n {\n private string[] _line;\n private int _index;\n private const char Separator = ' ';\n\n public Scanner()\n {\n _line = new string[0];\n _index = 0;\n }\n\n public string Next()\n {\n if (_index >= _line.Length)\n {\n string s = Console.ReadLine();\n while (s.Length == 0)\n {\n s = Console.ReadLine();\n }\n\n _line = s.Split(Separator);\n _index = 0;\n }\n\n return _line[_index++];\n }\n\n public int NextInt() => int.Parse(Next());\n public long NextLong() => long.Parse(Next());\n public double NextDouble() => double.Parse(Next());\n public decimal NextDecimal() => decimal.Parse(Next());\n public char NextChar() => Next()[0];\n public char[] NextCharArray() => Next().ToCharArray();\n\n public string[] Array()\n {\n string s = Console.ReadLine();\n _line = s.Length == 0 ? new string[0] : s.Split(Separator);\n _index = _line.Length;\n return _line;\n }\n\n public int[] IntArray() => Array().Select(int.Parse).ToArray();\n public long[] LongArray() => Array().Select(long.Parse).ToArray();\n public double[] DoubleArray() => Array().Select(double.Parse).ToArray();\n public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();\n }\n}\n\n// https://bitbucket.org/camypaper/complib\nnamespace CompLib.Mathematics\n{\n #region ModInt\n\n /// \n /// [0,) までの値を取るような数\n /// \n public struct ModInt\n {\n /// \n /// 剰余を取る値.\n /// \n public const long Mod = (int) 1e9 + 7;\n\n /// \n /// 実際の数値.\n /// \n public long num;\n\n /// \n /// 値が であるようなインスタンスを構築します.\n /// \n /// インスタンスが持つ値\n /// パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため, ∈ [0,) を満たすような を渡してください.このコンストラクタは O(1) で実行されます.\n public ModInt(long n)\n {\n num = n;\n }\n\n /// \n /// このインスタンスの数値を文字列に変換します.\n /// \n /// [0,) の範囲内の整数を 10 進表記したもの.\n public override string ToString()\n {\n return num.ToString();\n }\n\n public static ModInt operator +(ModInt l, ModInt r)\n {\n l.num += r.num;\n if (l.num >= Mod) l.num -= Mod;\n return l;\n }\n\n public static ModInt operator -(ModInt l, ModInt r)\n {\n l.num -= r.num;\n if (l.num < 0) l.num += Mod;\n return l;\n }\n\n public static ModInt operator *(ModInt l, ModInt r)\n {\n return new ModInt(l.num * r.num % Mod);\n }\n\n public static implicit operator ModInt(long n)\n {\n n %= Mod;\n if (n < 0) n += Mod;\n return new ModInt(n);\n }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(ModInt v, long k)\n {\n return Pow(v.num, k);\n }\n\n /// \n /// 与えられた 2 つの数値からべき剰余を計算します.\n /// \n /// べき乗の底\n /// べき指数\n /// 繰り返し二乗法により O(N log N) で実行されます.\n public static ModInt Pow(long v, long k)\n {\n long ret = 1;\n for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)\n if ((k & 1) == 1)\n ret = ret * v % Mod;\n return new ModInt(ret);\n }\n\n /// \n /// 与えられた数の逆元を計算します.\n /// \n /// 逆元を取る対象となる数\n /// 逆元となるような値\n /// 法が素数であることを仮定して,フェルマーの小定理に従って逆元を O(log N) で計算します.\n public static ModInt Inverse(ModInt v)\n {\n return Pow(v, Mod - 2);\n }\n }\n\n #endregion\n\n #region Binomial Coefficient\n\n public class BinomialCoefficient\n {\n public ModInt[] fact, ifact;\n\n public BinomialCoefficient(int n)\n {\n fact = new ModInt[n + 1];\n ifact = new ModInt[n + 1];\n fact[0] = 1;\n for (int i = 1; i <= n; i++)\n fact[i] = fact[i - 1] * i;\n ifact[n] = ModInt.Inverse(fact[n]);\n for (int i = n - 1; i >= 0; i--)\n ifact[i] = ifact[i + 1] * (i + 1);\n ifact[0] = ifact[1];\n }\n\n public ModInt this[int n, int r]\n {\n get\n {\n if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;\n return fact[n] * ifact[n - r] * ifact[r];\n }\n }\n\n public ModInt RepeatedCombination(int n, int k)\n {\n if (k == 0) return 1;\n return this[n + k - 1, k];\n }\n }\n\n #endregion\n}", "src_uid": "71029e5bf085b0f5f39d1835eb801891"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Numerics;\n\nnamespace cf420\n{\n class Program\n {\n static void Main(string[] args)\n {\n //Console.SetIn(new StreamReader(\"input.txt\"));\n solve_cf420B();\n }\n\n public static void solve_cf420B()\n {\n long[] mb = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);\n\n long m = mb[0];\n long b = mb[1];\n\n List> xy = new List>();\n\n for (long x = 0; x < (m * b) + 1; x++)\n {\n long xm = x / m;\n if (x % m == 0)\n {\n xy.Add(new KeyValuePair(x, -xm + b));\n }\n }\n\n long max = -1;\n for (int i = 0; i < xy.Count; i++)\n {\n long l = Math.Min(xy[i].Key, xy[i].Value);\n long n = Math.Max(xy[i].Key, xy[i].Value);\n\n long sum = 0;\n\n for (long j = 0; j <= l; j++)\n {\n sum += ((n + 1) * (j + n + j)) / 2;\n }\n max = Math.Max(max, sum);\n }\n\n Console.WriteLine(max);\n }\n }\n}\n", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.IO;\nusing System.Diagnostics;\n\nnamespace ConsoleApplication1 {\n struct Pair {\n public int X, Y;\n public Pair(int x, int y) {\n X = x;\n Y = y;\n }\n public override string ToString() {\n return string.Format(\"{0} {1}\", X, Y);\n }\n }\n\n class Graph : List> {\n public Graph(int num) : base(num) {\n for (int i = 0; i < num; i++) {\n this.Add(new List());\n }\n }\n }\n\n class Program {\n static int n, m, k, t, ans;\n static TextReader input;\n static int[] f;\n static bool[] u1, u2;\n static Graph g, rg;\n static void Main(string[] args) {\n#if TESTS \n Stopwatch sw = new Stopwatch();\n sw.Start();\n input = new StreamReader(\"input.txt\"); \n#else\n input = Console.In;\n#endif \n Solve(); \n#if TESTS\n Console.WriteLine();\n Console.WriteLine(\"Milliseconds: {0}\", sw.ElapsedMilliseconds);\n Console.ReadLine();\n#endif\n }\n\n #region read helpers\n public static int[] ReadIntArray() {\n return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();\n }\n\n public static List ReadIntList() {\n return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();\n }\n\n public static int ReadInt() {\n return int.Parse(input.ReadLine());\n }\n \n #endregion\n\n static void Solve() {\n int[] a = ReadIntArray();\n n = a[0];\n m = a[1];\n g = new Graph(n);\n rg = new Graph(n);\n u1 = new bool[n];\n u2 = new bool[n];\n f = ReadIntArray();\n for (int i = 0; i < m; i++) {\n int[] b = ReadIntArray();\n g[--b[0]].Add(--b[1]);\n rg[b[1]].Add(b[0]);\n }\n for (int i = 0; i < n; i++) {\n if (f[i] == 1 && !u1[i]) {\n Bfs1(i);\n }\n }\n for (int i = 0; i < n; i++) {\n if (f[i] == 2 && !u2[i]) {\n Bfs2(i);\n }\n }\n for (int i = 0; i < n; i++) {\n if (u1[i] && u2[i])\n Console.WriteLine(1);\n else\n Console.WriteLine(0);\n }\n }\n\n static void Bfs1(int v) {\n u1[v] = true;\n Queue q = new Queue();\n q.Enqueue(v);\n while (q.Count > 0) {\n int u = q.Dequeue();\n foreach (int i in g[u]) {\n if (!u1[i]) {\n u1[i] = true;\n q.Enqueue(i);\n }\n }\n }\n }\n\n static void Bfs2(int v) {\n u2[v] = true;\n Queue q = new Queue();\n q.Enqueue(v);\n while (q.Count > 0) {\n int u = q.Dequeue();\n foreach (int i in rg[u]) {\n if (!u2[i]) {\n u2[i] = true;\n if (f[i] != 1)\n q.Enqueue(i);\n }\n }\n }\n }\n\n static void Dfs1(int v) {\n u1[v] = true;\n foreach (int i in g[v]) {\n if (!u1[i]) Dfs1(i);\n }\n }\n\n static void Dfs2(int v) {\n u2[v] = true;\n if (f[v] == 1) return;\n foreach (int i in rg[v]) {\n if (!u2[i]) Dfs2(i);\n }\n }\n\n static int[] Count_Sort(int[] a, int k) {\n int n = a.Length;\n int[] b = new int[n];\n int[] c = new int[k];\n for (int i = 0; i < n; ++i)\n ++c[a[i]];\n for (int i = 1; i < k; ++i)\n c[i] += c[i - 1];\n for (int i = n - 1; i >= 0; --i) {\n b[c[a[i]] - 1] = a[i];\n --c[a[i]];\n }\n return b;\n }\n\n static void Radix_Sort(int[] a, int k) {\n int n = a.Length;\n int repeats = 32 / k;\n int size = 1 << k;\n int mask = size - 1;\n for (int i = 0; i < repeats; ++i) {\n int[] c = new int[size];\n int[] b = new int[n];\n for (int j = 0; j < n; ++j) {\n int r = (a[j] & (mask << (i * k))) >> (i * k);\n ++c[r];\n }\n for (int j = 1; j < size; ++j)\n c[j] += c[j - 1];\n for (int j = n - 1; j >= 0; --j) {\n int r = (a[j] & (mask << (i * k))) >> (i * k);\n b[c[r] - 1] = a[j];\n --c[r];\n }\n Array.Copy(b, a, n);\n }\n }\n }\n\n public static class Extensions {\n public static void Print(this IEnumerable e) {\n foreach (T item in e) {\n Console.Write(\"{0} \", item);\n }\n }\n }\n}\n", "src_uid": "87d869a0fd4a510c5e7e310886b86a57"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\n public class Given_Length_and_Sum_of_Digits\n {\n public static bool Can(int m, int s)\n {\n if (m == 0)\n {\n return s == 0;\n }\n return s >= 0 && s <= m * 9;\n }\n public static string Calculate(int m, int s)\n {\n var max = \"\";\n var min = \"\";\n\n if (!Can(m, s) || (s==0 && m!=1))\n {\n return \"-1 -1\";\n }\n var currentS = s;\n while (min.Length != m)\n {\n for(var i = 0; i <= 9; i++)\n {\n if(min.Length ==0 && i == 0 && m!=1)\n {\n continue;\n }\n\n if(Can(m - min.Length - 1, currentS - i))\n {\n min += i.ToString();\n currentS -= i;\n break;\n }\n }\n }\n currentS = s;\n while (max.Length != m)\n {\n for (var i = 9; i >= 0; i--)\n {\n if (max.Length == 0 && i == 0 && m != 1)\n {\n continue;\n }\n\n if (Can(m - max.Length - 1, currentS - i))\n {\n max += i.ToString();\n currentS -= i;\n break;\n }\n }\n }\n\n return min.ToString() + \" \" + max.ToString();\n }\n public static void Main()\n {\n var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();\n Console.WriteLine(Calculate(a[0], a[1]));\n }\n}\n", "src_uid": "75d062cece5a2402920d6706c655cad7"} {"source_code": "using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace test\n{\n class MainClass\n {\n public static void Main(string[] args)\n {\n\n int numberOfCards = Convert.ToInt32(Console.ReadLine()); \n int inputNumberCard = 0; \n List Cards = new List(); \n List Temp = new List(); \n for (int i = 0; i < numberOfCards; i++) \n { \n inputNumberCard = Convert.ToInt32(Console.ReadLine()); \n Cards.Add(inputNumberCard); \n } \n foreach (var el in Cards.Distinct()) \n { \n Temp.Add(Cards.Where(s => s == el).Count()); \n }\n if ((numberOfCards-Temp[0]) == Temp[0]) \n { \n var x = SearchDuplicateInList(Cards); \n if (x.Count == 2 && x[0] != x[1]) \n { \n Console.WriteLine(\"YES\"); \n Console.Write($\"{x[0]} {x[1]}\"); \n } \n else \n { Console.WriteLine(\"NO\");} \n } \n else \n { Console.WriteLine(\"NO\"); } \n }\n static List SearchDuplicateInList(List list)\n {\n List result = new List();\n foreach (var s in list)\n {\n if (!result.Contains(s))\n result.Add(s);\n }\n return result;\n }\n \n }\n}", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] nums = Console.ReadLine().Split();\n int n,c,max;\n n = Convert.ToInt32(nums[0]);\n c = Convert.ToInt32(nums[1]);\n nums = Console.ReadLine().Split();\n int[] ar=new int[n];\n int[] m = new int[n];\n for (int i = 0; i < n; i++)\n ar[i] = Convert.ToInt32(nums[i]);\n for (int i = 0; i < n-1; i++)\n m[i] = ar[i] - ar[i + 1] - c;\n\n max=m[0] ;\n for (int i = 0; i < n; i++)\n\n if (m[i] > max)\n max = m[i];\n Console.WriteLine(max);\n Console.ReadLine();\n\n\n\n\n }\n }\n}\n", "src_uid": "411539a86f2e94eb6386bb65c9eb9557"}