@@ -0,0 +1,1205 @@
+#! /usr/bin/python%0A%0Aimport sys, os%0A%0Aif len(sys.argv) %3C 3:%0A    print('Translate input data in AAAI%5C'15 format to separate config, men, women files.')%0A    print('Usage: %7B%7D %3Cinput file%3E %3Coutput directory%3E'.format(sys.argv%5B0%5D))%0A    sys.exit(1)%0A%0Ainfile = sys.argv%5B1%5D%0Aoutdir = sys.argv%5B2%5D%0A%0Aif os.path.exists(outdir):%0A    raise OSError('Output directory %7B%7D already exists!'.format(outdir))%0Aos.makedirs(outdir)%0A%0Awith open(infile, 'r') as fh:%0A    ctx = %5B line.strip() for line in fh %5D%0A    # Filter empty lines%0A    ctx = %5B line for line in ctx if line %5D%0A%0A# First line%0Aconfig = ctx%5B0%5D%0Asize = int(config.split()%5B0%5D)%0Aassert size * 2 + 1 == len(ctx)%0A%0A# Men preference matrix, index starts from 1%0Amenlist = ctx%5B1:1+size%5D%0Amenlist = %5B '%7B%7D: %7B%7D%5Cn'.format(idx+1, menlist%5Bidx%5D) for idx in xrange(size) %5D%0A%0A# Women preference matrix, index starts from 1%0Awomenlist = ctx%5B1+size:1+2*size%5D%0Awomenlist = %5B '%7B%7D: %7B%7D%5Cn'.format(idx+1, womenlist%5Bidx%5D) for idx in xrange(size) %5D%0A%0Awith open(os.path.join(outdir, 'config.txt'), 'w') as fh:%0A    fh.writelines(%5Bconfig%5D)%0A%0Awith open(os.path.join(outdir, 'men.list'), 'w') as fh:%0A    fh.writelines(menlist)%0A%0Awith open(os.path.join(outdir, 'women.list'), 'w') as fh:%0A    fh.writelines(womenlist)%0A%0A

Add utility to translate input data format.