Buggy python submission (verdict: Runtime Error):
from datetime import date
from datetime import timedelta
import datetime

def is_leap_year(y):
    return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)

def leap_year_count(target_y,benchmark_y):
    target = target_y // 4 - target_y // 100 + target_y // 400
    benchmark = benchmark_y // 4 - benchmark_y // 100 + benchmark_y // 400
    return target - benchmark

def ad2mayan(y, m, d):
    diff = 0
    if datetime.MAXYEAR < y:
        day_of_2012 = (date(2013, 1, 1) - date(2012, 12, 21)).days
        day_of_the_year = (date(1, m, d) - date(1, 1, 1)).days if is_leap_year(y) else (date(4, m, d) - date(4, 1, 1)).days
        
        days = (y - 2013) * 365 + leap_year_count(y, 2013)

        diff = day_of_2012 + days + day_of_the_year
    else:
        benchmark = date(2012, 12, 21)
        diff = (date(y, m, d) - benchmark).days
    
    ki, diff = diff % 20, diff // 20
    w, diff = diff % 18, diff // 18
    t, diff = diff % 20, diff // 20
    ka, diff = diff % 20, diff // 20
    b = diff % 13
    
    return b,ka,t,w,ki

def mayan2ad(b, ka, t, w, ki):
    ka += b * 20
    t += ka * 20
    w += t * 18
    ki += w * 20
    time = date(2012, 12, 21) + timedelta(ki)
    return time.year, time.month, time.day


import sys
f = sys.stdin

for line in f:
    if line == '#':
        continue
    t = list(map(int, line.split('.')))
    if len(t) == 3:
        print('.'.join(map(str, ad2mayan(*t))))
    else:
        print('.'.join(map(str, mayan2ad(*t))))

Fixed submission:
import datetime
from datetime import timedelta
from datetime import date

def ad2mayan(y, m, d):
    days = 0
    while datetime.MAXYEAR < y:
        days += 365 * 400 + 97
        y -= 400

    days += (date(y, m, d) - date(2012, 12, 21)).days
    
    ki, days = days % 20, days // 20
    w, days = days % 18, days // 18
    t, days = days % 20, days // 20
    ka, days = days % 20, days // 20
    b = days % 13
    
    return b,ka,t,w,ki

def mayan2ad(b, ka, t, w, ki):
    ka += b * 20
    t += ka * 20
    w += t * 18
    ki += w * 20
    dt = datetime.date(2012, 12, 21) + timedelta(ki)
    return dt.year, dt.month, dt.day

import sys
f = sys.stdin


for line in f:
    if line[0] == '#':
        break
    t = list(map(int, line.split('.')))
    
    if len(t) == 3:
        print('.'.join(map(str, ad2mayan(*t))))
    elif len(t) == 5:
        print('.'.join(map(str, mayan2ad(*t))))

Buggy python submission (verdict: Runtime Error):
import datetime

def is_leap_year(y):
    return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)

def leap_year_count(target_y,benchmark_y):
    target = target_y // 4 - target_y // 100 + target_y // 400
    benchmark = benchmark_y // 4 - benchmark_y // 100 + benchmark_y // 400
    return target - benchmark

def ad2mayan(y, m, d):
    diff = 0
    if datetime.MAXYEAR < y:
        day_of_2012 = (datetime.date(2013, 1, 1) - datetime.date(2012, 12, 21)).days
        day_of_the_year = (datetime.date(1, m, d) - datetime.date(1, 1, 1)).days if is_leap_year(y) else (datetime.date(4, m, d) - datetime.date(4, 1, 1)).days
        
        days = (y - 2013) * 365 + leap_year_count(y, 2013)

        diff = day_of_2012 + days + day_of_the_year
    else:
        benchmark = datetime.date(2012, 12, 21)
        diff = (datetime.date(y, m, d) - benchmark).days
    
    ki, diff = diff % 20, diff // 20
    w, diff = diff % 18, diff // 18
    t, diff = diff % 20, diff // 20
    ka, diff = diff % 20, diff // 20
    b = diff % 13
    
    return b,ka,t,w,ki

def mayan2ad(b, ka, t, w, ki):
    ka += b * 20
    t += ka * 20
    w += t * 18
    ki += w * 20
    time = datetime.date(2012, 12, 21) + datetime.timedelta(ki)
    return time.year, time.month, time.day


import sys
f = sys.stdin

for line in f:
    if line == '#':
        continue
    t = list(map(int, line.split('.')))
    if len(t) == 3:
        print('.'.join(map(str, ad2mayan(*t))))
    else:
        print('.'.join(map(str, mayan2ad(*t))))

Fixed submission:
import datetime
from datetime import timedelta
from datetime import date

def ad2mayan(y, m, d):
    days = 0
    while datetime.MAXYEAR < y:
        days += 365 * 400 + 97
        y -= 400

    days += (date(y, m, d) - date(2012, 12, 21)).days
    
    ki, days = days % 20, days // 20
    w, days = days % 18, days // 18
    t, days = days % 20, days // 20
    ka, days = days % 20, days // 20
    b = days % 13
    
    return b,ka,t,w,ki

def mayan2ad(b, ka, t, w, ki):
    ka += b * 20
    t += ka * 20
    w += t * 18
    ki += w * 20
    dt = datetime.date(2012, 12, 21) + timedelta(ki)
    return dt.year, dt.month, dt.day

import sys
f = sys.stdin


for line in f:
    if line[0] == '#':
        break
    t = list(map(int, line.split('.')))
    
    if len(t) == 3:
        print('.'.join(map(str, ad2mayan(*t))))
    elif len(t) == 5:
        print('.'.join(map(str, mayan2ad(*t))))

Buggy python submission (verdict: Runtime Error):
import datetime

def is_leap_year(y):
    return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)

def leap_year_count(target_y,benchmark_y):
    target = target_y // 4 - target_y // 100 + target_y // 400
    benchmark = benchmark_y // 4 - benchmark_y // 100 + benchmark_y // 400
    return target - benchmark

def ad2mayan(y, m, d):
    diff = 0
    if datetime.MAXYEAR < y:
        day_of_2012 = (datetime.date(2013, 1, 1) - datetime.date(2012, 12, 21)).days
        day_of_the_year = (datetime.date(1, m, d) - datetime.date(1, 1, 1)).days if is_leap_year(y) else (datetime.date(4, m, d) - datetime.date(4, 1, 1)).days
        
        days = (y - 2013) * 365 + leap_year_count(y, 2013)

        diff = day_of_2012 + days + day_of_the_year
    else:
        benchmark = datetime.date(2012, 12, 21)
        diff = (datetime.date(y, m, d) - benchmark).days
    
    ki, diff = diff % 20, diff // 20
    w, diff = diff % 18, diff // 18
    t, diff = diff % 20, diff // 20
    ka, diff = diff % 20, diff // 20
    b = diff % 13
    
    return b,ka,t,w,ki

def mayan2ad(b, ka, t, w, ki):
    ka += b * 20
    t += ka * 20
    w += t * 18
    ki += w * 20
    time = datetime.date(2012, 12, 21) + datetime.timedelta(ki)
    return time.year, time.month, time.day

import sys
f = sys.stdin

for line in f:
    t = list(map(int, line.split('.')))
    if len(t) == 3:
        print('.'.join(map(str, ad2mayan(*t))))
    elif len(t) == 5:
        print('.'.join(map(str, mayan2ad(*t))))

Fixed submission:
import datetime
from datetime import timedelta
from datetime import date

def ad2mayan(y, m, d):
    days = 0
    while datetime.MAXYEAR < y:
        days += 365 * 400 + 97
        y -= 400

    days += (date(y, m, d) - date(2012, 12, 21)).days
    
    ki, days = days % 20, days // 20
    w, days = days % 18, days // 18
    t, days = days % 20, days // 20
    ka, days = days % 20, days // 20
    b = days % 13
    
    return b,ka,t,w,ki

def mayan2ad(b, ka, t, w, ki):
    ka += b * 20
    t += ka * 20
    w += t * 18
    ki += w * 20
    dt = datetime.date(2012, 12, 21) + timedelta(ki)
    return dt.year, dt.month, dt.day

import sys
f = sys.stdin


for line in f:
    if line[0] == '#':
        break
    t = list(map(int, line.split('.')))
    
    if len(t) == 3:
        print('.'.join(map(str, ad2mayan(*t))))
    elif len(t) == 5:
        print('.'.join(map(str, mayan2ad(*t))))