Here is the mashup link (the problems are from Codeforces' problem set).

#### A. The Lone Element Quest

#### B. Festive Matrix

#### C. Winterbourne

#### D. Santa's Substrings

**Hint**

For a string $$$a$$$ to be a substring of another string $$$b$$$, the length of $$$a$$$ should be less or equal to that of $$$b$$$.

**Solution**

Sort all the strings by their lengths. Then, for each $$$i ∈ [0...n−2]$$$ check that $$$s_{i}$$$ is a substring of $$$s_{i + 1}$$$. If it doesn't hold for some $$$i$$$ then the answer is "NO". Otherwise, the answer is "YES", and the sorted array is the correct order of the strings.

If there are several strings of the same length, their order does not matter, because if the answer is "YES", then all the strings of the same length should be equal.

**Code**

n = int(input())
strings = []
for _ in range(n):
strings.append(input())
strings.sort(key=len)
for indx in range(n - 1):
if strings[indx] not in strings[indx + 1]:
print('NO')
exit()
print('YES')
for string in strings:
print(string)

#### E. Simon's Wordplay

**Hint 1**

Since the words only contain five characters $$$(a, b, c, d, e)$$$, we can approach the problem by maximizing the story for each character individually.

**Hint 2**

How can we quantify a word's impact on the overall story?

**Hint 3**

For a given character in a word, the word's contribution is expressed as $$$x - ( len(word) - x)$$$, with $$$x$$$ denoting the character's occurrences and $$$(len(word) - x)$$$ representing the rest of the letters in the word.

**Solution**

1.Calculate Contributions: For each word and for each character from ‘a’ to ‘e’, calculate the word’s contribution towards that character.

2.Sort Contributions: For each character, sort the words based on their contributions towards that character. Words with higher contributions are sorted higher.

3.Select Words: For each character, select the words in the order of their sorted contributions until the sum of the contributions becomes non-positive. This gives us the maximum number of words that can make an interesting story with that character as the majority character.

4.Find the Maximum: Repeat the above steps for all characters and keep track of the maximum number of words found. This will be the maximum number of words that can make an interesting story.

**Code**

```
t = int(input())
for _ in range(t):
n = int(input())
arr = []
for i in range(n):
arr.append(input())
ans = 0
#for each character(a,b,c,d,e)
for j in range(5):
char_count = []
char = chr(ord('a') + j)
for word in arr:
char_count.append(2*(word.count(char)) - len(word))
char_count.sort(reverse=True)
if char_count[0] <= 0:
continue
total = char_count[0]
i = 1
while i < len(char_count) and total + char_count[i] > 0:
total += char_count[i]
i += 1
ans = max(ans,i)
print(ans)
```

#### F. Enchanted Sorting: The Grid Conundrum

**Approach**

First, let's check whether the given grid is good. If it is, we can swap the first column with itself and print $$$1 1$$$ as an answer. If it is not, there is a row that has elements that should be swapped.

Let's say this row is $$$a$$$, and let $$$b$$$ be the sorted version of $$$a$$$. After having these, let's find the set of indices $$$i$$$ where $$$a_{i} ≠ b_{i}$$$. If there are 3 or more such positions, the answer is $$$−1$$$, because by making a single swap we can only correct at most 2 of them.

But if there are no more than 2 such positions where $$$a_{i} ≠ b_{i}$$$, then let's swap the corresponding columns and check whether each row is sorted. If the grid is now good, we have found the answer. If not, the answer is $$$−1$$$ because we can not sort $$$a$$$ in any other way and get a good grid after that.

**Code**

t = int(input())
for _ in range(t):
grid = []
n, m = map(int, input().split())
for row in range(n):
grid.append(list(map(int, input().split())))
unsorted_row = None
# check if every row is sorted
for row in range(n):
for col in range(1, m):
if grid[row][col - 1] > grid[row][col]:
unsorted_row = grid[row]
break
if unsorted_row != None:
break
# if all rows are already sorted we can swap the first column with itself as an answer
if unsorted_row == None:
print(1, 1)
continue
sorted_version = sorted(unsorted_row)
disordered_columns = []
can_be_good = True
# identify the indices whose values are not in their sorted positions in the unsorted row
for indx in range(m):
if unsorted_row[indx] != sorted_version[indx]:
disordered_columns.append(indx)
if len(disordered_columns) >= 3:
can_be_good = False
break
# if those indices are more than 3, we can't make it sorted with a single swap
if not can_be_good:
print(-1)
continue
# swap the corresponding columns of those indices
for row in range(n):
col1, col2 = disordered_columns
grid[row][col1], grid[row][col2] = grid[row][col2], grid[row][col1]
# check if all rows are sorted after the swap
for row in range(n):
for col in range(1, m):
if grid[row][col - 1] > grid[row][col]:
can_be_good = False
break
if not can_be_good:
break
if not can_be_good:
print(-1)
else:
print(disordered_columns[0] + 1, disordered_columns[1] + 1)