Problem:


Millennium

A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1.  Each year consists of 10 months, from month 1 through month 10, and starts from a big month.  A common year shall start with a big month, followed by small months and big months one after another.  Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one.  A big month consists of 20 days and a small month consists of 19 days.  However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month."

Many years have passed since the calendar started to be used.  For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery.  Write a program that helps people calculate the number of days since their birthdate to the millennium day.

Input

The input is formatted as follows.

    n

    Y1 M1 D1

    Y2 M2 D2

    ...

    Yn Mn Dn

Here, the first line gives the number of datasets as a positive integer n, which is less than or equal to 100.  It is followed by n datasets.  Each dataset is formatted in a line and gives three positive integers, Yi (< 1000), Mi (≤ 10), and Di (≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar.  These three numbers are separated by a space.

Output

For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive.  Output lines should not contain any character other than this number.

Sample Input

8
1 1 1
344 3 1
696 5 1
182 9 5
998 8 7
344 2 19
696 4 19
999 10 20

Output for the Sample Input

196470
128976
59710
160715
252
128977
59712
1



Sample input:
8
1 1 1
344 3 1
696 5 1
182 9 5
998 8 7
344 2 19
696 4 19
999 10 20


Sample output:
196470
128976
59710
160715
252
128977
59712
1

Submission status: Accepted

Solution code:
n = int(input())
n1 = 19*5 + 20*5
n2 = 20*10
for _ in range(n):
    y,m,d = map(int,input().split())
    ans = (999-y)//3*(n1*2+n2)
    if (999-y)%3 == 1:
        ans += n2
    elif (999-y)%3 == 2:
        ans += n1+n2
    if y%3 == 0:
        ans += (10-m)*20
    else:
        if m%2 == 0:
            ans += (10-m)//2*39
        else:
            ans += (10-m)//2*39+19
    if m%2 == 0 and y%3 != 0:
        ans += 19-d+1
    else:
        ans += 20-d+1
    print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
year=195
from math import ceil
for i in range(n):
	y,m,d=map(int,input().split())
	ans=0
	ans+=(999-y)*year
	ans+=(333-y//3)*5
	if y%3==0:
		ans+=(10-m)*20
		ans+=(20-d)+1
	else:
		ans+=(10-m)*20
		ans-=ceil((10-m)/2)
		if m%2==0:
			ans+=(19-d)+1
		else:
			ans+=(20-d)+1
	print(ans)

Submission status: Accepted

Solution code:
def calc(y, m):
    y += 1
    m += 1
    if m % 2 == 1:
        return 20
    if y % 3 == 0:
        return 20
    else:
        return 19


date = [ [ [0 for k in range(calc(i, j))] for j in range(10)] for i in range(1000)]

count = 0
for i in range(1000):
    for j in range(10):
        for k in range(calc(i,j)):
            date[i][j][k] = count
            count += 1

last = date[999][0][0]

n = int(input())
for i in range(n):
    y, m, d = map(int, input().split(' '))
    print(last - date[y-1][m-1][d-1])

Submission status: Accepted

Solution code:
n = int(input())

def f(y, m, d):
    ret = 0
    for i in range(1, y):
        if i % 3 == 0:
            ret += 20 * 10
        else:
            ret += 20 * 5 + 19 * 5
    for j in range(m - 1):
        if j % 2 == 0:
            ret += 20
        else:
            if y % 3 == 0:
                ret += 20
            else:
                ret += 19
    ret += d
    return ret

al = f(1000, 1, 1)
for i in range(n):
    y,m,d = map(int,input().split())
    print(al - f(y, m, d))

Submission status: Accepted

Solution code:
N = int(input())
YMD = [[0,0,0] for i in range(N)]
ans = [[[0 for i in range(20)] for j in range(10)] for k in range(1000)]
for i in range(N):
    line = input().split(" ")
    YMD[i] = [int(line[0])-1, int(line[1])-1, int(line[2])-1]

#print(YMD)
count = 0
for y in range(1000):
    if (y+1)%3 == 0:
        for m in range(10):
            for d in range(20):
                ans[y][m][d] = count
                count+=1
    else:
        for m in range(10):
            if m%2 == 0:
                for d in range(20):
                    ans[y][m][d] = count
                    count+=1
            else:
                for d in range(19):
                    ans[y][m][d] = count
                    count+=1
            
mile = ans[999][0][0]
for i in range(N):
    tmpYMD = YMD[i]
    tage = ans[tmpYMD[0]][tmpYMD[1]][tmpYMD[2]]
    diff = mile - tage
    print(diff)

Submission status: Accepted

Solution code:
"""
1年1月1日が1日目

3で割り切れる年は 1年が200日

割り切れない日は 1年が195日

3年単位で, 200+195+195 = 590日

+あまりの年×195


月から日への変換方法は

もし3で割り切れないあり and 

(i)月が奇数の時　 20

(ii)月が偶数の時 19

日はそのまま足す


1000年1月1日 を基準にする
計算時間短縮のために先に日に直しておこう
1年1月1日を1日目としているから　1年引く
(1000-1) // 3 = 333*3 

割り切れない　年から日は590*333 + 1*195

月から日は　割り切れない　1は奇数だから +20 と思いきや
1年1月1日を1日目としているから、1-1 = 0となる

よって 590*333  + 1 =196471

999 年　10月 20日の場合

999-1 //3 = 332 + 2


999は3で割り切れる

10-1 *20 = 180日 

590*332 + 2*195 +180 + 20 =196470

差分は1
"""
def get_days(y,m,d):
    day = 0
    if int((y-1) % 3) == 0: 
        day += (int(y-1)//3)*590
    elif int((y-1) % 3) != 0:
        day += (int((y-1)//3))*590 + (int((y-1)%3))*195

    if int(y% 3) == 0:
        day+= (m-1)*20
    else:
        day += (m-1)*20-int((m-1)//2)

    day += d

    comp = 196471 -day
    return comp



n = input()
n = int(n)
"""
inputlist = []

for i in range(n):
	yc , mc , dc = input().split()
	yc = int(yc)
	mc = int(mc)
	dc = int(dc)
	inputlist.append([yc,mc,dc])
	"""
#i = 0
while(True):

	if n == 0:
		break
	#day = 0
	
	yc , mc , dc = input().split()
	yc = int(yc)
	mc = int(mc)
	dc = int(dc)
	n -= 1
	#i += 1
	print(get_days(yc,mc,dc))

	"""
	y = inputlist[i][0]
	m =inputlist[i][1] 
	d = inputlist[i][2]
	"""
	
	
"""	
	if int((y-1) % 3) == 0:
		day += (y-1)*590
	elif int((y-1) % 3) != 0:
		day += (int((y-1)//3))*590 + (int((y-1)%3))*195
	
	if int(y % 3) == 0:
		day+= (m-1)*20
	else:
		day += (m-1)*20-int((m-1)//2)
	
	day += d
	
	comp= 196471 -day
	n -= 1
	i += 1
	print(comp)
	"""

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Millennium
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1179&lang=jp

"""
import sys

from itertools import accumulate

memo = [-1] * 1001
memo[1000] = 0
for y in range(999, 0, -1):
    memo[y] = (20 * 10 if y % 3 == 0 else 20 * 5 + 19 * 5) + memo[y+1]

def solve(y, m, d):
    months = [0] + [20, 19] * 5 if y % 3 else [0] + [20] * 10
    acc = list(accumulate(months))
    ans = memo[y] - acc[m-1] - (d-1)
    return ans


def main(args):
    n = int(input())
    for _ in range(n):
        y, m, d = map(int, input().split())
        ans = solve(y, m, d)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
for i in range(int(input())):
    y, m, d = map(int, input().split())
    print(196471 - ((y - 1) * 195 + (y - 1) // 3 * 5 + 20 * (m - 1) - min(1, y % 3) * ((m - 1) // 2) + d))

Submission status: Accepted

Solution code:
def cal(y0,m0,d0):
    y = 1
    m = 1
    d = 1
    for days in range(10**6):
        if (y,m,d) == (y0,m0,d0):
            return days
        d += 1
        if y % 3 == 0:
            if d == 21:
                m += 1
                d = 1
            if m == 11:
                y += 1
                m = 1
        else:
            if m % 2 == 1:
                if d == 21:
                    m += 1
                    d = 1
                if m == 11:
                    y += 1
                    m = 1
            elif m % 2 == 0:
                if d == 20:
                    m += 1
                    d = 1
                if m == 11:
                    y += 1
                    m = 1

n = int(input())
ymd = [list(map(int,input().split())) for _ in range(n)]

res = cal(1000,1,1)
for y,m,d in ymd:
    ans = res - cal(y,m,d)
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    y,m,d = map(int,input().split())
    only_dai = (1000 - y + 1) // 3 * 10 * 20
    dai_shou = ((1000 - y - 1) - (1000 - y + 1) // 3) * (20 * 5 + 19 * 5)
    if y % 3 == 0:
        hanpa_m = (10 - m) * 20
    else:
        hanpa_m = (10 - m) * 20 - (10 - m + 1) // 2
    if m % 2 == 0 and y % 3 != 0:
        hanpa_d = 19 - d
    else:
        hanpa_d = 20 - d
    ans = only_dai + dai_shou + hanpa_m + hanpa_d + 1
    print(ans)

Submission status: Accepted

Solution code:
def main():
    y, m, d = map(int, input().split())
    a = (y - 1) // 3
    b = (y - 1) % 3
    c = a * 590 + 195 * b 
    if y % 3:
        a = (m - 1) // 2
        b = (m - 1) % 2
        c += a * 39 + b * 20
    else:
        c += (m - 1) * 20
    c += d - 1
    print(196470-c)
n = int(input())
for i in range(n):
    main()

Submission status: Accepted

Solution code:
import sys
def f(y,m,d):
    res = (y-1)//3*200+(y-1-(y-1)//3)*195
    if y%3 == 0:
        res += (m-1)*20+d
    else:
        res += (m-1)//2*19+(m-1-(m-1)//2)*20+d
    return res
    
M = 196471
n  = int(sys.stdin.readline())
for i in range(n):
    y,m,d = [int(x) for x in sys.stdin.readline().split()]
    print(M-f(y,m,d))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AOJ A

n = int(input())
for _ in range(n):
    y,m,d = list(map(int,input().split()))
    sub = 1
    for i in range(y+1,1000):
        if i % 3 == 0:
            sub += 200
        else:
            sub += 19*5 + 100
    if y % 3 == 0:
        sub += (10 - m)*20 + (20 - d)
    else:
        if m % 2 == 0:
            sub += (19 - d) + (10 - m)//2*(20 + 19)
        else:
            sub += (10 - m + 1)//2*(20 + 19) - d
    print(sub)

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
  Y,M,D=map(int,input().split())
  
  if Y%3!=0 and M%2==0:
    day=(19-D)+1
  else:
    day=(20-D)+1

  for j in range(M+1,11):
    #print(j,day)
    if Y%3==0:
      day+=20
    elif j%2==0:
      day+=19
    else:
      day+=20
  #print(day)
  for j in range(Y+1,1000):
    #print(j,day)
    for l in range(1,11):
      if j%3==0:
        day+=20
      elif j%3!=0 and l%2==0:
        day+=19
      else:
        day+=20
  
  print(day)

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for z in range(n)]
ans1=196471
for i in range(n):
    ans2=0
    y=l[i][0]
    m=l[i][1]
    d=l[i][2]
    ans2+=(y-1)*195+int((y-1)/3)*5
    if y%3==0:
        ans2+=(m-1)*20
    else:
        if (m-1)%2==0:
            ans2+=39*(m-1)/2
        else:
            ans2+=39*(m-2)/2+20
    ans2+=d
    print(int(ans1-ans2))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    y, m, d = map(int, input().split())
    tmp = 0
    tmp += (y-1) * 195
    tmp += ((y-1) // 3) * 5
    tmp += (m-1) * 20
    if y % 3 != 0:
        tmp -= (m-1) // 2
    tmp += d
    print(196471 - tmp)

Submission status: Accepted

Solution code:
def count(Y, M, D) :
	thr = (Y - 1) // 3
	cnt = (Y - thr - 1) * 195 + thr * 200
	if(Y % 3 == 0) :
		cnt += (M - 1) * 20 + D
	else :
		m = (M - 1) // 2
		cnt += (M - m - 1) * 20 + m * 19 + D
	print(Mil - cnt + 1)

n = int(input())

Mil = 666 * 195 + 333 * 200

for i in range(n) :
	Y, M, D = map(int, input().split())
	count(Y, M, D)

Submission status: Accepted

Solution code:
# Millennium

ans = []
n = int(input())
for j in range(n):
    y, m, d = map(int, input().split())
    day = 0

    for i in range(m, 11):
        if y % 3 == 0:
            day += 20
        else:
            if i % 2 == 0:
                day += 19
            else:
                day += 20
    day -= d


    for i in range(y + 1, 1000):

        if i % 3 == 0:
            day += 200
        else:
            day += 195

    ans.append(day + 1)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
LGE = 20
SML = 19
FUTU = 195
URUU = 200
YEAR3 = 590

def main():
    howmany = int(input())

    for i in range(howmany):
        daycount = 0
        
        dataset = input()
        dataset = dataset.split(" ")
        
        for j in range(len(dataset)):
            dataset[j] = int(dataset[j])
        #print("-------------------------------------")
        #print("data::")
        #print(dataset)
        daycount += totopmonth(dataset)
        #print("to the top of month")
        #print(daycount)
        #print("date::")
        #print(dataset)
        #print("")
        
        if dataset[0] == 1000:
            print(daycount)
        else:
            daycount += totopyear(dataset)
            #print("to the top of year")
            #print(daycount)
            #print("date::")
            #print(dataset)
            #print("")
            
            if dataset[0] == 1000:
                print(daycount)
            else:
                daycount += totheend(dataset)
                print(daycount)
                

def totopmonth(array):
    count = 0
    
    if array[2] == 1:
        return count
    elif array[0] % 3 != 0:
        if array[1] % 2 == 1:
            count = LGE - array[2] + 1
            array[2] = 1
            array[1] += 1
        else:
            count = SML - array[2] + 1
            array[2] = 1
            array[1] += 1

    else:
        count = LGE - array[2] + 1
        array[2] = 1
        array[1] += 1

    if array[1] == 11:
        array[1] = 1
        array[0] += 1
        
    return count 
        
def totopyear(array):
    count = 0
    if array[1] == 1:
        return count
    elif array[0] % 3 != 0:
        if array[1] % 2 == 1:
            count = (10 - array[1] + 1) // 2 * (LGE + SML)
            array[1] = 1
            array[0] += 1
        else:
            count = (11 - array[1] + 1) // 2 * (LGE + SML) - LGE
            array[1] = 1
            array[0] += 1
    else:
        count = (10 - array[1] + 1) * LGE
        array[1] = 1
        array[0] += 1
    return count

def totheend(array):
    count = 0
    if array[0] % 3 == 0:
        count = (999 - array[0]) // 3 * YEAR3 + URUU
        return count
    elif array[0] % 3 == 1:
        count = (999 - array[0]) // 3 * YEAR3 + YEAR3
        return count
    else:
        count = (999 - array[0]) // 3 * YEAR3 + URUU + FUTU
        return count
main()

Submission status: Accepted

Solution code:
n=int(input())
table=[0,20, 39, 59, 78, 98, 117, 137, 156, 176, 195]
u_table=[0,20, 40, 60, 80, 100, 120, 140, 160, 180, 200]
for i in range(n):
    y,m,d=map(int,input().split())
    ans=0
    for j in range(y+1,1000):
        if j%3==0:
            ans+=u_table[-1]
        else:
            ans+=table[-1]
    if y%3==0:
        ans+=u_table[-1]-u_table[m]
        ans+=u_table[m]-u_table[m-1]-d+1
    else:
        ans+=table[-1]-table[m]
        ans+=table[m]-table[m-1]-d+1
    print(ans)

Submission status: Accepted

Solution code:
def solve(y, m, d):
    Y = [195, 195, 200]
    M = [20, 19]

    ret = 196471
    for i in range(y-1):
        ret -= Y[i % 3]
    if y % 3 == 0:
        ret -= (m-1) * 20
    else:
        for i in range(m-1):
            ret -= M[i % 2]
    ret -= d

    return ret


N = int(raw_input())
for _ in range(N):
    y, m, d = map(int, raw_input().split(" "))
    print solve(y, m, d)

Submission status: Output Limit Exceeded

Solution code:
n = int(input())

for _ in range(n):
    day_sum = 0
    year, month, day = map(int, input().split())

    # total days of the first year (including the first day)
    print("total days include the first day.")
    day_sum += 1

    print("for the first month {0} in the first year {1}:".format(month, year))
    if year % 3 == 0 or month % 2 == 1:
        day_sum += 20 - day
        print("plus {0} day.".format(20 - day))
    else:
        day_sum += 19 - day
        print("plus {0} day.".format(19 - day))

    for m in range(month+1, 11):
        print("for the month {0} in the first year:".format(m))
        if m % 2 == 1:
            day_sum += 20
            print("plus 20 day.")
        else:
            day_sum += 19
            print("plus 19 day.")

    # total days from the second year to the second year from the last
    for y in range(1, 1000-year):
        print("for year {0}:".format(year+y))
        for m in range(1, 11):
            print("for the month {0}".format(m))
            if y % 3 == 0 or m % 2 == 1:
                day_sum += 20
                print("plus 20 day.")
            else:
                day_sum += 19
                print("plus 19 day.")

    print(day_sum)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

n=int(raw_input())
for i in range(0,n):
	y,m,d=[int(e) for e in raw_input().split()]
	y-=1;m-=1
	print(196471-y*195-y//3*5-m*20+(m//2 if y%3!=2 else 0)-a[2])

Submission status: Runtime Error

Solution code:
#solve function
def solve(dates):
    counter = 0;
    start_month = dates[1]
    start_day, end_day = dates[2], 0

    for year in range(dates[0], 1000):
        for month in range(start_month, 11):
            if year%3 == 0 or month%2 == 1:
                end_day = 21
            else:
                end_day = 20

            # count days
            counter += (end_day - start_day)

            start_day = 1
        else:
            start_month = 1

    return counter


#main function
if __name__ == '__main__':
    n = int(input())

    dates = []
    tmp_dates = []
    for i in range(n):
        tmp_dates = input().split()
        for j, tmp_date in enumerate(tmp_dates):
            dates.append(int(tmp_date))

        date_count = solve(dates)
        print(date_count)

        dates.clear()

Submission status: Runtime Error

Solution code:
#solve function
def solve(dates):
    counter = 0;
    start_month = dates[1]
    start_day, end_day = dates[2], 0

    for year in range(dates[0], 1000):
        for month in range(start_month, 11):
            if year%3 == 0 or month%2 == 1:
                end_day = 21
            else:
                end_day = 20

            # count days
            counter += (end_day - start_day)

            start_day = 1
        else:
            start_month = 1

    return counter


#main function
if __name__ == '__main__':
    n = int(input())

    dates = []
    tmp_dates = []
    for i in range(n):
        tmp_dates = input().split()
        for j in range(len(tmp_dates)):
            dates.append(int(tmp_dates[j]))

        date_count = solve(dates)
        print(date_count)

        dates.clear()

Submission status: Runtime Error

Solution code:
N = int(raw_input())
D1 = 20*5 + 19*5
D2 = 20*10

for i in xrange(N):
    y, m, d = map(int, raw_input().split())
    ans = 0
    if d != 1:
        if y % 3 == 0 or m % 2 == 1:
            last = 20
        else:
            last = 19
        ans += last - d + 1
        d = 1
        if m < 10:
            m += 1
        else:
            y += 1
            m = 1
    if m != 1:
        while m < 11:
            if y % 3 == 0 or m % 2 == 1:
                ans += 20javascript:void(0);
            else:
                ans += 19
            m += 1
        m = 1
        y += 1
    while y < 1000:
        if y % 3 == 0:
            ans += D2
        else:
            ans += D1
        y += 1
    print ans

Submission status: Runtime Error

Solution code:
def datesOfTheYear(year):
    if year % 3 == 0:
        return 200
    return 195


def datesOfTheMonth(year, month):
    if year % 3 == 0:
        return 20
    if month % 2 == 0:
        return 19
    else:
        return  20


def datesFromBorn(birthyear, birthmonth, birthdate):
    result = 0
    for y in range(birthyear + 1, 1000):
        result += datesOfTheYear(y)
    for m in range(birthmonth + 1, 11):
        result += datesOfTheMonth(birthyear, m)
    result += datesOfTheMonth(birthyear, birthmonth) - birthdate + 1
    return result                                                 


if __name__ == "__main__":
    import sys
    import fileinput

    fin = fileinput.input()
    numberofcandidate = int(fin.next().sprit())

    for _ in range(numberofcandidate):
        year, month, date = fin.next().strip().split()
        print datesFromBorn(year, month, date)

    sys.exit(0)

Submission status: Runtime Error

Solution code:
import sys
if sys.version_info[0]>=3: raw_input=input

n=int(raw_input())
for i in range(0,n):
	a=map(int,raw_input())
	a[0]-=1;a[1]-=1
	print(196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2])