eolymp
bolt
Try our new interface for solving problems
Problems

Rotate List

Rotate List

Time limit 1 second
Memory limit 64 MiB

Given an array of integers. Create a Linked List from these numbers.

Write a method RotateRight that rotates the Linked List to the right by k places, where k is non-negative integer.

For example, if List = 12345NULL and k = 2, after rotation List = 45123NULL.

Write the code according to the next interface:

class Node

{

public:

int data;

Node *next;

Node() : next(NULL) {};

Node(int data, Node *next = NULL) : data(data), next(next) {};

};

class List

{

public:

Node *head, *tail;

List() : head(NULL), tail(NULL) {};

void AddToTail(int val); // Add number val to the end of the Linked List

void RotateRight(int k) // Rotate the list to the right by k places

void Print(void); // Print the elements of Linked List

};

You can create (use) additional methods if needed.

Input data

The first line contains number n (1n100). The second line contains n integers. Each of the next lines contains one number k (0k10^9).

Output data

For each number k print in the separate line the elements of the List after rotation to the right by k places. Print the elements of Linked List using Print method.

Examples

Input example #1
5
1 2 3 4 5
1
2
3
4
55
Output example #1
5 1 2 3 4 
3 4 5 1 2 
5 1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 
Author Mykhailo Medvediev
Source C++ Language