package main

import (
	"fmt"
	"io"
	"log"
)

func main() {
	var input []string
	var readInp string
	for {
		_, err := fmt.Scan(&readInp)
		if err != nil {
			if err != io.EOF {
				log.Fatal(err)
			}
			break
		}
		input = append(input, readInp)
	}

	santaResults := santa(input, 0, 2)
	santaResults["0;0"] = 1
	roboResults := santa(input, 1, 2)
	for i, k := range roboResults {
		santaResults[i] += k
	}
	fmt.Printf("Santa delivered presents to %d houses\n", len(santaResults))
}

func santa(input []string, offset, numWorkers int) map[string]int {
	var numDir int
	houses := make(map[string]int)
	var currX, currY int
	for _, k := range input {
		for _, r := range k {
			if numDir >= offset {
				if (numDir+offset)%(numWorkers) == 0 {
					// We've waited, now start visiting
					switch r {
					case '^':
						currY--
					case '>':
						currX++
					case 'v':
						currY++
					case '<':
						currX--
					}
					houseCoords := fmt.Sprintf("%d;%d", currX, currY)
					houses[houseCoords]++
				}
			}
			numDir++
		}
	}

	return houses
}