from collections import defaultdict
def solve(lst):
found, total = 0, len(set(lst))
hist = defaultdict(int)
l = 0
ans = len(lst)
for r in xrange(len(lst)):
occ = hist[lst[r]] = hist[lst[r]] + 1
if occ == 1:
found += 1
while l <= r and found == total:
ans = min(ans, r - l + 1)
occ = hist[lst[l]] = hist[lst[l]] - 1
if not occ:
found -= 1
l += 1
return ans
ZnJvbSBjb2xsZWN0aW9ucyBpbXBvcnQgZGVmYXVsdGRpY3QKCmRlZiBzb2x2ZShsc3QpOgogICAgZm91bmQsIHRvdGFsID0gMCwgbGVuKHNldChsc3QpKQogICAgaGlzdCA9IGRlZmF1bHRkaWN0KGludCkKICAgIGwgPSAwCiAgICBhbnMgPSBsZW4obHN0KQogICAgZm9yIHIgaW4geHJhbmdlKGxlbihsc3QpKToKICAgICAgICBvY2MgPSBoaXN0W2xzdFtyXV0gPSBoaXN0W2xzdFtyXV0gKyAxCiAgICAgICAgaWYgb2NjID09IDE6CiAgICAgICAgICAgIGZvdW5kICs9IDEKICAgICAgICB3aGlsZSBsIDw9IHIgYW5kIGZvdW5kID09IHRvdGFsOgogICAgICAgICAgICBhbnMgPSBtaW4oYW5zLCByIC0gbCArIDEpCiAgICAgICAgICAgIG9jYyA9IGhpc3RbbHN0W2xdXSA9IGhpc3RbbHN0W2xdXSAtIDEKICAgICAgICAgICAgaWYgbm90IG9jYzoKICAgICAgICAgICAgICAgIGZvdW5kIC09IDEKICAgICAgICAgICAgbCArPSAxCiAgICByZXR1cm4gYW5z