message
stringlengths
2
39.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
219
108k
cluster
float64
11
11
__index_level_0__
int64
438
217k
Provide a correct Python 3 solution for this coding contest problem. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD
instruction
0
48,624
11
97,248
"Correct Solution: ``` print("ABC" if len(input())<=3 else "ABD") ```
output
1
48,624
11
97,249
Provide a correct Python 3 solution for this coding contest problem. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD
instruction
0
48,625
11
97,250
"Correct Solution: ``` print("ABC" if len(input().rstrip()) <= 3 else "ABD") ```
output
1
48,625
11
97,251
Provide a correct Python 3 solution for this coding contest problem. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD
instruction
0
48,626
11
97,252
"Correct Solution: ``` s=int(input()) if(s>=1000): print('ABD') else: print('ABC') ```
output
1
48,626
11
97,253
Provide a correct Python 3 solution for this coding contest problem. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD
instruction
0
48,627
11
97,254
"Correct Solution: ``` s = input() print("ABC" if len(s)<=3 else "ABD") ```
output
1
48,627
11
97,255
Provide a correct Python 3 solution for this coding contest problem. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD
instruction
0
48,628
11
97,256
"Correct Solution: ``` n = int(input()) print('ABC' if 1 <= n < 1000 else 'ABD') ```
output
1
48,628
11
97,257
Provide a correct Python 3 solution for this coding contest problem. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD
instruction
0
48,629
11
97,258
"Correct Solution: ``` print("ABC" if (int(input())<1000) else "ABD") ```
output
1
48,629
11
97,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` n=int(input()) print('ABC' if n<1000 else 'ABD') ```
instruction
0
48,630
11
97,260
Yes
output
1
48,630
11
97,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` print("AB" + ("C" if int(input()) <= 999 else "D")) ```
instruction
0
48,631
11
97,262
Yes
output
1
48,631
11
97,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` N = int(input()) print("ABC" if N < 1000 else "ABD") ```
instruction
0
48,632
11
97,264
Yes
output
1
48,632
11
97,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` n=int(input()) print("AB"+"C"*(n<1000)+"D"*(n>=1000)) ```
instruction
0
48,633
11
97,266
Yes
output
1
48,633
11
97,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` a = input() b = input() X = b - a s = int((X*(X+1))/2 - b) print(s) ```
instruction
0
48,634
11
97,268
No
output
1
48,634
11
97,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` n = int(input()) if n < 1000: print("ABC%03d" % n) else: print("ABD%03d" % (n-1000)) ```
instruction
0
48,635
11
97,270
No
output
1
48,635
11
97,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` N = input() if N > 1000 : Npadded = '%03d' % N print("ABC",Npadded) else : Npadded = '%03d' % (N - 999) print("ABD",Npadded) ```
instruction
0
48,636
11
97,272
No
output
1
48,636
11
97,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as `ABC001`, `ABC002`, ... from the first round, but after the 999-th round `ABC999`, a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: `ABD001`, `ABD002`, ..., `ABD999`. You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Constraints * 1 \leq N \leq 1998 * N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. Examples Input 999 Output ABC Input 1000 Output ABD Input 1481 Output ABD Submitted Solution: ``` N = int(input()) if N < 1000: print("ABC{:03d}".format(N)) else: print("ABD{:03d}".format(N-999)) ```
instruction
0
48,637
11
97,274
No
output
1
48,637
11
97,275
Provide a correct Python 3 solution for this coding contest problem. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3
instruction
0
48,706
11
97,412
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys import os scores = [0] for s in sys.stdin: p, s = map(int, s.split(',')) if p == s == 0: break else: scores.append(s) score_set = set(scores) score_set = list(score_set) score_set.sort(reverse=True) for s in sys.stdin: n = int(s) teams_score = scores[n] print(score_set.index(teams_score) + 1) ```
output
1
48,706
11
97,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` t = [0] * 101 while 1: p, s = map(int, input().split(',')) if p == s == 0: break t[p] = s rank = list(set(t)) rank.sort(reverse=True) while 1: try: n = int(input()) print(rank.index(t[n])+1) except: break ```
instruction
0
48,710
11
97,420
Yes
output
1
48,710
11
97,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` import sys c,d=[],{} for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s for y in sys.stdin:print(sorted({*c})[::-1].index(d[int(y)])+1) ```
instruction
0
48,711
11
97,422
Yes
output
1
48,711
11
97,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` import itertools from operator import itemgetter nums={} while True: p,s=map(int,input().split(',')) if(p==0 and s==0):break if not s in nums: nums[s]=[] nums[s].append(p) while True: try: q=int(input()) ans=len(nums) for ns in nums.items(): if q in ns[1]: print(ans) break ans-=1 except: break ```
instruction
0
48,712
11
97,424
Yes
output
1
48,712
11
97,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` c=[] d={} while 1: a,b=map(int,input().split(',')) if a==0:break c+=[b] d[a]=b c=sorted(set(c))[::-1] while 1: try:print(c.index(d[int(input())])+1) except:break ```
instruction
0
48,713
11
97,426
Yes
output
1
48,713
11
97,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` team_score=[] while True: x,y=map(int,input().split(',')) if x==y==0: break team_score.append((x,y)) team_score.sort(key=lambda x:x[1],reverse=True) for i,j in team_score: print(i) ```
instruction
0
48,714
11
97,428
No
output
1
48,714
11
97,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0061 """ import sys def calc_rank(data): scores = {} # ?????????key, ???????????????id???????????????value??Β¨????????????????????? for id, point in data: if point in scores: scores[point].append(id) else: scores[point] = [id] ranks = [k for k in scores.keys()] # ranks.index(point) ????????????????????????????????? ranks.sort(reverse=True) ranks.insert(0, 0) # index???1?????????????????????????????????????????????????????\ return scores, ranks def check_rank(scores, ranks, id): for k, v in scores.items(): if id in v: return ranks.index(k) def main(args): data = [] id, point = [int(x) for x in input().strip().split(',')] while id != 0 or point != 0: data.append((id, point)) id, point = [int(x) for x in input().strip().split(',')] scores, ranks = calc_rank(data) for line in sys.stdin: id = int(line.strip()) result = check_rank(scores, ranks, id) print(result) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
48,715
11
97,430
No
output
1
48,715
11
97,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` import sys c,d=[],{} for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s for y in sys.stdin:print({*c}.sort()[::-1].index(d[int(y)])+1) ```
instruction
0
48,716
11
97,432
No
output
1
48,716
11
97,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the ranking is given in descending order of the number of correct answers, such as 1st, 2nd, and so on. Enter the qualifying result data and reference number from the keyboard, and create a program that outputs the ranking of the team with that number. Note In the data of the input example, if the teams are arranged in order of the number of correct answers: 3,30 1,20 2,20 6,20 4,10 5,10 It will be. Here, in order to determine the ranking based on the number of correct answers, the 30-question correct answer team is ranked 1st, the 20-question correct answer team is ranked 2nd, and the 10-question correct answer team is ranked 3rd. Please note that this is different from the usual ranking with the correct team in 5th place). Input The input data consists of two parts. The first half is the qualifying result data, and the second half is the inquiry of the team number for which you want to know the ranking. The format of the qualifying result data is as follows. p1, s1 p2, s2 ... ... 0,0 pi (1 ≀ pi ≀ 100) and si (0 ≀ si ≀ 30) are integers representing the reference number and the number of correct answers for the i-th team, respectively. It is assumed that the input of this data is completed when both the reference number and the number of correct answers are 0. Then multiple inquiries in the second half are given. The inquiry format is as follows. q1 q2 :: Each query is given the reference number qi (1 ≀ qi ≀ 30) on one line. Please process this until the end of the input. The number of inquiries does not exceed 100. Output For each inquiry, print the team ranking on one line. Example Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output 2 2 3 3 Submitted Solution: ``` def Inquiry(team): ranking=1 score=team_score[0][1] for i in team_score: if score>i[1]: ranking+=1 score=i[1] if i[0]==team: return ranking team_score=[] while True: x,y=map(int,input().split(',')) if x==y==0: break team_score.append((x,y)) print(team_score) team_score.sort(key=lambda x:x[1],reverse=True) print(team_score) while True: try: team=int(input()) print(Inquiry(team)) except EOFError: break ```
instruction
0
48,717
11
97,434
No
output
1
48,717
11
97,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nauuo is a girl who loves coding. One day she was solving a problem which requires to calculate a sum of some numbers modulo p. She wrote the following code and got the verdict "Wrong answer". <image> She soon discovered the bug β€” the ModAdd function only worked for numbers in the range [0,p), but the numbers in the problem may be out of the range. She was curious about the wrong function, so she wanted to know the result of it. However, the original code worked too slow, so she asked you to help her. You are given an array a_1,a_2,…,a_n and a number p. Nauuo will make m queries, in each query, you are given l and r, and you have to calculate the results of Sum(a,l,r,p). You can see the definition of the Sum function in the pseudocode above. Note that the integers won't overflow in the code above. Input The first line contains three integers n, m, p (1 ≀ n ≀ 10^6, 1 ≀ m ≀ 2 β‹… 10^5, 1 ≀ p ≀ 10^9) β€” the length of the given array, the number of queries and the modulus. Note that the modulus is used only in the ModAdd function. The second line contains n integers a_1,a_2,…,a_n (-10^9≀ a_i≀10^9) β€” the given array. In the following m lines, each line contains two integers l, r (1≀ l≀ r≀ n) β€” you have to calculate the result of Sum(a,l,r,p). Output The output contains m integers to answer the queries in the given order. Example Input 4 5 6 7 2 -3 17 2 3 1 3 1 2 2 4 4 4 Output -1 0 3 10 11 Submitted Solution: ``` n, m, p=[int(n) for n in input().split()] l=list(map(int,input().split())) for i in range(m): a, b=[int(a) for a in input().split()] k=sum(l[a-1:b]) if(k>=p): print(k-p) else: print(k) ```
instruction
0
48,905
11
97,810
No
output
1
48,905
11
97,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nauuo is a girl who loves coding. One day she was solving a problem which requires to calculate a sum of some numbers modulo p. She wrote the following code and got the verdict "Wrong answer". <image> She soon discovered the bug β€” the ModAdd function only worked for numbers in the range [0,p), but the numbers in the problem may be out of the range. She was curious about the wrong function, so she wanted to know the result of it. However, the original code worked too slow, so she asked you to help her. You are given an array a_1,a_2,…,a_n and a number p. Nauuo will make m queries, in each query, you are given l and r, and you have to calculate the results of Sum(a,l,r,p). You can see the definition of the Sum function in the pseudocode above. Note that the integers won't overflow in the code above. Input The first line contains three integers n, m, p (1 ≀ n ≀ 10^6, 1 ≀ m ≀ 2 β‹… 10^5, 1 ≀ p ≀ 10^9) β€” the length of the given array, the number of queries and the modulus. Note that the modulus is used only in the ModAdd function. The second line contains n integers a_1,a_2,…,a_n (-10^9≀ a_i≀10^9) β€” the given array. In the following m lines, each line contains two integers l, r (1≀ l≀ r≀ n) β€” you have to calculate the result of Sum(a,l,r,p). Output The output contains m integers to answer the queries in the given order. Example Input 4 5 6 7 2 -3 17 2 3 1 3 1 2 2 4 4 4 Output -1 0 3 10 11 Submitted Solution: ``` n, m, p=[int(n) for n in input().split()] l=list(map(int,input().split())) for i in range(m): a, b=[int(a) for a in input().split()] k=sum(l[a-1:b]) if(k>p): print(k-p) else: print(k) ```
instruction
0
48,906
11
97,812
No
output
1
48,906
11
97,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` list=[] while True: try: mt=float(input()) except: small=min(list) big=max(list) print(big-small) break list.append(mt) ```
instruction
0
49,521
11
99,042
Yes
output
1
49,521
11
99,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` import sys ms = [] for v in sys.stdin: ms.append(float(v)) print(max(ms)-min(ms)) ```
instruction
0
49,522
11
99,044
Yes
output
1
49,522
11
99,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` a = [] while True: try: n = float(input()) a.append(n) except: break a.sort() print(a[len(a) - 1] - a[0]) ```
instruction
0
49,523
11
99,046
Yes
output
1
49,523
11
99,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` import sys a=[float(e)for e in sys.stdin] print(max(a)-min(a)) ```
instruction
0
49,524
11
99,048
Yes
output
1
49,524
11
99,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` A=[] for i in range(0,5): a=float(input()) A.append(a) print(max(A)-min(A)) ```
instruction
0
49,525
11
99,050
No
output
1
49,525
11
99,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` try: while True: lst=[] a=list(input()) lst.append(a) lst.sort() print(max(lst)-min(lst)) except EOFError: pass ```
instruction
0
49,526
11
99,052
No
output
1
49,526
11
99,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` inputs = [flaot(i) for i in input()] print(max(inputs) - min(inputs)) ```
instruction
0
49,527
11
99,054
No
output
1
49,527
11
99,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given over multiple lines. All values ​​entered are real numbers greater than or equal to 0 and less than or equal to 1,000,000. The number of mountain heights entered is 50 or less. Output The elevation difference between the highest mountain and the lowest mountain is output as a real number. The output may contain an error of 0.01 or less. Example Input 3776.0 1819.0 645.2 2004.1 1208.6 Output 3130.8 Submitted Solution: ``` import sys ms = [] try: for v in sys.stdin: ms.append(float(v)) except: print(max(ms)-min(ms)) ```
instruction
0
49,528
11
99,056
No
output
1
49,528
11
99,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` n=int(input()) d={}; D={}; ans=[] for _ in range(n): s=input()+'/'; t=s.find('/',7); d.setdefault(s[:t],set()).add(s[t:]) for k in d: D.setdefault(frozenset(d[k]),[]).append(k) {ans.append(D[k]) for k in D if len(D[k])>1} print(len(ans)) print('\n'.join(map(' '.join,ans))) # Made By Mostafa_Khaled ```
instruction
0
50,103
11
100,206
Yes
output
1
50,103
11
100,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` n = int(input()) hosts = dict() for i in range(n): inp = input() pos = inp.find("/", 7) if pos == -1: pos = len(inp) hostName = inp[:pos] path = inp[pos:] if hostName not in hosts: hosts[hostName] = set() hosts[hostName].add(path) groups = dict() for name in hosts.keys(): paths = tuple(sorted(hosts[name])) if paths not in groups: groups[paths] = [] groups[paths].append(name) ans = [] for group in groups.values(): if len(group) > 1: ans.append(group) print(len(ans)) for group in ans: print(" ".join(group)) ```
instruction
0
50,104
11
100,208
Yes
output
1
50,104
11
100,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` n = int(input()) domains = {} for _ in range(n): request = input()[7:] domain, sep, path = request.partition('/') if domain in domains: domains[domain].add(sep + path) else: domains[domain] = {sep + path} path_hashes = [] for domain, paths in domains.items(): path_hashes.append(('|'.join(sorted(paths)), domain)) sorted_hashes = sorted(path_hashes, key=lambda x: x[0]) previous_hash = None previous_domains = [] groups = [] for path_hash, domain in sorted_hashes: if previous_hash == path_hash: previous_domains.append(domain) else: previous_hash = path_hash if len(previous_domains) > 1: groups.append(previous_domains) previous_domains = [domain] if len(previous_domains) > 1: groups.append(previous_domains) print(len(groups)) print('\n'.join(map(lambda x: ' '.join(map(lambda y: 'http://' + y, x)), groups))) ```
instruction
0
50,105
11
100,210
Yes
output
1
50,105
11
100,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` import sys from urllib.parse import urlparse import itertools as itt def main(): n = int(sys.stdin.readline().strip()) links = [sys.stdin.readline().strip() for i in range(n)] host_queries = {} for link in links: p = urlparse(link) host = "http://" + p.netloc query = p.path if not host in host_queries: host_queries[host] = set() host_queries[host].add(query) hosts = host_queries.keys() hosts = list(sorted(hosts, key=lambda h: "-".join(sorted(host_queries[h])))) groups = [] for key, group in itt.groupby(hosts, key=lambda h: "-".join(sorted(host_queries[h]))): g = list(group) if len(g) < 2: continue groups.append(g) print(len(groups)) for g in groups: print(" ".join(g)) if __name__ == "__main__": main() ```
instruction
0
50,106
11
100,212
Yes
output
1
50,106
11
100,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` import sys n = int(input()) domains = {} for full_request in sys.stdin: request = full_request[7:] domain, sep, path = request.partition('/') if domain in domains: domains[domain].add(sep + path) else: domains[domain] = {sep + path} path_hashes = [] for domain, paths in domains.items(): path_hashes.append(('|'.join(sorted(paths)), domain)) sorted_hashes = sorted(path_hashes, key=lambda x: x[0]) previous_hash = None previous_domains = [] groups = [] for path_hash, domain in sorted_hashes: if previous_hash == path_hash: previous_domains.append(domain) else: previous_hash = path_hash if len(previous_domains) > 1: groups.append(previous_domains) previous_domains = [domain] if len(previous_domains) > 1: groups.append(previous_domains) print(len(groups)) print('\n'.join(map(lambda x: ' '.join(map(lambda y: 'http://' + y, x)), groups))) ```
instruction
0
50,107
11
100,214
No
output
1
50,107
11
100,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` from sys import stdin def main(): l = stdin.read().splitlines() a = t = l[0] = '~' l.sort() r, pp = [], [a] for b in map(str.rstrip, l): if a == b: continue a = b i = a.find('/', 7) h, p = (a, '') if i == -1 else (a[:i], a[i:]) # if h == 'http://ip': # print(repr(h), repr(p)) if t == h: pp.append(p) else: r.append((' '.join(pp), t)) t, pp = h, [p] r.sort() l, s = [], [] for p, h in r: if h in ('http://ip', 'http://c.r.naey'): print(repr(h), repr(p)) if t == p: s.append(h) else: if len(s) > 1: l.append(' '.join(s)) t, s = p, [h] print(len(l)) print('\n'.join(l)) if __name__ == '__main__': main() ```
instruction
0
50,108
11
100,216
No
output
1
50,108
11
100,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` from sys import stdin def main(): l = stdin.read().splitlines() ptrn = a = l[0] = '~' l.sort() r, pp = [], [a] for b in l: if a == b: continue a = b i = a.find('/', 8) if i == -1: h, p = a, '' else: h, p = a[:i], a[i:] if ptrn == h: pp.append(p) else: r.append(('+'.join(sorted(pp)), ptrn)) ptrn, pp = h, [p] r.sort() l, res = [], [] for p, h in r: if ptrn == p: l.append(h) else: if len(l) > 1: res.append(' '.join(l)) ptrn, l = p, [h] print(len(res)) print('\n'.join(res)) if __name__ == '__main__': main() ```
instruction
0
50,109
11
100,218
No
output
1
50,109
11
100,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: * <hostname> β€” server name (consists of words and maybe some dots separating them), * /<path> β€” optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa β€” for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications. Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name. Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: * <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. * <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. Output First print k β€” the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. Examples Input 10 http://abacaba.ru/test http://abacaba.ru/ http://abacaba.com http://abacaba.com/test http://abacaba.de/ http://abacaba.ru/test http://abacaba.de/test http://abacaba.com/ http://abacaba.com/t http://abacaba.com/test Output 1 http://abacaba.de http://abacaba.ru Input 14 http://c http://ccc.bbbb/aba..b http://cba.com http://a.c/aba..b/a http://abc/ http://a.c/ http://ccc.bbbb http://ab.ac.bc.aa/ http://a.a.a/ http://ccc.bbbb/ http://cba.com/ http://cba.com/aba..b http://a.a.a/aba..b/a http://abc/aba..b/a Output 2 http://cba.com http://ccc.bbbb http://a.a.a http://a.c http://abc Submitted Solution: ``` import sys from urllib.parse import urlparse import itertools as itt def main(): n = int(sys.stdin.readline().strip()) links = [sys.stdin.readline().strip() for i in range(n)] host_queries = {} for link in links: p = urlparse(link) host = "http://" + p.netloc query = p.path[1:] if not host in host_queries: host_queries[host] = set() host_queries[host].add(query) hosts = host_queries.keys() hosts = list(sorted(hosts, key=lambda h: host_queries[h])) groups = [] for key, group in itt.groupby(hosts, key=lambda h: host_queries[h]): g = list(group) if len(g) < 2: continue groups.append(g) print(len(groups)) for g in groups: print(" ".join(g)) if __name__ == "__main__": main() ```
instruction
0
50,110
11
100,220
No
output
1
50,110
11
100,221
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,156
11
100,312
Tags: binary search, math Correct Solution: ``` import sys def solve(): t = int(sys.stdin.readline()) for ti in range(t): x, y, p, q = map(int, sys.stdin.readline().split()) if p == 0: # p/q = 0 if x == 0: print(0) else: print(-1) continue if p == q: # p/q = 1 if x == y: print(0) else: print(-1) continue if p*y == x*q: # p/q = x/y print(0) elif p*y > x*q: # p/q > x/y z = (q*(y - x) + q - p - 1) // (q - p) ans = (z + q - 1) // q * q - y print(ans) else: # p/q < x/y z = (q*x + p - 1) // p ans = (z + q - 1) // q * q - y print(ans) if __name__ == '__main__': solve() ```
output
1
50,156
11
100,313
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,157
11
100,314
Tags: binary search, math Correct Solution: ``` import math def main(): T = int(input()) for t in range(T): solve() def solve(): x, y, p, q = map(int, input().split()) if p == 1 and q == 1: if x == y: print(0) else: print(-1) return if p == 0 and q == 1: if x == 0: print(0) else: print(-1) return # n = max(math.ceil(y/q), math.ceil(x/p)) # while (n*q - y) < (n*p -x): # n += 1 n = max(math.ceil(y/q), math.ceil(x/p), math.ceil((y-x)/(q-p))) print(n*q-y) if __name__ == "__main__": # global stime # stime = time.clock() main() ```
output
1
50,157
11
100,315
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,158
11
100,316
Tags: binary search, math Correct Solution: ``` import math def result(): x, y, p, q = map(int, input().split()) if p == 1 and q == 1: if x == y: print(0) else: print(-1) return if p == 0 and q == 1: if x == 0: print(0) else: print(-1) return n = max(math.ceil(y/q), math.ceil(x/p), math.ceil((y-x)/(q-p))) print(n*q-y) t = int(input()) for i in range(t): result() ```
output
1
50,158
11
100,317
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,159
11
100,318
Tags: binary search, math Correct Solution: ``` for _ in range(int(input())): x, y, p, q = map(int, input().split()) d = q * int(1e9) c = p * int(1e9) if not (c >= x and d - y >= c - x): print(-1) continue i = -1 j = int(1e9) while j - i > 1: m = (i + j) // 2 d = q * m c = p * m if c >= x and d - y >= c - x: j = m else: i = m print(j * q - y) ```
output
1
50,159
11
100,319
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,160
11
100,320
Tags: binary search, math Correct Solution: ``` for _ in range(int(input())): x,y,p,q=map(int,input().split()) l,r,res=0,10**18,-1 while l<=r: mid=(l+r)//2 a,b=p*mid-x,q*mid-y if a<=b and a>-1 and b>-1:res=b;r=mid-1 else :l=mid+1 print(res) ```
output
1
50,160
11
100,321
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,161
11
100,322
Tags: binary search, math Correct Solution: ``` MAXN = int(2e18) def check(n, x, y, p, q): np, nq = n * p, n * q # print(x, y, np, nq) if nq < y: return False diff = nq - y return x <= np <= x + diff def solve(): x, y, p, q = map(int, input().split()) l, r = 1, int(MAXN) while l != r: m = (l + r) // 2 if not check(m, x, y, p, q): l = m + 1 else: r = m if r == MAXN: print(-1) else: print(l * q - y) t = int(input()) for _ in range(t): solve() ```
output
1
50,161
11
100,323
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,162
11
100,324
Tags: binary search, math Correct Solution: ``` tc = int(input()) for i in range(tc): x, y, p, q = map(int, input().split()) if p == 0: if x == 0: print('0') else: print('-1') elif p == q: if y > x: print('-1') else: print('0') elif p * y == x * q: print('0') else: #newy = y #while True: # newy += q - (newy % q) # newx = (newy // q) * p # if 0 <= newx - x <= newy - y: # print(str(newy - y)) # break def minmax(lob, hib): if lob == hib: return lob - y lower = (lob + hib) // 2 higher = lower + q - (lower % q) lower = higher - q newxh = (higher // q) * p if 0 <= newxh - x <= higher - y: newxl = (lower // q) * p if 0 <= newxl - x <= lower - y: return minmax(lob, lower) else: return higher - y else: return minmax(higher, hib) lob = y + q - (y % q) hib = 10**19 + q - (10**19 % q) print(str(minmax(lob, hib))) ```
output
1
50,162
11
100,325
Provide tags and a correct Python 3 solution for this coding contest problem. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
instruction
0
50,163
11
100,326
Tags: binary search, math Correct Solution: ``` def ext_gcd(a, b): if a == 0: return b, 0, 1 else: g, x, y = ext_gcd(b % a, a) return g, y - (b // a) * x, x def multinv(b, n): g, x, trash = ext_gcd(b, n) return x % n def solve(): x, y, p, q = map(int, input().split(' ')) if p == q: if x == y: return 0 else: return -1 if p == 0: if x == 0: return 0 else: return -1 c = p * y - q * x a = (multinv(q, p) * c ) % p if ((q*a)-c)//p < a: dif = (c//(q-p) - a) dif = dif//p a += p * (dif-3) while ((q*a)-c)//p < a or a < 0: a += p return ((q*a)-c)//p t = int(input()) for a0 in range(t): print(solve()) ```
output
1
50,163
11
100,327
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1. Submitted Solution: ``` t = int(input()) for zz in range(t): x, y, p, q = [int(i) for i in input().split()] if (x*q == y*p):print(0) elif ((p == 0 and x != 0) or (p == q and x != y)): print(-1) else: sel1 = y-x; sel2 = q-p; kalr = x // p + (0, 1)[x % p != 0] kalr = max(kalr, sel1 // sel2 + (0, 1)[sel1 % sel2 != 0]) q *= kalr print(q-y) ```
instruction
0
50,164
11
100,328
Yes
output
1
50,164
11
100,329