cache = []
IDX_KEY=0
IDX_VALUE=1

CACHE_LEN_UNLIMITED=-1
KEY_VALUE_DIFFERENT_ERROR='Warning: number of keys and values are not the same'

### Assumptions:s
# - 1 ≤ C ≤ 1000 or C = −1
# - 1 ≤ Nk,Nv ≤ 1000
# - Input keys can be converted to integers
# - Input keys are unique, no duplicates
# - Input values are non-null string

def negative(num):
  return 0 - num

# 1st input, Input keys can be converted to integers
LRU_CACHE_LEN = int(input())
# 2nd input, keys
KEYS = input()
# 3rd input, values
VALUES = input()

def convert_to_int(input_list):
  output = []
  for i in range(0,len(input_list)):
    output.append(int(input_list[i]))
  return output

def create_cache_element(list_keys, list_values):
  output = []
  for i in range(0,len(list_keys)):
    output.append([list_keys[i], list_values[i]])
  return output

# REQUIREMENTS: Keys must be stored as integers.
# ASSUMPTIONS: Input keys are unique, no duplicates
# ASSUMPTIONS: Input keys can be converted to integers
list_keys = convert_to_int(KEYS.split(','))
len_list_keys = len(list_keys)

# REQUIREMENTS: Values must be stored as strings.
# ASSUMPTIONS: Input values are non-null string
list_values = list(VALUES.split(','))
len_list_values = len(list_values)

# HANDLE: If the numbers of keys and values are different, 
# prints "Warning: number of keys and values are not the same" and outputs an empty cache.
if (len_list_keys != len_list_values):
  print(KEY_VALUE_DIFFERENT_ERROR)

# HANDLE: If the cache capacity is infinity
elif (LRU_CACHE_LEN == CACHE_LEN_UNLIMITED):
  cache = create_cache_element(list_keys, list_values)

# HANDLE: If the cache capacity is larger than or equal to the number of data items
elif (LRU_CACHE_LEN >= len_list_keys):
  cache = create_cache_element(list_keys, list_values)

# HANDLE:
# If the cache capacity is smaller than the number of data items, 
# keeps only those that are near the end of the inputs (right) up to the capacity
elif (LRU_CACHE_LEN < len_list_keys):
  temp = create_cache_element(list_keys, list_values)
  slice_start = negative(LRU_CACHE_LEN)
  cache = temp[slice_start:]

else:
  pass

print(cache)
