def solve(lines):
    pairs = [(int(lines[((i * 18) + 5)][6:]), int(lines[((i * 18) + 15)][6:])) for i in range(14)]
    stack = []
    constraints = {}
    for (i, (a, b)) in enumerate(pairs):
        if (a > 0):
            stack.append((i, b))
        else:
            (k, bk) = stack.pop()
            constraints[i] = (k, (bk + a))
    max_ans = {}
    min_ans = {}
    for (i, (k, d)) in constraints.items():
        max_ans[i] = min(9, (9 + d))
        max_ans[k] = min(9, (9 - d))
        min_ans[i] = max(1, (1 + d))
        min_ans[k] = max(1, (1 - d))
    p1 = ''.join((str(max_ans[i]) for i in range(14)))
    p2 = ''.join((str(min_ans[i]) for i in range(14)))
    print('Star 1:', p1)
    print('Star 2:', p2)
    submit(p1, part='a', day=24, year=2021)
    submit(p2, part='b', day=24, year=2021)
def solve(lines):
    pairs = [(int(lines[((i * 18) + 5)][6:]), int(lines[((i * 18) + 15)][6:])) for i in range(14)]
    stack = []
    constraints = {}
    for (i, (a, b)) in enumerate(pairs):
        if (a > 0):
            stack.append((i, b))
        else:
            (k, bk) = stack.pop()
            constraints[i] = (k, (bk + a))
    max_ans = {}
    min_ans = {}
    for (i, (k, d)) in constraints.items():
        max_ans[i] = min(9, (9 + d))
        max_ans[k] = min(9, (9 - d))
        min_ans[i] = max(1, (1 + d))
        min_ans[k] = max(1, (1 - d))
    p1 = .join((str(max_ans[i]) for i in range(14)))
    p2 = .join((str(min_ans[i]) for i in range(14)))
    print('Star 1:', p1)
    print('Star 2:', p2)
    submit(p1, part='a', day=24, year=2021)
    submit(p2, part='b', day=24, year=2021)