# %%

from itertools import *
from more_itertools import *

with open("input.txt") as file:
    lines = file.read()

groups = [[set(p) for p in g.split("\n")] for g in lines.strip().split("\n\n")]


def solve1(groups):
    return sum(len(last(accumulate(g, set.union))) for g in groups)


def solve2(groups):
    return sum(len(last(accumulate(g, set.intersection))) for g in groups)


print(f"{solve1(groups)=}")
print(f"{solve2(groups)=}")

assert 6903 == solve1(groups)
assert 3493 == solve2(groups)

7f0a9d9d6a31b51616a03464b795409a568924ad
<mask token>


def solve1(groups):
    return sum(len(last(accumulate(g, set.union))) for g in groups)


def solve2(groups):
    return sum(len(last(accumulate(g, set.intersection))) for g in groups)


<mask token>

<mask token>
with open('input.txt') as file:
    lines = file.read()
<mask token>


def solve1(groups):
    return sum(len(last(accumulate(g, set.union))) for g in groups)


def solve2(groups):
    return sum(len(last(accumulate(g, set.intersection))) for g in groups)


print(f'solve1(groups)={solve1(groups)!r}')
print(f'solve2(groups)={solve2(groups)!r}')
assert 6903 == solve1(groups)
assert 3493 == solve2(groups)

<mask token>
with open('input.txt') as file:
    lines = file.read()
groups = [[set(p) for p in g.split('\n')] for g in lines.strip().split('\n\n')]


def solve1(groups):
    return sum(len(last(accumulate(g, set.union))) for g in groups)


def solve2(groups):
    return sum(len(last(accumulate(g, set.intersection))) for g in groups)


print(f'solve1(groups)={solve1(groups)!r}')
print(f'solve2(groups)={solve2(groups)!r}')
assert 6903 == solve1(groups)
assert 3493 == solve2(groups)

from itertools import *
from more_itertools import *
with open('input.txt') as file:
    lines = file.read()
groups = [[set(p) for p in g.split('\n')] for g in lines.strip().split('\n\n')]


def solve1(groups):
    return sum(len(last(accumulate(g, set.union))) for g in groups)


def solve2(groups):
    return sum(len(last(accumulate(g, set.intersection))) for g in groups)


print(f'solve1(groups)={solve1(groups)!r}')
print(f'solve2(groups)={solve2(groups)!r}')
assert 6903 == solve1(groups)
assert 3493 == solve2(groups)

# %%

from itertools import *
from more_itertools import *

with open("input.txt") as file:
    lines = file.read()

groups = [[set(p) for p in g.split("\n")] for g in lines.strip().split("\n\n")]


def solve1(groups):
    return sum(len(last(accumulate(g, set.union))) for g in groups)


def solve2(groups):
    return sum(len(last(accumulate(g, set.intersection))) for g in groups)


print(f"{solve1(groups)=}")
print(f"{solve2(groups)=}")

assert 6903 == solve1(groups)
assert 3493 == solve2(groups)
