## 「CodeForces 1215E」 Marbles

Monocarp has arranged 𝑛 colored marbles in a row. The color of the 𝑖-th marble is 𝑎𝑖. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).

In other words, Monocarp wants to rearrange marbles so that, for every color 𝑗, if the leftmost marble of color 𝑗 is 𝑙-th in the row, and the rightmost marble of this color has position 𝑟 in the row, then every marble from 𝑙 to 𝑟 has color 𝑗.

To achieve his goal, Monocarp can do the following operation any number of times: choose two neighbouring marbles, and swap them.

You have to calculate the minimum number of operations Monocarp has to perform to rearrange the marbles. Note that the order of segments of marbles having equal color does not matter, it is only required that, for every color, all the marbles of this color form exactly one contiguous segment.

## 「CodeForces 1234F」Yet Another Substring Reverse

You are given a string 𝑠 consisting only of first 20 lowercase Latin letters ('a', 'b', ..., 't').

Recall that the substring 𝑠[𝑙;𝑟] of the string 𝑠 is the string 𝑠𝑙𝑠𝑙+1…𝑠𝑟. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top".

## 「CodeForces 1238E」Keyboard Purchase

You have a password which you often type — a string 𝑠 of length 𝑛. Every character of this string is one of the first 𝑚 lowercase Latin letters.

Since you spend a lot of time typing it, you want to buy a new keyboard.

A keyboard is a permutation of the first 𝑚 Latin letters. For example, if 𝑚=3, then there are six possible keyboards: abc, acb, bac, bca, cab and cba.

## 「2017 四川省赛」2017 Revenge

Bobo has n integers $a_1, a_2, \dots, a_n$
He would like to choose some of the integers and calculate their product (the product of the empty set is defined as 1).

Bobo would like to know the number of products whose remainder divided by 2017 is r. As the exact number is too large, he only asks for the number modulo 2.