from collections import defaultdict, deque, Counter
from itertools import combinations, combinations_with_replacement, permutations
import math
import numpy as np
from operator import add, mul, itemgetter, attrgetter
import re

CHALLENGE_DAY = "2"
REAL = open(CHALLENGE_DAY + ".txt").read()
SAMPLE_EXPECTED = 900
if SAMPLE_EXPECTED:
    SAMPLE = open(CHALLENGE_DAY + ".s.txt").read()
# SAMPLE_EXPECTED = 


def parse_lines(raw):
    # Groups.
    # groups = raw.split("\n\n")
    # return list(map(lambda group: group.split("\n"), groups))
    lines = raw.split("\n")
    return lines # raw
    # return list(map(lambda l: l.split(" "), lines)) # words.
    # return list(map(int, lines))
    # return list(map(lambda l: l.strip(), lines)) # beware leading / trailing WS

def solve(raw):
    parsed = parse_lines(raw)
    # Debug here to make sure parsing is good.
    ret = 0

    horiz = depth = aim = 0
    for line in parsed:
        dir, num = line.split(" ")
        num = int(num)
        if "forward" == dir:
            horiz += num
            depth += aim * num
        elif "down" == dir:
            aim += num
        elif "up" == dir:
            aim -= num
        else:
            assert None
        print(line, horiz, depth)
    return horiz * depth


if SAMPLE_EXPECTED != None:
    sample = solve(SAMPLE)
    if sample != SAMPLE_EXPECTED:
        print("SAMPLE FAILED: ", sample, " != ", SAMPLE_EXPECTED)
    assert sample == SAMPLE_EXPECTED
    print("\n*** SAMPLE PASSED ***\n")
else:
    print("Skipping sample")

solved = solve(REAL)
print("SOLUTION: ", solved)
import pandas as pd
df=pd.DataFrame([str(solved)])
df.to_clipboard(index=False,header=False)
print("COPIED TO CLIPBOARD")

from collections import defaultdict, deque, Counter
from itertools import combinations, combinations_with_replacement, permutations
import math
import numpy as np
from operator import add, mul, itemgetter, attrgetter
import re

CHALLENGE_DAY = "2"
REAL = open(CHALLENGE_DAY + ".txt").read()
SAMPLE_EXPECTED = 900
if SAMPLE_EXPECTED:
    SAMPLE = open(CHALLENGE_DAY + ".s.txt").read()
# SAMPLE_EXPECTED = 


def parse_lines(raw):
    # Groups.
    # groups = raw.split("\n\n")
    # return list(map(lambda group: group.split("\n"), groups))
    lines = raw.split("\n")
    return lines # raw
    # return list(map(lambda l: l.split(" "), lines)) # words.
    # return list(map(int, lines))
    # return list(map(lambda l: l.strip(), lines)) # beware leading / trailing WS

def solve(raw):
    parsed = parse_lines(raw)
    # Debug here to make sure parsing is good.
    ret = 0

    horiz = depth = aim = 0
    for line in parsed:
        dir, num = line.split(" ")
        num = int(num)
        if "forward" == dir:
            horiz += num
            depth += aim * num
        elif "down" == dir:
            aim += num
        elif "up" == dir:
            aim -= num
        else:
            assert None
        print(line, horiz, depth)
    return horiz * depth


if SAMPLE_EXPECTED != None:
    sample = solve(SAMPLE)
    if sample != SAMPLE_EXPECTED:
        print("SAMPLE FAILED: ", sample, " != ", SAMPLE_EXPECTED)
    assert sample == SAMPLE_EXPECTED
    print("\n*** SAMPLE PASSED ***\n")
else:
    print("Skipping sample")

solved = solve(REAL)
print("SOLUTION: ", solved)
import pandas as pd
df=pd.DataFrame([str(solved)])
df.to_clipboard(index=False,header=False)
print("COPIED TO CLIPBOARD")

# SAMPLE_EXPECTED = # Groups. # groups = raw.split("\n\n") # return list(map(lambda group: group.split("\n"), groups)) # raw # return list(map(lambda l: l.split(" "), lines)) # words. # return list(map(int, lines)) # return list(map(lambda l: l.strip(), lines)) # beware leading / trailing WS # Debug here to make sure parsing is good.