from json import dumps def minCubes(game:str) -> int: cubes = { "red": 1, "green": 1, "blue": 1, } rounds = game.split(";") for r in rounds: r = r.split(", ") for c in r: c = c.lstrip().split(" ") cubes[c[1]] = max(cubes[c[1]], int(c[0])) return cubes["red"]*cubes["green"]*cubes["blue"] def populateGames(g:list): populated = {} for game in g: name, g = game.split(":") populated[name] = minCubes(g) return populated def main(): games = [] game_dict = {} with open("input.in", "r") as f: for line in f: games.append(line.strip()) game_dict = populateGames(games) print(sum(game_dict.values())) if __name__ == "__main__": main()