## Codechef Python July Cook Off 2014

## Hi, here my performance in the July Cook Off 2014

Github Codechef Python July Cook Off 2014

**Problem Statement Copy-Paste**:

You had an array of integer numbers. You also had a beautiful operations called “Copy-Paste” which allowed you to copy any contiguous subsequence of your array and paste it in any position of your array. For example, if you have array [1, 2, 3, 4, 5] and copy it’s subsequence from the second to the fourth element and paste it after the third one, then you will get [1, 2, 3, 2, 3, 4, 4, 5] array. You remember that you have done a finite(probably zero) number of such operations over your initial array and got an array A as a result. Unfortunately you don’t remember the initial array itself, so you would like to know what could it be. You are interested by the smallest such array. So the task is to find the minimal size(length) of the array that A can be obtained from by using “Copy-Paste” operations.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case contains a single integer N denoting the number of elements in obtained array A. The second line contains N space-separated integers A1, A2, …, AN denoting the array.

Output

For each test case, output a single line containing the answer.

**My way**:

Here we only need to add all the elements to a set, and it will delete the repeated elements for us. Then, return the set.

Here **my code**:

cases = int(input()) for a in range(cases): n = int(input()) numbers = input().split() res = set(numbers) print(len(res))

**Problem Statement Sum Queries**:

Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B. Note that multiset may contain several elements with the same values. For example, if N equals to three, then A = {1, 2, 3}, B = {4, 5, 6} and C = {5, 6, 6, 7, 7, 7, 8, 8, 9}. Andrii has M queries about multiset C. Every query is defined by a single integer q. Andrii wants to know the number of times q is contained in C. For example, number 6 is contained two times, 1 is not contained in C at all.

Please, help Andrii to answer all the queries.

Input

The first line of the input contains two integers N and M. Each of the next M line contains one integer q, the query asked by Andrii.

Output

Output the answer for each query in separate lines as in example.

**My way**:

Here we need to read each query, and then we have three posibilities. If query is less or equal n + 1, then print 0, else if query is less or equal 2 * n + 1, then print query – n – 1, otherwise, print 3 * n – query + 1.

Here **my code**:

temp = input().split() n = int(temp[0]) queries = int(temp[1]) for i in range(queries): query = int(input()) if query <= n + 1: print(0) elif query <= (2 * n + 1): print(query - n - 1) else: print(3 * n - query + 1)

Thank you very much