Problem:

改元

平成31年4月30日をもって現行の元号である平成が終了し，その翌日より新しい元号が始まることになった．平成最後の日の翌日は新元号元年5月1日になる．

ACM-ICPC OB/OGの会 (Japanese Alumni Group; JAG) が開発するシステムでは，日付が和暦（元号とそれに続く年数によって年を表現する日本の暦）を用いて "平成 y 年 m 月 d 日" という形式でデータベースに保存されている．この保存形式は変更することができないため，JAGは元号が変更されないと仮定して和暦で表した日付をデータベースに保存し，出力の際に日付を正しい元号を用いた形式に変換することにした．

あなたの仕事はJAGのデータベースに保存されている日付を，平成または新元号を用いた日付に変換するプログラムを書くことである．新元号はまだ発表されていないため，"?" を用いて表すことにする．

Input

入力は複数のデータセットからなる．各データセットは次の形式で表される．

g y m d

g は元号を表す文字列であり， g=HEISEI が成り立つ．y, m, d は整数であり，それぞれ年，月，日を表す．1 ≤ y ≤ 100, 1 ≤ m ≤ 12, 1 ≤ d ≤ 31 が成り立つ．

2月30日などの和暦に存在しない日付はデータセットとして与えられない．和暦として正しく変換したときに，平成よりも前の元号を用いる必要がある日付もデータセットとして与えられない．

入力の終わりは '#' 一つのみからなる行であらわされる．データセットの個数は 100 個を超えない．

Output

各データセットについて，変換後の元号，年，月，日を空白で区切って 1 行に出力せよ．変換後の元号が "平成" である場合は "HEISEI" を元号として用い，新元号であれば "?" を用いよ．

通常，元号の第 1 年目は元年と表記するが，本問題の出力ではこの規則を無視し，1 を年として出力せよ．

Sample Input

HEISEI 1 1 8
HEISEI 31 4 30
HEISEI 31 5 1
HEISEI 99 12 31
HEISEI 38 8 30
HEISEI 98 2 22
HEISEI 2 3 26
HEISEI 28 4 23
#

Output for the Sample Input

HEISEI 1 1 8
HEISEI 31 4 30
? 1 5 1
? 69 12 31
? 8 8 30
? 68 2 22
HEISEI 2 3 26
HEISEI 28 4 23



Sample input:
HEISEI 1 1 8
HEISEI 31 4 30
HEISEI 31 5 1
HEISEI 99 12 31
HEISEI 38 8 30
HEISEI 98 2 22
HEISEI 2 3 26
HEISEI 28 4 23
#


Sample output:
HEISEI 1 1 8
HEISEI 31 4 30
? 1 5 1
? 69 12 31
? 8 8 30
? 68 2 22
HEISEI 2 3 26
HEISEI 28 4 23

Submission status: Wrong Answer

Solution code:
ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = 0
while True:
    try:
        g=input()
        y,m,d=map(int,input().split())
        ls_g.append(g)
        ls_y.append(y)
        ls_m.append(m)
        ls_d.append(d)
        cnt += 1
    except:
        break;

for _ in range(cnt):
    if ls_y[cnt]>31:
        ls_g[cnt]="?"
    elif ls_y[cnt]==31:
        if ls_m[cnt]>=5:
            ls_g[cnt]="?"
for _ in range(cnt):
    print(ls_[g]+" "+ls_y[cnt]+" "+ls_m[cnt]+" "+ls_d[cnt])

Submission status: Wrong Answer

Solution code:
ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = -1
while True:
    try:
        ls=input().split()
        ls_g.append(ls[0])
        ls_y.append(int(ls[1]))
        ls_m.append(int(ls[2]))
        ls_d.append(int(ls[3]))
        cnt += 1
    except:
        break;

for _ in range(cnt):
    if ls_y[cnt]>31:
        ls_g[cnt]="?"
    elif ls_y[cnt]==31:
        if ls_m[cnt]>=5:
            ls_g[cnt]="?"
for _ in range(cnt):
    print(ls_g[cnt]+" "+str(ls_y[cnt])+" "+str(ls_m[cnt])+" "+str(ls_d[cnt]))

Submission status: Wrong Answer

Solution code:
ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = -1
while True:
    try:
        ls=input().split()
        ls_g.append(ls[0])
        ls_y.append(int(ls[1]))
        ls_m.append(int(ls[2]))
        ls_d.append(int(ls[3]))
        cnt += 1
    except:
        break;

for _ in range(cnt):
    if ls_y[_]>31:
        ls_g[_]="?"
        ls_y[_]-=30
    elif ls_y[_]==31 and ls_m[_]>=5:
        ls_g[_]="?"
        ls_y[_]-=30
for i in range(cnt):
    print(ls_g[i]+" "+str(ls_y[i])+" "+str(ls_m[i])+" "+str(ls_d[i]))

Submission status: Wrong Answer

Solution code:
ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = -1
while True:
    try:
        ls=input().split()
        ls_g.append(ls[0])
        ls_y.append(int(ls[1]))
        ls_m.append(int(ls[2]))
        ls_d.append(int(ls[3]))
        cnt += 1
    except:
        break;

for _ in range(cnt):
    if ls_y[_]>31:
        ls_g[_]="?"
        ls_y[_]-=30
    elif ls_y[_]==31 and ls_m[_]>=5:
        ls_g[_]="?"
        ls_y[_]-=30
for i in range(cnt+1):
    print(ls_g[i]+" "+str(ls_y[i])+" "+str(ls_m[i])+" "+str(ls_d[i]))

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
while True:
    line = input()
    if line == '#':
        exit()

    g = line.split()[0]
    y, m, d = map(int, line.split()[1:])
    if y > 31:
        g = '?'
    elif m > 4:
        g = '?'
    print(g, y, m, d)

Submission status: Wrong Answer

Solution code:
while True:
    line = input()
    if line == '#':
        exit()

    g = line.split()[0]
    y, m, d = map(int, line.split()[1:])
    if y > 31:
        g = '?'
        y -= 30
    elif m > 4:
        g = '?'
    print(g, y, m, d)

Submission status: Wrong Answer

Solution code:
g=[]
y=[]
m=[]
d=[]

for i in range(100):
    a=input()
    if a=="#":
        break
    else:
        g1,y1,m1,d1=map(str,a.split())
        g.append(g1)
        y.append(int(y1))
        m.append(int(m1))
        d.append(int(d1))

for i in range(len(g)):
    if y[i]>32:
        g[i]="?"
        y[i]=y[i]-30
    if (y[i]==31)*(m[i]>4):
        g[i]="?"
        y[i]=y[i]-30
    print(g[i],y[i],m[i],d[i])

Submission status: Wrong Answer

Solution code:
g=[]
y=[]
m=[]
d=[]

for i in range(101):
    a=input()
    if a=="#":
        break
    else:
        g1,y1,m1,d1=map(str,a.split())
        g.append(g1)
        y.append(int(y1))
        m.append(int(m1))
        d.append(int(d1))

for i in range(len(g)):
    if y[i]>32:
        g[i]="?"
        y[i]=y[i]-30
    if (y[i]==31)*(m[i]>4):
        g[i]="?"
        y[i]=y[i]-30
    print(g[i],y[i],m[i],d[i])

Submission status: Wrong Answer

Solution code:
datum = []
while True:
    datum.append(input().split())
    if datum[-1][0]=='#':
        break
datum=datum[:-1]
ans = []
for data in datum:
    if int(data[1]) >= 31 and int(data[2]) >= 5:
        ans.append(['?', str(int(data[1])-30), str(data[2]), str(data[3])])
    else:
        ans.append(data)
ans2 = []
for a in ans:
    ans2.append(' '.join(a))
print('\n'.join(ans2))

Submission status: Wrong Answer

Solution code:
datum = []
while True:
    datum.append(input().split())
    if datum[-1][0]=='#':
        break
datum=datum[:-1]
ans = []
for data in datum:
    if int(data[1]) >= 31 or (int(data[1]) >= 31 and int(data[2]) >= 5):
        ans.append(['?', str(int(data[1])-30), str(data[2]), str(data[3])])
    else:
        ans.append(data)
ans2 = []
for a in ans:
    ans2.append(' '.join(a))
print('\n'.join(ans2))

Submission status: Wrong Answer

Solution code:
while True:
    po = input()
    if po == '#':
        break
    y,m,d = [int(i) for i in po.split()[1:]]
    if y > 32 or (y == 31 and m > 4):
        print(f"? {y-30} {m} {d}")
    else:
        print(f"HEISEI {y} {m} {d}")

Submission status: Accepted

Solution code:
while True:
    a = list(map(str, input().split()))
    if a[0] == "#":
        break
    elif int(a[1]) <= 30:
        print(" ".join(a))
    elif int(a[1]) == 31 and int(a[2]) <= 4:
        print(" ".join(a))
    else:
        a[0] = "?"
        s = int(a[1])
        s -= 30
        a[1] = str(s)
        print(" ".join(a))

Submission status: Accepted

Solution code:
# AOJ 2881: Change of the Era Name
# Python3 2018.7.10 bal4u

# y << 9, m << 5, d 
LAST = (31<<9) + (5<<5) + 1		# H31.5.1

while True:
	a = input()
	if a == "#": break
	era, y, m, d = a.split()
	y, m, d = int(y), int(m), int(d)
	date = (y<<9) + (m<<5) + d
	if date >= LAST: print('?', y-30, m, d)
	else: print(era, y, m, d)

Submission status: Accepted

Solution code:
ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = -1
while True:
    try:
        ls=input().split()
        ls_g.append(ls[0])
        ls_y.append(int(ls[1]))
        ls_m.append(int(ls[2]))
        ls_d.append(int(ls[3]))
        cnt += 1
    except:
        break;

for _ in range(cnt+1):
    if ls_y[_]>31:
        ls_g[_]="?"
        ls_y[_]-=30
    elif ls_y[_]==31 and ls_m[_]>=5:
        ls_g[_]="?"
        ls_y[_]-=30
for i in range(cnt+1):
    print(ls_g[i]+" "+str(ls_y[i])+" "+str(ls_m[i])+" "+str(ls_d[i]))

Submission status: Accepted

Solution code:
# 31年5月1日以降なら年号をマイナス60する
for _ in range(102):
    input_str = str(input())
    if (input_str[0] == '#'):
        exit()
    today = input_str.split()
    if int(today[1]) > 31:
        print(f'? {int(today[1])-30} {int(today[2])} {today[3]}')
        continue

    if int(today[1]) == 31 and int(today[2]) >= 5:
        print(f'? {int(today[1])-30} {int(today[2])} {today[3]}')
        continue
    print(' '.join(today))

Submission status: Accepted

Solution code:
while True:
    line = input()
    if line == '#':
        exit()

    g = line.split()[0]
    y, m, d = map(int, line.split()[1:])
    if y > 31 or y >= 31 and m >= 5:
        g = '?'
        y -= 30
    print(g, y, m, d)

Submission status: Accepted

Solution code:
# 31年5月以降が与えられたら-30する
while 1:
    day_string = str(input())
    if day_string[0] == '#':
        exit()

    g, y, m, d = day_string.split()

    if int(y) > 31 or (int(y) == 31 and int(m) >= 5):
        print(f'? {int(y)-30} {m} {d}')
    else:
        print(f'{g} {y} {m} {d}')

Submission status: Accepted

Solution code:
while True:
    po = input()
    if po == '#':
        break
    y,m,d = [int(i) for i in po.split()[1:]]
    if y > 31 or (y == 31 and m > 4):
        print(f"? {y-30} {m} {d}")
    else:
        print(f"HEISEI {y} {m} {d}")

Submission status: Accepted

Solution code:
while True:
    data = input()
    if data == "#": break
    data = data.split()
    y = int(data[1])
    m = int(data[2])
    d = int(data[3])

    if 31 > y or (y == 31 and 4 >= m):
        print("HEISEI {} {} {}".format(y,m,d))
    else:
        new_y = y - 31 + 1
        print("? {} {} {}".format(new_y,m,d))

Submission status: Accepted

Solution code:
import math
while 1:
    a = input().split()
    if a[0] == "#":
        break
    nengo = a[0]
    y = int(a[1])
    m = int(a[2])
    d = int(a[3])
    if y > 31:
        y -= 30
        nengo = "?"
    elif y == 31:
        if m >= 5:
            nengo = "?"
            y = 1
    print(nengo,y,m,d)

Submission status: Accepted

Solution code:
def get_four_data():
    four_data = input().split()
    return four_data

def change_era_name(four_data):
    era, year, month, day = four_data
    year = int(year)
    month = int(month)
    if year >31 or (year >= 31 and month >= 5):
        era = "?"
        year -= 30
    return era, year, month, day

if __name__ == "__main__":
    while True:
        four_data = get_four_data()
        if four_data[0] == "#":
            break
        era, year, month, day = change_era_name(four_data)
        print(era, year, month, day)

Submission status: Accepted

Solution code:
while True:
    a = input().split()
    if a == ["#"]:
        break
    a[1] = int(a[1])
    a[2] = int(a[2])
    if a[1] >= 32 or (a[1] == 31 and a[2] >= 5):
        a[1] -= 30
        a[0] = "?"
    a[1] = str(a[1])
    a[2] = str(a[2])
    print(" ".join(a))

Submission status: Accepted

Solution code:
while 1:
    s = input()
    if s=='#':
        break
    g, y, m, d=s.split()
    y=int(y)
    m=int(m)
    if y > 31:
        print('? ' + str(y-30) + ' ' + str(m) + ' ' + d)
    elif y == 31:
        if m > 4:
            print('? 1 ' + str(m) + ' ' + d)
        else:
            print('HEISEI 31 ' + str(m) + ' ' + d)
    else:
        print(s)

Submission status: Accepted

Solution code:
while True:
    s = input()
    if s == "#": break
    g, y, m, d = s.split()

    if (int(y) == 31 and int(m) > 4) or int(y) > 31:
        print("?", int(y)-30, m, d)
    else:
        print(g, y, m, d)

Submission status: Accepted

Solution code:
reiwa="?"
while True:
    data=input().split()
    g=data[0]
    if g == "#":
        break
    else:
        y=int(data[1])
        m=int(data[2])
        d=int(data[3])
    
    #平成
    if y<31 or (y==31 and m<5):
        print(f"{g} {y} {m} {d}")
    #新元号
    else:
        y=y-30
        print(f"{reiwa} {y} {m} {d}")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    while True:
        tmp = input().strip()
        if tmp[0] == "#":
            break
        g, y, m, d = tmp.split()
        y = int(y)
        m = int(m)
        d = int(d)
        if y < 31:
            print(tmp)
        elif y == 31:
            if m <= 4:
                print(tmp)
            else:
                print("?", y-30, m, d)
        else:
            print("?", y-30, m, d)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
while True:
    try:
        s,y,m,d=input().split()
    except:
        break
    if int(y)>31 or (int(y)==31 and int(m)>4):
        print("?",str(int(y)-30),m,d)
    else:
        print(s,y,m,d)

Submission status: Accepted

Solution code:
import sys


def solve(g,  y,  m,  d):
    y = int(y)
    m = int(m)
    d = int(d)

    if y == 31 and m >= 5:
        print('?', y-30, m, d)
    elif y >= 32:
        print('?', y-30, m, d)
    else:
        print(g, y, m, d)


while True:
    s = input()
    if s == "#":
        break
    solve(*map(str,  s.split()))

Submission status: Accepted

Solution code:
while 1:
    s = input()
    if s == "#":
        break
    y, m, d = map(int, s.split()[1:])
    if (y, m) >= (31, 5):
        print("? {} {} {}".format(y-30, m, d))
    else:
        print("HEISEI {} {} {}".format(y, m, d))

Submission status: Accepted

Solution code:

while 1:
    before_convert = input().split()

    era = before_convert[0]
    
    if era == "#":
        exit()
    
    heisei_year = int(before_convert[1])
    month = int(before_convert[2])
    day = before_convert[3]

    if heisei_year <= 30:
        era = "HEISEI"
        year = heisei_year
    elif heisei_year == 31:
        if month < 5:
            era = "HEISEI"
            year = heisei_year
        else:
            era = "?"
            year = 1
    else:
        era = "?"
        year = heisei_year - 30

    print("{0} {1} {2} {3}".format(era, year, month, day))

Submission status: Accepted

Solution code:
def main():
    while True:
        buf = input().split()
        if buf[0] == "#":
            return
        g = buf[0]
        y,m,d = map(int,buf[1::])
        y = int(y)
        m = int(m)
        d = int(d)
        if y > 31 or (y == 31 and m >= 5):
            g = "?"
            y -= 30
        print(g,y,m,d)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ans = []

while True:
    a = list(input().split())
    if a[0] == "#":
        break
    a[1], a[2], a[3] = int(a[1]), int(a[2]), int(a[3])
    if a[1] > 31:
        ans.append(["?", a[1] - 30, a[2], a[3]])
    
    elif a[1] == 31:    
        if a[2] >= 5:
            ans.append(["?", 1, a[2], a[3]])
        else:
            ans.append([a[0], a[1], a[2], a[3]])

    else:
        ans.append([a[0], a[1], a[2], a[3]])


for i in ans:
    print("{} {} {} {}".format(i[0], i[1], i[2], i[3]))

Submission status: Accepted

Solution code:
def solve(ip):
    g, y, m, d = ip.split()
    y, m, d = map(int, [y, m, d])
    if (y == 31 and m >= 5) or (y >= 32):
        g = "?"
        y -= 30

    return [g, y, m, d]


def main():
    ans = []
    while True:
        ip = input()
        if (ip[0] == "#"):
            break
        ans.append(solve(ip))
    for i in ans:
        print(*i)


main()

Submission status: Accepted

Solution code:
while True:
    s = input()
    if s == "#":
        break
    g, y, m, d = s.split()
    if int(y) >= 32:
        g = "?"
        y = str(int(y)-30)
    elif int(y) == 31:
        if int(m) >= 5:
            g = "?"
            y = str(int(y)-30)
    print(g, y, m, d)

Submission status: Accepted

Solution code:
while True:
  l=list(map(str,input().split()))
  if l[0]=="#":
    break
  #print(l)
  y=int(l[1])
  m=int(l[2])
  d=int(l[3])
  if y>=31 and m>=5:
    l[0]="?"
    y=y-30
  elif y>=32:
    l[0]="?"
    y=y-30
  print(l[0],y,m,d)

Submission status: Accepted

Solution code:
while True:
    input_data = input()
    if input_data == "#":
        break
    g, y, m, d = input_data.split()
    y = int(y)
    m = int(m)
    d = int(d)
    if y < 31 or (y == 31 and m <= 4):
        print(g, y, m, d)
    else:
        print("?", str(y - 30), str(m), str(d))

Submission status: Accepted

Solution code:
while True:
  s = input()
  if s=="#":
    break

  g, y, m, d = s.split()
  y, m, d = int(y), int(m), int(d)
  if y>=32 or (y==31 and m>=5):
    g = "?"
    y -= 30
  print(g, y, m, d)

Submission status: Accepted

Solution code:
while True :
  try :
    g, y, m, d = map(str, input().split())
    y = int(y)
    m = int(m)
    d = int(d)
    if(y <= 30) :
      print('HEISEI', y, m, d)
    elif(y == 31 and m <= 4):
      print('HEISEI',y , m, d)
    else:
      y = y - 30
      print('?', y, m, d)
  except :
      break

Submission status: Accepted

Solution code:
while True:
    a=list(input().split())
    if(a[0]=="#"):
        break
 
    y=int(a[1])
    m=int(a[2])
    d=int(a[3])
    if(y <= 30):
        print(a[0],y,m,d)
    elif(y == 31 and m<=4):
        print(a[0],y,m,d)
    else:
        n=y-30
        print("?",n,m,d)

Submission status: Accepted

Solution code:
while True :
    try :
        g, y, m, d = map(str, input().split())
        y = int(y)
        m = int(m)
        d = int(d)
        if(y <= 30) :
            print("HEISEI", y, m, d)
        elif(y == 31 and m <= 4):
            print("HEISEI",y , m, d)
        else:
            y = y - 30
            print("?", y, m, d)
    except :
        break

Submission status: Accepted

Solution code:
while True:
    a = input()
    if(a == "#"):
        break
    g,y,m,d = map(lambda x:x,a.split(" "))
    if(int(y) <=30):
        print(g,y,m,d)
    elif(int(y) <= 31 and int(m) <= 4 and int(d) <= 30):
        print(g,y,m,d)
    else:
        print("?",int(y)-30,m,d)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

def main(n):
	if n[0] == "#":
		return
	if (int(n[1]) > 31) or (int(n[1]) == 31 and int(n[2]) > 4):
		n[0] = "?"
		n[1] = str(int(n[1]) - 30)
	print(" ".join(n))
	return main(input().split())

main(input().split())

Submission status: Accepted

Solution code:
while 1:
    s=list(map(str,input().split()))
    if s[0]=="#":break
    if int(s[1])==31 and int(s[2])>=5 or int(s[1])>=32:
        s[0]="?"
        s[1]=str(int(s[1])-30)
    print(' '.join(map(str, s)))

Submission status: Accepted

Solution code:
"""
a = int(input())
# スペース区切りの整数の入力
b, c = map(int, input().split())
# 文字列の入力
s = input()
# 出力
print(str(a+b+c) + " " + s)
"""


def main():
	while(1):
		N = input().split() 
		if N[0] == "#":
			break
		y = int(N[1])
		m = int(N[2])
		d = int(N[3])
		if y >= 32:
			print("? {} {} {}".format(y-30,m,d))
		if y < 31:
			print("{} {} {} {}".format(N[0],y,m,d))
		if y==31:
			if m>=5:

				print("? {} {} {}".format(y-30,m,d))
			else:
				print("{} {} {} {}".format(N[0],y,m,d))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while 1:
    data = input()
    if data == "#":
        break

    _, y, m, d = data.split()
    y = int(y)
    m = int(m)
    d = int(d)

    if y == 31:
        if m <= 4:
            gen = "HEISEI"
        else:
            gen = "?"
            y -= 30
    elif y < 31:
        gen = "HEISEI"
    else:
        gen = "?"
        y -= 30

    print(gen, y, m, d)

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**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 = []

    def f(s):
        g, y, m, d = s.split()
        y = int(y)
        m = int(m)
        d = int(d)
        if (y,m,d) >= (31, 5, 1):
            g = '?'
            y = y - 30
        return '{} {} {} {}'.format(g,y,m,d)

    while 1:
        s = S()
        if s == '#':
            break
        rr.append(f(s))

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


print(main())

Submission status: Accepted

Solution code:
while True:
    store = input().split()
    g = store[0]
    if g == '#':
        break
    y,m,d = map(int,store[1:])
    if y > 31 or (y == 31 and m > 4):
        print('? %d %d %d' % (y-30,m,d))
    else:
        print('HEISEI %d %d %d' % (y,m,d))

Submission status: Accepted

Solution code:
ans = []
while True:
    data = input().split()
    g = data[0]
    if g == '#':
        break
    y, m, d = map(int, data[1:])
    if y > 30 and m > 4:
        ans.append(("? %d %d %d") % (y-30, m, d))
    elif y > 31:
        ans.append(("? %d %d %d") % (y-30, m, d))
    else:
        ans.append(("%s %d %d %d") % (g, y, m, d))
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
answer = []

while True :
    s = input().split()
    
    if s[0] == "#" :
        break
    else :
        if (int(s[1]) > 31) or (int(s[1]) == 31 and int(s[2]) >= 5) : 
            answer.append("?" + " " + str(int(s[1]) - 30) + " " + s[2] + " " + s[3])
        else :
            answer.append(" ".join(s))
            
for a in answer :
    print(a)

Submission status: Runtime Error

Solution code:
while True:
    a = list(map(str, input().split()))
    if a[0] == "0":
        break
    elif int(a[1]) <= 30:
        print(" ".join(a))
    elif int(a[1]) == 31 and int(a[2]) <= 4:
        print(" ".join(a))
    else:
        a[0] = "?"
        s = int(a[1])
        s -= 30
        a[1] = str(s)
        print(" ".join(a))