

from __future__ import annotations

import math



class        _a		:


					'''simple docstring'''






					def __init__(					self       ,			A__     ):
						A__				:       Union[str, Any]	  =						size
						# approximate the overall size of segment tree with given value
						A__				:       Any	  =						[0 for i in range(0       ,			4 * size     )]
						# create array to store lazy update
						A__				:       Union[str, Any]	  =						[0 for i in range(0       ,			4 * size     )]
						A__				:       Optional[Any]	  =						[0 for i in range(0       ,			4 * size     )]  # flag for lazy update






					def     __A     (					self       ,			A__     ):
						return idx * 2






					def     __A     (					self       ,			A__     ):
						return idx * 2 + 1






					def     __A     (					self       ,			A__       ,			A__       ,			A__       ,			A__     ):
						if left_element == right_element:
							A__				:       Optional[int]	  =						a[left_element - 1]
						else:
							A__				:       Any	  =						(left_element + right_element) // 2
							self.build(self.left(A__     )       ,			A__       ,			A__       ,			A__     )
							self.build(self.right(A__     )       ,			mid + 1       ,			A__       ,			A__     )
							A__				:       List[Any]	  =						max(
							    self.segment_tree[self.left(A__     )]       ,			self.segment_tree[self.right(A__     )]     )






					def     __A     (					self       ,			A__       ,			A__       ,			A__       ,			A__       ,			A__       ,			A__     ):
						if self.flag[idx] is True:
							A__				:       Dict	  =						self.lazy[idx]
							A__				:       str	  =						False
							if left_element != right_element:
								A__				:       Any	  =						self.lazy[idx]
								A__				:       Dict	  =						self.lazy[idx]
								A__				:       Dict	  =						True
								A__				:       int	  =						True

						if right_element < a or left_element > b:
							return True
						if left_element >= a and right_element <= b:
							A__				:       Optional[int]	  =						val
							if left_element != right_element:
								A__				:       Optional[int]	  =						val
								A__				:       List[str]	  =						val
								A__				:       Dict	  =						True
								A__				:       Union[str, Any]	  =						True
							return True
						A__				:       List[Any]	  =						(left_element + right_element) // 2
						self.update(self.left(A__     )       ,			A__       ,			A__       ,			A__       ,			A__       ,			A__     )
						self.update(self.right(A__     )       ,			mid + 1       ,			A__       ,			A__       ,			A__       ,			A__     )
						A__				:       Union[str, Any]	  =						max(
						    self.segment_tree[self.left(A__     )]       ,			self.segment_tree[self.right(A__     )]     )
						return True






					def     __A     (					self       ,			A__       ,			A__       ,			A__       ,			A__       ,			A__     ):
						if self.flag[idx] is True:
							A__				:       Optional[Any]	  =						self.lazy[idx]
							A__				:       Tuple	  =						False
							if left_element != right_element:
								A__				:       Any	  =						self.lazy[idx]
								A__				:       Union[str, Any]	  =						self.lazy[idx]
								A__				:       Dict	  =						True
								A__				:       Dict	  =						True
						if right_element < a or left_element > b:
							return -math.inf
						if left_element >= a and right_element <= b:
							return self.segment_tree[idx]
						A__				:       Optional[int]	  =						(left_element + right_element) // 2
						A__				:       Optional[Any]	  =						self.query(self.left(A__     )       ,			A__       ,			A__       ,			A__       ,			A__     )
						A__				:       Optional[int]	  =						self.query(self.right(A__     )       ,			mid + 1       ,			A__       ,			A__       ,			A__     )
						return max(A__       ,			A__     )






					def __str__(					self     ):
						return str([self.query(1       ,			1       ,			self.size       ,			A__       ,			A__     ) for i in range(1       ,			self.size + 1     )]     )


if __name__ == "__main__":
	A_			:					Dict    			=     [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
	A_			:					Any    			=     15
	A_			:					Optional[Any]    			=     SegmentTree(size)
	segt.build(1, 1, size, A)
	print(segt.query(1, 1, size, 4, 6))
	print(segt.query(1, 1, size, 7, 11))
	print(segt.query(1, 1, size, 7, 12))
	segt.update(1, 1, size, 1, 3, 111)
	print(segt.query(1, 1, size, 1, 15))
	segt.update(1, 1, size, 7, 8, 235)
	print(segt)






import argparse
import copy

def 		UpperCamelCase   (lowercase_:					Any   )	-> Union[str, Any]:
	A__				:       int	  =						{}

	with open(lowercase_   ) as f:
		for line in f:
			if line.split()[0] not in dict_of_neighbours:
				A__				:       int	  =						[]
				_list.append([line.split()[1], line.split()[2]]   )
				A__				:       Any	  =						_list
			else:
				dict_of_neighbours[line.split()[0]].append(
				    [line.split()[1], line.split()[2]]   )
			if line.split()[1] not in dict_of_neighbours:
				A__				:       Optional[int]	  =						[]
				_list.append([line.split()[0], line.split()[2]]   )
				A__				:       Any	  =						_list
			else:
				dict_of_neighbours[line.split()[1]].append(
				    [line.split()[0], line.split()[2]]   )

	return dict_of_neighbours

def 		UpperCamelCase   (lowercase_:					Tuple       , lowercase_:					List[str]   )	-> Tuple:

	with open(lowercase_   ) as f:
		A__				:       List[Any]	  =						f.read(1   )
	A__				:       Union[str, Any]	  =						start_node

	A__				:       List[Any]	  =						[]

	A__				:       str	  =						start_node

	A__				:       List[str]	  =						0
	while visiting not in first_solution:
		A__				:       Dict	  =						10000
		for k in dict_of_neighbours[visiting]:
			if int(k[1]   ) < int(lowercase_   ) and k[0] not in first_solution:
				A__				:       Tuple	  =						k[1]
				A__				:       Optional[Any]	  =						k[0]

		first_solution.append(lowercase_   )
		A__				:       Optional[int]	  =						distance_of_first_solution + int(lowercase_   )
		A__				:       str	  =						best_node

	first_solution.append(lowercase_   )

	A__				:       Any	  =						0
	for k in dict_of_neighbours[first_solution[-2]]:
		if k[0] == start_node:
			break
		position += 1

	A__				:       int	  =						(
	    distance_of_first_solution
	    + int(dict_of_neighbours[first_solution[-2]][position][1]   )
	    - 10000
	)
	return first_solution, distance_of_first_solution

def 		UpperCamelCase   (lowercase_:					Any       , lowercase_:					str   )	-> Any:
	A__				:       int	  =						[]

	for n in solution[1:-1]:
		A__				:       Union[str, Any]	  =						solution.index(lowercase_   )
		for kn in solution[1:-1]:
			A__				:       List[Any]	  =						solution.index(lowercase_   )
			if n == kn:
				continue

			A__				:       Union[str, Any]	  =						copy.deepcopy(lowercase_   )
			A__				:       int	  =						kn
			A__				:       Optional[int]	  =						n

			A__				:       Dict	  =						0

			for k in _tmp[:-1]:
				A__				:       Dict	  =						_tmp[_tmp.index(lowercase_   ) + 1]
				for i in dict_of_neighbours[k]:
					if i[0] == next_node:
						A__				:       List[Any]	  =						distance + int(i[1]   )
			_tmp.append(lowercase_   )

			if _tmp not in neighborhood_of_solution:
				neighborhood_of_solution.append(_tmp   )

	A__				:       Optional[Any]	  =						len(neighborhood_of_solution[0]   ) - 1

	neighborhood_of_solution.sort(key=lambda lowercase_   : x[index_of_last_item_in_the_list]   )
	return neighborhood_of_solution

def 		UpperCamelCase   (lowercase_:					List[str]       , lowercase_:					Tuple       , lowercase_:					Dict       , lowercase_:					Dict       , lowercase_:					Tuple   )	-> Union[str, Any]:
	A__				:       Union[str, Any]	  =						1
	A__				:       List[str]	  =						first_solution
	A__				:       Dict	  =						[]
	A__				:       Union[str, Any]	  =						distance_of_first_solution
	A__				:       Any	  =						solution

	while count <= iters:
		A__				:       Optional[int]	  =						find_neighborhood(lowercase_       , lowercase_   )
		A__				:       Union[str, Any]	  =						0
		A__				:       str	  =						neighborhood[index_of_best_solution]
		A__				:       int	  =						len(lowercase_   ) - 1

		A__				:       List[str]	  =						False
		while not found:
			A__				:       Dict	  =						0
			while i < len(lowercase_   ):
				if best_solution[i] != solution[i]:
					A__				:       Any	  =						best_solution[i]
					A__				:       Optional[int]	  =						solution[i]
					break
				A__				:       Any	  =						i + 1

			if [first_exchange_node, second_exchange_node] not in tabu_list and [
			    second_exchange_node,
			    first_exchange_node,
			] not in tabu_list:
				tabu_list.append([first_exchange_node, second_exchange_node]   )
				A__				:       List[str]	  =						True
				A__				:       List[Any]	  =						best_solution[:-1]
				A__				:       Optional[Any]	  =						neighborhood[index_of_best_solution][best_cost_index]
				if cost < best_cost:
					A__				:       Tuple	  =						cost
					A__				:       int	  =						solution
			else:
				A__				:       List[Any]	  =						index_of_best_solution + 1
				A__				:       Tuple	  =						neighborhood[index_of_best_solution]

		if len(lowercase_   ) >= size:
			tabu_list.pop(0   )

		A__				:       Any	  =						count + 1

	return best_solution_ever, best_cost

def 		UpperCamelCase   (lowercase_:					Union[str, Any]=None   )	-> List[str]:
	A__				:       Union[str, Any]	  =						generate_neighbours(args.File   )

	A__  ,  A__				:       int	  =						generate_first_solution(
	    args.File       , lowercase_   )

	A__  ,  A__				:       str	  =						tabu_search(
	    lowercase_       , lowercase_       , lowercase_       , args.Iterations       , args.Size       , )

	print(f"""Best solution: {best_sol}, with total distance: {best_cost}."""   )


if __name__ == "__main__":
	A_			:					str    			=     argparse.ArgumentParser(description='Tabu Search')
	parser.add_argument(
	    '-f',
	    '--File',
	    type=str,
	    help='Path to the file containing the data',
	    required=True,
	)
	parser.add_argument(
	    '-i',
	    '--Iterations',
	    type=int,
	    help='How many iterations the algorithm should perform',
	    required=True,
	)
	parser.add_argument(
	    '-s', '--Size', type=int, help='Size of the tabu list', required=True
	)

	# Pass the arguments to main method
	main(parser.parse_args())



