xaviers-assignment

Xavier is a computer science student.He is given a task by his teacher the task is to 
generate a code which accepts an array of n integers.He now has to select an integer from this array but there is a trick in selection of integer from the array.
                   For the selection process he first has to accept an integer m less than the size of array,then he has to delete the  mth element from this array,then again he starts counting from the next element after the deleted element in a form of loop like a circular array and deletes the m th element from that position.He continues this process until a single integer remains.
                    Now after he has one integer remaining in that array he has to check whether it is odd or even.If that number is odd than he has to print all odd numbers present in the original array else he has to print all even numbers present in the original array. But the ouput must be in sorted manner.

INPUT:

First line contains integer n for size of array.
Second line inputs the integer array.
third line inputs the value of m.

OUTPUT:

The set of odd or even numbers as per the task.

CONSTRAINTS

3<n<100
1<m<n.

SAMPLE INPUT
6
3 5 7 1 2 8
3

SAMPLE OUTPUT
1 3 5 7

Explanation

The first line inputs no of integer that is 6
The next line has the integer 3,5 7,1,2,8 then 3 is given as input .
so,the third element is deleted now new array is 3,5,1,2,8 now begin from 1 and delete the third element from there so new array is 3,5,1,2.Now the process continues from beginning as the deleted element was the last element of array so we again begin from starting.
This process is continued untill a single no. remains in the array.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
x=input()
n=int(x)
a=[]
x=input()
x=x.split()
for i in x:
	a.append([int(i),True])
x=input()
m=int(x)

def noofelement(array):
	coun=0
	for i in range(len(array)):
		if array[i][1]==True:
			coun=coun+1
	return coun
	
def getSingleValue(array):
	for i in range(len(array)):
		if array[i][1]==True:
			return array[i][0]
			
def getEven(array):
	val=''
	for i in range(len(array)):
		if array[i][0]%2==0:
			val.append(array[i][0])
	val.sort()
	return val
	
def getOdd(array):
	val=[]
	for i in range(len(array)):
		if array[i][0]%2!=0:
			val.append(array[i][0])
	val.sort()
	return val
	
loop=noofelement(a)
while loop>1:

	count=0
	i=0
	while i <m:	
		if a[count][1]==False:
			count=count+1
			if count>=len(a):
				count=0
			continue
		if i==(m-1):
			a[count][1]=False
		count=count+1
		if count>=len(a):
			count=0
		i=i+1
	loop=noofelement(a)
check=getSingleValue(a)
if check%2==0:
	out=(getEven(a))
else:
	out=(getOdd(a))
o=''
for i in out:
	o=o+str(i)+' '
print(o)


def josephus(ls, skip):
	skip -= 1
	idx = skip
	while len(ls) > 1:
		ls.pop(idx)
		idx = (idx + skip) % len(ls)
	return ls[0]

n = int(input())
l = list(map(int,input().split()))
l1 = l[::]
skip = int(input())
num = josephus(l1,skip)
if num%2==0:
	q = [i for i in l if i%2==0]
	print(" ".join(map(str,sorted(q))))
else:
	q = [i for i in l if i%2!=0]
	print(" ".join(map(str,sorted(q))))


n = int(input())
A = input().split()
for i in range(0,n):
	A[i] = int(A[i])
B = A
m = int(input())
count = 0
first = 0
while count < n-1:
	first += m
	first%=n-count
	count+=1
if(A[first]%2==0):
	A.sort()
	for i in range(0,n):
		if(A[i]%2==0):print(A[i], end=' ')
if(A[first]%2==1):
	A.sort()
	for i in range(0,n):
		if(A[i]%2==1):print(A[i], end=' ')


n = eval(input())
array = list(map(int, input().split()))
m = eval(input())-1

tmp = array
orig_m = m
deleted = []

while len(deleted) != len(array)-1:
	if array[m] in deleted:
		m += 1
		continue
	deleted.append(array[m])
	array = array[m+1:] + array[0:m+1]
	m = orig_m

remained = (set(array) - set(deleted)).pop()
array = []
for a in tmp:
	if remained%2 and a%2:
		array.append(a)
	elif not remained%2 and not a%2:
		print(array.append(a))
		
for e in sorted(array):
	print(e, end=' ')


from collections import deque
def deletes(arr, step):     
	arr = deque(arr)
	while len(arr) > 1:
		arr.rotate(1-step)
		arr.popleft()
	return arr[0]

inlen = eval(input())
arr = list(map(int, input().split()))
step= eval(input())
left= deletes(arr, step)
arrs = list(map(str, arr))
ans = []
if left & 0:
	for x in arr:
		if x % 2 == 0:
			ans.append(x)
else:
	for x in arr:
		if x % 2 == 1:
			ans.append(x)
print(" ".join(map(str, sorted(ans))))            
			


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n=int(input())
a=[int(x) for x in input().split(' ')]
im=int(input())
temp=[x for x in a]

def output(a,x):
	a.sort()
	if x:
		for i in a:
			if(i%2==0):
				print(i, end=' ')
	else:
		for i in a:
			if(i%2!=0):
				print(i, end=' ')

m=im-1
while len(temp) !=1:
	#print("Removing ",temp[m])
	#print(m)
	temp.remove(temp[m])
	#print(temp)
	m+=im-1
	m%=len(temp)
	#print "new value of m",m
	
if temp[0] % 2 ==0:
	output(a,1)
else:
	output(a,0)