Problem:
Problem A: Cache Control Mr. Haskins is working on tuning a database system. The database is a simple associative storage that contains key-value pairs. In this database, a key is a distinct identification (ID) number and a value is an object of any type. In order to boost the performance, the database system has a cache mechanism. The cache can be accessed much faster than the normal storage, but the number of items it can hold at a time is limited. To implement caching, he selected least recently used (LRU) algorithm: when the cache is full and a new item (not in the cache) is being accessed, the cache discards the least recently accessed entry and adds the new item. You are an assistant of Mr. Haskins. He regards you as a trusted programmer, so he gave you a task. He wants you to investigate the cache entries after a specific sequence of accesses. Input The first line of the input contains two integers N and M . N is the number of accessed IDs, and M is the size of the cache. These values satisfy the following condition: 1 ≤ N , M ≤ 100000. The following N lines, each containing one ID, represent the sequence of the queries. An ID is a positive integer less than or equal to 10 9 . Output Print IDs remaining in the cache after executing all queries. Each line should contain exactly one ID. These IDs should appear in the order of their last access time, from the latest to the earliest. Sample Input and Output Input #1 3 2
1
2
3 Output #1 3
2 Input #2 5 3
1
2
3
4
1 Output #2 1
4
3

Solution (Python):
N,M=map(int,raw_input().split())
L=[input() for i in range(N)]
S=set()
cnt=0
for i in range(N):
    if L[N-i-1] not in S:
        print L[N-i-1]
        S.add(L[N-i-1])
        cnt+=1
    if cnt==M:
        break

Solution (Python):
N, M = map(int, raw_input().split(' '))

q = [ int(input()) for _ in range(N) ]
poll = set()

cnt = 0

for _ in reversed(q):
	if not _ in poll:
		print(_)
		
		cnt = cnt + 1
		
		if cnt == M:
			break	
		
		poll.add(_)