+/AoC

advent of code

git clone https://git.julia.blue/+/AoC

Joseph RyanAdd 20202c992d4

master
22.0 KiB972 linesraw
1import sys
2import copy
3from functools import reduce
4import string
5import itertools
6from collections import defaultdict, deque
7
8with open("input") as f:
9    temp = f.read().split("\n\n")
10
11p1 = deque(map(int,temp[0].split()[2:]))
12p2 = deque(map(int,temp[1].split()[2:]))
13
14while p1 and p2:
15    x += 1
16    a = p1.popleft()
17    b = p2.popleft()
18    if a > b:
19        p1.append(a)
20        p1.append(b)
21    else:
22        p2.append(b)
23        p2.append(a)
24if not p1:
25    p1 = p2
26
27print(sum(n * (i+1) for i,n in enumerate(list(p1)[::-1])))
28
29sys.exit()
30
31with open("myinput") as f:
32    temp = f.read().split("\n\n")
33
34# 0 1 2 3 == right down left up
35
36tiles = set()
37for tile in temp:
38    _, title, *data = tile.split()
39    n = int(title[:-1])
40    l = len(data[0])
41    r = "".join(data[-i - 1][-1] for i in range(l))
42    d = data[-1]
43    l = "".join(data[-i - 1][0] for i in range(l))
44    u = data[0]
45    flip = lambda x: x[::-1]
46    tiles.add(
47        (
48            n,
49            (  # rotations
50                (r, d, l, u),
51                (u, r, d, l),
52                (l, u, r, d),
53                (d, l, u, r),
54                # flips (along y)
55                (l, flip(d), r, flip(u)),
56                (flip(u), l, flip(d), r),
57                (r, flip(u), l, flip(d)),
58                (flip(d), r, flip(u), l),
59                # flops (along x)
60                (flip(r), u, flip(l), d),
61                (d, flip(r), u, flip(l)),
62                (flip(l), d, flip(r), u),
63                (u, flip(l), d, flip(r)),
64            ),
65        )
66    )
67
68corner = None
69total = 1
70for a in sorted(tiles):
71    found = [False] * 4
72    current = a[1][0]
73    for b in tiles:
74        if a == b:
75            continue
76        orientations = b[1]
77        for o in orientations:
78            if o[2] == current[0]:
79                found[0] = True
80            if o[3] == current[1]:
81                found[1] = True
82            if o[0] == current[2]:
83                found[2] = True
84            if o[1] == current[3]:
85                found[3] = True
86    if sum(found) == 2:
87        if found == [True, False, False, True]:
88            corner = a
89        total *= a[0]
90
91print(total)
92
93
94class Wildcard(object):
95    def __eq__(self, other):
96        return True
97
98
99size = int(len(tiles) ** 0.5)
100
101
102def apply_constraint(board, tile, work, pos):
103    x, y = pos
104    r = range(0, size)
105    if (x + 1, y) not in board and x + 1 in r:
106        if type(work[(x + 1, y)][2]) is str:
107            print("AHHHH")
108            sys.exit()
109        work[(x + 1, y)][2] = tile[0]
110    if (x - 1, y) not in board and x - 1 in r:
111        if type(work[(x - 1, y)][0]) is str:
112            print("AHHHH")
113            sys.exit()
114        work[(x - 1, y)][0] = tile[2]
115    if (x, y + 1) not in board and y + 1 in r:
116        if type(work[(x, y + 1)][1]) is str:
117            print("AHHHH")
118            sys.exit()
119        work[(x, y + 1)][1] = tile[3]
120    if (x, y - 1) not in board and y - 1 in r:
121        if type(work[(x, y - 1)][3]) is str:
122            print("AHHHH")
123            sys.exit()
124        work[(x, y - 1)][3] = tile[1]
125
126
127def dfs(board, tiles, work):
128    if not tiles:
129        return board
130    if len(tiles) == 1:
131        print()
132        for k, v in sorted(board.items()):
133            print(k, v)
134        for thing in work.values():
135            print([i if type(i) is str else None for i in thing])
136        print(tiles)
137        # sys.exit()
138    # if len(tiles) % 2 == 0:
139    #     print(" " * (len(tiles) // 2) + "X")
140    potential = set(work.keys())
141    for pos in potential:
142        for tile in tiles:
143            for o in tile[1]:
144                if o == tuple(work[pos]):
145                    newboard = copy.deepcopy(board)
146                    newwork = copy.deepcopy(work)
147                    newtiles = copy.deepcopy(tiles)
148
149                    newtiles.remove(tile)
150                    del newwork[pos]
151                    newboard[pos] = (o, tile[0])
152                    apply_constraint(newboard, o, newwork, pos)
153
154                    finished = dfs(newboard, newtiles, newwork)
155                    if finished:
156                        return finished
157
158
159n, orientations = corner
160tiles.remove(corner)
161board = {(0, 0): (orientations[0], n)}
162work = defaultdict(lambda: [Wildcard()] * 4)
163apply_constraint(board, board[(0, 0)][0], work, (0, 0))
164
165board = dfs(board, tiles, work)
166
167for b in board:
168    print(b, board[b][1])
169
170print(
171    board[(0, 0)][1]
172    * board[(0, size - 1)][1]
173    * board[(size - 1, 0)][1]
174    * board[(size - 1, size - 1)][1]
175)
176
177sys.exit()
178
179with open("myinput") as f:
180    lines, messages = f.read().split("\n\n")
181    lines = lines.split("\n")
182    messages = messages.split()
183
184stuff = dict()
185for line in lines:
186    k, rest = line.split(":")
187    k = int(k)
188    rest = rest.split()
189
190    if rest[0][0] == '"':
191        stuff[k] = str(rest[0][1])
192        continue
193
194    stuff[k] = []
195    temp = []
196    for current in rest:
197        if current == "|":
198            stuff[k].append(temp)
199            temp = []
200        else:
201            temp.append(int(current))
202    stuff[k].append(temp)
203
204print(stuff)
205print(messages)
206
207
208def validate(msg, rule, i):
209    print(i, msg, stuff[rule])
210    if type(stuff[rule]) is str:
211        return msg[i] == rule
212    for seq in stuff[rule]:
213        temp = i
214        good = True
215        for r in seq:
216            pass
217            # if (i:=validate(msg, )) == -1
218        # print(list((msg, r, i + n) for n, r in enumerate(seq)))
219        if all(validate(msg, r, i + n) for n, r in enumerate(seq)):
220            return True
221    return False
222
223
224print(validate(messages[0], 0, 0))
225# print(sum(validate(msg, 0, 0) for msg in messages))
226
227
228sys.exit()
229
230with open("input") as f:
231    lines = f.readlines()
232
233
234def evaluate(tokens, lhs, i):
235    if tokens[i] == "(":
236        return evalexpr(tokens, i + 1)
237    elif tokens[i] == "+":
238        result, newi = evaluate(tokens, lhs, i + 1)
239        return lhs + result, newi
240    elif tokens[i] == "*":
241        result, newi = evaluate(tokens, lhs, i + 1)
242        while newi < len(tokens) and tokens[newi] == "+":
243            result, newi = evaluate(tokens, result, newi)
244        return lhs * result, newi
245    else:
246        return int(tokens[i]), i + 1
247
248
249def evalexpr(tokens, i):
250    acc = 0
251    while i < len(tokens) and tokens[i] != ")":
252        acc, i = evaluate(tokens, acc, i)
253    return acc, i + 1
254
255
256tokenize = lambda line: line.replace(")", " )").replace("(", "( ").split()
257print(sum(evalexpr(tokenize(line), 0)[0] for line in lines))
258
259# print(evalexpr(0)[0])
260
261sys.exit()
262
263with open("input") as f:
264    lines = enumerate(map(str.strip, f.readlines()))
265
266current = set()
267for i, line in lines:
268    for j, c in enumerate(line):
269        if c == "#":
270            current.add((0, 0, j, i))
271
272
273def adj(pos):
274    x, y, z = pos
275    return set(
276        (
277            (i + x, j + y, k + z)
278            for i in range(-1, 2)
279            for j in range(-1, 2)
280            for k in range(-1, 2)
281            if any((i, j, k))
282        )
283    )
284
285
286def adj4(pos):
287    w, x, y, z = pos
288    return set(
289        (
290            (h + w, i + x, j + y, k + z)
291            for h in range(-1, 2)
292            for i in range(-1, 2)
293            for j in range(-1, 2)
294            for k in range(-1, 2)
295            if any((h, i, j, k))
296        )
297    )
298
299
300for _ in range(6):
301    neighbors = defaultdict(int)
302    for pos in current:
303        for n in adj4(pos):
304            neighbors[n] += 1
305
306    new_current = set()
307    for pos, n in neighbors.items():
308        if pos in current and 2 == n or n == 3:
309            new_current.add(pos)
310
311    current = new_current
312
313print(len(current))
314
315sys.exit()
316
317with open("input") as f:
318    raw = f.read()
319    lines = raw.split("\n\n")
320
321rules = dict()
322kinds = []
323departure_rules = []
324for line in lines[0].split("\n"):
325    temp = line.split("-")
326    a = temp[0].split()[-1]
327    b = temp[1].split()[0]
328    c = temp[1].split()[-1]
329    d = temp[2].split()[0]
330    kind = temp[0].split(":")[0]
331    rules[kind] = (range(int(a), int(b) + 1), range(int(c), int(d) + 1))
332    kinds.append(kind)
333    if kind.split()[0] == "departure":
334        departure_rules.append(kind)
335
336flatrules = [r for rule in rules.values() for r in rule]
337yours = list(map(int, lines[1].split()[2].split(",")))
338nearby = [list(map(int, x.split(","))) for x in lines[2].split()[2:]]
339flatnearby = [n for near in nearby for n in near]
340
341
342valid_tickets = []
343total = 0
344for near in nearby:
345    rip = False
346    for n in near:
347        if not any(n in r1 or n in r2 for r1, r2 in rules.values()):
348            total += n
349            rip = True
350            break
351    if not rip:
352        valid_tickets.append(near)
353
354print(total)
355nearby = valid_tickets
356
357N = range(len(kinds))
358possibilities = [set(kinds) for _ in N]
359for near in nearby:
360    for k, (r1, r2) in rules.items():
361        for i in N:
362            if near[i] not in r1 and near[i] not in r2:
363                possibilities[i].discard(k)
364
365cantbe = set()
366answers = [0] * len(kinds)
367stuff = sorted(enumerate(possibilities), key=lambda p: len(p[1]))
368for p in stuff:
369    i = p[0]
370    answers[i] = p[1] - cantbe
371    cantbe |= answers[i]
372    answers[i] = answers[i].pop()
373
374print(
375    reduce(
376        (lambda x, y: x * y),
377        (yours[i] for i, k in enumerate(answers) if k.split()[0] == "departure"),
378    )
379)
380
381sys.exit()
382
383stuff = list(map(int, "8,13,1,0,18,9".split(",")))
384
385current = stuff[-1]
386stuff = {n: i for i, n in enumerate(stuff[:-1])}
387
388N = 30000000
389for i in range(len(stuff), N - 1):
390    # print("turn", i, "- current:", current)
391    to_add = current
392    if current in stuff:
393        # print("current was last seen at", stuff[current])
394        current = i - stuff[current]
395    else:
396        current = 0
397    stuff[to_add] = i
398
399print(current)
400
401sys.exit()
402
403with open("input") as f:
404    lines = f.readlines()
405
406setbits = 0
407clearbits = 0
408mem = dict()
409for line in lines:
410    comp = line.split()
411    if comp[0] == "mask":
412        clearbits = ~int(
413            comp[-1].replace("1", "X").replace("0", "1").replace("X", "0"), 2
414        )
415        setbits = int(comp[-1].replace("X", "0"), 2)
416    elif comp[0][:3] == "mem":
417        addr = int(comp[0][4:-1])
418        temp = int(comp[-1])
419        temp &= clearbits
420        temp |= setbits
421        mem[addr] = temp
422
423print(sum(mem.values()))
424
425mask = None
426writes = []
427for line in lines:
428    comp = line.split()
429    if comp[0] == "mask":
430        mask = comp[-1][::-1]
431    elif comp[0][:3] == "mem":
432        addr = int(comp[0][4:-1])
433        finaladdr = [0] * 36
434        for i in range(36):
435            if mask[i] == "1":
436                finaladdr[i] = "1"
437            elif mask[i] == "X":
438                finaladdr[i] = "X"
439            elif ((addr >> i) & 1) == 1:
440                finaladdr[i] = "1"
441            else:
442                finaladdr[i] = "0"
443        writes.append((finaladdr[::-1], int(comp[-1])))
444
445current = writes[-1][0]
446actualwrites = [(current[::], writes[-1][1])]
447
448# print("writes")
449# for w in writes:
450#     print(''.join(w[0]), w[1])
451# print("\nactual")
452# for w in actualwrites:
453#     print(''.join(w[0]), w[1])
454# print()
455
456for w in writes[-2::-1]:
457    some = False
458    thismask = w[0]
459    oldcurrent = current[::]
460    count = 0
461    for i in range(36):
462        if current[i] == "1" and thismask[i] != "1":
463            count += 1
464            current[i] = "X"
465            some = True
466            if thismask[i] == "X":
467                thismask[i] = "0"
468        elif current[i] == "0" and thismask[i] != "0":
469            count += 1
470            current[i] = "X"
471            some = True
472            if thismask[i] == "X":
473                thismask[i] = "1"
474    if some:
475        print("current", "".join(oldcurrent))
476        print("this   ", "".join(thismask))
477        print(count, "\n")
478        actualwrites.append((thismask[::], w[1]))
479
480for w in actualwrites:
481    print("".join(w[0]), w[1])
482
483print(sum(2 ** addr.count("X") * val for addr, val in actualwrites))
484
485sys.exit()
486
487with open("input") as f:
488    first, second = f.readlines()
489
490earliest = int(first)
491busses = [int(x) for x in second.split(",") if x != "x"]
492
493
494def solvea():
495    i = earliest
496    while True:
497        for b in busses:
498            if i % b == 0:
499                print(b * (i - earliest))
500                return
501        i += 1
502
503
504solvea()
505
506busses = [(int(x), n) for n, x in enumerate(second.split(",")) if x != "x"]
507# print(busses)
508# sys.exit()
509for i in range(len(busses)):
510    busses[i] = busses[i][0], (busses[i][0] * 2 - busses[i][1]) % busses[i][0]
511
512print(busses)
513
514bus, off = list(zip(*busses))
515print(bus, off)
516
517
518def extended_eucalid(a, b):
519    x, y, u, v = 0, 1, 1, 0
520    while a != 0:
521        q, r = b // a, b % a
522        m, n = x - u * q, y - v * q
523        b, a, x, y, u, v = a, r, u, v, m, n
524    return x, y
525
526
527def crt_solve_for_x(off, bus):
528    terms = len(off)
529    constants = [1] * terms
530    product = reduce((lambda x, y: x * y), bus)
531
532    for i in range(terms):
533        other_prod = product // bus[i]
534        eucalid_result = extended_eucalid(other_prod, bus[i])[0]
535        if eucalid_result < 0:
536            eucalid_result += bus[i]
537        constants[i] = other_prod * eucalid_result * off[i]
538
539    return sum(constants) % product, product
540
541
542print(crt_solve_for_x([0, 3, 4], [3, 4, 5]))  # should = 39
543
544from math import gcd
545
546for i in bus:
547    for j in bus:
548        if i != j and gcd(i, j) != 1:
549            print("NOPE", i, j)
550            sys.exit()  # they're all coprime
551
552print(crt_solve_for_x(off, bus))
553
554sys.exit()
555
556with open("input") as f:
557    lines = f.readlines()
558
559d = 0
560directions = ["E", "S", "W", "N"]
561x = 0
562y = 0
563for line in lines:
564    command, amount = line[0], int(line[1:])
565    if command == "F":
566        command = directions[d]
567
568    if command == "R":
569        d = (d + amount // 90) % 4
570    elif command == "L":
571        d = (d + 4 - amount // 90) % 4
572    elif command == "N":
573        y += amount
574    elif command == "S":
575        y -= amount
576    elif command == "E":
577        x += amount
578    elif command == "W":
579        x -= amount
580
581print(abs(x) + abs(y))
582
583x = y = 0
584wx = 10
585wy = -1
586for line in lines:
587    command, amount = line[0], int(line[1:])
588    if command == "L":
589        command = "R"
590        amount = 360 - amount
591    # print(x, y, "waypoint", wx, wy)
592    # print(command, amount)
593
594    if command == "F":
595        x += wx * amount
596        y += wy * amount
597    elif command == "R":
598        # print(wx, wy)
599        for _ in range(amount // 90):
600            (wx, wy) = (-wy, wx)
601            # print(wx, wy)
602        # print()
603    elif command == "N":
604        wy -= amount
605    elif command == "S":
606        wy += amount
607    elif command == "E":
608        wx += amount
609    elif command == "W":
610        wx -= amount
611
612print(abs(x) + abs(y))
613
614sys.exit()
615
616with open("input") as f:
617    grid = list(map(lambda x: list(x.strip()), f.readlines()))
618
619h = len(grid[0])
620w = len(grid)
621
622
623def neighbors(x, y, g):
624    directions = set(itertools.product(range(-1, 2), range(-1, 2)))
625    directions.discard((0, 0))
626    result = set()
627    for (xi, yi) in directions:
628        newx = max(min(w - 1, x + xi), 0)
629        newy = max(min(h - 1, y + yi), 0)
630        result.add((newx, newy))
631    result.discard((x, y))
632    return sum(g[j][k] == "#" for (j, k) in result)
633
634
635def extended_neighbors(x, y, g):
636    directions = set(itertools.product(range(-1, 2), range(-1, 2)))
637    directions.discard((0, 0))
638    total = 0
639    for (xi, yi) in directions:
640        (cx, cy) = (x, y)
641        while True:
642            cx += xi
643            cy += yi
644            if cx not in range(0, w) or cy not in range(0, h) or g[cx][cy] == "L":
645                break
646            if g[cx][cy] == "#":
647                total += 1
648                break
649
650    return total
651
652
653def printgrid(g):
654    for row in g:
655        print("".join(row))
656    print("\n")
657
658
659temp = copy.deepcopy(grid)
660
661while True:
662    changed = False
663    for x in range(w):
664        for y in range(h):
665            current = grid[x][y]
666            total = extended_neighbors(x, y, grid)
667            if current == "L" and total == 0:
668                temp[x][y] = "#"
669                changed = True
670            elif current == "#" and total >= 5:
671                temp[x][y] = "L"
672                changed = True
673    # printgrid(grid)
674    if not changed:
675        break
676    grid = copy.deepcopy(temp)
677
678print(sum(sum(x == "#" for x in row) for row in grid))
679
680sys.exit()
681
682with open("input") as f:
683    l = list(map(int, f.readlines()))
684
685dist = 25
686target = None
687for i in range(dist, len(l)):
688    before = l[i - dist : i]
689    subs = [l[i] - n for n in before]
690    if not any(n in subs for n in before):
691        target = l[i]
692        break
693
694print(target)
695
696i = 0
697j = 0
698total = l[0]
699while True:
700    if total == target:
701        r = l[i : j + 1]
702        print(max(r) + min(r))
703        sys.exit()
704
705    while total < target:
706        j += 1
707        total += l[j]
708
709    while total > target:
710        total -= l[i]
711        i += 1
712
713
714sys.exit()
715
716with open("input") as f:
717    l = [0] + sorted(map(int, f.readlines()))
718    l += [l[-1] + 3]
719
720diffs = [0, 0, 0]
721for i in range(len(l) - 1):
722    diff = l[i + 1] - l[i]
723    diffs[diff - 1] += 1
724
725print(diffs[0] * diffs[2])
726
727memo = {n: None for n in l}
728memo[l[-1]] = 1
729
730
731def calculate(n):
732    if n not in memo:
733        return 0
734    if not memo[n]:
735        memo[n] = calculate(n + 1) + calculate(n + 2) + calculate(n + 3)
736    return memo[n]
737
738
739print(calculate(0))
740
741sys.exit()
742
743with open("input") as f:
744    lines = list(enumerate(map(str.split, f.readlines())))
745
746pc = 0
747acc = 0
748seen = set()
749
750while True:
751    if pc in seen:
752        print(pc, acc)
753        break
754    seen.add(pc)
755    ins = lines[pc][1][0]
756    if ins == "jmp":
757        pc += int(lines[pc][1][1])
758    else:
759        if ins == "acc":
760            acc += int(lines[pc][1][1])
761        pc += 1
762
763
764def check(newlines):
765    pc = 0
766    acc = 0
767    seen = set()
768    target = len(newlines)
769
770    while pc < target:
771        if pc in seen:
772            return
773        seen.add(pc)
774        ins = newlines[pc][1][0]
775        if ins == "jmp":
776            pc += int(newlines[pc][1][1])
777        else:
778            if ins == "acc":
779                acc += int(newlines[pc][1][1])
780            pc += 1
781
782    print(pc, acc)
783    sys.exit()
784
785
786for i in range(len(lines)):
787    ins = lines[i][1][0]
788    if ins == "nop":
789        newlines = copy.deepcopy(lines)
790        newlines[i][1][0] = "jmp"
791        check(newlines)
792    elif ins == "jmp":
793        newlines = copy.deepcopy(lines)
794        newlines[i][1][0] = "nop"
795        check(newlines)
796
797print("didnt find")
798
799sys.exit()
800
801with open("input") as f:
802    lines = list(map(str.strip, f.readlines()))
803
804parents = defaultdict(list)
805children = defaultdict(list)
806for line in lines:
807    words = line.split()
808    current = " ".join(words[0:2])
809    if len(words) == 7:
810        children[current] = 1
811        continue
812    for i in range(4, len(words), 4):
813        children[current].append((" ".join(words[i + 1 : i + 3]), int(words[i])))
814        parents[(" ".join(words[i + 1 : i + 3]))].append(
815            (current, int(words[i])),
816        )
817
818contain = set(i[0] for i in parents["shiny gold"])
819
820old_size = len(contain)
821new_size = 0
822
823while old_size != new_size:
824    new_size = old_size
825    to_add = set()
826    for name in contain:
827        for parent in parents[name]:
828            to_add.add(parent[0])
829    contain |= to_add
830    old_size = len(contain)
831
832print(len(contain))
833
834
835def count_children(name):
836    print(name, "\t", children[name])
837    if children[name] == 1:
838        return 1
839    return 1 + sum(n * count_children(s) for s, n in children[name])
840
841
842print(count_children("shiny gold") - 1)
843sys.exit()
844
845with open("input") as f:
846    raw = f.read()
847print(sum(len(set(group.replace("\n", ""))) for group in raw.split("\n\n")))
848print(sum(len(set.intersection(*map(set, line.split()))) for line in raw.split("\n\n")))
849
850sys.exit()
851
852with open("input") as f:
853    stuff = map(str.strip, f.readlines())
854
855ids = set()
856for line in stuff:
857    fb = line[:7].replace("F", "0").replace("B", "1")
858    lr = line[7:].replace("L", "0").replace("R", "1")
859    ids.add(int(fb, 2) * 8 + int(lr, 2))
860
861possible = set()
862for i in range(1, 127):
863    for j in range(8):
864        possible.add(i * 8 + j)
865
866print(len(possible), len(ids))
867print(max(ids))
868print(possible - ids)
869sys.exit()
870
871with open("input") as f:
872    raw = f.read()
873    lines = raw.split("\n\n")
874    passports = [dict(elem.split(":") for elem in line.split()) for line in lines]
875
876
877fields = ("byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid")
878
879# def verify(port):
880#     return all(f in port for f in fields)
881
882
883def verify(port):
884    if not all(f in port for f in fields):
885        return False
886    year = port["byr"]
887    if not year.isdigit() or not 1920 <= int(year) <= 2002:
888        return False
889    year = port["iyr"]
890    if not year.isdigit() or not 2010 <= int(year) <= 2020:
891        return False
892    year = port["eyr"]
893    if not year.isdigit() or not 2020 <= int(year) <= 2030:
894        return False
895    height = port["hgt"]
896    if height[-2:] == "in":
897        n = height[:-2]
898        if not n.isdigit() or not 59 <= int(n) <= 76:
899            return False
900    elif height[-2:] == "cm":
901        n = height[:-2]
902        if not n.isdigit() or not 150 <= int(n) <= 193:
903            return False
904    else:
905        return False
906    hair = port["hcl"]
907    if (
908        hair[0] != "#"
909        or len(hair) != 7
910        or not all(c in string.hexdigits for c in hair[1:])
911    ):
912        return False
913    if port["ecl"] not in ("amb", "blu", "brn", "gry", "grn", "hzl", "oth"):
914        return False
915    if len(port["pid"]) != 9 or not port["pid"].isdigit():
916        return False
917    return True
918
919
920print(sum((verify(x) for x in passports)))
921sys.exit()
922
923dots = [[1 if c == "." else 0 for c in line] for line in lines]
924
925
926def traverse(right, down):
927    x = 0
928    y = 0
929    count = 0
930    while y < len(dots):
931        count += not (dots[y][x])
932        x += right
933        x %= len(dots[0])
934        y += down
935    return count
936
937
938# print()
939# for row in dots:
940#     print("".join(map(str, row)))
941# print(dots)
942# print()
943
944# print(sum(n.count('#') for n in dots))
945
946# print(traverse(3, 1))
947print(
948    traverse(1, 1) * traverse(3, 1) * traverse(5, 1) * traverse(7, 1) * traverse(1, 2)
949)
950
951import sys
952
953sys.exit()
954count = 0
955
956for line in lines:
957    temp = line.split()
958    least, most = map(int, temp[0].split("-"))
959    target = temp[1][0]
960    print(least, most, target)
961    pw = temp[2]
962    if (
963        pw[least - 1] == target
964        and pw[most - 1] != target
965        or pw[least - 1] != target
966        and pw[most - 1] == target
967    ):
968        count += 1
969    # if least <= temp[2].count(target) <= most:
970    #     count += 1
971
972print(count)