import os,sys
from pprint import pprint

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:
# - 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()

# REQUIREMENTS: Keys must be stored as integers.
# ASSUMPTIONS: Input keys are unique, no duplicates
# ASSUMPTIONS: Input keys can be converted to integers
list_keys = list(map(lambda x: int(x), 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 = list(map(lambda x: [x[IDX_KEY],x[IDX_VALUE]], zip(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 = list(map(lambda x: [x[IDX_KEY],x[IDX_VALUE]], zip(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 = list(map(lambda x: [x[IDX_KEY],x[IDX_VALUE]], zip(list_keys, list_values)))
  slice_start = negative(LRU_CACHE_LEN)
  cache = temp[slice_start:]

else:
  pass

print(cache)
