message
stringlengths
2
20.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
1.95k
109k
cluster
float64
17
17
__index_level_0__
int64
3.91k
217k
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,061
17
52,122
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` #!/usr/bin/python3 delims = [0, 1989, 1999, 2099, 3099, 13099, 113099, 1113099, 11113099, 111113099, 1111113099] n = int(input()) for i in range(n): suf = input()[4:] min_val = delims[len(suf)] d = int(suf) while d < min_val: d += 10 ** len(suf) print(d) ```
output
1
26,061
17
52,123
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,062
17
52,124
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` import sys sys.stderr = sys.stdout def iao(n, A): d = [None] * 10 y = 1989 b = 10 for k in range(1, 10): d[k] = y, b, y % b y += b b *= 10 for s in A: y, b, a0 = d[len(s)-4] a = int(s[4:]) o = a - a0 if o < 0: o += b yield y + o def main(): n = readint() A = [input() for _ in range(n)] print('\n'.join(map(str, iao(n, A)))) ########## def readint(): return int(input()) def readinti(): return map(int, input().split()) def readintt(): return tuple(readinti()) def readintl(): return list(readinti()) def readinttl(k): return [readintt() for _ in range(k)] def readintll(k): return [readintl() for _ in range(k)] def log(*args, **kwargs): print(*args, **kwargs, file=sys.__stderr__) if __name__ == '__main__': main() ```
output
1
26,062
17
52,125
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,063
17
52,126
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` import math def find_year(iao): if len(iao) == 1: year = 1980 + int(iao) if year < 1989: year += 10 return year else: pre_year = find_year(iao[1:]) pre_year_str = list(str(pre_year)) if len(iao) > len(pre_year_str): pre_year_str = ['0' for _ in range(len(iao) - len(pre_year_str))] + pre_year_str if int(iao[0]) <= int(pre_year_str[-len(iao)]): pre_year_str[-len(iao)] = iao[0] return int(int("".join(pre_year_str)) + math.pow(10, len(iao))) else: pre_year_str[-len(iao)] = iao[0] return int("".join(pre_year_str)) def solve(): n = int(input()) for _ in range(n): y = input()[4:] year = find_year(y) print(year) if __name__ == '__main__': solve() ```
output
1
26,063
17
52,127
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,064
17
52,128
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` def solve(x): l = len(x) if l == 1: return '19' + ('8' if x == '9' else '9') + x if l == 2: return ('19' if x == '99' else '20') + x if l == 3: return ('3' if int(x) <= 98 else '2') + x if l >= 4: y = int((l - 4) * '1' + '3098') return ('1' if int(x) <= y else '') + x n = int(input()) for i in range(n): k = input()[4:] print(solve(k)) ```
output
1
26,064
17
52,129
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,065
17
52,130
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` x = [0, 1989] for i in range(1, 10): x.append(x[-1]+10**i) for i in range(int(input())): k = input().split("'")[1] lb = x[len(k):len(k)+2] if int(k) < int(str(lb[0])[-len(k):]): print(str(lb[1]-1)[:-(len(str(k)))]+k) else: print(str(lb[0]-1)[:-(len(str(k)))]+k) ```
output
1
26,065
17
52,131
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,066
17
52,132
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` def run(n): l = len(n) - 1 b = 1989 l = 10**l while l > 1: b += l l //= 10 if b <= int(n): return n b = str(b) if len(b) == len(n): return '1' + n else: if b[-len(n):] <= n: return b[:-len(n)] + n return str(int(b[:-len(n)])+1) + n n = int(input()) for i in range(n): print(run(input()[4:])) ```
output
1
26,066
17
52,133
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,067
17
52,134
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` n = int(input()) res = [] for i in range(n): line = input() year = 1989 for u in range(len(line)-1, 3, -1): a = line[u:] k = len(a) while year%(10**k)!=int(a): year = year+10**(k-1) year += 10**(k) res.append(year-10**k) for i in res: print(i) ```
output
1
26,067
17
52,135
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
26,068
17
52,136
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` for i in range(int(input())): t = input()[4:] q, d = int(t), 10 ** len(t) while q < 1988 + d // 9: q += d print(q) # Made By Mostafa_Khaled ```
output
1
26,068
17
52,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` T=int(input()) for _ in range(T): s=input() s=s[4:] l=len(s) s=int(s) x=1988 t=1 for i in range(l): y=s%(t*10) z=x%(t*10) while True: x=x+t z=x%(t*10) if y==z: break t=t*10 print(x) ```
instruction
0
26,069
17
52,138
Yes
output
1
26,069
17
52,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` delims = [0, 1989, 1999, 2099, 3099, 13099, 113099, 1113099, 11113099, 111113099, 1111113099] n = int(input()) for i in range(n): suf = input()[4:] min_val = delims[len(suf)] d = int(suf) while d < min_val: d += 10 ** len(suf) print(d) ```
instruction
0
26,070
17
52,140
Yes
output
1
26,070
17
52,141
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` list_sep=[1998,2098,3098,13098,113098,1113098,11113098,111113098,1111113098] def go(st): length=len(st) if length>=4: if int(st)<=list_sep[length-2]: print('1'+st) else: print(st) else: if length==3: if int(st)<99: print('3'+st) else: print('2'+st) else: if length==2: if int(st)==99: print('1999') else: print('20'+st) else: if int(st)==9: print('1989') else: print('199'+st) n=int(input()) for i in range(n): #print(input()[4:]) go(input()[4:]) ```
instruction
0
26,071
17
52,142
Yes
output
1
26,071
17
52,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def listring(l): return ' '.join([str(x) for x in l]) def printlist(l): print(' '.join([str(x) for x in l])) for _ in range(it()): string = ip() string = string[4:] k = 1988 for i in range(len(string)-1,-1,-1): suffix = string[i:] t = len(suffix) k += 10**(t-1) while not str(k).endswith(suffix): k += 10**(t-1) pt(k) ```
instruction
0
26,072
17
52,144
Yes
output
1
26,072
17
52,145
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` from sys import stdin n=int(stdin.readline().strip()) st=set() s1=[] for i in range(n): s=(stdin.readline().strip()[4::]) s1.append((int(s),i,s)) s1.sort() if n==1000: print(s1) ans=[0 for i in range(n)] for i in range(n): x=10**(len(str(s1[i][2]))) s2=int(s1[i][0]) x1=x//10 while s2<1989 or s2 in st or s2<x1: s2+=x st.add(s2) ans[s1[i][1]]=s2 for i in ans: print(i) ```
instruction
0
26,073
17
52,146
No
output
1
26,073
17
52,147
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` list_sep=[1998,2098,3098,13098,113098,1113098,11113098,111113098,1111113098] def go(st): length=len(st) if length>=4: if int(st)<list_sep[length-2]: print('1'+st) else: print(st) else: if length==3: if int(st)<99: print('3'+st) else: print('2'+st) else: if length==2: if int(st)==99: print('1999') else: print('20'+st) else: if int(st)==9: print('1989') else: print('199'+st) n=int(input()) for i in range(n): #print(input()[4:]) go(input()[4:]) ```
instruction
0
26,074
17
52,148
No
output
1
26,074
17
52,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` n = int(input()) for i in range(0,n): s = input() j = s[4:] mi = 10*(10**(len(j)-1) - 1)/9 + 1989 v = int(j); fr = 0 while int(str(fr) + j) < mi: fr+=1 print("IAO'"+str(int(str(fr) + j))) ```
instruction
0
26,075
17
52,150
No
output
1
26,075
17
52,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` def gcd(a,b): if a==0: return b return gcd(b%a,a) d=input() d=int(d) l=[] for _ in range(d): x=input() s= int(x[4:]) x=0 ss=s while True: if ss>=1989 and (ss not in l): l.append(ss) break x=x+1 ss=int(str(x)+str(s)) for i in range(len(l)): print(l[i]) ```
instruction
0
26,076
17
52,152
No
output
1
26,076
17
52,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall is standing in a row with Many Other Balls. More precisely, there are exactly n Balls. Balls are proud of their home land — and they want to prove that it's strong. The Balls decided to start with selecting exactly m groups of Balls, each consisting either of single Ball or two neighboring Balls. Each Ball can join no more than one group. The Balls really want to impress their Enemies. They kindly asked you to calculate number of such divisions for all m where 1 ≤ m ≤ k. Output all these values modulo 998244353, the Enemies will be impressed anyway. Input There are exactly two numbers n and k (1 ≤ n ≤ 109, 1 ≤ k < 215), denoting the number of Balls and the maximim number of groups, respectively. Output You should output a sequence of k values. The i-th of them should represent the sought number of divisions into exactly i groups, according to PolandBall's rules. Examples Input 3 3 Output 5 5 1 Input 1 1 Output 1 Input 5 10 Output 9 25 25 9 1 0 0 0 0 0 Note In the first sample case we can divide Balls into groups as follows: {1}, {2}, {3}, {12}, {23}. {12}{3}, {1}{23}, {1}{2}, {1}{3}, {2}{3}. {1}{2}{3}. Therefore, output is: 5 5 1. Submitted Solution: ``` #!/usr/bin/env python import sys #n = int(input()) #k = int(input()) n, k = map(int, input().split()) res = [1 if i <= n else 0 for i in range(k+1)] for r in range(2, n+1): temp = res[1] res[1] = 2 * r - 1 for c in range(2, n-r+2): temp2 = res[c] res[c] = temp + res[c-1] + temp2 temp = temp2 res = [str(x) for x in res] print(' '.join(res[1:])) ```
instruction
0
26,119
17
52,238
No
output
1
26,119
17
52,239
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,221
17
52,442
Tags: brute force, combinatorics, math Correct Solution: ``` ct=[0]*10 fact=[1]*20 ans=0 def setAns(lol): global ans ans=lol def calc(k,fr): if(k==10): # print(fr) tot=sum(fr) w0=fact[tot] # print(tot,w0) for i in range(10): w0//=fact[fr[i]] wo0=0 if(fr[0]>0): fr[0]-=1 wo0=fact[tot-1] for i in range(10): wo0//=fact[fr[i]] fr[0]+=1 tp=w0-wo0 # print(w0,wo0) setAns(ans+tp) return if(ct[k]==0): calc(k+1,fr) return for i in range(1,ct[k]+1): # print(k,i) fr[k]=i calc(k+1,fr) fact[0]=1 for i in range(1,20): fact[i]=fact[i-1]*i n=int(input()) while(n>0): k=n%10 n//=10 ct[k]+=1 freq=[0]*10 calc(0,freq) print(ans) ```
output
1
26,221
17
52,443
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,223
17
52,446
Tags: brute force, combinatorics, math Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time import math def test(num, a, step): if step == 10: s = sum(a) ans = s - a[0] s -= 1 ans *= math.factorial(s) for i in a: if i!=0: ans /= math.factorial(i) return int(ans) if num[step] == 0: return test(num, a, step+1) ans = 0 a[step] = 0 for i in range(num[step]): a[step] += 1 ans += test(num, a, step+1) return ans n = [int(i) for i in input()] start = time.time() num = [0 for i in range(10)] for i in n: num[i] += 1 a = [0 for i in range(10)] ans = test(num, a, 0) print(ans) finish = time.time() #print(finish - start) ```
output
1
26,223
17
52,447
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,224
17
52,448
Tags: brute force, combinatorics, math Correct Solution: ``` def fact(n): global fa if fa[n] != -1: return fa[n] else: fa[n] = fact(n - 1) * n return fa[n] fa = [-1] * 20 fa[0] = 1 fa[1] = 1 fa[2] = 2 res = 0 a = int(input()) b = str(a) s = [0] * 10 for i in range(len(b)): s[int(b[i])] += 1 for i0 in range(s[0] + 1): if i0 > 0 or s[0] == 0: for i1 in range(s[1] + 1): if i1 > 0 or s[1] == 0: for i2 in range(s[2] + 1): if i2 > 0 or s[2] == 0: for i3 in range(s[3] + 1): if i3 > 0 or s[3] == 0: for i4 in range(s[4] + 1): if i4 > 0 or s[4] == 0: for i5 in range(s[5] + 1): if i5 > 0 or s[5] == 0: for i6 in range(s[6] + 1): if i6 > 0 or s[6] == 0: for i7 in range(s[7] + 1): if i7 > 0 or s[7] == 0: for i8 in range(s[8] + 1): if i8 > 0 or s[8] == 0: for i9 in range(s[9] + 1): if i9 > 0 or s[9] == 0: w2 = [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9] su = 0 for i in range(10): su += w2[i] for i in range(1, 10): if w2[i] > 0: w2[i] -= 1 su -= 1 res += fact(su)/(fact(w2[0]) * fact(w2[1]) * fact(w2[2]) * fact(w2[3]) * fact(w2[4]) * fact(w2[5]) * fact(w2[6]) * fact(w2[7]) * fact(w2[8]) * fact(w2[9])) su += 1 w2[i] += 1 print(int(res)) ```
output
1
26,224
17
52,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` n = input() facts = {0: 1} def fact(a): global facts if a in facts: return facts[a] res = 1 for i in range(1, a+1): res *= i facts[i] = res return facts[a] occ = [0] * 10 for i in range(len(n)): occ[int(n[i])] += 1 ans = 0 def go_find(hame, start): # print("Start: " + str(start)) # print(hame) global ans if hame[0] == 0: res = fact(sum(hame)) for i in range(10): res //= fact(hame[i]) else: res2 = fact(sum(hame)-1) for i in range(1, 10): res2 //= fact(hame[i]) res2 //= fact(hame[0]-1) res = fact(sum(hame)) for i in range(10): res //= fact(hame[i]) res -= res2 # print(res) # print("=============") ans += res for i in range(start, 10): if hame[i] > 1: hame[i] -= 1 go_find(hame, i) hame[i] += 1 go_find(occ, 0) print(ans) ```
instruction
0
26,228
17
52,456
Yes
output
1
26,228
17
52,457
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` from collections import Counter from itertools import product s = input() ds = Counter(s) fac = [1 for i in range(100)] for i in range(1, 100): fac[i] = fac[i-1] * i res = 0 for possib in product(*[zip([k] * n, range(1, n+1)) for k, n in ds.items()]): possib = list(possib) non_zero_sum = sum(v for k, v in possib if k != '0') total = sum(v for _, v in possib) value = non_zero_sum * fac[total-1] for _, v in possib: value //= fac[v] res += value print(res) ```
instruction
0
26,229
17
52,458
Yes
output
1
26,229
17
52,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` a = map(int,input()); cnts = [0]*10; for aa in a: cnts[aa]+=1 mem = {} mem[(1,0,0,0,0,0,0,0,0,0)] = 0; for i in range(1,10): mem[(0,)*(i) + (1,) + (0,)*(10-i-1)] = 1; def get(a): if (tuple(a) in mem): return mem[tuple(a)] else: aa = list(a) tot = 0 for i in range(0,10): if (a[i] != 0): aa[i] -= 1; tot += get(aa); aa[i] += 1; mem[tuple(a)] = tot return tot bigTot = 0 def goThrough(pre, post): global bigTot if (len(post) == 0) : bigTot += get(pre) elif (post[0] == 0): goThrough(pre + (0,) , post[1:]) else: for i in range(1,post[0]+1): goThrough(pre + (i,) , post[1:]) goThrough((), cnts) print(bigTot) ```
instruction
0
26,230
17
52,460
Yes
output
1
26,230
17
52,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` def faktorijel(n): if n == 0: return 1 else: x = 1 for i in range(1, n+1): x *= i return x n = list(input()) znams = [0,0,0,0,0,0,0,0,0,0] for i in n: znams[int(i)] += 1 #print(znams) broj = 0 for broj0 in range(min(znams[0],1), max(1,znams[0]+1)): for broj1 in range(min(znams[1],1), max(1,znams[1]+1)): for broj2 in range(min(znams[2],1), max(1,znams[2]+1)): for broj3 in range(min(znams[3],1), max(1,znams[3]+1)): for broj4 in range(min(znams[4],1), max(1,znams[4]+1)): for broj5 in range(min(znams[5],1), max(1,znams[5]+1)): for broj6 in range(min(znams[6],1), max(1,znams[6]+1)): for broj7 in range(min(znams[7],1), max(1,znams[7]+1)): for broj8 in range(min(znams[8],1), max(1,znams[8]+1)): for broj9 in range(min(znams[9],1), max(1,znams[9]+1)): #print("vrtise") broj += faktorijel(broj0+broj1+broj2+broj3+broj4+broj6+broj7+broj8+broj9)/(faktorijel(broj0)*faktorijel(broj1)*faktorijel(broj2)*faktorijel(broj3)*faktorijel(broj4)*faktorijel(broj5)*faktorijel(broj6)*faktorijel(broj7)*faktorijel(broj8)*faktorijel(broj9)) if broj0 != 0: broj += - faktorijel(broj0-1+broj1+broj2+broj3+broj4+broj6+broj7+broj8+broj9)/(faktorijel(broj0-1)*faktorijel(broj1)*faktorijel(broj2)*faktorijel(broj3)*faktorijel(broj4)*faktorijel(broj5)*faktorijel(broj6)*faktorijel(broj7)*faktorijel(broj8)*faktorijel(broj9)) print(int(broj)) ```
instruction
0
26,231
17
52,462
No
output
1
26,231
17
52,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` def main(): def fact(x): if x == 0: return 1 return x * fact(x - 1) n = input() l = len(n) def helper(dc): a = 0 temp = [dc[j] for j in dc if j != '0'] s = sum(temp) try: ret = fact(s) * fact(s + dc['0'] - 1) // (fact(s - 1) * fact(dc['0'])) except: ret = fact(s) for i in temp: ret = ret // fact(i) for i in dc: if dc[i] != 1: d = dc d[i] -= 1 a += helper(d) return ret + a dct = {} for i in set(n): dct[i] = n.count(str(i)) print(helper(dct)) return 0 main() ```
instruction
0
26,232
17
52,464
No
output
1
26,232
17
52,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) fact = [1] * 1000 for i in range(2, 1000): fact[i] = fact[i - 1] * i s = input() cnt = {} for d in '0123456789': cnt[int(d)] = s.count(d) ans = 0 def getcnt(p): q0 = p[0] q = [pi for pi in p if pi != 0] num = fact[sum(q)] den = 1 for qi in q: den *= fact[qi] gc = num // den if q0 == 0: return gc q = [pi for pi in p[1:] if pi != 0] num = fact[sum(q)] den = 1 for qi in q: den *= fact[qi] gc -= num // den return gc def rec(d, p): global ans if d == 10: #print(p, getcnt(p)) ans += getcnt(p) return if cnt[d] == 0: p[d] = 0 rec(d + 1, p) return for c in range(1, cnt[d] + 1): p[d] = c rec(d + 1, p) p = [0] * 10 rec(0, p) print(ans) ```
instruction
0
26,233
17
52,466
No
output
1
26,233
17
52,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≤ n ≤ 10^{18}) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer — the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` def fac(k): if k<=0: return 1 else: return k*fac(k-1) def a(n): maxer=0 sumer=0 for i in range(10): sumer+=sk[i] if sk[i]>maxer: maxer=sk[i] if maxer<=1: t=fac(sumer-1)*(sumer-sk[0]) for i in range(10): t=t//fac(sk[i]) return t else: t=fac(sumer-1)*(sumer-sk[0]) for i in range(10): if sk[i]>=1: t=t//fac(sk[i]) for j in range(10): st=sk if sk[j]>=2: st[j]-=1 t+=a(st) return t n=int(input()) sk=[0]*10 while n>0: sk[n%10]+=1 n=n//10 k=a(n) if k==12598174728720: k=29340299842560 print(k) ```
instruction
0
26,234
17
52,468
No
output
1
26,234
17
52,469
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,399
17
52,798
"Correct Solution: ``` #0174 while True: A = 0 B = 0 r = input() if r == '0': break for i in range(1,len(r)): if r[i] == 'A': A += 1 else: B += 1 if A > B: A += 1 elif B > A: B += 1 print(A,B) ```
output
1
26,399
17
52,799
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,400
17
52,800
"Correct Solution: ``` while 1: a=input() if a=='0':break d,e=a[1:].count('A'),a[1:].count('B') (b,c)=(0,1) if d<e else (1,0) print(d+b,e+c) ```
output
1
26,400
17
52,801
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,401
17
52,802
"Correct Solution: ``` def judge(r): pa = pb = 0 for c in r[1:]: if c == "A": pa += 1 else: pb += 1 if pa < pb: print(pa, pb + 1) else: print(pa + 1, pb) while True: r1 = input() if r1 == "0": break judge(r1) judge(input()) judge(input()) ```
output
1
26,401
17
52,803
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,402
17
52,804
"Correct Solution: ``` while True: po=input() if po=="0": break A,B=0,0 for i in range(1,len(po)): if po[i]=="A": A+=1 else : B+=1 if A>B: A+=1 else : B+=1 print(A,B) ```
output
1
26,402
17
52,805
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,403
17
52,806
"Correct Solution: ``` while True: re=input() if re=="0": break a=0 b=0 n=len(re)-1 for i in range(n): if re[i+1]=="A": a+=1 else: b+=1 if a>b: a+=1 else: b+=1 print(a, b) ```
output
1
26,403
17
52,807
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,404
17
52,808
"Correct Solution: ``` while True: a = input() if a == '0': break b, c = a[1:].count('A'), a[1:].count('B') if b < c: d, e = 0, 1 else: d, e = 1, 0 Ap = b+d Bp = c+e print(Ap,Bp) ```
output
1
26,404
17
52,809
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,405
17
52,810
"Correct Solution: ``` while True: str = input(); if (str == '0'): break; scorea = 0; scoreb = 0; for i in range(1, len(str)): if (str[i] == 'A'): scorea += 1; else: scoreb += 1; if (scorea > scoreb): scorea += 1; else: scoreb += 1; print(scorea, scoreb); ```
output
1
26,405
17
52,811
Provide a correct Python 3 solution for this coding contest problem. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11
instruction
0
26,406
17
52,812
"Correct Solution: ``` try: while True: x = input() if x=='0': break a = 0 b = 0 for i in range(1,len(x)): if x[i]=='A': a = a + 1 elif x[i]=='B': b = b + 1 if a > b: a = a + 1 elif a < b: b = b + 1 print(a,b) except EOFError: pass ```
output
1
26,406
17
52,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11 Submitted Solution: ``` while True: r = input() if r =="0": break a = r[1:].count('A') b = r[1:].count('B') if a > b: print(a+1,b) else: print(a,b+1) ```
instruction
0
26,407
17
52,814
Yes
output
1
26,407
17
52,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11 Submitted Solution: ``` while True: l=str(input()) if l=="0": break A,B = 0,0 for i in range(1,len(l)): if l[i]=="A": A+=1 else: B+=1 if A>B: A+=1 else: B+=1 print(A,B) ```
instruction
0
26,408
17
52,816
Yes
output
1
26,408
17
52,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11 Submitted Solution: ``` while True: n=str(input()) if n=='0': break B=len(n) N=list(n) a=0 b=0 for i in range(B-1): C=N[i+1] if C=='A': a=a+1 else: b=b+1 if a>b: a=a+1 else: b=b+1 print(a,b) ```
instruction
0
26,409
17
52,818
Yes
output
1
26,409
17
52,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points first wins the game. * The first serve of the first game starts with Mr. A, but the next serve is done by the person who got the previous point. * In the 2nd and 3rd games, the person who took the previous game makes the first serve. * After 10-10, the winner will be the one who has a difference of 2 points. After all the games were over, I tried to see the score, but referee C forgot to record the score. However, he did record the person who hit the serve. Create a program that calculates the score from the records in the order of serve. However, the total number of serves hit by two people is 100 or less, and the record of the serve order is represented by the character string "A" or "B" representing the person who hit the serve. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: record1 record2 record3 The i-line is given a string that represents the serve order of the i-game. The number of datasets does not exceed 20. Output For each dataset, output the score of Mr. A and the score of Mr. B of the i-game on the i-line, separated by blanks. Example Input ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 Output 11 8 10 12 11 7 11 8 11 0 0 11 Submitted Solution: ``` while True: R=str(input()) if R=='0': break r=list(R) a=0 b=0 for i in range(len(r)-1): if r[i+1]=='A': a+=1 else: b+=1 if a>b: print(a+1,b) else: print(a,b+1) ```
instruction
0
26,410
17
52,820
Yes
output
1
26,410
17
52,821
Provide a correct Python 3 solution for this coding contest problem. Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. Input The input consists of multiple datasets, each in the following format. n a1 a2 … an A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. Output For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. Sample Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output for the Sample Input 0 1 5 Example Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output 0 1 5
instruction
0
26,447
17
52,894
"Correct Solution: ``` # coding: utf-8 while 1: n=int(input()) if n==0: break d=sorted(list(map(int,input().split()))) mn=99999999 for i in range(1,len(d)): mn=min(mn,d[i]-d[i-1]) print(mn) ```
output
1
26,447
17
52,895
Provide a correct Python 3 solution for this coding contest problem. Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. Input The input consists of multiple datasets, each in the following format. n a1 a2 … an A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. Output For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. Sample Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output for the Sample Input 0 1 5 Example Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output 0 1 5
instruction
0
26,448
17
52,896
"Correct Solution: ``` from itertools import combinations ans_list = [] while True: n = int(input()) if n == 0: break A = list(map(int,input().split())) ans = float("inf") for (a, b) in combinations(A,2): ans = min(ans,abs(a-b)) ans_list.append(ans) for ans in ans_list: print(ans) ```
output
1
26,448
17
52,897
Provide a correct Python 3 solution for this coding contest problem. Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. Input The input consists of multiple datasets, each in the following format. n a1 a2 … an A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. Output For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. Sample Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output for the Sample Input 0 1 5 Example Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output 0 1 5
instruction
0
26,449
17
52,898
"Correct Solution: ``` while True: n=int(input()) if n==0: break A=list(map(int,input().split())) A.sort() B=[] for i in range(n-1): B.append(A[i+1]-A[i]) print(min(B)) ```
output
1
26,449
17
52,899
Provide a correct Python 3 solution for this coding contest problem. Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. Input The input consists of multiple datasets, each in the following format. n a1 a2 … an A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. Output For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. Sample Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output for the Sample Input 0 1 5 Example Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output 0 1 5
instruction
0
26,450
17
52,900
"Correct Solution: ``` 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**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 = [] while True: n = I() if n == 0: break a = sorted(LI()) r = inf for i in range(n-1): tr = a[i+1] - a[i] if r > tr: r = tr rr.append(r) return '\n'.join(map(str, rr)) print(main()) ```
output
1
26,450
17
52,901
Provide a correct Python 3 solution for this coding contest problem. Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. Input The input consists of multiple datasets, each in the following format. n a1 a2 … an A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. Output For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. Sample Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output for the Sample Input 0 1 5 Example Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output 0 1 5
instruction
0
26,451
17
52,902
"Correct Solution: ``` #成績の差が最も小さい 2 人を選ぶプログラム #1 行目には学生の人数 n (2 ≤ n ≤ 1000) #2 行目には  ai(1 ≤ i ≤ n)が i 番目の学生の成績 while True: #1行目nを読み込む n =int(input()) #もしn==0ならbreak if n==0: break else : #配列a[i]を読み込む(1<=i<=n) a = sorted(list(map(int, input().strip().split()))) a_sub = 1000000 for i in range(n-1): if abs(a[i]-a[i+1]) < a_sub : a_sub = abs(a[i]-a[i+1]) print(a_sub) ```
output
1
26,451
17
52,903
Provide a correct Python 3 solution for this coding contest problem. Selection of Participants of an Experiment Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. Input The input consists of multiple datasets, each in the following format. n a1 a2 … an A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. Output For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. Sample Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output for the Sample Input 0 1 5 Example Input 5 10 10 10 10 10 5 1 5 8 9 11 7 11 34 83 47 59 29 70 0 Output 0 1 5
instruction
0
26,453
17
52,906
"Correct Solution: ``` def solve(n,a): a.sort() ans = abs(a[0]-a[1]) for i in range(n-1): ans = min(ans,abs(a[i] - a[i+1])) return ans while True: n = int(input()) if n == 0: break a = list(map(int,input().split())) print(solve(n,a)) ```
output
1
26,453
17
52,907
Provide tags and a correct Python 3 solution for this coding contest problem. Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to <image>. In particular, if student A has rating strictly lower then student B, A will get the strictly better position than B, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students. The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n). Output In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input. Examples Input 3 1 3 3 Output 3 1 1 Input 1 1 Output 1 Input 5 3 5 3 4 5 Output 4 1 4 3 1 Note In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
instruction
0
26,921
17
53,842
Tags: brute force, implementation, sortings Correct Solution: ``` n=int(input()) t=list(map(int,input().split())) s=list(set(t)) s.sort() p=[] for i in range(len(s)): p.append(t.count(s[i])) for k in range(len(t)): print(1+sum(p[s.index(t[k])+1:]),end=' ') ```
output
1
26,921
17
53,843
Provide tags and a correct Python 3 solution for this coding contest problem. Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to <image>. In particular, if student A has rating strictly lower then student B, A will get the strictly better position than B, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students. The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n). Output In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input. Examples Input 3 1 3 3 Output 3 1 1 Input 1 1 Output 1 Input 5 3 5 3 4 5 Output 4 1 4 3 1 Note In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
instruction
0
26,922
17
53,844
Tags: brute force, implementation, sortings Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) k=0 while(k<n): p=1+sum(i>l[k] for i in l) k+=1 print(p,end=" ") ```
output
1
26,922
17
53,845
Provide tags and a correct Python 3 solution for this coding contest problem. Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to <image>. In particular, if student A has rating strictly lower then student B, A will get the strictly better position than B, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students. The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n). Output In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input. Examples Input 3 1 3 3 Output 3 1 1 Input 1 1 Output 1 Input 5 3 5 3 4 5 Output 4 1 4 3 1 Note In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
instruction
0
26,923
17
53,846
Tags: brute force, implementation, sortings Correct Solution: ``` input() arr = list(map(int, input().split())) arr2 = {} i = 1 c = 0 while c < len(arr): max_ = max(arr) count = arr.count(max_) for j in range(count): ind = arr.index(max_) arr2[ind] = i arr[ind] = -1 c += 1 i += count for i in arr2.items(): print(i[1], end=' ') ```
output
1
26,923
17
53,847
Provide tags and a correct Python 3 solution for this coding contest problem. Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to <image>. In particular, if student A has rating strictly lower then student B, A will get the strictly better position than B, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students. The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n). Output In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input. Examples Input 3 1 3 3 Output 3 1 1 Input 1 1 Output 1 Input 5 3 5 3 4 5 Output 4 1 4 3 1 Note In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
instruction
0
26,924
17
53,848
Tags: brute force, implementation, sortings Correct Solution: ``` n=int(input()) L=list(map(int,input().split())) A=[0]*(max(L)+1) for k in range(n): A[L[k]-1]+=1 for k in range(1,len(A)): A[k]+=A[k-1] print(" ".join([str(n+1-A[L[k]-1]) for k in range(n)])) ```
output
1
26,924
17
53,849
Provide tags and a correct Python 3 solution for this coding contest problem. Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to <image>. In particular, if student A has rating strictly lower then student B, A will get the strictly better position than B, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students. The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n). Output In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input. Examples Input 3 1 3 3 Output 3 1 1 Input 1 1 Output 1 Input 5 3 5 3 4 5 Output 4 1 4 3 1 Note In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
instruction
0
26,925
17
53,850
Tags: brute force, implementation, sortings Correct Solution: ``` n = int(input()) A = list(map(int, input().split())) B = {} A.insert(0, 0) res = 0 if n == 1: print(1) exit() B[0] = 0 for i in range(1, n + 1): higher = 0 for j in range(1, n + 1): if A[i] < A[j]: higher += 1 B[i] = 1 + higher for i in range(1, n + 1): print(B[i], end=" ") ```
output
1
26,925
17
53,851