0% found this document useful (0 votes)
12 views

Problems 25 - Codeforces

Uploaded by

Disha Swamy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Problems 25 - Codeforces

Uploaded by

Disha Swamy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Problems - Codeforces 21/06/24, 11:07 AM

Contest 26 (Icathia)

A. Beautiful Strings
1 second, 256 megabytes

You are given an integer n. Determine the number of strings of length 𝑛 which are beautiful modulo 109 + 7.

A string is called beautiful if it is lexicographically (alphabetically) sorted and only consists of vowels [𝑎𝑒𝑖𝑜𝑢].
The strings 𝑎𝑒𝑖𝑜𝑢 and 𝑎𝑎𝑜𝑢 are beautiful strings as they are lexicographically sorted and consist of vowels only but string 𝑎𝑧 is not beautiful as it
consists of the non-vowel alphabet and string 𝑒𝑎 is not beautiful as it is not lexicographically sorted.

Example: 𝑛 = 2 . All possible strings of length 2 are


[𝑎𝑎, 𝑎𝑒, 𝑎𝑖, 𝑎𝑜, 𝑎𝑢, 𝑒𝑒, 𝑒𝑖, 𝑒𝑜, 𝑒𝑢, 𝑖𝑖, 𝑖𝑜, 𝑖𝑢, 𝑜𝑜, 𝑜𝑢, 𝑢𝑢]
. Therefore the answer is 15.

Constraints

1 ≤ 𝑇 ≤ 102
1 ≤ 𝑛 ≤ 106

Input

The first line contains an integer 𝑇 denoting the number of test cases.
For each test case:

The first line contains a single integer 𝑛 denoting the length of the string.

Output
For each test case in a new line, print the answer.

input
input
2
1
2

output
output
5
15

B. Alphabetical String
1 second, 256 megabytes

While creating an account on a new website, you choose a certain string of letters as your password. However, you are alerted that the website
requires your password to be an alphabetical string. It explains, "A string of lowercase letters is called alphabetical if deleting zero or more of its letters
can result in the alphabet string abcdefghijklmnopqrstuvwxyz."

Because of this requirement, you need to ensure that your password is alphabetical. Your goal is to find the minimum number of letters that must be
inserted in order to make your password alphabetical.

Example: Given string 𝑠 = "xyzabcdefghijklmnopqrstuvw", the optimal solution is to insert "xyz" at the end of the string to obtain the alphabetical
string "xyzabcdefghijklmnopqrstuvwxyz". (Note that this is alphabetical because if you delete the first three letters, "xyz", it results in the alphabet
string "abcdefghijklmnopqrstuvwxyz".) Because this requires 3 letter insertions, the answer is 3. There is no way to make fewer than 3 insertions and
end up with an alphabetical string.

Constraints

1 ≤ 𝑇 ≤ 30
1 ≤ Length of string s ≤ 105
𝑠 contains only lowercase english letters

Input

First line contains an integer 𝑇 , denoting number of test cases.

Each of the next 𝑇 lines contains a string 𝑠 denoting the string that you are required to make alphabetical.

https://codeforces.com/gym/531207/problems Page 1 of 2
Problems - Codeforces 21/06/24, 11:07 AM

Each of the next 𝑇 lines contains a string 𝑠 denoting the string that you are required to make alphabetical.

Output
For each test case, print the minimum number of letters that must be inserted in order to make your password alphabetical, in a new line.

input
input
1
zgwabcdegqwdhiklmnopqadsrtuwevxzgwe

output
output
5

In this sample, one optimal way to do the task is to insert 'f', 'j', 's', 'w', and 'y' to obtain the alphabetical string.

"zgwabcdefgqwdhijklmnopqadsrstuwevwxyzgwe", which contains all the english letters in alphabetical order (as seen in bold). Since there is no way
to do this with fewer than 5 insertions, the answer is 5.

C. A Big Binary Number


1 second, 256 megabytes

You are given a number 𝑛 . Find the decimal value of the number that is formed by concatenating the binary representation of the first 𝑛 positive
9
integers. Print the answer modulo 10 + 7 .

Example: Consider 𝑛 = 2.

The binary representation of 1 is 1.


The binary representation of 2 is 10.
So, the number formed after concatenation is 110. In decimals, this is equivalent to 6.

Constraints

1 ≤ 𝑛 ≤ 109

Input
The first line contains an integer 𝑛 .

Output
9
Print the answer modulo 10 + 7.

input
input
3

output
output
27

Binary representation of 1: 1
Binary representation of 2: 10
Binary representation of 3: 11

Hence, the number formed after concatenation is 11011 which is 27.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov


The only programming contests Web 2.0 platform

https://codeforces.com/gym/531207/problems Page 2 of 2

You might also like