message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
instruction
0
76,430
14
152,860
Tags: dp Correct Solution: ``` def solve(): n=int(input()) arr=list(map(int,input().split())) ones = 0 ones2s = 0 ones2s1s = 0 ones2s1s2s = 0 for value in arr: if value==1: ones+=1 ones2s1s = max(ones2s1s+1,ones2s+1) if value==2: ones2s = max(ones2s+1,ones+1) ones2s1s2s = max(ones2s1s+1,ones2s1s2s+1) print (max(max(ones,ones2s),max(ones2s1s2s,ones2s1s))) try: solve() except Exception as e: print (e) ```
output
1
76,430
14
152,861
Provide tags and a correct Python 2 solution for this coding contest problem. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
instruction
0
76,431
14
152,862
Tags: dp Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_num(): return int(raw_input()) def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ n=in_num() l=in_arr() dp=[0,0,0,0] for i in l: if i==1: dp[0]+=1 dp[2]=max(dp[2]+1,dp[1]+1) else: dp[1]=max(dp[1]+1,dp[0]+1) dp[3]=max(dp[3]+1,dp[2]+1) pr_num(max(dp)) ```
output
1
76,431
14
152,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) pref = [0] * (n + 1) for i in range(n): pref[i + 1] = pref[i] + (1 if a[i] == 1 else 0) suf = [0] * (n + 1) for i in reversed(range(n)): suf[i] = suf[i + 1] + (1 if a[i] == 2 else 0) dp = [0, 0, 0, 0] for i in range(n): new_dp = [max(dp[i], dp[i - 1]) if i > 0 else dp[i] for i in range(4)] if a[i] == 1: new_dp[0] += 1 new_dp[2] += 1 else: new_dp[1] += 1 new_dp[3] += 1 dp = new_dp print(max(max([pref[i] + suf[i] for i in range(n + 1)]), max(dp))) ```
instruction
0
76,432
14
152,864
Yes
output
1
76,432
14
152,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` n=int(input()) a=[int(k)-1 for k in input().split(" ")] nbmax= [0,0,0,0] for k in a: if k: nbmax[1]=max(nbmax[1]+1,nbmax[0]+1) nbmax[3]=max(nbmax[3]+1,nbmax[2]+1) else: nbmax[0]+=1 nbmax[2]=max(nbmax[1]+1,nbmax[2]+1) print (max(nbmax)) ```
instruction
0
76,433
14
152,866
Yes
output
1
76,433
14
152,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` """Codeforces P934C. A Twisty Movement (=P933A) (http://codeforces.com/problemset/problem/934/C) Problem tags : brute force, dp Hint: Same as finding the longest subsequence of [1, ..., 1, 2, ..., 2, 1, ..., 1, 2, ..., 2] Time Complexity: O(n) """ def main(): n = int(input()) a = [int(x) for x in input().split()] val = [1, 2, 1, 2] # max_len[i] : length of longest sequence of # [ val[0] * (n0), val[1] * (n1), ... , val[i] * (ni) ] max_len = [0, 0, 0, 0] for x in a: for i in range(4): if x == val[i]: max_len[i] += 1 if i > 0: max_len[i] = max(max_len[i - 1], max_len[i]) print(max_len[-1]) if __name__ == '__main__': main() ```
instruction
0
76,434
14
152,868
Yes
output
1
76,434
14
152,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` # n = int(input().strip()) # res = list() # while n > 0: # if n >= 2: # res.append(8) # n -= 2 # elif n == 1: # res.append(6) # n -= 1 # if len(res) > 18: # print('-1') # else: # print(''.join(map(str, res))) n = int(input().strip()) a = list(map(int, input().strip().split())) ones = [0] * (n+1) twos = [0] * (n+1) for i in range(n): ones[i+1] = ones[i] if a[i] == 2 else ones[i] + 1 twos[i+1] = twos[i] if a[i] == 1 else twos[i] + 1 if twos[n] == 0: print(n) exit(0) res = 0 for i in range(n): best1 = 0 for j in range(i+1): c1 = ones[j] c2 = twos[i+1] - twos[j] best1 = max(best1, c1 + c2) best2 = 0 for j in range(i+1, n+1): d1 = ones[j] - ones[i+1] d2 = twos[n] - twos[j] best2 = max(best2, d1 + d2) res = max(res, best1 + best2) print(res) ```
instruction
0
76,435
14
152,870
Yes
output
1
76,435
14
152,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` #https://codeforces.com/contest/933/problem/A import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ # do magic here def solve(temp): i = 0 while i < len(temp) and temp[i]==1: i+=1 while i < len(temp) and temp[i]==2: i+=1 while i < len(temp) and temp[i]==1: i+=1 while i < len(temp) and temp[i]==2: i+=1 return i n = int(input()) arr = list(map(int,input().split())) ans = 0 for x in range(n): ans = max(ans,solve(arr[x:])) print(ans) ```
instruction
0
76,436
14
152,872
No
output
1
76,436
14
152,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` n = int(input()) num = list(map(int, input().split())) pref = [1] suff = [1] smth = [1] ans = -1 flag = True if n == 2 and num == [2, 1]: print(2) else: for i in range(n - 1): if num[i] != num[i + 1]: flag = False break if flag: print(n) else: for i in range(1, n): if num[i] >= num[i - 1]: pref.append(pref[-1] + 1) else: pref.append(1) for i in range(len(num) - 2, -1, -1): if num[i] <= num[i + 1]: smth.append(smth[-1] + 1) else: smth.append(1) for i in range(len(num) - 2, -1, -1): if num[i] >= num[i + 1]: suff.append(suff[-1] + 1) else: suff.append(1) for i in range(1, n - 1): for j in range(i + 1, n - 1): if suff[len(num) - i - 1] != 1 and i + suff[len(num) - i - 1] - 1 == j: if num[i - 1] <= num[j] and num[i] <= num[j + 1]: if ans < pref[i - 1] + j - i + 1 + smth[n - j - 2]: ans = pref[i - 1] + j - i + 1 + smth[n - j - 2] elif num[i - 1] <= num[j] and num[i] > num[j + 1]: if pref[i - 1] + j - i > ans: ans = pref[i - 1] + j - i elif num[i - 1] > num[j] and num[i] <= num[j + 1]: if j - i + smth[n - j - 2] > ans: ans = j - i + smth[n - j - 2] print(ans) ```
instruction
0
76,437
14
152,874
No
output
1
76,437
14
152,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` n = int(input()) num = list(map(int, input().split())) pref = [1] suff = [1] smth = [1] ans = -1 flag = True for i in range(n - 1): if num[i] != num[i + 1]: flag = False break if flag: print(n) else: for i in range(1, n): if num[i] >= num[i - 1]: pref.append(pref[-1] + 1) else: pref.append(1) for i in range(len(num) - 2, -1, -1): if num[i] <= num[i + 1]: smth.append(smth[-1] + 1) else: smth.append(1) for i in range(len(num) - 2, -1, -1): if num[i] >= num[i + 1]: suff.append(suff[-1] + 1) else: suff.append(1) for i in range(1, n - 1): for j in range(i + 1, n - 1): if suff[len(num) - i - 1] != 1 and i + suff[len(num) - i - 1] - 1 == j: if num[i - 1] <= num[j] and num[i] <= num[j + 1]: if ans < pref[i - 1] + j - i + 1 + smth[n - j - 2]: ans = pref[i - 1] + j - i + 1 + smth[n - j - 2] elif num[i - 1] <= num[j] and num[i] > num[j + 1]: if pref[i - 1] + j - i > ans: ans = pref[i - 1] + j - i elif num[i - 1] > num[j] and num[i] <= num[j + 1]: if j - i + smth[n - j - 2] > ans: ans = j - i + smth[n - j - 2] print(ans) ```
instruction
0
76,438
14
152,876
No
output
1
76,438
14
152,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an. Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k. Input The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence. The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n). Output Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Examples Input 4 1 2 1 2 Output 4 Input 10 1 1 2 2 2 1 1 2 2 1 Output 9 Note In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) c=0 k=0 c=0 p=[0,0] for j in l: if j>=c: c=j k+=1 else: p.append(k) k=1 c=j p.append(k) c=max(p) p.remove(c) d=max(p) print(c+d) ```
instruction
0
76,439
14
152,878
No
output
1
76,439
14
152,879
Provide a correct Python 3 solution for this coding contest problem. "Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the shop is open. However, since I know the interval and number of customers coming from many years of experience, I decided to analyze the waiting time based on that. There are 17 seats in the store facing the counter. The store opens at noon, and customers come as follows. * 100 groups from 0 to 99 will come. * The i-th group will arrive at the store 5i minutes after noon. * The number of people in the i-th group is 5 when i% 5 is 1, and 2 otherwise. (x% y represents the remainder when x is divided by y.) * The i-th group finishes the meal in 17 (i% 2) + 3 (i% 3) + 19 minutes when seated. The arrival times, number of people, and meal times for the first 10 groups are as follows: Group number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- Arrival time (minutes later) | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 Number of people (people) | 2 | 5 | 2 | 2 | 2 | 2 | 5 | 2 | 2 | 2 Meal time (minutes) | 19 | 39 | 25 | 36 | 22 | 42 | 19 | 39 | 25 | 36 In addition, when guiding customers to their seats, we do the following. * Seats are numbered from 0 to 16. * A group of x people can only be seated when there are x open seats in a row. Also, if there are multiple places to sit, sit in the place with the lowest seat number. For example, if only seats 0, 1, 2, 4, and 5 are available, a group of 5 people cannot be seated. If you are in a group of two, you will be seated at number 0 and 1. * Once you are seated, you will not be asked to move your seat. * Customers come and go in 1 minute increments. At each time, we will guide customers in the following order. 1. The next group can be seated at the same time as the previous group leaves. 2. When seating customers, seat as many groups as possible at the same time, starting with the group at the top of the line. It does not overtake the order of the matrix. In other words, if the first group cannot be seated, even if other groups in the procession can be seated, they will not be seated. 3. Groups arriving at that time will line up at the end of the procession, if any. If there is no line and you can sit down, you will be seated, and if you cannot, you will wait in line. As an example, the following shows how the first 10 groups arrive. From left to right, the three columns in each row show the time, seating, and queue. For seats, the "_" is vacant and the number indicates that the group with that number is sitting in that seat. Time: Seat procession 0: 00 _______________: 5: 0011111 ___________: 10: 001111122 ________: 15: 00111112233______: 18: 00111112233______: 19: __111112233______: 20: 44111112233 ______: 25: 4411111223355____: 30: 4411111223355____: 66666 Group 6 arrives 34: 4411111223355____: 66666 35: 4411111__3355____: 6666677 Group 7 arrives 40: 4411111__3355____: 666667788 Group 8 arrives 41: 4411111__3355____: 666667788 42: __11111__3355____: 666667788 43: __11111__3355____: 666667788 44: 6666677883355____: Groups 6, 7 and 8 are seated 45: 666667788335599__: Group 9 arrives and sits down For example, at time 40, the eighth group arrives, but cannot be seated and joins the procession. The fourth group eats until time 41. At time 42, seats in the 4th group are available, but the 6th group is not yet seated due to the lack of consecutive seats. The first group eats until time 43. At time 44, the first group will be vacant, so the sixth group will be seated, and at the same time the seventh and eighth groups will be seated. The ninth group arrives at time 45 and will be seated as they are available. Based on this information, create a program that outputs the time (in minutes) that the nth group of customers waits by inputting an integer n that is 0 or more and 99 or less. Input Given multiple datasets. Each dataset consists of one integer n. The number of datasets does not exceed 20. Output For each dataset, print the minute wait time (integer greater than or equal to 0) for the nth customer on a single line. Example Input 5 6 7 8 Output 0 14 9 4
instruction
0
76,608
14
153,216
"Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0147 """ import sys from sys import stdin from heapq import heappop, heappush from collections import deque input = stdin.readline class Seat(): def __init__(self, n): self.seat = '_' * n def get(self, num): i = self.seat.find('_'*num) if i != -1: self.seat = self.seat[0:i] + 'o'*num + self.seat[i+num:] return i return None def release(self, i, num): self.seat = self.seat[0:i] + '_'*num + self.seat[i+num:] def solve(): waiting_time = [-1] * 100 NUM_OF_SEAT = 17 seat = Seat(NUM_OF_SEAT) LEAVE = 0 COME = 1 in_out = [] # ??\????????????????????????????????? Q = deque() # ??§?????????????????? # 100???????????\???????????????????????? for group_id in range(100): if group_id % 5 == 1: num = 5 else: num = 2 heappush(in_out, (group_id * 5, COME, NUM_OF_SEAT+1, group_id, num)) while in_out: time, event, start_seat, group_id, num = heappop(in_out) if event == COME: Q.append((time, group_id, num)) else: seat.release(start_seat, num) while Q: res = seat.get(Q[0][2]) if res is not None: arrive, group_id, num = Q.popleft() waiting_time[group_id] = time - arrive eating_time = 17 * (group_id % 2) + 3*(group_id % 3) + 19 heappush(in_out, (time + eating_time, LEAVE, res, group_id, num)) else: break return waiting_time def main(args): waiting_time = solve() for line in sys.stdin: print(waiting_time[int(line)]) if __name__ == '__main__': main(sys.argv[1:]) ```
output
1
76,608
14
153,217
Provide a correct Python 3 solution for this coding contest problem. "Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the shop is open. However, since I know the interval and number of customers coming from many years of experience, I decided to analyze the waiting time based on that. There are 17 seats in the store facing the counter. The store opens at noon, and customers come as follows. * 100 groups from 0 to 99 will come. * The i-th group will arrive at the store 5i minutes after noon. * The number of people in the i-th group is 5 when i% 5 is 1, and 2 otherwise. (x% y represents the remainder when x is divided by y.) * The i-th group finishes the meal in 17 (i% 2) + 3 (i% 3) + 19 minutes when seated. The arrival times, number of people, and meal times for the first 10 groups are as follows: Group number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- Arrival time (minutes later) | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 Number of people (people) | 2 | 5 | 2 | 2 | 2 | 2 | 5 | 2 | 2 | 2 Meal time (minutes) | 19 | 39 | 25 | 36 | 22 | 42 | 19 | 39 | 25 | 36 In addition, when guiding customers to their seats, we do the following. * Seats are numbered from 0 to 16. * A group of x people can only be seated when there are x open seats in a row. Also, if there are multiple places to sit, sit in the place with the lowest seat number. For example, if only seats 0, 1, 2, 4, and 5 are available, a group of 5 people cannot be seated. If you are in a group of two, you will be seated at number 0 and 1. * Once you are seated, you will not be asked to move your seat. * Customers come and go in 1 minute increments. At each time, we will guide customers in the following order. 1. The next group can be seated at the same time as the previous group leaves. 2. When seating customers, seat as many groups as possible at the same time, starting with the group at the top of the line. It does not overtake the order of the matrix. In other words, if the first group cannot be seated, even if other groups in the procession can be seated, they will not be seated. 3. Groups arriving at that time will line up at the end of the procession, if any. If there is no line and you can sit down, you will be seated, and if you cannot, you will wait in line. As an example, the following shows how the first 10 groups arrive. From left to right, the three columns in each row show the time, seating, and queue. For seats, the "_" is vacant and the number indicates that the group with that number is sitting in that seat. Time: Seat procession 0: 00 _______________: 5: 0011111 ___________: 10: 001111122 ________: 15: 00111112233______: 18: 00111112233______: 19: __111112233______: 20: 44111112233 ______: 25: 4411111223355____: 30: 4411111223355____: 66666 Group 6 arrives 34: 4411111223355____: 66666 35: 4411111__3355____: 6666677 Group 7 arrives 40: 4411111__3355____: 666667788 Group 8 arrives 41: 4411111__3355____: 666667788 42: __11111__3355____: 666667788 43: __11111__3355____: 666667788 44: 6666677883355____: Groups 6, 7 and 8 are seated 45: 666667788335599__: Group 9 arrives and sits down For example, at time 40, the eighth group arrives, but cannot be seated and joins the procession. The fourth group eats until time 41. At time 42, seats in the 4th group are available, but the 6th group is not yet seated due to the lack of consecutive seats. The first group eats until time 43. At time 44, the first group will be vacant, so the sixth group will be seated, and at the same time the seventh and eighth groups will be seated. The ninth group arrives at time 45 and will be seated as they are available. Based on this information, create a program that outputs the time (in minutes) that the nth group of customers waits by inputting an integer n that is 0 or more and 99 or less. Input Given multiple datasets. Each dataset consists of one integer n. The number of datasets does not exceed 20. Output For each dataset, print the minute wait time (integer greater than or equal to 0) for the nth customer on a single line. Example Input 5 6 7 8 Output 0 14 9 4
instruction
0
76,609
14
153,218
"Correct Solution: ``` from collections import deque from heapq import heappush, heappop que = deque() q = [] N = 100 for i in range(N): heappush(q, (5*i, 0, i)) M = 17 S = [-1]*M T = [0]*N while q: t = None while q and (t is None or q[0][0] == t): t, c, i = heappop(q) if c == 0: que.append(i) else: for j in range(M): if S[j] == i: S[j] = -1 while que: i = que[0] m = 5 if i % 5 == 1 else 2 cnt = 0; j = -1 for k in range(M): if S[k] == -1: cnt += 1 if cnt == m: j = k-m+1 break else: cnt = 0 if j == -1: break for k in range(m): S[j + k] = i T[i] = t - 5*i que.popleft() heappush(q, (t + (17*(i%2) + 3*(i%3) + 19), 1, i)) open(1, 'w').writelines(["{}\n".format(T[v]) for v in map(int, open(0).read().split())]) ```
output
1
76,609
14
153,219
Provide a correct Python 3 solution for this coding contest problem. "Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the shop is open. However, since I know the interval and number of customers coming from many years of experience, I decided to analyze the waiting time based on that. There are 17 seats in the store facing the counter. The store opens at noon, and customers come as follows. * 100 groups from 0 to 99 will come. * The i-th group will arrive at the store 5i minutes after noon. * The number of people in the i-th group is 5 when i% 5 is 1, and 2 otherwise. (x% y represents the remainder when x is divided by y.) * The i-th group finishes the meal in 17 (i% 2) + 3 (i% 3) + 19 minutes when seated. The arrival times, number of people, and meal times for the first 10 groups are as follows: Group number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- Arrival time (minutes later) | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 Number of people (people) | 2 | 5 | 2 | 2 | 2 | 2 | 5 | 2 | 2 | 2 Meal time (minutes) | 19 | 39 | 25 | 36 | 22 | 42 | 19 | 39 | 25 | 36 In addition, when guiding customers to their seats, we do the following. * Seats are numbered from 0 to 16. * A group of x people can only be seated when there are x open seats in a row. Also, if there are multiple places to sit, sit in the place with the lowest seat number. For example, if only seats 0, 1, 2, 4, and 5 are available, a group of 5 people cannot be seated. If you are in a group of two, you will be seated at number 0 and 1. * Once you are seated, you will not be asked to move your seat. * Customers come and go in 1 minute increments. At each time, we will guide customers in the following order. 1. The next group can be seated at the same time as the previous group leaves. 2. When seating customers, seat as many groups as possible at the same time, starting with the group at the top of the line. It does not overtake the order of the matrix. In other words, if the first group cannot be seated, even if other groups in the procession can be seated, they will not be seated. 3. Groups arriving at that time will line up at the end of the procession, if any. If there is no line and you can sit down, you will be seated, and if you cannot, you will wait in line. As an example, the following shows how the first 10 groups arrive. From left to right, the three columns in each row show the time, seating, and queue. For seats, the "_" is vacant and the number indicates that the group with that number is sitting in that seat. Time: Seat procession 0: 00 _______________: 5: 0011111 ___________: 10: 001111122 ________: 15: 00111112233______: 18: 00111112233______: 19: __111112233______: 20: 44111112233 ______: 25: 4411111223355____: 30: 4411111223355____: 66666 Group 6 arrives 34: 4411111223355____: 66666 35: 4411111__3355____: 6666677 Group 7 arrives 40: 4411111__3355____: 666667788 Group 8 arrives 41: 4411111__3355____: 666667788 42: __11111__3355____: 666667788 43: __11111__3355____: 666667788 44: 6666677883355____: Groups 6, 7 and 8 are seated 45: 666667788335599__: Group 9 arrives and sits down For example, at time 40, the eighth group arrives, but cannot be seated and joins the procession. The fourth group eats until time 41. At time 42, seats in the 4th group are available, but the 6th group is not yet seated due to the lack of consecutive seats. The first group eats until time 43. At time 44, the first group will be vacant, so the sixth group will be seated, and at the same time the seventh and eighth groups will be seated. The ninth group arrives at time 45 and will be seated as they are available. Based on this information, create a program that outputs the time (in minutes) that the nth group of customers waits by inputting an integer n that is 0 or more and 99 or less. Input Given multiple datasets. Each dataset consists of one integer n. The number of datasets does not exceed 20. Output For each dataset, print the minute wait time (integer greater than or equal to 0) for the nth customer on a single line. Example Input 5 6 7 8 Output 0 14 9 4
instruction
0
76,610
14
153,220
"Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0147 """ import sys from sys import stdin from heapq import heappop, heappush from collections import deque input = stdin.readline class Seat(): # ??????????????¶??????????????????????????? # '_'?????????????????????'o'???????????§??£?????????????????? def __init__(self, n): self.seat = '_' * n def get(self, num): # num????????£?¶?????????§???????????????????????°?????§???????????????????????????????????????????????????????????????????????°-1???????????? i = self.seat.find('_'*num) if i != -1: self.seat = self.seat[0:i] + 'o'*num + self.seat[i+num:] return i return -1 def release(self, i, num): # ??§??£???????????????????????????????????????????????????????????????????????????????????´??§??????????????? self.seat = self.seat[0:i] + '_'*num + self.seat[i+num:] def solve(): waiting_time = [-1] * 100 # ?????°??????????????¨??????????????? NUM_OF_SEAT = 17 seat = Seat(NUM_OF_SEAT) # ???????????¶???????????????????????????????????? LEAVE = 0 # ??\???????£???????????????????????????????????????\ COME = 1 # LEAVE??¨COME??????????????????????????´????????????????????\?????§LEAVE????????????????????????????????????????????´??????????????? in_out = [] # ??\????????????????????????????????? Q = deque() # ??§?????????????????? # 100???????????\???????????????????????? for group_id in range(100): if group_id % 5 == 1: num = 5 else: num = 2 heappush(in_out, (group_id * 5, COME, NUM_OF_SEAT+1, group_id, num)) # ????????????????????????????????????????¨?????????????????????´????????????????????????????????°????????????????????\????????° # ???????????\?????????????????????????????????????????????????????? while in_out: time, event, start_seat, group_id, num = heappop(in_out) if event == COME: Q.append((time, group_id, num)) # ??\????????´???????????¢????????£?????????????????§??????????????§??????????????§????????? else: seat.release(start_seat, num) # ?£??????????????????????????????? while Q: # ?????£???????????°??????????????§?????????????????§???????????? res = seat.get(Q[0][2]) # ?????????????????????????????§???????????? if res != -1: arrive, group_id, num = Q.popleft() waiting_time[group_id] = time - arrive # ????????°?????????????????\?????????????????§???????????§????????????????¨???? eating_time = 17 * (group_id % 2) + 3*(group_id % 3) + 19 # ?£?????????? heappush(in_out, (time + eating_time, LEAVE, res, group_id, num)) # ?????????????????????????????¨??????????????????????????? else: break # ??????????????????????????°??????????????§???????????£????????§????¬??????°?????????????¢?????????? return waiting_time # ??¨??°?????????????????????????????? def main(args): waiting_time = solve() for line in sys.stdin: print(waiting_time[int(line)]) if __name__ == '__main__': main(sys.argv[1:]) ```
output
1
76,610
14
153,221
Provide a correct Python 3 solution for this coding contest problem. "Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the shop is open. However, since I know the interval and number of customers coming from many years of experience, I decided to analyze the waiting time based on that. There are 17 seats in the store facing the counter. The store opens at noon, and customers come as follows. * 100 groups from 0 to 99 will come. * The i-th group will arrive at the store 5i minutes after noon. * The number of people in the i-th group is 5 when i% 5 is 1, and 2 otherwise. (x% y represents the remainder when x is divided by y.) * The i-th group finishes the meal in 17 (i% 2) + 3 (i% 3) + 19 minutes when seated. The arrival times, number of people, and meal times for the first 10 groups are as follows: Group number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- Arrival time (minutes later) | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 Number of people (people) | 2 | 5 | 2 | 2 | 2 | 2 | 5 | 2 | 2 | 2 Meal time (minutes) | 19 | 39 | 25 | 36 | 22 | 42 | 19 | 39 | 25 | 36 In addition, when guiding customers to their seats, we do the following. * Seats are numbered from 0 to 16. * A group of x people can only be seated when there are x open seats in a row. Also, if there are multiple places to sit, sit in the place with the lowest seat number. For example, if only seats 0, 1, 2, 4, and 5 are available, a group of 5 people cannot be seated. If you are in a group of two, you will be seated at number 0 and 1. * Once you are seated, you will not be asked to move your seat. * Customers come and go in 1 minute increments. At each time, we will guide customers in the following order. 1. The next group can be seated at the same time as the previous group leaves. 2. When seating customers, seat as many groups as possible at the same time, starting with the group at the top of the line. It does not overtake the order of the matrix. In other words, if the first group cannot be seated, even if other groups in the procession can be seated, they will not be seated. 3. Groups arriving at that time will line up at the end of the procession, if any. If there is no line and you can sit down, you will be seated, and if you cannot, you will wait in line. As an example, the following shows how the first 10 groups arrive. From left to right, the three columns in each row show the time, seating, and queue. For seats, the "_" is vacant and the number indicates that the group with that number is sitting in that seat. Time: Seat procession 0: 00 _______________: 5: 0011111 ___________: 10: 001111122 ________: 15: 00111112233______: 18: 00111112233______: 19: __111112233______: 20: 44111112233 ______: 25: 4411111223355____: 30: 4411111223355____: 66666 Group 6 arrives 34: 4411111223355____: 66666 35: 4411111__3355____: 6666677 Group 7 arrives 40: 4411111__3355____: 666667788 Group 8 arrives 41: 4411111__3355____: 666667788 42: __11111__3355____: 666667788 43: __11111__3355____: 666667788 44: 6666677883355____: Groups 6, 7 and 8 are seated 45: 666667788335599__: Group 9 arrives and sits down For example, at time 40, the eighth group arrives, but cannot be seated and joins the procession. The fourth group eats until time 41. At time 42, seats in the 4th group are available, but the 6th group is not yet seated due to the lack of consecutive seats. The first group eats until time 43. At time 44, the first group will be vacant, so the sixth group will be seated, and at the same time the seventh and eighth groups will be seated. The ninth group arrives at time 45 and will be seated as they are available. Based on this information, create a program that outputs the time (in minutes) that the nth group of customers waits by inputting an integer n that is 0 or more and 99 or less. Input Given multiple datasets. Each dataset consists of one integer n. The number of datasets does not exceed 20. Output For each dataset, print the minute wait time (integer greater than or equal to 0) for the nth customer on a single line. Example Input 5 6 7 8 Output 0 14 9 4
instruction
0
76,611
14
153,222
"Correct Solution: ``` # AOJ 0147 Fukushimaken # Python3 2018.6.23 bal4u # キューで待ち行列 S = 17 seat = [[0 for t in range(27)] for id in range(27)] ans = [0]*105 id = 0 Q = [] for i in range(S): seat[i][0] = -1 t = -1 while ans[99] == 0: t += 1 # グループ到着 if t % 5 == 0 and id <= 99: n = 5 if (id % 5) == 1 else 2 Q.append((id, n, t)) id += 1 # 食事時間の確認 for i in range(S): if seat[i][1] == 0: continue seat[i][1] -= 1 if seat[i][1] == 0: seat[i][0] = -1 # 待ち行列の案内 f = len(Q) while f > 0: i, n = Q[0][0], Q[0][1] f = 0; for j in range(S): g = 0 for k in range(n): if seat[j+k][0] >= 0: g = 1 break if g: continue ans[i] = t-Q[0][2] del Q[0] f = len(Q) for k in range(n): seat[j+k][0] = i seat[j+k][1] = 17*(i&1) + 3*(i%3) + 19 break while 1: try: n = int(input()) except: break print(ans[n]) ```
output
1
76,611
14
153,223
Provide a correct Python 3 solution for this coding contest problem. "Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the shop is open. However, since I know the interval and number of customers coming from many years of experience, I decided to analyze the waiting time based on that. There are 17 seats in the store facing the counter. The store opens at noon, and customers come as follows. * 100 groups from 0 to 99 will come. * The i-th group will arrive at the store 5i minutes after noon. * The number of people in the i-th group is 5 when i% 5 is 1, and 2 otherwise. (x% y represents the remainder when x is divided by y.) * The i-th group finishes the meal in 17 (i% 2) + 3 (i% 3) + 19 minutes when seated. The arrival times, number of people, and meal times for the first 10 groups are as follows: Group number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- Arrival time (minutes later) | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 Number of people (people) | 2 | 5 | 2 | 2 | 2 | 2 | 5 | 2 | 2 | 2 Meal time (minutes) | 19 | 39 | 25 | 36 | 22 | 42 | 19 | 39 | 25 | 36 In addition, when guiding customers to their seats, we do the following. * Seats are numbered from 0 to 16. * A group of x people can only be seated when there are x open seats in a row. Also, if there are multiple places to sit, sit in the place with the lowest seat number. For example, if only seats 0, 1, 2, 4, and 5 are available, a group of 5 people cannot be seated. If you are in a group of two, you will be seated at number 0 and 1. * Once you are seated, you will not be asked to move your seat. * Customers come and go in 1 minute increments. At each time, we will guide customers in the following order. 1. The next group can be seated at the same time as the previous group leaves. 2. When seating customers, seat as many groups as possible at the same time, starting with the group at the top of the line. It does not overtake the order of the matrix. In other words, if the first group cannot be seated, even if other groups in the procession can be seated, they will not be seated. 3. Groups arriving at that time will line up at the end of the procession, if any. If there is no line and you can sit down, you will be seated, and if you cannot, you will wait in line. As an example, the following shows how the first 10 groups arrive. From left to right, the three columns in each row show the time, seating, and queue. For seats, the "_" is vacant and the number indicates that the group with that number is sitting in that seat. Time: Seat procession 0: 00 _______________: 5: 0011111 ___________: 10: 001111122 ________: 15: 00111112233______: 18: 00111112233______: 19: __111112233______: 20: 44111112233 ______: 25: 4411111223355____: 30: 4411111223355____: 66666 Group 6 arrives 34: 4411111223355____: 66666 35: 4411111__3355____: 6666677 Group 7 arrives 40: 4411111__3355____: 666667788 Group 8 arrives 41: 4411111__3355____: 666667788 42: __11111__3355____: 666667788 43: __11111__3355____: 666667788 44: 6666677883355____: Groups 6, 7 and 8 are seated 45: 666667788335599__: Group 9 arrives and sits down For example, at time 40, the eighth group arrives, but cannot be seated and joins the procession. The fourth group eats until time 41. At time 42, seats in the 4th group are available, but the 6th group is not yet seated due to the lack of consecutive seats. The first group eats until time 43. At time 44, the first group will be vacant, so the sixth group will be seated, and at the same time the seventh and eighth groups will be seated. The ninth group arrives at time 45 and will be seated as they are available. Based on this information, create a program that outputs the time (in minutes) that the nth group of customers waits by inputting an integer n that is 0 or more and 99 or less. Input Given multiple datasets. Each dataset consists of one integer n. The number of datasets does not exceed 20. Output For each dataset, print the minute wait time (integer greater than or equal to 0) for the nth customer on a single line. Example Input 5 6 7 8 Output 0 14 9 4
instruction
0
76,612
14
153,224
"Correct Solution: ``` from collections import deque que = deque() t = 0 seat = [0] * 17 score = [] while que or t < 500: if t % 5 == 0 and t < 500: i = t // 5 que.append([t, 5 if i % 5 == 1 else 2, 17 * (i % 2) + 3 * (i % 3) + 19]) for i in range(17): if seat[i]: seat[i] -= 1 while que: need_space = que[0][1] for i in range(18 - need_space): if not any(seat[i:i+need_space]): for j in range(i, i + need_space): seat[j] = que[0][2] score.append(t - que[0][0]) que.popleft() break else: break t += 1 while True: try: print(score[int(input())]) except EOFError: break ```
output
1
76,612
14
153,225
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,619
14
153,238
"Correct Solution: ``` # AOJ 0545: Party # Python3 2018.7.1 bal4u import sys from sys import stdin input = stdin.readline while True: n, m = int(input()), int(input()) if n == 0: break n += 1 f, tbl = [0]*n, [] for i in range(m): a, b = map(int, input().split()) if a == 1 or b == 1: f[a] = f[b] = 1 else: tbl.append((a, b)) for a, b in tbl: if f[a] == 1 and f[b] == 1: continue if f[a] == 1: f[b] = 2 elif f[b] == 1: f[a] = 2 ans = 0 for i in range(2, n): if f[i]: ans += 1 print(ans) ```
output
1
76,619
14
153,239
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,620
14
153,240
"Correct Solution: ``` while True: n = int(input()) if not n: break m = int(input()) li = [[] for _ in range(n + 1)] for _ in range(m): a, b = [int(i) for i in input().split()] li[a].append(b) li[b].append(a) ans = set() for i in li[1]: ans.add(i) for j in li[i]: ans.add(j) if 1 in ans: ans.remove(1) print(len(ans)) ```
output
1
76,620
14
153,241
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,621
14
153,242
"Correct Solution: ``` def s(): import sys r=sys.stdin.readline for e in iter(r,'0\n'): R=[[]for _ in[0]*-~int(e)] for _ in[0]*int(r()): a,b=map(int,r().split()) R[a]+=[b];R[b]+=[a] for m in R[1][:]:R[1]+=R[m] print(len({*R[1]}-{1})) s() ```
output
1
76,621
14
153,243
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,622
14
153,244
"Correct Solution: ``` while True: n = int(input()) m = int(input()) if n==0: break tab = [[] for _ in range(n)] for _ in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 tab[a].append(b) tab[b].append(a) ans = set(tab[0]) foff = set() for i in ans: foff = foff | set(tab[i]) print(len((ans|foff)-{0})) ```
output
1
76,622
14
153,245
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,623
14
153,246
"Correct Solution: ``` while 1: n = int(input()) m = int(input()) if n == m == 0: break a = [] for i in range(m): x, y = map(int,input().split()) a.append([x, y]) a.sort(key = lambda x: x[0]) f1 = [] f2 = [] for i in range(m): if a[i][0] == 1: f1.append(a[i][1]) elif a[i][0] in f1 and not (a[i][1] in f1) and not (a[i][1] in f2): f2.append(a[i][1]) elif a[i][1] in f1 and not (a[i][0] in f1) and not (a[i][0] in f2): f2.append(a[i][0]) print(len(f1) + len(f2)) ```
output
1
76,623
14
153,247
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,624
14
153,248
"Correct Solution: ``` for e in iter(input,'0'): R=[set()for _ in[0]*-~int(e)] for _ in[0]*int(input()): a,b=map(int,input().split()) R[a]|={b} if a-1:R[b]|={a} for m in set(R[1]): R[1]|=R[m] print(len(R[1])) ```
output
1
76,624
14
153,249
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,625
14
153,250
"Correct Solution: ``` while True: n = int(input()) m = int(input()) if m == 0: break dataset = [input().split() for _ in range(m)] list_ = {i+1: [] for i in range(n)} for data in dataset: idx_x, idx_y = map(int, data) list_[idx_x].append(idx_y) list_[idx_y].append(idx_x) ans = list_[1].copy() for i in list_[1]: ans += list_[i] print(len(set(ans))-1) ```
output
1
76,625
14
153,251
Provide a correct Python 3 solution for this coding contest problem. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None
instruction
0
76,626
14
153,252
"Correct Solution: ``` def solve(): while True: n = int(input()) if not n: break m = int(input()) edge = [[0 for i in range(n + 1)] for j in range(n + 1)] for i in range(m): a,b = map(int,input().split()) edge[a][b] = 1 edge[b][a] = 1 friends1 = [i for i in range(n + 1) if edge[1][i]] friends2 = [] for friend in friends1: friends_lst = [i for i in range(n + 1) if edge[friend][i]] friends2.extend(friends_lst) ans = len(set(friends1 + friends2)) if ans: ans -= 1 print(ans) solve() ```
output
1
76,626
14
153,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` for e in iter(input,'0'): R=[[]for _ in[0]*-~int(e)] for _ in[0]*int(input()): a,b=map(int,input().split()) R[a]+=[b];R[b]+=[a] for m in R[1][:]:R[1]+=R[m] print(len({*R[1]}-{1})) ```
instruction
0
76,627
14
153,254
Yes
output
1
76,627
14
153,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` while 1: n=int(input()) m=int(input()) friend=[[0 for i in range(1)] for j in range(n+1)] if n==m==0:break for i in range(m): a,b=map(int,input().split()) friend[a].append(b) friend[b].append(a) friend_1st=friend[1] friend_2nd=friend_1st[:] for i in friend_1st: friend_2nd.extend(friend[i]) ans=list(set(friend_2nd)) if 0 in ans:ans.remove(0) if 1 in ans:ans.remove(1) print(len(ans)) ```
instruction
0
76,628
14
153,256
Yes
output
1
76,628
14
153,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` def s(): import sys r=sys.stdin.readline for e in iter(r,'0\n'): R=[[]for _ in[0]*-~int(e)] for _ in[0]*int(r()): a,b=map(int,r().split()) R[a]+=[b];R[b]+=[a] for m in R[1][:]:R[1]+=R[m] print(len({*R[1]}-{1})) if'__main__'==__name__:s() ```
instruction
0
76,629
14
153,258
Yes
output
1
76,629
14
153,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` while True: n = int(input()) if not n: break m = int(input()) edge = [[0 for i in range(n + 1)] for j in range(n + 1)] for i in range(m): a,b = map(int,input().split()) edge[a][b] = 1 edge[b][a] = 1 friends1 = [i for i in range(n + 1) if edge[1][i]] friends2 = [] for friend in friends1: friends_lst = [i for i in range(n + 1) if edge[friend][i]] friends2.extend(friends_lst) ans = len(set(friends1 + friends2)) if ans: ans -= 1 print(ans) ```
instruction
0
76,630
14
153,260
Yes
output
1
76,630
14
153,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` while True: n, m = int(input()), int(input()) if m == 0: break d = {k+1:[] for k,_ in enumerate(range(m))} for _ in range(m): a, b = map(int, input().split()) d[a].append(b) ans = d[1].copy() for k in d[1]: ans += d[k] print(len(set(ans))) ```
instruction
0
76,631
14
153,262
No
output
1
76,631
14
153,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` while True: n=int(input()) if n==0:break m=int(input()) rel=sorted([[int(s)for s in input().split(" ")]for i in range(m)],key=lambda x:x[0]) isf=[False for i in range(n)] inv=[False for i in range(n)] isf[0]=True for r in rel: if r[0]==1: isf[r[1]-1]=True inv[r[1]-1]=True elif isf[r[0]-1]==True:inv[r[1]-1]=True print(inv.count(True)) ```
instruction
0
76,632
14
153,264
No
output
1
76,632
14
153,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0545 """ import sys from sys import stdin input = stdin.readline def main(args): while True: n = int(input()) m = int(input()) if n == 0 and m == 0: break G = [[] for _ in range(n+1)] for _ in range(m): a, b = map(int, input().split()) G[a].append(b) invitees = set() for f in G[1]: invitees.add(f) # ??´??\????????? for ff in G[f]: invitees.add(ff) # ??????????????? #print(invitees) print(len(invitees)) if __name__ == '__main__': main(sys.argv[1:]) ```
instruction
0
76,633
14
153,266
No
output
1
76,633
14
153,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks for the number of students you will invite to your Christmas party. input The input consists of multiple datasets. Each dataset is given in the following format. The first line of the dataset contains the number of students in the school n (2 ≤ n ≤ 500), and the second line contains the length of the list m (1 ≤ m ≤ 10000). The input consists of 2 + m lines in total. Line 2 + i (1 ≤ i ≤ m) contains two integers ai and bi (1 ≤ ai <bi ≤ n) separated by blanks, and the students with numbers ai and bi are friends. Represents that. From the 3rd line to the 2 + m line, the lines representing the same friendship do not appear twice. When both n and m are 0, it indicates the end of input. The number of data sets does not exceed 5. output For each dataset, print the number of students you invite to the Christmas party on one line. Examples Input 6 5 1 2 1 3 3 4 2 3 4 5 6 5 2 3 3 4 4 5 5 6 2 5 0 0 Output 3 0 Input None Output None Submitted Solution: ``` while True: n = int(input()) m = int(input()) if m == 0: break dataset = [input().split() for _ in range(m)] list_ = {i+1: [] for i in range(n)} for data in dataset: idx, friend_idx = int(data[0]), int(data[1]) list_[idx].append(friend_idx) ans = list_[1].copy() for i in list_[1]: ans += list_[i] print(len(set(ans))-1) ```
instruction
0
76,634
14
153,268
No
output
1
76,634
14
153,269
Provide a correct Python 3 solution for this coding contest problem. Problem Gaccho loses motivation as the final exam approaches and often misses school. There are N days left until the final exam. Gaccho's motivation on day i is Xi, and the motivation needed to go to school on day i is Yi. Gaccho goes to school only on days when Xi ≥ Yi. Haji, who was worried about Gaccho, decided to encourage him to go to school as much as possible. Haji has an encouraging power P at first. When Haji encourages Gacho by consuming the encouragement force t (t is any real number greater than or equal to 0) on day i, Gacho's motivation on day i increases by t, and Haji Your encouragement is reduced by t. Furthermore, when i & plus; 1 ≤ N, Gacho-kun's motivation Xi & plus; 1 on the first day of i & plus; changes to max (0, Xi & plus; 1 − t). Haji cannot encourage beyond his own encouraging power. Find the maximum number of days Gacho will go to school when Haji gives the best encouragement. Constraints The input satisfies the following conditions. * 1 ≤ N ≤ 100 * 0 ≤ P ≤ 106 * 0 ≤ Xi ≤ 106 * 0 ≤ Yi ≤ 106 Input The input is given in the following format. N P X1 Y1 X2 Y2 ... XN YN All inputs are given as integers. On the first line, the number of days until the final exam and the encouraging power P that Haji has first are given separated by blanks. The N lines that continue from the second line are given the motivation Xi of the i (i = 1,2, ..., N) day of Gacho-kun and the motivation Yi necessary to go to school, separated by blanks. Output Print out the maximum number of days you can go to school on one line. Examples Input 3 10 1 6 5 10 0 5 Output 2 Input 5 5 1 1 1 2 1 2 1 3 1 3 Output 4
instruction
0
76,651
14
153,302
"Correct Solution: ``` N,P=map(int,input().split()) xs=[] ys=[] dp=[[[1e9 for i in range(N+1)] for j in range(N+1)] for k in range(N+1)] memo=[[0 for i in range(N+1)] for j in range(N+1)] for i in range(N): x,y=map(int,input().split()) xs.append(x) ys.append(y) for start in range(N): preuse=0 for now in range(start,N+1): if(now==start): preuse=0 memo[start][now]=0 else: nx=max(0,xs[now-1]-preuse) preuse=max(0,ys[now-1]-nx) memo[start][now]=memo[start][now-1]+preuse dp[0][0][0]=0 for now in range(N): for l in range(now+1): for score in range(N): dp[now+1][l][score+1]=min(dp[now+1][l][score+1],dp[now][l][score]+memo[l][now+1]-memo[l][now]) dp[now+1][now+1][score]=min(dp[now+1][now+1][score],dp[now][l][score]) ans=0 for l in range(N+1): for score in range(N): if(dp[N][l][score]<=P): ans=max(ans,score) print(ans) ```
output
1
76,651
14
153,303
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,768
14
153,536
Tags: binary search, brute force, greedy, math Correct Solution: ``` import sys input = sys.stdin.readline q=int(input()) Q=[list(map(int,input().split())) for i in range(q)] for a,b,m in Q: MIN=[a] MAX=[a] SUMMIN=a SUMMAX=a flag=1 for k in range(51): if MIN[-1]<=b<=MAX[-1]: break MIN.append(SUMMIN+1) MAX.append(SUMMAX+m) SUMMIN+=MIN[-1] SUMMAX+=MAX[-1] if MIN[-1]>10**14 or MIN[-1]>b: flag=0 break if flag==0: print(-1) continue SA=b-MIN[-1] PLUS=[0]*k #print(SA,k) for j in range(k): x=SA//max(1,2**(k-j-2)) if x>m-1: x=m-1 PLUS[j]=x+1 SA-=x*max(1,2**(k-j-2)) #print(PLUS) ANS=[a] SUM=a for j in range(k): ANS.append(SUM+PLUS[j]) SUM+=ANS[-1] print(len(ANS),*ANS) ```
output
1
76,768
14
153,537
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,769
14
153,538
Tags: binary search, brute force, greedy, math Correct Solution: ``` for _ in range(int(input())): a,b,m=map(int,input().split()) if a==b: print(1,a) continue for k in range(2,51): pw=1<<(k-2) mn=pw*(a+1) mx=pw*(a+m) if mn<=b<=mx: r=[0]*(k+1) add=b-mn r[1]=a for i in range(2,k): r[i]=min(m-1,add//(1<<(k-i-1))) add-=r[i]*(1<<(k-i-1)) r[i]+=1 r[k]=add+1 x=[0]*(k+1) s=0 for i in range(1,k+1): x[i]=s+r[i] s+=x[i] print(k,*(x[1:]),sep=' ') break else: print(-1) ```
output
1
76,769
14
153,539
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,770
14
153,540
Tags: binary search, brute force, greedy, math Correct Solution: ``` # https://codeforces.com/contest/1166/problem/D def creat_r(X, k, m, p): q = X // p[k] r = X % p[k] R = [] for _ in range(k+1): R.append(q) s = bin(r)[2:] for i in range(1, len(s)+1): if s[-i] == '1': R[-(i+1)] += 1 return R i = 1 p = [1] for _ in range(50): i*=2 p.append(i) T = int(input()) ans = [] for _ in range(T): a, b, m = map(int, input().split()) if a == b: print(1, a) continue flg = False for i in range(50): if p[i] * a >= b: break k = i X = b - (p[i] * a) if X >= p[k] and X <= p[k]*m: flg = True R = creat_r(X, k, m, p) sR = 0 A = [a] for _ in range(k+1): A.append(p[_]*a+sR+R[_]) sR += sR + R[_] print(len(A), end=' ') for x in A: print(x, end=' ') print() break if flg == False: print(-1) ```
output
1
76,770
14
153,541
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,771
14
153,542
Tags: binary search, brute force, greedy, math Correct Solution: ``` q = int(input()) def prepare_sequence(a, b, curr_two_pow, m): sequence = [a] curr_pow = 1 diff = b-curr_two_pow*a while curr_two_pow > 1: m_candidate = 1 diff -= m_candidate while diff > curr_two_pow//2: m_candidate*=2 diff = diff-(m_candidate-m_candidate//2) if diff < curr_two_pow//2: m_candidate //=2 diff = diff + (m_candidate) curr_candidate = m_candidate//(curr_two_pow//2) if curr_candidate > m: diff = diff + ((curr_candidate-m)*(curr_two_pow//2)) curr_candidate = m sequence.append(sum(sequence)+curr_candidate) curr_pow *= 2 curr_two_pow //= 2 sequence.append(b) return sequence def satisfies(a, b, m): if a == b: return [a] curr_two_pow = 1 while curr_two_pow*a < b: diff = b-curr_two_pow*a if diff >= curr_two_pow and diff <= curr_two_pow*m: return prepare_sequence(a, b, curr_two_pow, m) curr_two_pow *= 2 return None for i in range(q): a, b, m = map(int, input().split()) res = satisfies(a,b,m) if res: print("%s %s" % (len(res), " ".join(map(str, res)))) else: print(-1) ```
output
1
76,771
14
153,543
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,772
14
153,544
Tags: binary search, brute force, greedy, math Correct Solution: ``` def solve(): a, b, m = (int(x) for x in input().split()) if a == b: print(1, a) return curr = a curr_const = 1 steps_nr = 0 while b - curr > curr_const * m: curr *= 2 curr_const *= 2 steps_nr += 1 if b - curr < curr_const: print(-1) return left = b - curr - curr_const ans = [a] sum = a curr_const //= 2 while curr_const > 0: curr_try = left // curr_const curr_try = min(m - 1, curr_try) left -= curr_try * curr_const ans.append(sum + curr_try + 1) sum += ans[-1] curr_const //= 2 curr_const = 1 curr_try = left // curr_const curr_try = min(m - 1, curr_try) left -= curr_try * curr_const ans.append(sum + curr_try + 1) sum += ans[-1] curr_const //= 2 print(len(ans), *ans) if __name__ == '__main__': q = int(input()) for _ in range(q): solve() ```
output
1
76,772
14
153,545
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,773
14
153,546
Tags: binary search, brute force, greedy, math Correct Solution: ``` for _ in range(int(input())): a, b, m = [int(i) for i in input().split()] if a == b: print("1 " + str(a)) continue l = a + 1 r = a + m cnt = 1 while r < b: l += l r += r cnt += 1 if l > b: print(-1) continue ls = [1] * cnt p2 = [2 ** (cnt - 2 - i) for i in range(cnt - 1)] + [1] for i in range(cnt): tmp = min((b - l) // p2[i], m - 1); ls[i] += tmp l += tmp * p2[i] ans = [a] ps = a for i in ls: a = ps + i ps += a ans += [a] print(str(cnt + 1) + " " + ' '.join(str(i) for i in ans)) ```
output
1
76,773
14
153,547
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,774
14
153,548
Tags: binary search, brute force, greedy, math Correct Solution: ``` # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code if __name__ == "__main__": q = int(input()) po = [1,1,2] l = 4 for i in range(55): po.append(l) l *= 2 while q > 0: q -= 1 a,b,m = map(int,input().split()) se = 0 for ub in range(1,51): s = sum(po[:ub-1]) if b < s + po[ub - 1] * a: print(-1) se = 2 break if b <= s*m + po[ub - 1]*a : k = b - po[ub - 1]*a - po[ub - 1] arr = [] for j in range(1,ub): i = k//po[ub - 1 - j] i = min(m - 1, i) k -= i*po[ub - 1 - j] arr.append(i + 1) print(ub,a,end=" ") s = a k = [] for i in arr: k.append(s + i) s += (s + i) print(' '.join([str(i) for i in k])) se = 2 break # print(arr) if se != 2: print(-1) ```
output
1
76,774
14
153,549
Provide tags and a correct Python 3 solution for this coding contest problem. Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m. You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it. Input The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries. Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query. Output For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1. Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute. It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms. If there are multiple possible sequences, you may print any of them. Example Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 Note Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted. In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.
instruction
0
76,775
14
153,550
Tags: binary search, brute force, greedy, math Correct Solution: ``` from sys import stdin, stdout n = int(stdin.readline()) for nn in range(n): a, b, m = map(int,stdin.readline().split()) if a == b: stdout.write('{} {}\n'.format(1,a)) else: for j in range(2,51): if (a+1)<<(j-2) <= b and b <= (a+m)<<(j-2): B = b b -= a<<(j-2) stdout.write('{} {}'.format(j, a)) s = a for i in range(j-2): left = 1 right = m while left < right: k = (left+right+1)//2 if b - (k<<(j-3-i)) >= 1<<(j-3-i): left = k else: right = k-1 a = s+left stdout.write(' {}'.format(a)) s += a b -= left<<(j-3-i) stdout.write(' {}\n'.format(B)) break else: stdout.write('-1\n') ```
output
1
76,775
14
153,551
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,049
14
154,098
Tags: implementation Correct Solution: ``` n = int(input()) li = tuple((map(int, input().split()))) li1 = [] diff = [] i = 0 flag = 0 flag1 = 0 for i in range(len(li)): try: diff.append(abs(li[i] - li[i + 1])) li1.append([li[i], li[i + 1]]) except IndexError: diff.append(abs(li[i] - li[0])) li1.append([li[i], li[0]]) for i in range(n): try: if li[i % n] == li[(i % n) + 1]: print(i % n + 1, (i % n) + 2) flag = 1 flag1 = 1 break except IndexError: if li[i % n] == li[(i + 1) % n]: print(i % n + 1, (i + 1) % n + 1) flag = 1 flag1 = 1 break if flag1 == 0: min_m = min(diff) # print(diff.index(min_m) % n, diff.index(min_m)+1 % n) if (diff.index(min_m) + 1 % n) + 1 <= n: print((diff.index(min_m) % n) + 1, ((diff.index(min_m) + 1 % n) + 1)) else: print((diff.index(min_m) % n) + 1, 1) # print(diff) # print(diff.index(min_m)) # print(li[80], li[81]) ```
output
1
77,049
14
154,099
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,050
14
154,100
Tags: implementation Correct Solution: ``` n = int(input()) a = list(int(b) for b in input().split()) mi = n-1 md = abs(a[0]-a[mi]) for i in range(n-1): td = abs(a[i]-a[i+1]) if td < md: md = td mi = i if md == 0: break print(mi+1, (mi+1)%n+1) ```
output
1
77,050
14
154,101
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,051
14
154,102
Tags: implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) ab=max(a) ind=-1 for i in range(1,n): if abs(a[i]-a[i-1]) < ab: ab=abs(a[i]-a[i-1]) ind=i if ab<abs(a[-1]-a[0]): print(ind+1,ind) else: print(n,1) ```
output
1
77,051
14
154,103
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,052
14
154,104
Tags: implementation Correct Solution: ``` n = int(input()) heights = [int(x) for x in input().split(' ')] mn = abs(heights[len(heights)-1] - heights[0]) ans = [len(heights), 1] for i in range(len(heights)-1): if abs(heights[i+1] - heights[i]) < mn: mn = abs(heights[i+1] - heights[i]) ans = [i+1, i+2] print(*ans) ```
output
1
77,052
14
154,105
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,053
14
154,106
Tags: implementation Correct Solution: ``` n = int(input()) lst = list(map(int, input().split())) mn = abs(lst[1] - lst[0]) sol = [1, 2] for i in range(2, len(lst)): tmp = abs(lst[i] - lst[i-1]) if tmp < mn: sol[0] = i sol[1] = i + 1 mn = tmp if abs(lst[-1] - lst[0]) < mn: sol[0] = n sol[1] = 1 print(sol[0], sol[1]) ```
output
1
77,053
14
154,107
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,054
14
154,108
Tags: implementation Correct Solution: ``` n = int(input()) s = list(map(int,input().strip().split()))[:n] in1,in2,h=0,0,1000 for i in range(n): k = abs(s[i] - s[(i+1)%n]) if k<h: h=k in1= i+1 in2 = ((i+1)%n) + 1 print(in1,in2) ```
output
1
77,054
14
154,109
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,055
14
154,110
Tags: implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) ans=abs(l[-1]-l[0]) x,y=0,n-1 for i in range(n-1): if(ans>abs(l[i]-l[i+1])): ans=abs(l[i]-l[i+1]) x,y=i,i+1 print(x+1,y+1) ```
output
1
77,055
14
154,111
Provide tags and a correct Python 3 solution for this coding contest problem. n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction. Output Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Examples Input 5 10 12 13 15 10 Output 5 1 Input 4 10 20 30 40 Output 1 2
instruction
0
77,056
14
154,112
Tags: implementation Correct Solution: ``` N=int(input()) ara=list(map(int,input().split())) min=abs(ara[-1]-ara[0]) x=N y=1 for i in range(1,N): if(abs(ara[i]-ara[i-1])<min): min=abs(ara[i]-ara[i-1]) x=i y=i+1 print(x,y) ```
output
1
77,056
14
154,113
Provide tags and a correct Python 3 solution for this coding contest problem. Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: * "+ ri" — the reader with registration number ri entered the room; * "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors. Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence. Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you. Input The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors. Output Print a single integer — the minimum possible capacity of the reading room. Examples Input 6 + 12001 - 12001 - 1 - 1200 + 1 + 7 Output 3 Input 2 - 1 - 2 Output 2 Input 2 + 1 - 1 Output 1 Note In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
instruction
0
77,119
14
154,238
Tags: implementation Correct Solution: ``` ins = [] sumi = [] ous = [] n = int(input()) l = [] for i in range(n): l.append(str(input())) sumi.append(0) sumi.append(0) for i in range(n): if l[i][0] == "+": ins.append(l[i][2:len(l[i])]) for j in range(i+1, n+1): sumi[j]+=1 elif l[i][0] == "-" and l[i][2:len(l[i])] in ins: ins.remove(l[i][2:len(l[i])]) for j in range(i+1, n+1): sumi[j]-=1 else: for j in range(0, i+1): sumi[j]+=1 print(max(sumi)) ```
output
1
77,119
14
154,239
Provide tags and a correct Python 3 solution for this coding contest problem. Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms: * "+ ri" — the reader with registration number ri entered the room; * "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors. Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence. Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you. Input The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors. Output Print a single integer — the minimum possible capacity of the reading room. Examples Input 6 + 12001 - 12001 - 1 - 1200 + 1 + 7 Output 3 Input 2 - 1 - 2 Output 2 Input 2 + 1 - 1 Output 1 Note In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.
instruction
0
77,120
14
154,240
Tags: implementation Correct Solution: ``` n = int(input()) people = [] current = 0 num = [0] for i in range(n): x, y = input().split() if x == "+": people.append(y) current += 1 num.append(current) else: try: people.remove(y) current -= 1 except: num = [*map(lambda x : x + 1, num)] num.append(current) print(max(num)) ```
output
1
77,120
14
154,241