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 a correct Python 3 solution for this coding contest problem. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170
instruction
0
40,210
14
80,420
"Correct Solution: ``` import bisect n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() a_cum = [0 for _ in range(n+1)] for i in range(n): a_cum[i+1] = a_cum[i] + a[i] l, r = 0, 10 ** 6 while r - l > 1: x = (l + r) // 2 cnt = 0 for i in range(n): idx = bisect.bisect_left(a, x-a[i]) cnt += n - idx if cnt >= m: l = x else: r = x ans = 0 cnt = 0 for i in range(n): idx = bisect.bisect_left(a, l-a[i]) cnt += n - idx ans += a_cum[n] - a_cum[idx] ans += a[i] * (n - idx) if cnt > m: ans -= l * (cnt - m) print(ans) ```
output
1
40,210
14
80,421
Provide a correct Python 3 solution for this coding contest problem. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170
instruction
0
40,211
14
80,422
"Correct Solution: ``` def count(pre, a, x): cnt = 0 val = 0 for i in reversed(range(n)): if 2*a[i] < x: break lo, hi = 0, n-1 while lo < hi: mid = (lo + hi)//2 if a[mid] + a[i] < x: lo = mid + 1 else: hi = mid cnt += 1 + 2*(i - lo) val += 2*(i-lo+1)*a[i] + (pre[i] - pre[lo])*2 return cnt, val n, m = map(int, input().split()) a = list(sorted(map(int, input().split()))) pre = [0] for i in range(n): pre.append(a[i] + pre[-1]) lo, hi = 0, 2*a[-1] while lo < hi: mid = (lo + hi + 1) // 2 cnt, _ = count(pre, a, mid) if cnt < m: hi = mid - 1 else: lo = mid cnt, val = count(pre, a, lo) print(val - (cnt - m)*lo) ```
output
1
40,211
14
80,423
Provide a correct Python 3 solution for this coding contest problem. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170
instruction
0
40,212
14
80,424
"Correct Solution: ``` from bisect import bisect_left N,M=map(int,input().split()) A=list(map(int,input().split())) A.sort() l=1 r=200000+1 def chk(x): c=0 for la in A: y=bisect_left(A,x-la) c+=N-y if c>=M: return True else: return False while l+1<r: mid=(l+r)//2 if chk(mid): l=mid else: r=mid AN=l S=[0]*(N+1) for i in range(N): S[i+1]=S[i]+A[i] ans1=0 c=0 for la in A: ll = -1 rr = N while ll + 1 < rr: mi = (ll + rr) // 2 if A[mi] > AN - la: rr = mi else: ll = mi c+=N-rr ans1=ans1+la*(N-rr)+S[N]-S[rr] ans=ans1+(M-c)*AN print(ans) ```
output
1
40,212
14
80,425
Provide a correct Python 3 solution for this coding contest problem. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170
instruction
0
40,213
14
80,426
"Correct Solution: ``` n, m = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) cumsumA = [] total = 0 for a in A: total += a cumsumA.append(total) cumsumA.append(0) l = 0 r = 10 ** 6 while l + 1 < r: num = (l+r)//2 pair_idx = n-1 count = 0 for a in A: while a + A[pair_idx] < num and pair_idx >= 0: pair_idx -= 1 count += pair_idx+1 if count < m: r = num continue elif count >= m: l = num ans = 0 count = 0 num = l pair_idx = n-1 for a in A: while a + A[pair_idx] < num and pair_idx >= 0: pair_idx -= 1 count += pair_idx+1 ans += cumsumA[pair_idx] + a*(pair_idx+1) diff = count - m ans -= num * diff print(ans) ```
output
1
40,213
14
80,427
Provide a correct Python 3 solution for this coding contest problem. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170
instruction
0
40,214
14
80,428
"Correct Solution: ``` import sys input = sys.stdin.readline # 昇順ソートされた配列の挿入位置indexを返す O(logN) from bisect import bisect_left def isOver(a,n,x): cnt = 0 for i in range(n): cnt += n-bisect_left(a,x-a[i]) return cnt def calX(a,n,m,l,r): while r-l>1: # x: 握手で得たい最低パワー値 x = (l+r)//2 if isOver(a,n,x) >= m: l = x else: #握手する限界回数すら満たせないほど大きいxなら r = x return l n,m = map(int, input().split()) a = list(map(int, input().split())) #累積和の下準備 a.sort() s = [0]*(n+1) for i in range(n): s[i+1] = s[i]+a[i] x = calX(a,n,m,a[0]*2,a[n-1]*2) out = 0 for i in range(n): idx = bisect_left(a,x-a[i]) out += s[n]-s[idx]+a[i]*(n-idx) out -= (isOver(a,n,x)-m)*x print(out) ```
output
1
40,214
14
80,429
Provide a correct Python 3 solution for this coding contest problem. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170
instruction
0
40,215
14
80,430
"Correct Solution: ``` from itertools import accumulate MAX = 2 * 10 ** 5 + 5 N, M, *A = map(int, open(0).read().split()) B = [0] * MAX for a in A: B[a] += 1 C = list(accumulate(reversed(B)))[::-1] ng, ok = 1, MAX while abs(ok - ng) > 1: m = (ok + ng) // 2 if sum(C[max(0, m - a)] for a in A) >= M: ng = m else: ok = m D = list(accumulate(reversed(list(i * b for i, b in enumerate(B)))))[::-1] print(sum(D[max(0, ng - a)] - (ng - a) * C[max(0, ng - a)] for a in A) + ng * M) ```
output
1
40,215
14
80,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` # input N, M = map(int, list(input().split())) A = list(map(int, input().split())) # process A.sort(reverse=True) # 1回の握手の幸福度がx以上となるものの数、幸福度の合計を求める def calc(x): count, sum = 0, 0 j, t = 0, 0 for i in reversed(range(N)): while j < N and A[i]+A[j] >= x: t += A[j] j += 1 count += j sum += A[i]*j + t return (count, sum) # 2分探索で答えを求める def binary_search(x, y): mid = (x+y)//2 count, sum = calc(mid) if count < M: return binary_search(x, mid) else: if x == mid: print(sum-(count-M)*mid) else: return binary_search(mid, y) # 実行 binary_search(0, A[0]*2+1) ```
instruction
0
40,216
14
80,432
Yes
output
1
40,216
14
80,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` def ints(): return [int(x) for x in input().split()] def ii(): return int(input()) N, M = ints() A = ints() A.sort() A.reverse() def combinations(x): s = 0 i = 0 for j in reversed(range(N)): while i<N and A[i]+A[j]>=x: i += 1 s += i return s def koufukudo(x): s = 0 si = 0 i = 0 for j in reversed(range(N)): while i<N and A[i]+A[j]>=x: si += A[i] i += 1 s += si + A[j]*i return s def bsearch(l, u): m = (l+u)//2 c = combinations(m) if c<M: return bsearch(l, m) else: if l==m: return (l, c-M) return bsearch(m, u) x, dm = bsearch(0, A[0]*2+1) print(koufukudo(x)-dm*x) ```
instruction
0
40,217
14
80,434
Yes
output
1
40,217
14
80,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` N,M=map(int,input().split()) A=list(map(int,input().split())) A.sort(reverse=True) B=[0]*(N+1) for i in range(1,N+1): B[i]=B[i-1]+A[i-1] D=[0]*(2*10**5+1) for i in range(N): D[A[i]]+=1 for i in range(len(D)-1,0,-1): D[i-1]+=D[i] #print(D) #print(A) #print(D) l=-1 r=2*10**5+1 while r-l>1: m=(l+r)//2 s=0 for i in range(N): s+=D[max(1,m-A[i])] if s>=M: l=m else: r=m ans=0 s=0 for i in range(N): v=max(0,r-A[i]) t=max(0,min(D[v],M-s)) ans+=B[t]+t*A[i] s+=t ans+=l*(M-s) print(ans) ```
instruction
0
40,218
14
80,436
Yes
output
1
40,218
14
80,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` import bisect N,M=map(int,input().split()) A=list(map(int,input().split())) A.sort() #C[i]=パワーがi以下の人数 C=[0]*(10**5*2+1) for a in A: C[a]+=1 for i in range(1,len(C)): C[i]+=C[i-1] #和がx以上になる組み合わせの総数を求める関数 def pattern_num_ge_x(x): p=0 for a in A: p+=(N-(C[x-a-1] if x-a-1>=0 else 0)) return(p) #pattern_num_ge_x(x)がM未満になる最小のxを探す(=r) #lはM以上になる最大のx l=-1 r=10**5*2+1 while r-l>1: m=(r+l)//2 if pattern_num_ge_x(m)<M: r=m else: l=m #和がr以上になる組み合わせの総和を求める(累積和を使用) S=[0]+list(reversed(A[:])) for i in range(1,N+1): S[i]+=S[i-1] ans=0 for a in A: idx=bisect.bisect_left(A,r-a) ans+=a*(N-idx) + S[N-idx] M-=(N-idx) #回数のあまり分lを足す ans+=l*M print(ans) ```
instruction
0
40,219
14
80,438
Yes
output
1
40,219
14
80,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` n,m=map(int,input().split()) A=sorted(list(map(int,input().split()))) # M回の握手の幸福度最大化 # X以上になる握手を全て採用したときに、M通りを越える # Xの最大値を求める import bisect ok=-1 ng=10**15+1 # x以上の握手をm通り以上作れるか def isOk(x,m): cnt=0 # 左手をループする for i in range(len(A)): left=A[i] minright=x-left # minright以上の数を数える cnt+=n-bisect.bisect_left(A,minright) if cnt>=m: return True return cnt>=m while abs(ok-ng)>1: mid=abs(ok+ng)//2 if isOk(mid,m): ok=mid else: ng=mid x=ok # x以上となる幸福度を足し合わせる # 足し合わせた握手がMを越える場合、xぴったりを足し過ぎている # 効率化のため累積和を作成 Asum=[0]+A for i in range(1,len(Asum)): Asum[i]=Asum[i-1]+Asum[i] # Aの添字i以降を全て足すときは、 # Asum[-1]-Asum[i] ans=0 cnt=0 for i in range(len(A)): left=A[i] minright=x-left start=bisect.bisect_left(A,minright) cnt+=n-start ans+=left*(n-start)+(Asum[-1]-Asum[start]) if cnt>m: ans-=(cnt-m)*x print(ans) ```
instruction
0
40,220
14
80,440
No
output
1
40,220
14
80,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` def solve(n, m, a) -> int: from bisect import bisect_left, bisect_right from itertools import accumulate from collections import Counter *a, = sorted(a) acc = (0,) + tuple(accumulate(a)) c = Counter(a) def is_ok(h): ret = 0 for i, x in enumerate(a): j = bisect_left(a, h - x) ret += (n - j) * 2 if ret >= m * 2: return True return False def binary_search(): ok = 0 ng = a[-1] * 2 + 1 # ペアの最小値 while abs(ng - ok) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok min_pair_happiness = binary_search() ret = 0 for i, x in enumerate(a): j = bisect_left(a, min_pair_happiness - x) k = bisect_right(a, min_pair_happiness - x) ret += (n - j) * x + (acc[n] - acc[j]) if j != k: ret -= a[j] + x return ret def main(): n, m = map(int, input().split()) *a, = map(int, input().split()) print(solve(n, m, a)) if __name__ == '__main__': main() ```
instruction
0
40,221
14
80,442
No
output
1
40,221
14
80,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` import numpy as np N ,M= map(int,input().split()) l=list(map(int,input().split())) n0 = 2**int(np.ceil(np.log2(2*(max(l)+1) - 1))) A = np.zeros(n0) #B=np.zeros(n0) #l=list(map(int,input().split())) for i in range(N): A[l[i]]+=1 # B[i]=l[i] C = np.fft.ifft( np.fft.fft(A)*np.fft.fft(A) ) ans=0 j=1 q=[] for ci in np.real(C[:2*(max(l)+1)- 1] + 0.5): #ans+=int(ci)*j q.append([int(ci),j]) j+=1 q.reverse() z=0 j=0 while z<M: ans+=q[j][0]*q[j][1] j+=1 z+=q[j][0] ans-=(z-M)*q[j-1][1] print(ans) ```
instruction
0
40,222
14
80,444
No
output
1
40,222
14
80,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes? Constraints * 1 \leq N \leq 10^5 * 1 \leq M \leq N^2 * 1 \leq A_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the maximum possible happiness after M handshakes. Examples Input 5 3 10 14 19 34 33 Output 202 Input 9 14 1 3 5 110 24 21 34 5 3 Output 1837 Input 9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076 Output 8128170 Submitted Solution: ``` N,M = list(map(int,input().split())) A = list(map(int,input().split())) A.sort() ans = [0] for i in reversed(range(N)): #ans = np.r_[ans,A[i]*2 ,[A[i]] + np.array(A[i+1:n+1]),[A[i]] + np.array(A[i+1:n+1])] ans.append(A[i]*2) [ans.extend([A[i]+a,A[i]+a]) for a in A[:i]] ans.sort() ans = ans[-M:] print(int(sum(ans[-M:]))) ```
instruction
0
40,223
14
80,446
No
output
1
40,223
14
80,447
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,746
14
81,492
Tags: implementation Correct Solution: ``` n = int(input()) bunch = [] for i in range(n): leaf = input() if (leaf not in bunch): bunch.append(leaf) print(len(bunch)) ```
output
1
40,746
14
81,493
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,747
14
81,494
Tags: implementation Correct Solution: ``` tot = set() for _ in range(int(input())): tot.add(tuple(input().split())) print(len(tot)) ```
output
1
40,747
14
81,495
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,748
14
81,496
Tags: implementation Correct Solution: ``` n = int(input()) g = set() for i in range(n): b = input() g.add(b) print(len(g)) ```
output
1
40,748
14
81,497
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,749
14
81,498
Tags: implementation Correct Solution: ``` int1=int(input()) d=[] for i in range(int1): d.append(input().strip()) #print(d) print(len(set(d))) ```
output
1
40,749
14
81,499
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,750
14
81,500
Tags: implementation Correct Solution: ``` n = int(input()) s = [] for i in range(n): m = input() if s.count(m) == 0: s.append(m) print(len(s)) ```
output
1
40,750
14
81,501
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,752
14
81,504
Tags: implementation Correct Solution: ``` # cook your dish here d={} c=0 n=int(input()) for _ in range(n): a,b=input().split() if(a in d and b not in d[a]): d[a].append(b) c+=1 elif(a not in d): d[a]=[b] c+=1 #(d) print(c) ```
output
1
40,752
14
81,505
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,753
14
81,506
Tags: implementation Correct Solution: ``` x = [] for _ in range(int(input())): x.append(input()) print(len(set(x))) ```
output
1
40,753
14
81,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` n = int(input()) l = [] for i in range(n): s = input() l.append(s) print(len(set(l))) ```
instruction
0
40,754
14
81,508
Yes
output
1
40,754
14
81,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` s = set() t = int(input()) for i in range(t): a = input() s.add(a) print(len(s)) ```
instruction
0
40,755
14
81,510
Yes
output
1
40,755
14
81,511
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` n = int(input()) bouquet = [] leaf = () a = '' b = '' number_of_leaves = 0 for i in range(n): a, b = [x for x in input().split()] leaf = (a, b) if not leaf in bouquet: bouquet.append(leaf) number_of_leaves += 1 print(number_of_leaves) ```
instruction
0
40,756
14
81,512
Yes
output
1
40,756
14
81,513
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` import sys Input = sys.stdin.readline n = int(Input()) tmp = [] for i in range(n): tmp.append(Input()) print(len(set(tmp))) # Codeforcesian # ♥ ```
instruction
0
40,757
14
81,514
Yes
output
1
40,757
14
81,515
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` n = int(input()) my_set=[] for i in range(n): str = input(); my_set = set(str) print(len(my_set)) ```
instruction
0
40,758
14
81,516
No
output
1
40,758
14
81,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` n = int(input()) d = {} c = 0 for i in range(n): k, v = str(input()).split(" ") try : if(d[k] != v): c+=1 except : d[k] = v c+=1 print(c) ```
instruction
0
40,759
14
81,518
No
output
1
40,759
14
81,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` a=[] b=[] cnt=0 j=0 for i in range(int(input())): s,c=input().split() if((s not in a) and (c not in b)): a.append(s) b.append(c) cnt=cnt+1 elif((s in a) and (c not in b)): a.append(s) b.append(c) cnt=cnt+1 elif((s not in a) and (c in b)): a.append(s) b.append(c) cnt=cnt+1 else: j=1 print(cnt) ```
instruction
0
40,760
14
81,520
No
output
1
40,760
14
81,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number — the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1 Submitted Solution: ``` a=[] b=[] cnt=0 j=0 for i in range(int(input())): s,c=input().split() if((s not in a) and (c not in b)): a.append(s) b.append(c) cnt=cnt+1 elif((s in a) and (c not in b)): a.append(s) b.append(c) cnt=cnt+1 elif((s not in a) and (c in b)): a.append(s) b.append(c) cnt=cnt+1 else: j=1 print(cnt+1) ```
instruction
0
40,761
14
81,522
No
output
1
40,761
14
81,523
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes n pictures. When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The i-th picture has a non-negative weight w_i, and the probability of the i-th picture being displayed is \frac{w_i}{∑_{j=1}^nw_j}. That is to say, the probability of a picture to be displayed is proportional to its weight. However, Nauuo discovered that some pictures she does not like were displayed too often. To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add 1 to its weight; otherwise, she would subtract 1 from its weight. Nauuo will visit the website m times. She wants to know the expected weight of each picture after all the m visits modulo 998244353. Can you help her? The expected weight of the i-th picture can be denoted by \frac {q_i} {p_i} where \gcd(p_i,q_i)=1, you need to print an integer r_i satisfying 0≤ r_i<998244353 and r_i⋅ p_i≡ q_i\pmod{998244353}. It can be proved that such r_i exists and is unique. Input The first line contains two integers n and m (1≤ n≤ 2⋅ 10^5, 1≤ m≤ 3000) — the number of pictures and the number of visits to the website. The second line contains n integers a_1,a_2,…,a_n (a_i is either 0 or 1) — if a_i=0 , Nauuo does not like the i-th picture; otherwise Nauuo likes the i-th picture. It is guaranteed that there is at least one picture which Nauuo likes. The third line contains n positive integers w_1,w_2,…,w_n (w_i ≥ 1) — the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed 998244352-m. Output The output contains n integers r_1,r_2,…,r_n — the expected weights modulo 998244353. Examples Input 2 1 0 1 2 1 Output 332748119 332748119 Input 1 2 1 1 Output 3 Input 3 3 0 1 1 4 3 5 Output 160955686 185138929 974061117 Note In the first example, if the only visit shows the first picture with a probability of \frac 2 3, the final weights are (1,1); if the only visit shows the second picture with a probability of \frac1 3, the final weights are (2,2). So, both expected weights are \frac2 3⋅ 1+\frac 1 3⋅ 2=\frac4 3 . Because 332748119⋅ 3≡ 4\pmod{998244353}, you need to print 332748119 instead of \frac4 3 or 1.3333333333. In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, w_1 will be increased by 1. So, the expected weight is 1+2=3. Nauuo is very naughty so she didn't give you any hint of the third example.
instruction
0
41,300
14
82,600
Tags: dp, probabilities Correct Solution: ``` P = 998244353 N, M = map(int, input().split()) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] li = sum([A[i]*B[i] for i in range(N)]) di = sum([(A[i]^1)*B[i] for i in range(N)]) X = [1] SU = li+di PO = [0] * (5*M+10) for i in range(-M-5, 2*M+5): PO[i] = pow((SU+i)%P, P-2, P) def calc(L): su = sum(L) pl = 0 pd = 0 RE = [] for i in range(len(L)): a = li + i b = di - (len(L) - 1 - i) pd = b * L[i] * PO[a+b-SU] RE.append((pl+pd)%P) pl = a * L[i] * PO[a+b-SU] RE.append(pl%P) return RE for i in range(M): X = calc(X) ne = 0 po = 0 for i in range(M+1): po = (po + X[i] * (li + i)) % P ne = (ne + X[i] * (di - M + i)) % P invli = pow(li, P-2, P) invdi = pow(di, P-2, P) for i in range(N): print(po * B[i] * invli % P if A[i] else ne * B[i] * invdi % P) ```
output
1
41,300
14
82,601
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,542
14
83,084
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` n = int(input()) A = [0, 0, 0, 0, 0] B = map(int, input().split(' ')) for i in B: A[i] += 1 res = min(A[1], A[2]) A[1] -= res A[2] -= res A[3] += res res += 2 * (A[1] // 3) A[3] += A[1] // 3 A[1] %= 3 res += 2 * (A[2] // 3) A[3] += 2 * (A[2] // 3) A[2] %= 3 assert(A[1] == 0 or A[2] == 0) if (A[1] == 1): if (A[3] > 0): res += 1 #; A[1] = 0; A[3] -= 1; A[4] += 1 elif (A[4] > 1): res += 2 #; A[1] = 0; A[4] -= 2; A[3] += 3 else: print(-1) exit() elif (A[1] == 2): if (A[4] > 0): res += 2 #; A[1] = 0; A[4] -= 1; A[3] += 1 elif (A[3] > 1): res += 2 #; A[1] = 0; A[3] -= 2; A[4] += 2 else: print(-1) exit() if (A[2] == 1): if (A[4] > 0): res += 1 #; A[4] -= 1; A[2] = 0; A[3] += 1 elif (A[3] > 1): res += 2; #; A[2] = 0; A[3] -= 2; A[4] += 2 else: print(-1) exit() elif (A[2] == 2): res += 2 #; A[2] = 0; A[4] += 1 print(res) ```
output
1
41,542
14
83,085
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,543
14
83,086
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` #! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (counts[1] // 3) counts[3] += counts[1] // 3 counts[1] %= 3 if counts[3] > 0: ans += counts[1] elif counts[1] != 0: ans += 2 else: ans += counts[1] counts[2] -= counts[1] ans += 2 * (counts[2] // 3) counts[2] %= 3 if counts[4] > 0: ans += counts[2] elif counts[2] != 0: ans += 2 print(ans) else: print(-1) ```
output
1
41,543
14
83,087
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,544
14
83,088
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## from collections import Counter import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = list(map(int, input().split()))''' n = int(input()) #n,k=map(int, input().split()) arr = list(map(int, input().split())) f=0 if sum(arr)<3 or sum(arr)==5: f=1 a=arr.count(4) b=arr.count(3) c=arr.count(2) d=arr.count(1) var=min(c,d) d-=var c-=var b+=var ans=var if c: add=c//3 ans+=2*add b+=2*add c=c%3 ans+=1 if c==1 and a>=1 else 2 if c else 0 if d: add=d//3 ans+=2*add b+=add d=d%3 ans+=1 if b and d==1 else 2 if d else 0 print(ans if f==0 else -1) ```
output
1
41,544
14
83,089
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,545
14
83,090
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` a = [0] * 5 tot, ans = 0, 0 input() for x in list(map(int, input().split())): a[x] += 1 tot += x if tot < 3 or tot == 5: exit(print(-1)) mn = min(a[1], a[2]) a[1] -= mn a[2] -= mn a[3] += mn ans += mn if a[1]: add = a[1] // 3 a[1] %= 3 a[3] += add ans += 2 * add ans += 1 if a[1] == 1 and a[3] else 2 if a[1] else 0 if a[2]: add = a[2] // 3 a[2] %= 3 a[3] += 2 * add ans += 2 * add ans += 1 if a[2] == 1 and a[4] else 2 if a[2] else 0 print(ans) ```
output
1
41,545
14
83,091
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,546
14
83,092
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` n = int(input()) seq = list(map(int, input().split(" "))) if sum(seq) < 3 or sum(seq) == 5: print(-1) else: arr = [0,0,0,0,0] for s in seq: arr[s] += 1 #print(arr) ans = 0 if arr[2] >= arr[1]: ans += arr[1] arr[2] -= arr[1] arr[3] += arr[1] arr[1] = 0 else: ans += arr[2] arr[1] -= arr[2] arr[3] += arr[2] arr[2] = 0 #print(arr, ans) ans += 2*(arr[1]//3) arr[3] += arr[1]//3 arr[1] %= 3 #print(arr, ans) if (arr[3] >= arr[1]): ans += arr[1] arr[4] += arr[1] arr[3] -= arr[1] arr[1] = 0 else: if arr[1] < 2: ans += arr[3] arr[4] += arr[3] arr[1] -= arr[3] arr[3] = 0 #print(arr, ans) if arr[1] > 0: if arr[1] == 2: ans += arr[1] arr[4] -= 1 arr[3] += 2 arr[1] = 0 else: ans += 2 arr[4] -= 2 arr[3] += 2 arr[1] = 0 ans += 2*(arr[2]//3) arr[3] += 2*(arr[2]//3) arr[2] %= 3 #print(arr, ans) if arr[2] > 0: if (arr[4] >= arr[2]): ans += arr[2] arr[4] -= arr[2] arr[3] += 2*arr[2] arr[2] = 0 #print(arr, ans) ans += 2*(arr[2]) arr[4] += 2*arr[2] arr[3] -= arr[2] arr[2] = 0 #print(arr, ans) else: if (arr[4] > 0): ans += arr[2] arr[4] -= arr[2] arr[3] += 2*arr[2] arr[2] = 0 #print(arr, ans) else: if arr[2] == 1: ans += 2*arr[2] arr[3] += 2 arr[2] = 0 else: ans += arr[2] arr[4] += 1 arr[2] = 0 print(ans) ```
output
1
41,546
14
83,093
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,547
14
83,094
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` #! /usr/bin/env python n = int(input()) counts = [0] * 5 s = 0 for x in [int(x) for x in input().split()]: counts[x] += 1 s += x if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (counts[1] // 3) counts[3] += counts[1] // 3 counts[1] %= 3 if counts[3] > 0: ans += counts[1] elif counts[1] != 0: ans += 2 else: ans += counts[1] counts[2] -= counts[1] ans += 2 * (counts[2] // 3) counts[2] %= 3 if counts[4] > 0: ans += counts[2] elif counts[2] != 0: ans += 2 print(ans) else: print(-1) ```
output
1
41,547
14
83,095
Provide tags and a correct Python 3 solution for this coding contest problem. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0
instruction
0
41,548
14
83,096
Tags: combinatorics, constructive algorithms, greedy, implementation Correct Solution: ``` #! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (counts[1] // 3) counts[3] += counts[1] // 3 counts[1] %= 3 if counts[3] > 0: ans += counts[1] elif counts[1] != 0: ans += 2 else: ans += counts[1] counts[2] -= counts[1] ans += 2 * (counts[2] // 3) counts[2] %= 3 if counts[4] > 0: ans += counts[2] elif counts[2] != 0: ans += 2 print(ans) else: print(-1) # Made By Mostafa_Khaled ```
output
1
41,548
14
83,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0 Submitted Solution: ``` a = [0] * 5 tot, ans = 0, 0 input() for x in list(map(int, input().split())): a[x] += 1 tot += x if tot < 3: exit(print(-1)) mn = min(a[1], a[2]) a[1] -= mn a[2] -= mn a[3] += mn ans += mn print(a, ans) if a[1]: add = a[1] // 3 a[1] %= 3 a[3] += add ans += 2 * add ans += 1 if a[1] == 1 and a[3] else 2 if a[1] else 0 if a[2]: add = a[2] // 3 a[2] %= 3 a[3] += 2 * add ans += 2 * add ans += 1 if a[2] == 1 and a[4] else 2 if a[2] else 0 print(ans) ```
instruction
0
41,549
14
83,098
No
output
1
41,549
14
83,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. Examples Input 5 1 2 2 4 3 Output 2 Input 3 4 1 1 Output 2 Input 4 0 3 0 4 Output 0 Submitted Solution: ``` import math n=int(input()) arr=list(map(int,input().strip().split(' '))) dic=[0 for i in range(5)] sum=0 for i in arr: sum+=i dic[i]+=1 if sum in [1,2,5]: print(-1) quit() res=0 res+=dic[1] dic[2]-=dic[1] if dic[2]>0: if dic[2]>dic[4]: res+=dic[4] else: res+=dic[2] dic[2]-=dic[4] if dic[2]>0: res+=math.ceil(dic[2]/3)*2 print(res) ```
instruction
0
41,551
14
83,102
No
output
1
41,551
14
83,103
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,578
14
83,156
Tags: data structures, implementation Correct Solution: ``` n, t, c = map(int, input().split()) arr = list(map(int, input().split())) i, j, res = 0, 0, 0 while i < n: while i < n and arr[i] <= t: i += 1 r = i - j if r >= c: res += (r - c + 1) i += 1 j = i print(res) ```
output
1
41,578
14
83,157
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,579
14
83,158
Tags: data structures, implementation Correct Solution: ``` n, t, c = map(int, input().split()) ps = list(map(int, input().split())) s = [0] + [i + 1 for i in range(n) if ps[i] > t] + [n + 1] print(sum(s[i] - s[i-1] - c for i in range(1, len(s)) if s[i] - s[i-1] > c)) ```
output
1
41,579
14
83,159
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,580
14
83,160
Tags: data structures, implementation Correct Solution: ``` n, t, c = map(int, input().split()) a = list(map(int, input().split())) b = [-1] res = 0 tmp = 0 for i in range(n): if a[i] > t: b.append(i) b.append(n) for i in range(1, len(b)): tmp = b[i] - b[i - 1] - 1 res += max(tmp - c + 1, 0) print(res) ```
output
1
41,580
14
83,161
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,581
14
83,162
Tags: data structures, implementation Correct Solution: ``` # prison transfer def main(): n, t, c = [int(c) for c in input().split()] s = ''.join([str(int(int(c) <= t)) for c in input().split()]) s = s.split('0') res = 0 for e in s: if len(e) >= c: res += len(e) - c + 1 print(res) if __name__ == '__main__': main() ```
output
1
41,581
14
83,163
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,582
14
83,164
Tags: data structures, implementation Correct Solution: ``` n, t, c = map(int, input().split()) lis = [int(x) for x in input().split()] ans = 0 cnt = 0 for i in lis: if(i <= t): cnt += 1 else: cnt = 0 if(cnt >= c): ans += 1 print(ans) ```
output
1
41,582
14
83,165
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,583
14
83,166
Tags: data structures, implementation Correct Solution: ``` n,t,c = map(int,input().split()) s = [int(i) for i in input().split()] cnt = 0 d = [-1] for i in range(n): if s[i]>t: d.append(i) d.append(n) for i in range(len(d)-1): a = d[i+1]-d[i]-1 if a>=c: cnt+=a-c+1 print(cnt) ```
output
1
41,583
14
83,167
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,584
14
83,168
Tags: data structures, implementation Correct Solution: ``` n, t, c = [int(x) for x in input().split()] ex_id = [-1] + [i for i, v in enumerate(input().split()) if int(v) > t] + [n] ans = 0 for i in range(1, len(ex_id)): diff = ex_id[i] - ex_id[i-1] - 1 ans += max(diff- c + 1, 0) print(ans) ```
output
1
41,584
14
83,169
Provide tags and a correct Python 3 solution for this coding contest problem. The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, * The chosen c prisoners has to form a contiguous segment of prisoners. * Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. Input The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the c prisoners. Examples Input 4 3 3 2 3 1 1 Output 2 Input 1 1 1 2 Output 0 Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4 Output 6
instruction
0
41,585
14
83,170
Tags: data structures, implementation Correct Solution: ``` n, t, c = map(int, input().split()) v = list(map(int, input().split())) f = [] cont1 = 0 conTot = 0 for i in range(n): if(v[i] <= t): cont1 += 1 else: cont1 = 0 if(cont1 >= c): conTot += 1 print(conTot) ```
output
1
41,585
14
83,171
Provide tags and a correct Python 3 solution for this coding contest problem. There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of groups. Each of the following n lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot. Output Print minimum number of rooms needed to hold all groups classes on Monday. Examples Input 2 0101010 1010101 Output 1 Input 3 0101011 0011001 0110111 Output 3 Note In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
instruction
0
41,752
14
83,504
Tags: implementation Correct Solution: ``` n = int(input()) dictt ={} arr=[] for i in range(n): a = input() arr.append(a) for i in range(0,n): for j in range(0,7): if (arr[i][j]=='1'): try:dictt[j]+=1 except:dictt[j]=1 try:print(max(dictt.values())) except:print(0) ```
output
1
41,752
14
83,505
Provide tags and a correct Python 3 solution for this coding contest problem. There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of groups. Each of the following n lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot. Output Print minimum number of rooms needed to hold all groups classes on Monday. Examples Input 2 0101010 1010101 Output 1 Input 3 0101011 0011001 0110111 Output 3 Note In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
instruction
0
41,753
14
83,506
Tags: implementation Correct Solution: ``` t = int(input()) classes = [] answer = 0 for i in range(t): s = input() classes.insert(i, s) for i in range(7): room = 0 for j in range(len(classes)): if int(classes[j][i]) == 1: room += 1 if room > answer: answer = room print(answer) ```
output
1
41,753
14
83,507
Provide tags and a correct Python 3 solution for this coding contest problem. There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of groups. Each of the following n lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot. Output Print minimum number of rooms needed to hold all groups classes on Monday. Examples Input 2 0101010 1010101 Output 1 Input 3 0101011 0011001 0110111 Output 3 Note In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
instruction
0
41,754
14
83,508
Tags: implementation Correct Solution: ``` n = int(input()) arr = [0 for i in range(7)] for i in range(n): s = input() for j in range(7): if s[j] == '1': arr[j] += 1 print(max(arr)) ```
output
1
41,754
14
83,509