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: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    y,m,t=map(int,input().split())
    a.append([y,m,t])
for k in range(n):
    if a[k][0]%3!=0:
        if a[k][1]%2==0:
            a[k][2]=196-10*a[k][1]+19*(a[k][1]-2)/2-a[k][2]
        else:
            a[k][2]=196-39*(a[k][1]-1)/2-a[k][2]
    else:
        a[k][2]=201-20*(a[k][1]-1)-a[k][2]
    a[k][0]+=1
    while a[k][0]<1000:
        if a[k][0]%3==0:
            a[k][2]+=200
        else:
            a[k][2]+=195
        a[k][0]+=1
    print(a[k][2])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    y,m,t=map(int,input().split())
    a.append([y,m,t])
for k in range(n):
    if a[k][0]%3!=0:
        if a[k][1]==1:
            a[k][2]=196-a[k][2]

        else:
            if a[k][1]%2==0:
                a[k][2]=196-10*a[k][1]+19*(a[k][1]-2)/2-a[k][2]
            else:
                a[k][2]=196-39*(a[k][1]-1)/2-a[k][2]
    else:
        if a[k][1]==1:
            a[k][2]=201-a[k][2]

        else:
            a[k][2]=201-20*(a[k][1]-1)-a[k][2]
    a[k][0]+=1
    while a[k][0]<1000:
        if a[k][0]%3==0:
            a[k][2]+=200
        else:
            a[k][2]+=195
        a[k][0]+=1
    print(a[k][2])

Submission status: Wrong Answer

Solution code:
n = int(input())
for _ in range(n):
    (y, m, d) = [int(x) for x in input().split()]
    day = (999-y)*195 + (999-y)//3*5
    if y%3 == 0:
        day += (10-m)//2
    day += (10-m)*19 + (10-m)
    if y%3 != 0 and m%2 == 0:
        day += (19-d)
    else:
        day += (20-d)
    print(day+1)

Submission status: Wrong Answer

Solution code:
def day(y, m, d):
    days = 0
    days += (y-1)*195
    days += (y-1)//3*5
    days += (m-1)*19
    if y%3 == 0:
        days += (m-1)
    else:
        days += (m-1)//2
    days += (d-1)
    return days

def main():
    n = int(input())
    for _ in range(n):
        (y, m, d) = [int(x) for x in input().split()]
        print(day(1000,1,1) - day(y,m,d))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
M = [20, 19]
Y = sum(M) * 5

for i in range(int(input())):
    res = 0
    y,m,d = list(map(int,input().split()))
    for y_2 in range(1000-1, y, -1):
        res += Y if y_2 % 3 != 0 else 200

    for m_2 in range(10, m, -1):
        res += M[m_2 % 2] if y % 3 != 0 else 20

    res += (M[m%2] if y % 3 != 0 else 20) - d +1

    print(res)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:

def da(Y,M,D):
    day = (Y / 3) * 590
    if Y % 3 == 2:
        day = day + 390 + (M - 1)*20 + D
    else:
        day = day + (Y%3 - 1) * 195
        if M%2 == 1:
            day = day + (M/2 * 39) + D
        else:
            day = day + (M/2 - 1) * 39 + 20 + D
    return day
n = int(raw_input())
for i in range(n):
        l = map(int,raw_input().split())
        Y = l[0]
        M = l[1]
        D = l[2]
        print da(1000,1,1) - da(Y,M,D)

Submission status: Wrong Answer

Solution code:

def da(Y,M,D):
    day = (Y / 3) * 590
    if Y % 3 == 2:
        day = day + 390 + (M - 1)*20 + D
    elif Y % 3 == 1:
        day = day + (Y%3 - 1) * 195
        if M%2 == 1:
            day = day + (M/2 * 39) + D
        else:
            day = day + (M/2 - 1) * 39 + 20 + D
    else:
        if M%2 == 1:
            day = day + (M/2 * 39) + D
        else:
            day = day + (M/2 - 1) * 39 + 20 + D
        
        
    return day
n = int(raw_input())
for i in range(n):
        l = map(int,raw_input().split())
        Y = l[0]
        M = l[1]
        D = l[2]
        print da(1000,1,1) - da(Y,M,D)

Submission status: Wrong Answer

Solution code:

def da(Y,M,D):
    day = (Y / 3) * 590
    if Y % 3 == 0:
        day = day - 200 + (M - 1)*20 + D
    elif Y % 3 == 1:
        day = day + (Y%3 - 1) * 195
        if M%2 == 1:
            day = day + (M/2 * 39) + D
        else:
            day = day + (M/2 - 1) * 39 + 20 + D
        
        
    return day
n = int(raw_input())
for i in range(n):
        l = map(int,raw_input().split())
        Y = l[0]
        M = l[1]
        D = l[2]
        print da(1000,1,1) - da(Y,M,D)

Submission status: Wrong Answer

Solution code:
n = int(input())

def solve(Y,M,D):
    ans = 1 
    year = (999 - Y)
    ans += year * (20 + 19) * 5
    ans += ((year-1) // 3) * 5 + 5
    month = 10-M
    ans += month * 19
    ans += month //2
    ans += 20 - D
    if M % 2 == 0:
        ans -=1
    print(ans)


for i in range(n):
    l = input().split(' ')
  
    solve(int(l[0]) , int(l[1]), int(l[2]))

Submission status: Wrong Answer

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

n=int(raw_input())
for i in range(0,n):
	a=[int(e) for e in raw_input().split()]
	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])

Submission status: Accepted

Solution code:
# AOJ 1179: Millennium
# Python3 2018.7.14 bal4u

for cno in range(int(input())):
	y, m, d = map(int, input().split())
	ans = 195*y
	if y > 1: ans += 5*((y-1)//3)
	if y % 3: ans += 19*(m-1) + m//2
	else: ans += (m-1)*20
	print(196666-ans-d)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

n = input()

for loop in range(n):
    y, m, d = map(int, raw_input().split())
    m_lst = [20, 19, 20, 19, 20, 19, 20, 19, 20, 19]
    cnt = 0
    for i in range(m - 1):
        cnt += m_lst[i]
    if y % 3 == 0:
        cnt += (m - 1) // 2
    y -= 1
    cnt += y * 195 + (y // 3) * 5
    cnt += d - 1

    print 196470 - cnt

Submission status: Accepted

Solution code:
n = int(input())
anslist = []

Y = 1000
M = 1
D = 1
ans = 195 * (Y - 1)
ans += (Y - 1) // 3 * 5
ans += 20 * (M - 1)
ans += D
if Y % 3 != 0:
    ans -= (M - 1) // 2
milenium = ans

for i in range(n):

    Y, M, D = map(int, input().split())
    ans = 195 * (Y - 1)
    ans += (Y - 1) // 3 * 5
    ans += 20 * (M - 1)
    ans += D
    if Y % 3 != 0:
        ans -= (M - 1) // 2
    anslist.append(milenium - ans)


for i in anslist:
    print(i)

Submission status: Accepted

Solution code:
c = int(input())
a = [0]
for i in range(30):
    if i%2 == 0 or i >= 20:
        a.append(a[i]+20)
    else:
        a.append(a[i]+19)
for i in range(c):
    y, m, d = map(int,input().split())
    b = int((y-1)/3) * 590 + a[m + ((y+2)%3) * 10 - 1] + d
    print(196470 - b + 1)

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
  y,m,d = map(int,input().split())
  days = 0
  if d!=1:
    days += (20-d) if y%3!=0 and m%2==0 else (21-d)
    d = 1
    if m==10:
      y += 1
      m = 1
    else:
      m+=1
  if y!=1000:
    days += sum([19 if y%3!=0 and i%2==0 else 20 for i in range(11-m)])
    y += 1
    days += sum([19*5+20*5 if i%3!=0 else 20*10 for i in range(1000-y)])
  print(days)

Submission status: Accepted

Solution code:
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)-d)

Submission status: Accepted

Solution code:
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)-d)

Submission status: Accepted

Solution code:
def day(y, m, d):
    days = 0
    days += (y-1)*195
    days += (y-1)//3*5
    days += (m-1)*19
    if y%3 == 0:
        days += (m-1)
    else:
        days += m//2
    days += (d-1)
    return days

def main():
    n = int(input())
    for _ in range(n):
        (y, m, d) = [int(x) for x in input().split()]
        print(day(1000,1,1) - day(y,m,d))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n = input()
        mil = 196470
        for i in range(n):
            y, m, d = map(int, raw_input().split())
            elapsed = 0
            elapsed += 590 * ((y - 1) / 3) + 195 * ((y - 1) % 3)
            if y % 3 == 0:
                elapsed += 20 * (m - 1)
            else:
                elapsed += 39 * ((m - 1) / 2) + 20 * ((m - 1) % 2)
            elapsed += d - 1
            # print elapsed
            print mil - elapsed
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def date2num(y,m,d):
    t = (y-1)//3
    days = t*10*20 + (y-1-t)*5*20+(y-1-t)*5*19
    if y%3 == 0:
        days += (m-1)*20+d
    else:
        days += (m-1)//2*19+(m-1-(m-1)//2)*20+d
    return days
    
for i in range(int(input())):
    y,m,d = map(int,input().split(" "))
    print(date2num(1000,1,1) - date2num(y,m,d))

Submission status: Accepted

Solution code:
M = [19, 20]
Y = sum(M) * 5

for i in range(int(input())):
    res = 0
    y,m,d = list(map(int,input().split()))
    for y_2 in range(1000-1, y, -1):
        res += Y if y_2 % 3 != 0 else 200

    for m_2 in range(10, m, -1):
        res += M[m_2 % 2] if y % 3 != 0 else 20

    res += (M[m%2] if y % 3 != 0 else 20) - d +1

    print(res)

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
	Y, M, d = map(int, raw_input().split(" "))
	day_total = 0
	if Y % 3 == 0:
		day_sub = (M-1) * 20 + d - 1
	else :
		small_M = (M - 1) / 2
		day_sub = (M - 1 - small_M) * 20 + small_M * 19 + d - 1 
	for y in range(Y,1000):
		if y % 3 == 0:
			day_total += 10 * 20
		else :
			day_total += (20 + 19) * 5
	print day_total - day_sub

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    y,m,d = map(int, input().split())
    dif = 999 - y
    leap = int(dif / 3) + 1
    common = dif - leap + 1
    days = leap * 200 + common * 195 # days from y 1 1
    days -= (m - 1) * 20
    if y % 3 != 0:
        days += int((m - 1) / 2)
    days -= (d - 1)
    print(days)

Submission status: Accepted

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)
    day_sum += 1

    if year % 3 == 0 or month % 2 == 1:
        day_sum += 20 - day
    else:
        day_sum += 19 - day

    for m in range(month+1, 11):
        if year % 3 == 0 or m % 2 == 1:
            day_sum += 20
        else:
            day_sum += 19

    # total days from the second year to the second year from the last
    for y in range(1, 1000-year):
        for m in range(1, 11):
            if (year+y) % 3 == 0 or m % 2 == 1:
                day_sum += 20
            else:
                day_sum += 19

    print(day_sum)

Submission status: Accepted

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 = [0 for i in range(3)]
    tmp_dates = []
    for i in range(n):
        tmp_dates = input().split()
        for j in range(len(tmp_dates)):
            dates[j] = int(tmp_dates[j])

        date_count = solve(dates)
        print(date_count)

Submission status: Accepted

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 = [0 for i in range(3)]
    tmp_dates = []
    for i in range(n):
        tmp_dates = input().split()
        for j, tmp_date in enumerate(tmp_dates):
            dates[j] = int(tmp_date)

        date_count = solve(dates)
        print(date_count)

Submission status: Accepted

Solution code:
n = input()
for _ in xrange(n):
    y, m, d = map(int, raw_input().split())
    m -= 1

    ans = 1
    for t in xrange(y+1, 1000):
        ans += 195 if t%3 else 200
    for t in xrange(m+1, 10):
        ans += 19 if y%3 and t%2 else 20
    ans += 19-d if y%3 and m%2 else 20-d

    print ans

Submission status: Accepted

Solution code:

n = int(input())
for i in range(n):
	y, m, d = map(int, input().split())
	count = 0
	while (y, m, d) != (1000, 1, 1):
		d += 1
		if y % 3 == 0:
			if 20 < d:
				m += 1
				d = 1
		else:
			if m % 2 == 0:
				if 19 < d:
					m += 1
					d = 1
			else:
				if 20 < d:
					m += 1
					d = 1
		if 10 < m:
			y += 1
			m = 1
		count += 1

	print(count)

Submission status: Accepted

Solution code:
n = int(raw_input())

for i in range(n):
    y, m, d = map(int, raw_input().split())
    cnt = 0

    while y < 1000:
        while m <= 10:
            while d <= 20:
                cnt += 1
                d += 1
                if m % 2 == 0 and d > 19 and y % 3 != 0:
                    break
            m += 1
            d = 1
        y += 1
        m = 1
    print cnt

Submission status: Accepted

Solution code:
n = int(raw_input())
base = 196471
year = 195
month = [20,19,20,19,20,19,20,19,20,19]
for _ in xrange(n):
  Y,M,D = map(int, raw_input().split())
  days = 0
  days += (Y-1) * year + (Y-1) / 3 * 5
  for i in xrange(M-1):
    if Y%3 == 0:
      days += 20
    else:
      days += month[i]
  days += D
  print base - days

Submission status: Accepted

Solution code:

def da(Y,M,D):
    day = (Y / 3) * 590
    if Y % 3 == 0:
        day = day - 200 + (M - 1)*20 + D
    else:
        day = day + (Y%3 - 1) * 195
        if M%2 == 1:
            day = day + (M/2 * 39) + D
        else:
            day = day + (M/2 - 1) * 39 + 20 + D
        
        
    return day
n = int(raw_input())
for i in range(n):
        l = map(int,raw_input().split())
        Y = l[0]
        M = l[1]
        D = l[2]
        print da(1000,1,1) - da(Y,M,D)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    y,m,d = map(int,input().split())
    vy,vm,vd = y-1,m-1,d-1
    r = vy//3*590 + vy%3*195
    r += vd
    if (vy+1)%3==0: r += vm*20
    else: r += vm//2*39 + vm%2*20
    print(196470-r)

Submission status: Accepted

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 += 20
            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: Accepted

Solution code:
# coding: utf-8
def day(y,m,d):
    my,mm,md = y-1,m-1,d-1 
    day = my // 3 * 590 + my % 3 * 195 + md
    if y % 3 == 0:
        day += mm * 20
    else:
        day += mm // 2 * 39 + mm % 2 * 20
    return day
n = int(input())
for i in range(n):
    Y,M,D = [int(x) for x in input().split()]
    print(196470 - day(Y,M,D))

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    y,m,d=map(int,input().split())
    y-=1;m-=1
    print(196471-(y//3*590+y%3*195+(m*20 if y%3==2 else m//2*39+m%2*20)+d))

Submission status: Accepted

Solution code:
def Year():
    Ya = 0
    for j in range(Y-1):
        Ya += 19*5+20*5
    for j in range((Y-1)/3):
        Ya += 5
    return Ya
def Mouth():
    Ma = 0
    for i in range(1, M):
        if Y%3 == 0:
            Ma += 20
        else:
            Ma += 19 + (i%2)
    return Ma

x = int(raw_input())
for i in range(x):
    Y,M,D = map(int,raw_input().split())
    print 196471 - (Year()+Mouth()+D)

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    y, m, d = map(int, input().split())
    ans = (1000 - y) * 195 + (1002 - y) // 3 * 5
    if y % 3 == 0:
        tyear = (m - 1) * 20 + d - 1
    else:
        tyear = (m - 1) * 20 + d - 1 - ((m - 1) // 2)
    print(ans - tyear)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    for _ in range(n):
        count = 0
        y,m,d = list(map(int,input().strip().split()))
        if y %3 == 0:count += 20 - d +1
        elif m &1: count +=20 -d + 1
        else :count += 19-d+1
        for i in range(m + 1,11):
            if y % 3 ==0: count +=20
            elif i &1: count += 20
            else:count += 19
        for i in range(y + 1,1000):
            if i %3 ==0: count+= 20* 10
            else:count += 20 * 5 + 19 * 5
        print(count)

Submission status: Accepted

Solution code:
N = int(input())
src = [map(int,input().split()) for i in range(N)]

days_normal = (20+19)*5
days_special = 20*10
days_3years = 2*days_normal + days_special

def passed(y,m,d):
    ret = ((y-1)//3) * days_3years
    ret += ((y-1)%3) * days_normal
    for i in range(m-1):
        ret += (20 if y%3 == 0 or i%2 == 0 else 19)
    ret += d
    return ret

for i in range(N):
    y,m,d = src[i]
    print(passed(1000,1,1) - passed(y,m,d))

Submission status: Accepted

Solution code:
n = int(raw_input())

for i in range(n):
    Y, M, D = map(int, raw_input().split())
    days = 0
    for i in range(1, Y):
        if i % 3 == 0:
            days += 200
        else:
            days += 39*5
    
    for i in range(1, M):
        if Y % 3 != 0 and i % 2 == 0:
            days += 19
        else:
            days += 20

    days += D

    print 196471 - days

Submission status: Accepted

Solution code:
n = int(raw_input())

for _ in range(n):
    Y, M, D = map(int, raw_input().split())
    days = 0
    for i in range(1, Y):
        if i % 3 == 0:
            days += 200
        else:
            days += 39*5
    
    for i in range(1, M):
        if Y % 3 != 0 and i % 2 == 0:
            days += 19
        else:
            days += 20

    days += D

    print 196471 - days

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    y, m, d = map(int, input().split())
    ans = 0

    while y < 1000:
        while m < 11:
            if y % 3 == 0 or m % 2 > 0:
                ans += 20 - d + 1
            else:
                ans += 19 - d + 1
            d = 1
            m += 1
        m = 1
        y += 1
    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    n = I()
    a = [LI() for _ in range(n)]

    def f(y,m,d):
        t = (y-1) * 195
        t += (y-1) // 3 * 5
        t += (m-1) * 20
        if y % 3 > 0:
            t -= (m-1) // 2
        t += d - 1
        return t

    t = f(1000,1,1)
    for y,m,d in a:
        k = f(y,m,d)
        rr.append(t - k)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
n = int(input())

def solve(Y,M,D):
    ans = 0
    ans += (Y - 1) * (19 + 20) * 5
    ans += ((Y -1)// 3) * 5
    ans += 19 * (M-1)
    if Y % 3 ==0:
        ans += (M-1)
    else:
        ans += (M // 2)
    ans += (D-1)
    print(196470 - ans)
    

for i in range(n):
    l = input().split(' ')
  
    solve(int(l[0]) , int(l[1]), int(l[2]))

Submission status: Accepted

Solution code:
n=int(input())
for _ in range(n):
    y,m,d=list(map(int,input().split()))
    c=0
    for i in range(1,y):
        if i%3:c+=195
        else:c+=200
    for i in range(1,m):
        if y%3:
            if i%2:c+=20
            else:c+=19
        else:
            c+=20
    c+=(d-1)
    print(196470-c)

Submission status: Accepted

Solution code:
#!/usr/bin/python
import sys

n=int(sys.stdin.readline())
for i in range(0,n):
	a=map(int,sys.stdin.readline().split())
	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]

Submission status: Accepted

Solution code:
def calc(y, m, d):
	ret = d
	ret += (y - 1) * 39 * 5
	ret += 5 * ((y - 1) / 3)

	for j in range(1, m):
		if y % 3 == 0:
			ret += 20
		else:
			ret += 19 + (j % 2)

	return ret

for i in range(int(raw_input())):
	print calc(1000, 1, 1) - calc(*map(int, raw_input().split()))

Submission status: Accepted

Solution code:
import sys

def daysOfYear(y):
    if y <= 0:
        return 0
    elif y % 3 == 0:
        return 200
    else:
        return 195

def daysOfMonth(y, m):
    if y % 3 == 0 or m % 2 == 1:
        return 20
    else:
        return 19


mil = 1
for i in xrange(1, 1000):
    mil += daysOfYear(i)

raw_input()
for line in sys.stdin:
    y, m, d = map(int, line.split())
    s = 0
    for i in xrange(1, y):
        s += daysOfYear(i)
    for i in xrange(1, m):
        s += daysOfMonth(y, i)
    print mil - s - d

Submission status: Accepted

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().strip())

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

    sys.exit(0)

Submission status: Accepted

Solution code:
for i in range(input()):
    y,m,d=map(int,raw_input().split())
    s=sum(200 if i%3==0 else 195 for i in range(y+1,1000))
    t=0
    for i in range(m,11):
        if y%3!=0:
            t+=20 if i%2==1 else 19
        else:
            t+=20
    print s+t-d+1

Submission status: Accepted

Solution code:
n = input()
for i in range(n):
    a = 0
    y, m, d = map(int, raw_input().split())
    a += 195 * (999 - y)
    a += (999 / 3 - y / 3) * 5
    if y % 3 :
        a += (10 - m) * 19 + (10 - m) / 2
        a += 20 - d - (m + 1) % 2 + 1
    else:
        a += (10 - m) * 20
        a += 20 - d + 1
    print a

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n=int(sys.stdin.readline())
for i in range(0,n):
	a=map(int,sys.stdin.readline().split())
	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])

Submission status: Accepted

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().split())
	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])

Submission status: Accepted

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

n=int(raw_input())
for i in range(0,n):
	a=[int(e) for e in raw_input().split()]
	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])

Submission status: Accepted

Solution code:
def days(y, m, d) :
    cnt = 0
    for i in range(1, y) :
        if i % 3 == 0 :
            cnt += 200
        else :
            cnt += 195
    for i in range(1, m) :
        if y % 3 == 0 :
            cnt += 20
        else :
            if i % 2 == 0 :
                cnt += 19
            else :
                cnt += 20
    cnt += d-1
    return cnt

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

Submission status: Accepted

Solution code:
def get_no_days(day_str):
    day_split = day_str.split(' ')
    year = int(day_split[0])
    month = int(day_split[1])
    day = int(day_split[2])
    result = 0

    for y in range(1, year, 1):
        if y % 3 != 0:
            result += 195
        else:
            result += 200
    year_not_mod_3 = (year % 3 != 0)
    for m in range(1, month, 1):
        if year_not_mod_3 and m % 2 == 0:
            result += 19
        else:
            result += 20
    result += day
    return 196471 - result

total = int(input())
for i in range(total):
    d = input()
    print(str(get_no_days(d)))

Submission status: Accepted

Solution code:
import math

oneYear = 20*5 + 19*5
threeYears = oneYear*2 + 20*10
millennium = 196471

N = int(input())
for i in range(N):
    data = input().split()
    birthYear = int(data[0])
    birthMonth = int(data[1])
    birthDay = int(int(data[2]))

    day = 0
    #Calc passed years
    passedYears = birthYear - 1
    day += (passedYears%3 * oneYear) + (math.floor(passedYears/3)*threeYears)
    if birthYear%3 == 0:
        passedMonth = birthMonth-1
        day += passedMonth*20
        day += birthDay
    else:
        passedMonth = birthMonth-1
        day += math.floor(passedMonth/2) * 39
        day += passedMonth%2 * 20
        day += birthDay
    ans = millennium - day
    print(ans)

Submission status: Accepted

Solution code:
def get_input_data():
    input_data = int(input())
    return input_data

def make_calendar():
    calendar_dict = dict()
    duration = 0
    y, m, d = 1000, 1, 1
    while y > 1 or m > 1 or d > 1:
        duration += 1
        if d > 1:
            d -= 1
        elif m > 1:
            m -= 1
            d = calculate_month_having_date(y, m)
        else:
            y -= 1
            m = 10
            d = calculate_month_having_date(y, m)
        calendar_dict[(y, m, d)] = duration
    return calendar_dict

def calculate_month_having_date(y, m):
    if y % 3 == 0 or m % 2 == 1:
        d = 20
    else:
        d = 19
    return d

def show_the_duration(calendar_dict):
    birthday = input().split()
    for i, v in enumerate(birthday):
        birthday[i] = int(v)
    duration = calendar_dict[tuple(birthday)]
    return duration

if __name__ == "__main__":
    calendar_dict = make_calendar()
    # print("calendar_dict", calendar_dict) # debug
    people_num = get_input_data()
    for i in range(people_num):
        duration = show_the_duration(calendar_dict)
        print(duration)

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0
ans = []
for i in range(n):
    cnt = 0
    y,m,d = map(int,input().split())
    if y % 3 == 0:
        cnt += (10-m)*20 + (20-d+1)
        y += 1
    else:
        cnt += ((10-m)- ((10-m)//2)) * 20 + ((10-m)//2) * 19 + (19-d+1) + 5
        y += 1
    cnt += ((1000-y)//3) * 200 + ((1000-y)-((1000-y)//3)) * 195
    ans.append(cnt)
for i in ans:
    print(i)