"Oook!", said the librarian when he found that a mistake had occured. Mrakoplas had mixed up the alphabet again. Books in the library are sorted according to the first letter and those with the same first letter are sorted according to the number of pages. As usually Mrakoplas had interchanged two letters of the alphabet and now it is necessary to exchange blocks of books starting with these letters to make the ordering of books correct. But this is a big problem, because there is no empty shelf in the library.
Task: There are given numbers n,i,j,k,l, where 1 <= i <= j < k <= l <= n and an array a[1..n] of integers. Let's cut array into five blocks: a[1]...a[i-1], a[i]...a[j], a[j+1]...a[k-1], a[k]...a[l], a[l+1]...a[n] (some blocks can have zero length). Your task is to rearange the array so that the second and the fourth block will be exchanged, i.e. array will look like this: a[1]...a[i-1], a[k]...a[l], a[j+1]...a[k-1], a[i]...a[j], a[l+1]...a[n]. Besides array a you can use only variables of type integer (i.e. don't use other arrays, files , etc. )
Example:
Input:
n=7, i=2, j=3, k=6, l=6
a=(1,2,3,4,5,6,7)
Output:
a=(1,6,4,5,2,3,7)
Task: Write a program which reads a date of Zoro's death, today's date and writes how many days have elapsed since his death. Clerks in the insurance company are lazy and untidy so it can happen that some cases will be carried out after some years. Thus the difference between given dates can be longer than one hundred days. You can assume that given dates are in years 1901-1999.
Lord Zoltan is a big philanderer. N beautiful ladies live near his castle. Each lady has a castle with a lot of beautiful towers and that's what Zoltan likes most. Nowadays Zoltan is afraid of jealous robbers waiting for him on some roads. Of course he doesn't use these roads and he wants to know if it is possible to visit each beautiful lady using only safe roads.
Task: There are given numbers N and K, where N is the number of beautiful ladies and K is the number of safe roads. Castles are numbered 1...N+1, Zoltan's castle has a number N+1. Each road connects two castles and is given by their numbers. Write a program which reads numbers N and K followed by a list of safe roads and computes if it is possible for Zoltan to visit each lady (Zoltan can travel through several castles).
Example:
Input:
N=3, K=2
roads:
4 3
1 3
Output:
NO (he cannot visit lady in castle with number 2)
Task: Help the students to prove to Mr. Bracket, that under the sun there are better mathematicians than he is. Find (your program will surely help you) arithmetic sequence of prime numbers as long as possible. Arithmetic sequence is a sequence of numbers, where the difference between each two consecutive numbers is equal. The length of this sequence is the number of its members. We will value the sequence you will find, but also the way you looked for the sequence. Please, enclose the program and describe in words the method of searching.
Example:
An example of such sequence with the length 3 is 3, 7, 11.
Suddenly it became dark around the frog Julia. Really. Bad Moricko threw his hat on her. It would be nothing strange for a present but you don't know yet that Moricko's hat has a rectangular ground-plane with size M x N. Julia started to jump and call for a help: "Kvaaaaak". She jumped so frantically that she didn't notice how she was knocking at the hat and she's reflecting his walls with the same angle of reflection as the angle of collision was. While jumping she realized with amazement that the hat is at a strawberry field. When she leaped to a strawberry, she ate it. So it wasn't so bad at last.
Task: There are given P, N, M and an array a[1..N,1..M]. At every square of array a is a number of strawberries that are there situated. Further there are given x and y which determine a position of frog and dx, dy determining direction of her first jump (if Julia does not knocks at a wall, after the first jump her coordinates will be [x+dx,y+dy]). Write a program that will simulate P jumps of frog. If there are still some strawberries at her new position, Julia will eat one of them. Using characters illustrate the whole situation after every jump of Julia at the screen. At the end of simulation write the number of strawberries which Julia ate.
Example:
Let dx=-2, dy=-4. Then a frog with position [6,4] jumps to the position [4,1] (after knocking a wall) and after other jump she will be at the position [2,5].