def re_arrange(arr, n):
	def right_rotate(arr, n, out_of_place, cur):
		temp = arr[cur]
		for i in range(cur, out_of_place, -1):
			arr[i] = arr[i - 1]
		arr[out_of_place] = temp
		return arr
	
	out_of_place = -1
	for index in range(n):
		if (out_of_place >= 0):
			if ((arr[index] >= 0 and arr[out_of_place] < 0) or
			(arr[index] < 0 and arr[out_of_place] >= 0)):
				arr = right_rotate(arr, n, out_of_place, index)
				if (index-out_of_place > 2):
					out_of_place += 2
				else:
					out_of_place = - 1
		if (out_of_place == -1):
			if ((arr[index] >= 0 and index % 2 == 0) or
			 (arr[index] < 0 and index % 2 == 1)):
				out_of_place = index
	return arr
def re_arrange(o, n):
    def right_rotate(o, n, out_of_place, cur):
        temp = o[cur]
        for i in range(cur, out_of_place, -1):
            o[i] = o[i - 1]
        o[out_of_place] = temp
        return o
    out_of_place = -1
    for index in range(n):
        if out_of_place >= 0:
            if (
                (o[index] >= 0 and o[out_of_place] < 0)
                or
               
                (o[index] < 0 and o[out_of_place] >= 0)
            ):
                o = right_rotate(o, n, out_of_place, index)
                if index - out_of_place > 2:
                    out_of_place += 2
                else:
                    out_of_place = -1
        if out_of_place == -1:
            if (o[index] >= 0 and index % 2 == 0) or (o[index] < 0 and index % 2 == 1):
                out_of_place = index
    return o