## Cards Permutation

Alice was given the integers from to . She wrote all possible permutations in increasing lexicographical order, and wrote each permutation in a new line. For example, for , there are possible permutations: She then chose one permutation among them as her favorite permutation. After some time, she forgot some elements of her favorite permutation. Nevertheless, she still tried to write down its elements. She wrote a in every position where she forgot the true value. She wants to know

## String Construction

Amanda has a string of lowercase letters that she wants to copy to a new string. She can perform the following operations with the given costs. She can perform them any number of times to construct a new string : Append a character to the end of string at a cost of dollar. Choose any substring of and append it to the end of at no charge. Given strings , find and print the minimum cost of copying each to on a new line. For example, given a string , it can be copied for dollars. St

## Maximum Palindromes

Madam Hannah Otto, the CEO of Reviver Corp., is fond of palindromes, or words that read the same forwards or backwards. She thinks palindromic brand names are appealing to millennials. As part of the marketing campaign for the company's new juicer called the Rotator™, Hannah decided to push the marketing team's palindrome-searching skills to a new level with a new challenge. In this challenge, Hannah provides a string consisting of lowercase English letters. Every day, for days, she woul

A gene is represented as a string of length (where is divisible by ), composed of the letters , , , and . It is considered to be steady if each of the four letters occurs exactly times. For example, and are both steady genes. Bear Limak is a famous biotechnology scientist who specializes in modifying bear DNA to make it steady. Right now, he is examining a gene represented as a string . It is not necessarily steady. Fortunately, Limak can choose one (maybe empty) substring of and replac

## Count Strings

A regular expression is used to describe a set of strings. For this problem the alphabet is limited to 'a' and 'b'. We define to be a valid regular expression if: 1) is "" or "". 2) is of the form "", where and are regular expressions. 3) is of the form "" where and are regular expressions. 4) is of the form "" where is a regular expression. Regular expressions can be nested and will always have have two elements in the parentheses. ('' is an element, '' is not; basically, th