N = gets.to_i A = gets.split(" ").map{|s| s.to_i} d = Array.new(N) {Array.new(N, 0)} 0.upto(N-1) {|i| 0.upto(N-1) {|j| d[i][j] = A[i] * A[j] if i != j } } notvisit = 1.upto(N-1).to_a visited = "1" i = 0 while notvisit.length > 0 do max = 0 max_i = nil notvisit.each {|j| dj = d[i][j] if dj > max then max = dj max_i = j end } i = max_i visited << " #{i+1}" notvisit.delete(i) end visited << " 1" puts visited