TORONTO KIDS COMPUTER CLUB | PMCA Friday 19:00 Python Homework 21.05.21.
19507
post-template-default,single,single-post,postid-19507,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

PMCA Friday 19:00 Python Homework 21.05.21.

26 May PMCA Friday 19:00 Python Homework 21.05.21.

Question 1(continue to think and go to question 2):

Little Marin spent all his day generating test data for COCI. He simply couldn’t make it work, so he had a nervous breakdown and can’t even see clearly anymore. Every time he blinks while reading, the letters in a word get mixed up so that the letters from the second half of the word (the shorter half, if the length is an odd number) “jump in” between the letters from the first half in the following way:

  • the last letter “jumps in” between the first and the second letter
  • the penultimate letter “jumps in” between the second and the third letter
  • the kth letter from the end “jumps in” between the kth and the (k+1)th letter from the beginning

For example, the word abcdef would become afbecd after blinking.

If Marin blinks again, the same thing happens. After two blinks, the word abcdef becomes adfcbe.

Marin has decided to write a program to help him determine what’s exactly written on the screen. Unfortunately, after a day’s work, he’s simply too tired and he needs your help. You are given X, the number of blinks, and the word Marin sees on the screen. Write a program to solve the mystery for Marin and determine what was actually the word before he blinked X times.

Input

The first line of input contains a positive integer X (1X1000000000), the number of times Marin blinked.

The second line of input contains the word from the screen, its length being from the interval [3,1000].

The word will consist only from small letters of English alphabet.

Output

The first and only line of output must contain the original word, before Marin blinked X times.

Sample Input 1
4
acefdb

Sample Output 1
abcdef

Explanation for Sample Output 1
The word gets altered in the following order:
abcdef,afbecd,adfcbe,aedbfc,acefdb.

Sample Input 2
1000
aaaaaa

Sample Output 2
aaaaaa

Sample Input 3
11
srama

Sample Output 3
sarma

Question 2:
You are in charge of adding cheese topping to a pizza prepared for a special customer. This pizza is a very long rectangular strip. It is divided into N slices, numbered 1 to N from left to right. To add cheese topping to the pizza, you have a special machine that can add 1 unit of cheese on each slice in a consecutive group of slices (for example, you can add 1 unit of cheese on each slice between slice 2 and 4 inclusive, adding a total of 3 units of cheese). Each slice can carry an unlimited amount of cheese.

You plan to run the machine R times, each time adding 1 unit of cheese to each slice in a given range.

The customer is on a diet. When he eats the section of pizza from slice x to slice y, inclusive, he would like to know how many units of cheese he is consuming.

Input Specification
The first line will contain the integer N, the length of your long pizza.

The second line will consist of two space-separated integers x and y, indicating that the customer is planning to eat every slice between slice x and slice y inclusive.

The third line will contain the integer R, the number of times you plan to run the topping machine.

The following R lines will each describe one planned run of the topping machine using 2 space-separated integers, l and r (lr), indicating that the machine will add 1 unit of cheese onto each slice between slices l and r, inclusive.

Output Specification
Please output the total number of units of cheese on all of the slices the customer is planning to eat.

Sample Input
10
3 5
3
2 6
4 5
3 3

Sample Output
6

Explanation of Sample Output
After running the machine three times, the amount of cheese on each slice of pizza is as follows:
Slice #: 1 2 3 4 5 6 7 8 9 10
Cheese: 0 1 2 2 2 1 0 0 0 0
Therefore, slices 3−5 have a total of 6 units of cheese.

No Comments

Sorry, the comment form is closed at this time.