Page not loading? Try clicking here.
Placeholder

#1071

Divisors and Multiples 1s 32MB

Problems

Given a list of integers, output the sum of those that are divisors of the given number, and the sum of those that are multiples of the given number.

For example, if the 6 integers 2, 3, 5, 12, 18, 24 are given and the input number is 12:

  • The divisors of 12 among the given integers are 2, 3, 12.

  • The multiples of 12 among the given integers are 12, 24.


Input

The first line contains an integer n (1 \le n \le 40), the number of integers.

The second line contains the nnn integers.

The third line contains the integer m (1 \le m \le 100), for which divisors and multiples are to be found.


Output

Print two lines:

  • The sum of all divisors of mmm among the given integers.

  • The sum of all multiples of mmm among the given integers.


Example

6

2 3 5 12 18 24
12
17

36


Source

JUNGOL - comkiwer

You must sign in to write code.