Efficient table-lookup computation
Score: 679685 (A=64, B=6)

T = {
    # three digits: first day of the month, 0-based (12 entries)
    &quot;001&quot;: &quot;4&quot;, &quot;002&quot;: &quot;0&quot;, &quot;003&quot;: &quot;0&quot;, &quot;004&quot;: &quot;3&quot;, &quot;005&quot;: &quot;5&quot;, &quot;006&quot;: &quot;1&quot;, &quot;007&quot;: &quot;3&quot;, &quot;008&quot;: &quot;6&quot;, &quot;009&quot;: &quot;2&quot;, &quot;010&quot;: &quot;4&quot;, &quot;011&quot;: &quot;0&quot;, &quot;012&quot;: &quot;2&quot;, 
    # two digits ab: lookup table for (a + b) % 7 (52 entries)
    &quot;00&quot;: &quot;0&quot;, &quot;01&quot;: &quot;1&quot;, &quot;02&quot;: &quot;2&quot;, &quot;03&quot;: &quot;3&quot;, &quot;04&quot;: &quot;4&quot;, &quot;05&quot;: &quot;5&quot;, &quot;06&quot;: &quot;6&quot;, 
    &quot;10&quot;: &quot;1&quot;, &quot;11&quot;: &quot;2&quot;, &quot;12&quot;: &quot;3&quot;, &quot;13&quot;: &quot;4&quot;, &quot;14&quot;: &quot;5&quot;, &quot;15&quot;: &quot;6&quot;, &quot;16&quot;: &quot;0&quot;, 
    &quot;20&quot;: &quot;2&quot;, &quot;21&quot;: &quot;3&quot;, &quot;22&quot;: &quot;4&quot;, &quot;23&quot;: &quot;5&quot;, &quot;24&quot;: &quot;6&quot;, &quot;25&quot;: &quot;0&quot;, &quot;26&quot;: &quot;1&quot;, 
    &quot;30&quot;: &quot;3&quot;, &quot;31&quot;: &quot;4&quot;, &quot;32&quot;: &quot;5&quot;, &quot;33&quot;: &quot;6&quot;, &quot;34&quot;: &quot;0&quot;, &quot;35&quot;: &quot;1&quot;, &quot;36&quot;: &quot;2&quot;, 
    &quot;40&quot;: &quot;4&quot;, &quot;41&quot;: &quot;5&quot;, &quot;42&quot;: &quot;6&quot;, &quot;43&quot;: &quot;0&quot;, &quot;44&quot;: &quot;1&quot;, &quot;45&quot;: &quot;2&quot;, &quot;46&quot;: &quot;3&quot;, 
    &quot;50&quot;: &quot;5&quot;, &quot;51&quot;: &quot;6&quot;, &quot;52&quot;: &quot;0&quot;, &quot;53&quot;: &quot;1&quot;, &quot;54&quot;: &quot;2&quot;, &quot;55&quot;: &quot;3&quot;, &quot;56&quot;: &quot;4&quot;, 
    &quot;60&quot;: &quot;6&quot;, &quot;61&quot;: &quot;0&quot;, &quot;62&quot;: &quot;1&quot;, &quot;63&quot;: &quot;2&quot;, &quot;64&quot;: &quot;3&quot;, &quot;65&quot;: &quot;4&quot;, &quot;66&quot;: &quot;5&quot;, &quot;67&quot;: &quot;6&quot;, &quot;68&quot;: &quot;0&quot;, &quot;69&quot;: &quot;1&quot;, 
}

# (d2 + 6) % 7 = (d2 - 1) % 7
d2_0d1 = T[&quot;6&quot; + d2]

# (d2 - 1 + 1*d1) % 7
d2_1d1 = T[d1 + d2_0d1]

# (d2 - 1 + 2*d1) % 7
d2_2d1 = T[d1 + d2_1d1]

# (d2 - 1 + 3*d1) % 7 = (d2 - 1 + 10*d1) % 7 = (d1d2 - 1) % 7
day_of_month = T[d1 + d2_2d1]

month_start = T[&quot;0&quot; + m1 + m2]

output = T[month_start + day_of_month]

Try it online! and try the Generator / Testing program!