def METHOD_NAME(outpath, dtype, inpath):
    print('building fbformat:' + dtype)
    episodes = list(convert_file(inpath))
    # save the raw json version for span selection task (default)
    with PathManager.open(os.path.join(outpath, dtype + '.txt'), 'w') as fout1:
        for ep in episodes:
            fout1.write(json.dumps(ep) + "\n")
    # save the file for passage selection task
    with PathManager.open(os.path.join(outpath, dtype + '.passage.txt'), 'w') as fout2:
        for dic in episodes:
            lq = dic["query"]
            if dtype != "test":
                ans = [
                    cleanup(d["passage_text"])
                    for d in dic["passages"]
                    if d["is_selected"] == 1
                ]
                if not ans:
                    continue
            else:
                # ground truth for test data is not available yet
                ans = []
            cands = [cleanup(d["passage_text"]) for d in dic["passages"]]
            if cands and not ans:
                cands.append("")
            if not cands:
                continue
            fout2.write('1 {}\t{}\t\t{}\n'.format(lq, '|'.join(ans), '|'.join(cands)))