import gzip


def read_sid_cid_map(filename):
  """
  Read SID->CID map.

  Parameters
  ----------
  filename : str
    SID->CID map.
  """
  if filename.endswith('.gz'):
    f = gzip.open(filename)
  else:
    f = open(filename)
  try:
    sid_cid = {}
    for line in f:
      sid, cid = line.split()
      assert int(sid) not in sid_cid
      sid_cid[int(sid)] = int(cid)
    return sid_cid
  finally:
    f.close()