using System.Collections.Generic;
using System.Text.RegularExpressions;
internal class TaskSolver
public static void Main(string[] args)
Console.WriteLine("All Test completed!");
static bool isValid(string word, Dictionary<char, int> letters)
return Regex.IsMatch(word, @"[а-яёА-ЯЁa-zA-Z]")&& word.GroupBy(c => c).ToDictionary(c => c.Key, c => c.Count()).All(x => letters.ContainsKey(x.Key) && letters[x.Key] >= x.Value);
public static List<int> GetWordSubWords(List<string> words, List<string> wordDictionary)
var kolvoWords = new List<int>();
foreach(string word in words){
var letters = word.GroupBy(c => c).ToDictionary(c => c.Key, c => c.Count());
foreach(string userWord in wordDictionary)
if(isValid(userWord, letters)) count++;
class ArrayComparer : IEqualityComparer<int[]>
public bool Equals(int[] x, int[] y)
return x.SequenceEqual(y);
public int GetHashCode(int[] obj)
foreach (int item in obj)
heigth = (heigth << 5) + 3 + heigth^ item.GetHashCode();
public static int FindPath(int[][] gridMap, int sX, int sY, int eX, int eY, int energyAmount)
Queue<int[]> queue = new Queue<int[]>();
Queue<int[]> cont = new Queue<int[]>();
queue.Enqueue(new[] { sX, sY });
cont.Enqueue(new[] { sX, sY });
for (int i = 0; i < k; i++)
if (tmp[0] == eX && tmp[1] == eY)
if (tmp[1] + 1 < gridMap.Length && gridMap[gridMap.Length - tmp[1] - 1][tmp[0]] != 0 && cont.Contains(tmp, new ArrayComparer()) == false)
queue.Enqueue(new[] { tmp[0], tmp[1] });
cont.Enqueue(new[] { tmp[0], tmp[1] });
if (tmp[1] >= 0 && gridMap[gridMap.Length - tmp[1] - 1][tmp[0]] != 0 && cont.Contains(tmp, new ArrayComparer()) == false)
queue.Enqueue(new[] { tmp[0], tmp[1] });
cont.Enqueue(new[] { tmp[0], tmp[1] });
if (tmp[0] >= 0 && gridMap[gridMap.Length - tmp[1] - 1][tmp[0]] != 0 && cont.Contains(tmp, new ArrayComparer()) == false)
queue.Enqueue(new[] { tmp[0], tmp[1] });
cont.Enqueue(new[] { tmp[0], tmp[1] });
if (tmp[0] < gridMap[0].Length && gridMap[gridMap.Length - tmp[1] - 1][tmp[0]] != 0 && cont.Contains(tmp, new ArrayComparer()) == false)
queue.Enqueue(new[] { tmp[0], tmp[1] });
cont.Enqueue(new[] { tmp[0], tmp[1] });
public static string FormatPrettyCoins(long value, char separator)
answer = value.ToString();
answer = (value/1000).ToString() + " " + ((value%1000)!=0 ? (value%1000).ToString() : "000") ;
answer = (value/1000).ToString() + "K";
answer = (value/1000000).ToString() + " " + ( (value%1000000)!=0 ?((value%1000000)/1000).ToString() : "000") + "K";
else if(value<1000000000)
answer = (value/1000000).ToString() + "M";
answer = (value/1000000000).ToString() + " " + ( (value%1000000000)!=0 ? ((value%1000000000)/1000000).ToString() : "000") + "M";
static bool IsEmpty<T>(Stack<T> stack) {
public static int FindMaxRect(List<int> heights)
var stack = new Stack<int>();
int n = heights.Count()-1;
if (IsEmpty(stack) ||heights[i] >= heights[stack.Peek()]) {
area = heights[tp] * (IsEmpty(stack) ? i : i - stack.Peek() - 1);
maxArea = Math.Max(maxArea, area);
while (!IsEmpty(stack)) {
area = heights[tp] * (IsEmpty(stack) ? i : i - stack.Peek() - 1);
maxArea = Math.Max(maxArea, area);
private static void TestGetWordSubWords()
var wordsList = new List<string>
"кот", "ток", "око", "мимо", "гром", "ром",
"рог", "морг", "огр", "мор", "порог",
AssertSequenceEqual( GetWordSubWords(new List<string>{"кот"}, wordsList), new []{2} );
AssertSequenceEqual( GetWordSubWords(new List<string>{"Cat"}, wordsList), new []{1} );
AssertSequenceEqual( GetWordSubWords(new List<string>{"cat"}, wordsList), new []{2} );
AssertSequenceEqual( GetWordSubWords(new List<string>{"мама"}, wordsList), new []{0} );
AssertSequenceEqual( GetWordSubWords(new List<string>{"погром", "гром"}, wordsList), new []{7, 6} );
private static void TestFindPath()
new[] {1, 1, 1, 0, 1, 1},
new[] {1, 1, 1, 0, 1, 1},
new[] {1, 1, 1, 0, 0, 0},
new[] {1, 1, 1, 1, 1, 1},
new[] {1, 1, 1, 1, 1, 1},
new[] {1, 1, 1, 1, 1, 1},
AssertEqual(FindPath(gridA, 0,0,2, 2, 5), 4);
AssertEqual(FindPath(gridA, 0,0,5, 5, 30), -1);
AssertEqual(FindPath(gridA, 0,0,0, 5, 3), -1);
private static void TestFormatPrettyCoins()
AssertEqual(FormatPrettyCoins(1, ' '), "1");
AssertEqual(FormatPrettyCoins(10, ' '), "10");
AssertEqual(FormatPrettyCoins(100, ' '), "100");
AssertEqual(FormatPrettyCoins(1233, ' '), "1 233");
AssertEqual(FormatPrettyCoins(20000, ' '), "20 000");
AssertEqual(FormatPrettyCoins(100000, ' '), "100K");
AssertEqual(FormatPrettyCoins(1717310, ' '), "1 717K");
AssertEqual(FormatPrettyCoins(1000000, ' '), "1 000K");
AssertEqual(FormatPrettyCoins(10000000, ' '), "10M");
AssertEqual(FormatPrettyCoins(100000000, ' '), "100M");
AssertEqual(FormatPrettyCoins(7172343310, ' '), "7 172M");
AssertEqual(FormatPrettyCoins(10000000000, ' '), "10 000M");
private static void FindMaxRect()
AssertEqual(FindMaxRect(new List<int>{1, 2, 3, 4, 4, 4, 5, 4, 6}), 24);
AssertEqual(FindMaxRect(new List<int>{1, 2, 3, 5, 5, 4, 2, 4, 6}), 16);
AssertEqual(FindMaxRect(new List<int>{8, 9, 3, 5, 5, 2, 3, 4, 6, 1, 6}), 18);
private static void Assert(bool value)
throw new Exception("Assertion failed");
private static void AssertEqual(object value, object expectedValue)
if (value.Equals(expectedValue))
throw new Exception($"Assertion failed expected = {expectedValue} actual = {value}");
private static void AssertSequenceEqual<T>(IEnumerable<T> value, IEnumerable<T> expectedValue)
if (ReferenceEquals(value, expectedValue))
throw new ArgumentNullException(nameof(value));
if (expectedValue is null)
throw new ArgumentNullException(nameof(expectedValue));
var valueList = value.ToList();
var expectedValueList = expectedValue.ToList();
if (valueList.Count != expectedValueList.Count)
throw new Exception($"Assertion failed expected count = {expectedValueList.Count} actual count = {valueList.Count}");
for (var i = 0; i < valueList.Count; i++)
if (!valueList[i].Equals(expectedValueList[i]))
throw new Exception($"Assertion failed expected value at {i} = {expectedValueList[i]} actual = {valueList[i]}");