Problem

11 /11


List Generators

Theory Click to read/hide

List generators

The Python language allows you to solve many problems concisely and reliably. Let's list the main possibilities for filling an array. 1) Creating and populating an array can be written like this: A = [i for i in range(N)] # With N = 5, array A = [0,1,2,3,4] A = [i*i for i in range(N)] # With N = 5, array A = [0,1,4,9,16] for i in range(N) - loops through all i values ​​from 0 to N-1.

The next element of the array will contain the value that comes before the word for, in the first case i, in the second - i*i.

We get the same result using the following notation:
A = list(range(N)) # with N = 5, array A = [0,1,2,3,4]

2) You can write to the array not all values, but only those that satisfy a certain condition.
 
Example
Filling the array with all even numbers in the range 0 to 9. A = [i for i in range(10) if i % 2 == 0] print(*A) # array A = [0,2,4,6,8] In this case, you need to understand that the length of the array will be less than 10. 

3) Filling an array from the keyboard with elements that are located one per line can be done in two ways.
 
N=5 A = [0]*5 for i in range(N): A[i] = int(input())
A = [int(input()) for i in range(N)]
# each time the loop repeats,
# the input string is converted
# to an integer (using int)
# and this number is added to the array


4) Filling an array from the keyboard with elements that are all located on the same line is a bit more complicated. You need to read the string, split it into elements, and then convert each element to an integer s = input().split()  A = [int(i) for i in s]  or so A = list(map(int, input().split())) # built-in function list()   # transforms the sequence   # to mutable list

Array output

You can also display an array on the screen in different ways.
 
Standard way, used in many programming languages. Such a cycle can be written shorter. The value of х at each step of the loop is filled with the next element of the array. In Python, you can write like this.
for i in range(len(A)): print(A[i], end=" ") for x in A: print(x, end=" ")
print(*A)
# sign * in front of the name
# of the array means that
# needs to be converted
# array into a set of individual values

Problem

The input is the number N - the number of array elements. 
Next come two arrays of N integers each:
- elements of the first array go one per line;
- elements of the second array - all written in one line separated by a space.
Fill in two arrays and print their elements separated by a space in one line:
- the first array in the first line;
- the second array in the second line.
 
Examples
# Input Output
1 3
1
2
3
4 5 6
1 2 3
4 5 6