text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Tags: greedy Correct Solution: ``` from collections import defaultdict n,k=[int(el) for el in input().split()] h=[int(el) for el in input().split()] l=len(h) d=defaultdict(int) maxh=h[0] minh=h[0] for i in range(l): d[h[i]]+=1 maxh=max(maxh,h[i]) minh=min(minh,h[i]) if n==1 or minh==maxh: print(0) raise SystemExit s=list(d.keys()) s.sort() cur1=s.pop() curval=0 out=1 while s!=[]: cur2=s.pop() qnt=d[cur1] dif=cur1-cur2 val=dif*qnt if curval+val<k: curval += val d[cur2]+=d[cur1] dele = d.pop(cur1) cur1=cur2 continue if curval+val==k: if s==[]: print(out) raise SystemExit else: out+=1 curval=0 d[cur2]+=d[cur1] cur1=cur2 continue q=(k-curval)//qnt if q==0: out+=1 curval=0 s.append(cur2) else: curval=0 d[cur1-q]=d[cur1-q]+d[cur1] dele=d.pop(cur1) cur1=cur1-q out+=1 s.append(cur2) print (out) ```
96,100
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` n,k = map(int,input().split()) h = list(map(int,input().split())) flag = True for i in range(n-1): if (h[i]!=h[i+1]): flag = False break if (n==1 or flag): print(0) else: val = [0]*200005 for i in range(n): val[h[i]] += 1 i = 200004 count = 0 while (i>0 and val[i]<n): cost = 0 while (i>0 and val[i]+cost<=k): cost += val[i] val[i-1] += val[i] val[i] = 0 i -= 1 count += 1 if (val[i]==n): break print(count) ``` Yes
96,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` n,k = map(int,input().split()) mas = list(map(int,input().split())) di = {i:0 for i in range(1,200006)} a,b = 0,300000 for i,x in enumerate(mas): if x>a: a=x if x<b: b=x di[x]+=1 res,q,w = 0,0,0 e=a if e==b: print(0) else: for i in range(e-b): t = di[a] if q+t+w<=k: q+=t+w a-=1 w+=t else: res+=1 q=t+w a-=1 w+=t print(res+1) ``` Yes
96,102
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` n,k = map(int,input().split()) h = list(map(int,input().split())) count = [0 for i in range(200001)] for x in h:count[x]+=1 ans = 0 max_h = 200000 cost = 0 while True: while count[max_h] == 0:max_h -=1 if count[max_h] == n: if cost !=0: ans +=1 break if cost+count[max_h] > k: ans += 1 cost = 0 continue cost += count[max_h] count[max_h-1]+=count[max_h] count[max_h]=0 print(ans) ``` Yes
96,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` while True: try: def solution(k): buld = list(map(int, input().split())) Max = 0 Min = 10**12 stats = [0]*(3*(10)**5) for i in range(len(buld)): Max = max(Max, buld[i]) Min = min(Min, buld[i]) stats[buld[i]] += 1 for i in range(Max, Min-1, -1): stats[i] += stats[i+1] sum = 0 step = 0 for i in range(Max, Min, -1): if sum + stats[i] > k: sum = 0 step += 1 sum += stats[i] if sum: step += 1 print(step) if __name__ == "__main__": n, k = map(int, input().split()) solution(k) except EOFError: break ``` Yes
96,104
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() hs1 = [0 for _ in range(a[-1])] for i in range(n): hs1[a[i] - 1] += 1 pluser = 0 hs = [0 for _ in range(a[-1])] for i in range(a[-1]): pluser += hs1[a[-1] - i - 1] hs[a[-1] - i - 1] = pluser floor = a[-1] - 1 ans = 0 count = 0 while floor > a[0] - 1: while floor > a[0] - 1 and count + hs[floor] <= k: floor -= 1 count += hs[floor] ans += 1 count = 0 print(ans) ``` No
96,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` n,k = map(int,input().split()) a=[0]*1000000 b=[0]*1000000 pos=0 ans=0 res=0 for i in input().split(): a[int(i)+1]-=1 a[1]+=1 pos = max(pos,int(i)) for i in range(pos+1): a[i]+=a[i-1] if a[i] == n: ans = i # for i in range(pos+1,-1,-1): # b[i]=b[i-1]+a[i] for i in range(pos,ans-1,-1): b[i] = a[i] + b[i+1] if b[i] > k: res+=1 b[i] = a[i] print(i, a[i], b[i]) # print(*[a[i]for i in range(pos+1)]) print(res) ``` No
96,106
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math from math import gcd import io import os from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?############################################################ def isPrime(x): for i in range(2, x): if i*i > x: break if (x % i == 0): return False return True #?############################################################ def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p #?############################################################ def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: l.append(int(i)) n = n / i if n > 2: l.append(n) return list(set(l)) #?############################################################ def power(x, y, p): res = 1 x = x % p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): res = (res * x) % p y = y >> 1 x = (x * x) % p return res #?############################################################ def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #?############################################################ def digits(n): c = 0 while (n > 0): n //= 10 c += 1 return c #?############################################################ def ceil(n, x): if (n % x == 0): return n//x return n//x+1 #?############################################################ def mapin(): return map(int, input().split()) #?############################################################ input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # python3 15.py<in>op mm =200009 n, k = map(int, input().split()) l = [int(x) for x in input().split()] ll = [0]*(mm) for i in l: ll[i]+=1 ss = sum(l) temp = n for i in range(mm): temp-=ll[i] ll[i] = ss ss-=temp temp = 0 ans = 0 cap = 0 for kk in range(mm): i = mm-kk-1 ll[i]-=cap if(ll[i] == k): break elif(ll[i]> k): ans+=1 cap += ll[i+1] ll[i]-=ll[i+1] temp =0 print(ans) ``` No
96,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of h_i cubes, so it has height h_i. Let's define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower's height equal to H. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to k (k ≥ n). <image> Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. Input The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, n ≤ k ≤ 10^9) — the number of towers and the restriction on slices, respectively. The second line contains n space separated integers h_1, h_2, ..., h_n (1 ≤ h_i ≤ 2 ⋅ 10^5) — the initial heights of towers. Output Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth. Examples Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 Note In the first example it's optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the second one is on height 1 (its cost is 4). Submitted Solution: ``` n,k=[int(x) for x in input().split()] d={} ns=[int(x) for x in input().split()]+[0] for c in ns: if c in d: d[c]+=1 else: d[c]=1 def eat(i,need): al=(ns[i]-ns[i+1])*d[ns[i]] if al>need: thick=d[ns[i]] eath=need//thick d[ns[i] - eath]=d[ns[i]] ns[i]-=eath return i,0 if al==need: d[ns[i+1]]+=d[ns[i]] return i+1,0 if al<need: d[ns[i + 1]] += d[ns[i]] return i+1,need-al ns=list(d.keys()) ns.sort(reverse=True) ans=0 i=0 newn=k if len(ns)<=2: print(0) quit() while i<len(ns)-1: i,newn=eat(i,newn) if newn==0: ans+=1 newn=k if i==len(ns)-2: break print(ans) ``` No
96,108
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x = int(input()) if x == 1: print('-1') elif x == 2 or x == 3: print('2 2') elif x == 4: print('4 2') elif x%2 == 0: print(str(x-2)+' 2') else: print(str(x-1)+' 2') ```
96,109
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x = int(input()) a, b = None, None for i in range(1, x + 1): for j in range(1, x + 1): if(i % j == 0 and i*j > x and i//j < x): a = i b = j break if(a != None or b != None): break if(a == None or b == None): print(-1) else: print(a, b) ```
96,110
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x = int(input()) if x == 1:print(-1) elif x%2 == 0: a,b = x,2 print(a,b) else: a,b = x-1,2 print(a,b) ```
96,111
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x = int(input()) print(-1) if x == 1 else print(x - x % 2, 2) ```
96,112
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` t=1 while t>0: t-=1 n=int(input()) if n==1: print(-1) else: print(n,n) ```
96,113
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x = int(input()) if x > 1: num = str(x) +" "+ str(x) print (num) else: print (-1) ```
96,114
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x=int(input()) if(x!=1): print(x," ",x) else: print(-1) ```
96,115
Provide tags and a correct Python 3 solution for this coding contest problem. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Tags: brute force, constructive algorithms Correct Solution: ``` x = int(input()) if x == 1: print(-1) else: for b in range(1, x+1): for a in range(b, x+1): if a % b == 0 and a * b > x and a / b < x: print(a, b) break else: continue break ```
96,116
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` x = int(input()) if x == 1 : print(-1) elif x == 2 or x == 3: print(2,2) else: print(2*(x//2),x//2) ``` Yes
96,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` x=int(input()) flag=False h=0 g=0 for k in range(1,x+1): for j in range(1,x+1): if (k%j)==0 and (k//j)<x and (j*k)>x: h=j g=k flag=True break break if flag==True: print('{} {}'.format(g,h)) else: print("-1") ``` Yes
96,118
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` a=int(input()) if a==1: print(-1) else: if a%2==0: print(a,2) else: print(a-1,2) ``` Yes
96,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` x=int(input()) a,b=0,0 for i in range(x+1): for j in range(x+1): if(i*j>x and i%j==0 and i//j<x): a=i b=j break if(a!=0 and b!=0): break if(a!=0 and b!=0): print(a,b) else: print("-1") ``` Yes
96,120
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` x=int(input()) flag=False h=0 g=0 for k in range(1,x+1): for j in range(1,x+1): if j//k<x and j*k>x: h=j g=k flag=True break break if flag==True: print('{} {}'.format(h,g)) else: print("-1") ``` No
96,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` import math def search(x): if(x == 1): print(-1) else: if (math.floor(x/2)+1 % 2== 0): print(math.floor(x/2)+1, math.floor(x/2)+1) else: print(math.floor(x/2)+2, math.floor(x/2)+2) search(int(input())) ``` No
96,122
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` import sys import os.path from collections import * import math import bisect if (os.path.exists('input.txt')): sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") else: input = sys.stdin.readline ############## Code starts here ########################## n = int(input()) if n == 1 or n == 2 or n == 3: print(-1) else: x = (n // 2) * 2 y = (n // 2) print(x,y) ############## Code ends here ############################ ``` No
96,123
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes). Examples Input 10 Output 6 3 Input 1 Output -1 Submitted Solution: ``` x=int(input()) n=x//2 if n%2==0: a=(n+2) b=a//2 if a*b>x and (a%b==0) and a//b<x: print(a,b) else: a=(n+1) b=a//2 print(a,b) ``` No
96,124
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` for _ in range(int(input())): n = int(input()) s = input() x = int(s[0]) cnt = 0 for i in range(1,n-1): if int(s[i]) > 0: cnt += 1 if cnt or int(s[0]) < int(s[n-1]): print("YES") print(2) print(s[0],s[1:]) else: print("NO") ```
96,125
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` t=int(input()) for i in range (t): # print(i,"fun") n=int(input()) s=input() if n==2: s=int(s) if s%10>s//10: print("YES") print(2) print(s//10,s%10) else: print("NO") else: f_half=n//2 if n%2==0: f_half-=1 f_s=int(s[:f_half]) s_s=int(s[f_half:]) print("YES") print(2) print(f_s,s_s) ```
96,126
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Aug 16 16:23:36 2020 @author: MridulSachdeva """ CASES = int(input()) for i in range(CASES): n = int(input()) s = input() #print(s) if int(s[0]) >= int(s[1:]): print('NO') else: print('YES') print(2) print(s[0], s[1:]) ```
96,127
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` Input=lambda:map(int,input().split()) for i in range(int(input())): n = int(input()) number = input() if n == 2: if number[0] < number[1]: print("YES") print(2) print(number[0],number[1]) else: print("NO") else: print("YES") print(2) print(number[0],number[1:]) ''' openvpn vpnbook sEN6DC9 ''' ```
96,128
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` q = int(input()) for qq in range(q): n = int(input()) s = input() if n == 2 and s[0] >= s[1]: print('NO') else: print('YES') print('2') print(s[0] , s[1 : ]) ```
96,129
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` q = int(input()) for i in range(q): n = int(input()) x = list(input()) if n == 2 and x[0] >= x[1]: print('NO') else: print('YES') print(2) print(*x[0] + ' ', *x[1:], sep='') ```
96,130
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` t=int(input()) for i in range(t): n=int(input()) s=input() k1=int(s[0]) k2=int(s[1]) if n==2 and k1>=k2: print('NO') else: print('YES') print('2') print(s[0],s[1:],end=" ") print() ```
96,131
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Tags: greedy, strings Correct Solution: ``` n=int(input()) for i in range(n): d=int(input()) s=input() if len(s)==2: if int(s[0])>=int(s[1]): print('NO') else: print('YES') print(2) print(s[0],s[1]) else: print('YES') print(2) print(s[0],s[1:]) ```
96,132
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` from sys import stdin read = stdin.readline q = int(read()) for _q in range(q): n = int(read()) s = read()[:-1] if n<=2: if s[:1] < s[1:]: print('YES') print(2) print(s[0] + ' ' + s[1]) else: print('NO') continue print('YES') print(2) print(s[0] + ' ' + s[1:]) ``` Yes
96,133
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` n=int(input()) for i in range(0,n): p=int(input()) s=input().rstrip() x=list(s) if len(x)==1: print("NO") else: f=x[0:1] F=x[1:len(x)] c=int(''.join(f)) C=int(''.join(F)) if C>c: print("YES") print(2) print(c,C) else: print("NO") ``` Yes
96,134
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` q = int(input()) a = [] for i in range(q): n = int(input()) s = input() if n == 2 and s[0] >= s[1]: a.append('NO') else: a.append('YES') a.append(2) a.append(str(s[0]) + ' ' + str(s[1:])) for x in a: print(x) ``` Yes
96,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` def check(cur,present): n=len(cur) m=len(present) if(n>m): return True if(m>n): return False if(cur==present): return False for i in range(0,n): if((int)(cur[i])>(int)(present[i])): return True if((int)(cur[i])<(int)(present[i])): return False return False def solve(s,n): ans=[] present="" cur="" for ch in s: cur+=ch if(check(cur,present)): ans.append(cur) present=cur cur="" if(cur!="" and check(cur,present)==False): ans[len(ans)-1]=ans[len(ans)-1]+cur print("YES") print(len(ans)) for ch in ans: print(ch,end=" ") if __name__=="__main__": t=int(input()) while t>0: n=int(input()) s=str(input()) if(n==2): if(int(s[0])<int(s[1])): print("YES") print(2,s[0]+" "+s[1]) else : print("NO") else: solve(s,n) print() t=t-1 ``` Yes
96,136
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` n = int(input()) for i in range(n): q = int(input()) if q == 2: print("NO") else: s = input() print(s[0] + s[1:]) ``` No
96,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` for _ in range(int(input())): n=int(input()) s=input() if n==2: if int(s[1])>int(s[0]): print(2) print('YES') else: print('NO') else: print(2) print(s[:int(n/2)-1],s[int(n/2)-1:]) ``` No
96,138
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` q=int(input()) for i in range(q): n=int(input()) s=input() if(n==1): print("NO") continue if(int(s[:1])<int(s[1:])): print("YES") print(s[:1]," ",s[1:]) else: print("NO") ``` No
96,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence s consisting of n digits from 1 to 9. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is t_1, t_2, ..., t_k, where k is the number of element in a division, then for each i from 1 to k-1 the condition t_{i} < t_{i + 1} (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if s=654 then you can divide it into parts [6, 54] and it will be suitable division. But if you will divide it into parts [65, 4] then it will be bad division because 65 > 4. If s=123 then you can divide it into parts [1, 23], [1, 2, 3] but not into parts [12, 3]. Your task is to find any suitable division for each of the q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 300) — the number of queries. The first line of the i-th query contains one integer number n_i (2 ≤ n_i ≤ 300) — the number of digits in the i-th query. The second line of the i-th query contains one string s_i of length n_i consisting only of digits from 1 to 9. Output If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print k_i — the number of parts in your division of the i-th query sequence and in the third line print k_i strings t_{i, 1}, t_{i, 2}, ..., t_{i, k_i} — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string s_i. See examples for better understanding. Example Input 4 6 654321 4 1337 2 33 4 2122 Output YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22 Submitted Solution: ``` from sys import stdin,stdout from collections import Counter def ai(): return list(map(int, stdin.readline().split())) def ei(): return map(int, stdin.readline().split()) def ip(): return int(stdin.readline().strip()) def op(ans): return stdout.write(str(ans) + '\n') for i in range(ip()): n = ip() s = input() if len(set(s))==1 and n == 2: print('NO') else: print('YES') print(2) print(s[:-1],s[-1]) ``` No
96,140
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) h=[0]*n m=[0]*n for i in range(n): h[i],m[i] = map(int,input().split()) k = int(input()) for i in range(n): if k>=h[i] and k<=m[i]: g=i break print(n-g) ```
96,141
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) lr = [list(map(int, input().split())) for _ in range(n)] k = int(input()) ans = n for lri in lr: if lri[0] <= k <= lri[1]: print(ans) break else: ans -= 1 ```
96,142
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) v = [] for i in range(n): v.append(int(input().split()[1])) p = int(input()) for pos, i in enumerate(v): if i >= p: print(n-pos) break ```
96,143
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) a = [] for i in range(n): l, r = map(int, input().split()) a.append(l) a.append(r) k = int(input()) i = 0 while a[i] < k: i += 1 print(n - i // 2) ```
96,144
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) tail = [] for i in range(n): a, b = map(int, input().split()) tail.append(b) m = int(input()) for i in range(m): if m <= tail[i]: print(n - i) break ```
96,145
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n=int(input()) lfi=[] for i in range(n): l=input().split() lfi.append([int(i) for i in l]) k=int(input()) for i in range(n): if(k>=lfi[i][0] and k<=lfi[i][1]): ans=i break print(n-ans) ```
96,146
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) start = [] end = [] for i in range(n): a,b = map(int,input().split()) start.append(a) end.append(b) k = int(input()) for i in range(n): if k in range(start[i],end[i]+1): break print(n-i) ```
96,147
Provide tags and a correct Python 3 solution for this coding contest problem. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Tags: implementation Correct Solution: ``` n = int(input()) tmp = [] for i in range(n): tmp.append([int(x) for x in input().split(' ')]) k = int(input()) for i in range(n): if tmp[i][0] <= k <= tmp[i][1]: print(n - i) ```
96,148
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` n=int(input()) start=[]; end=[] for t in range(n): a,b=map(int, input().split()) start.append(a) end.append(b) k=int(input()) for i in range(n): if k<=end[i]: print(n-i) break ``` Yes
96,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` hop = [] for i in range(int(input())): a, b = map(int, input().split()) hop.append(b) k = int(input()) for i in range(len(hop)): if k <= hop[i]: print(len(hop) - i) break ``` Yes
96,150
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` n, res = int(input()), [] for i in range(n): res.append([int(i) for i in input().split()]) k = int(input()) for i in res: if i[0] <= k <= i[1]: print(n - res.index(i)) ``` Yes
96,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` mi = lambda: [int(i) for i in input().split()] n = int(input()) dat = [mi() for _ in range(n)] k = int(input()) readed = 0 for i in dat: l, r = i if l <= k and r >= k: print(n - readed) exit() readed += 1 print(n) ``` Yes
96,152
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` x = int(input()) y = [] a = 0 for i in range(x): y.append(list(map(int, input().split(" ")))) z = int(input())-1 for i in y: if i[0]<z<i[1]: a += 1 else: pass if len(y) == a: print(1) else: print(x-a) ``` No
96,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` A=[] k=int(input()) for i in range(k): C,D=input().split() A.append(int(D)) Z=int(input()) Z=Z-1 tmp=0 for j in range(k): if(Z<=A[j]): break else: tmp+=1 print(k-tmp) ``` No
96,154
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` n = int(input()) l = [] for i in range(n): s = input().split() l.append(s) k = input() for i in range(n): if l[i][0] <= k < l[i][1]: print(len(l) - i) break if k == l[i][1]: print(len(l) - i) ``` No
96,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). Input The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chapters in the book. There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages. The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page. Output Print a single integer — the number of chapters which has not been completely read so far. Examples Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 Note In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3. The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2. Submitted Solution: ``` a = int(input()) p = 0 k = [] for i in range(a): k.append([int(i) for i in input().split()]) b = int(input()) for i in range(a): if(k[i].count(b)!=0): p = i print(a-p) ``` No
96,156
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` inf = 10 ** 6 n, k = map(int, input().split()) a = [-inf] + list(map(int, input().split())) ans = [-1]*(n+10) leftnext = [-1]*(n+10) rightnext = [-1]*(n+10) for i in range(1, n + 1): rightnext[i] = i + 1 leftnext[i] = i - 1 visited = [False]*(n+10) stack = [(a[i], i) for i in range(1, n+1)] stack.sort() phase = 0 loop = 0 while stack: loop += 1 while stack and visited[stack[-1][1]] == True: stack.pop() if not stack: continue value, index = stack.pop() ans[index] = phase + 1 rightcnt, leftcnt = 0, 0 lend, rend = -1, -1 now = index while rightcnt <= k and now <= n: rightcnt += 1 now = rightnext[now] if rightcnt <= k: visited[now] = True ans[now] = phase + 1 rend = now now = index while leftcnt <= k and now >= 1: leftcnt += 1 now = leftnext[now] if leftcnt <= k: visited[now] = True ans[now] = phase + 1 lend = now leftnext[rend] = lend rightnext[lend] = rend phase += 1 phase %= 2 print("".join(map(str,ans[1:n+1]))) ```
96,157
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` n, k = map(int, input().split()) lst = map(int, input().split()) def debug(): print('-') lst = [0 for _ in range(n)] for i in range(n): node = table[i] lst[node.index] = node.team print (''.join(str(x) for x in lst)) print('-') class Node: def __init__(self, index): self.index = index self.team = 0 self.prev = None self.next = None table = [None for _ in range(n)] prev_node = None for index, element in enumerate(lst): node = Node(index) if prev_node: prev_node.next = node node.prev = prev_node table[element - 1] = node prev_node = node team = 1 for i in reversed(range(n)): # taken if table[i].team != 0: continue node = table[i] node.team = team next_node = node.next for j in range(k): if next_node is None: break next_node.team = team next_node = next_node.next prev_node = node.prev for j in range(k): if prev_node is None: break prev_node.team = team prev_node = prev_node.prev if prev_node is not None: prev_node.next = next_node if next_node is not None: next_node.prev = prev_node team = 1 if team == 2 else 2 lst = [0 for _ in range(n)] for i in range(n): node = table[i] lst[node.index] = node.team print (''.join(str(x) for x in lst)) ```
96,158
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` # AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] self.index += 1 return val def next_int(self): return int(self.next()) def solve(self): n = self.next_int() k = self.next_int() x = [self.next_int() for _ in range(0, n)] bf = [x - 1 for x in range(0, n)] nx = [x + 1 for x in range(0, n)] t = [0 for _ in range(0, n)] od = [0 for _ in range(0, n)] for i in range(0, n): od[x[i] - 1] = i tt = 1 for i in range(n - 1, -1, -1): if t[od[i]] == 0: o = od[i] t[o] = tt for _ in range(0, k): o = bf[o] if o == -1: break t[o] = tt oo = od[i] for _ in range(0, k): oo = nx[oo] if oo == n: break t[oo] = tt if o != -1 and bf[o] != -1: nx[bf[o]] = oo if oo == n else nx[oo] if oo != n and nx[oo] != n: bf[nx[oo]] = o if o == -1 else bf[o] tt = 3 - tt print(''.join(map(lambda xx: str(xx), t))) if __name__ == '__main__': Main().solve() ```
96,159
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` n,k=[int(x) for x in input().split()] a=[int(x) for x in input().split()] team=[0]*n nxt=[x+1 for x in range(len(a))] nxt[-1]=n+2*k prv=[x-1 for x in range(len(a))] prv[0]=-2*k loc=[0]*(len(a)+1) for i,v in enumerate(a): loc[v]=i left=n val=1 while left>0: start=loc[left] left = left - 1 if team[start]>0: continue team[start]=val nx=nxt[start] pv=prv[start] if pv>=0: nxt[pv]=nx if nx<n: prv[nx]=pv ctdown=k while nx<n and ctdown>0: team[nx]=val if prv[nx]>=0: nxt[prv[nx]] = nxt[nx] if nxt[nx]<n: prv[nxt[nx]] = prv[nx] nx = nxt[nx] ctdown = ctdown - 1 ctdown=k while pv>=0 and ctdown>0: team[pv]=val if prv[pv]>=0: nxt[prv[pv]] = nxt[pv] if nxt[pv]<n: prv[nxt[pv]] = prv[pv] pv = prv[pv] ctdown = ctdown - 1 val = 3 - val print("".join(str(x) for x in team)) ```
96,160
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` def solve(n, k, a): pre, nex, d = {}, {}, {} for i in range(n): pre[i] = i - 1 nex[i] = i + 1 d[a[i]] = i a.sort(reverse=True) res = [0] * n turn = 1 for x in a: index = d[x] if res[index]: continue res[index] = turn left, right = pre[index], nex[index] for i in range(k): if left < 0: break res[left] = turn left = pre[left] for i in range(k): if right >= n: break res[right] = turn right = nex[right] nex[left] = right pre[right] = left turn = 3 - turn return ''.join(map(str, res)) n,k = map(int, input().split()) a = list(map(int, input().split())) print(solve(n, k, a)) ```
96,161
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` class Node: def __init__(self, v, i): self.v = v self.i = i self.left = None self.right = None n, k = map(int, input().split()) nums = list(map(int, input().split())) nodes = [Node(v, i) for i, v in enumerate(nums)] sort = [[v, i] for i, v in enumerate(nums)] sort = sorted(sort, key = lambda x: [x[0], x[1]],reverse=True) for i in range(len(nodes)): if i < len(nodes) - 1: nodes[i].right = nodes[i + 1] if i > 0: nodes[i].left = nodes[i - 1] ans = [0] * n team = 1 for pair in sort: v, i = pair # if nodes[i].left == None and nodes[i].right == None: # continue if nodes[i].i == None: continue # print(v, i) ans[i] = team if team == 1 else 2 cur = nodes[i].right right = None for j in range(k): if cur == None: break right = cur.right ans[cur.i] = team if team == 1 else 2 cur.i = None cur = right cur = nodes[i].left # print(cur.i, cur.v) left = None for j in range(k): if cur == None: break left = cur.left ans[cur.i] = team if team == 1 else 2 cur.i = None cur = left # if left == None and right == None: # break if left: left.right = right if right: right.left = left team = team ^ 1 print(''.join([str(i) for i in ans])) ```
96,162
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` import sys input = sys.stdin.readline n,k=map(int,input().split()) A=list(map(int,input().split())) A_INV=[-1]*n for i in range(n): A_INV[A[i]-1]=i L=list(range(-1,n-1)) R=list(range(1,n+1)) USELIST=[0]*n ANS=[0]*n NOW=1 for a in A_INV[::-1]: if USELIST[a]==1: continue USELIST[a]=1 ANS[a]=NOW if 0<=a<n and 0<=L[a]<n: R[L[a]]=R[a] if 0<=a<n and 0<=R[a]<n: L[R[a]]=L[a] r=a for step in range(k): r=R[r] if r<0 or r>=n: break ANS[r]=NOW USELIST[r]=1 if 0<=r<n and 0<=L[r]<n: R[L[r]]=R[r] if 0<=r<n and 0<=R[r]<n: L[R[r]]=L[r] l=a for step in range(k): l=L[l] if l<0 or l>=n: break ANS[l]=NOW USELIST[l]=1 if 0<=l<n and 0<=L[l]<n: R[L[l]]=R[l] if 0<=l<n and 0<=R[l]<n: L[R[l]]=L[l] NOW=3-NOW #print(*ANS,USELIST,L,R) print("".join(map(str,ANS))) ```
96,163
Provide tags and a correct Python 3 solution for this coding contest problem. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Tags: data structures, implementation, sortings Correct Solution: ``` import sys input = sys.stdin.readline n, k = map(int, input().split()) left = [i-1 for i in range(n)] right = [i+1 for i in range(n)] ans = [0] * n def next(i): upd = [i] i = right[i] while i < n and ans[i] != 0: upd.append(i) i = right[i] for x in upd: right[x] = i return i def prev(i): upd = [i] i = left[i] while i >= 0 and ans[i] != 0: upd.append(i) i = left[i] for x in upd: left[x] = i return i a = list(map(int, input().split())) pos = [0] * (n+1) for i in range(n): pos[a[i]] = i team = 1 for x in range(n, 0, -1): i = pos[x] if ans[i] != 0: continue; ans[i] = team j = i for _ in range(k): j = next(j) if j >= n: break ans[j] = team j = i for _ in range(k): j = prev(j) if j < 0: break ans[j] = team team = 3 - team print(''.join(map(str, ans))) ```
96,164
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` #! /usr/bin/env python3 # -*- coding: UTF-8 -*- class BitTree: def __init__(self, size): self.size = size self.arr = [0 for _ in range(size + 1)] def add(self, idx, val): i = idx while i <= self.size: self.arr[i] += val i += i & (-i) def sum(self, idx): ret = 0 i = idx while i > 0: ret += self.arr[i] i -= i & (-i) return ret def find_left(self, idx, k): x = self.sum(idx) l, r = 1, idx while l <= r: m = (l + r) // 2 tmp = self.sum(idx) - self.sum(m - 1) if tmp > k: l = m + 1 else: r = m - 1 return l def find_right(self, idx, k): x = self.sum(idx) l, r = idx, self.size while l <= r: m = (l + r) // 2 tmp = self.sum(m - 1) - self.sum(idx) if tmp < k: r = m - 1 else: l = m + 1 return r def find_left(lst, ans, idx, k, tag): idx = lst[idx][0] while k > 0 and idx >= 1: ans[idx] = tag k -= 1 idx = lst[idx][0] return max(idx, 0) def find_right(lst, ans, idx, k, tag, n): idx = lst[idx][1] while k > 0 and idx <= n: ans[idx] = tag k -= 1 idx = lst[idx][1] return min(idx, n+1) def main(): line = input() n, k = int(line.split(' ')[0]), int(line.split(' ')[1]) line = input() ans = ['0' for _ in range(n + 2)] arr = [] lst = [] for i in range(n + 2): lst.append([max(i - 1, 0), min(i + 1, n + 1)]) for i, val in enumerate(line.split(' ')): arr.append((i + 1, int(val))) arr.sort(key=lambda x: x[1], reverse=True) tag = 1 for item in arr: idx = item[0] if ans[idx] != '0': continue ans[idx] = str(tag) left = find_left(lst, ans, idx, k, str(tag)) right = find_right(lst, ans, idx, k, str(tag), n) lst[left][1] = right lst[right][0] = left tag = 3 - tag print(''.join(ans[1:-1])) # print(''.join(ans)) if __name__ == '__main__': main() ``` Yes
96,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` #pajenegod def delete(i,grp): l = left[i] r = right[i] if l != -1: right[l] = r if r != n: left[r] = l used[i] = grp n,k = map(int,input().split()) arr = list(map(int,input().split())) left = [-1]*n right = [n]*n used = [-1]*n for i in range(n): left[i] = i-1 right[i] = i+1 order = sorted(range(n) , key = lambda i : arr[i] , reverse = True) grp = 1 for i in order: if used[i] != -1: continue l = left[i] r = right[i] delete(i,grp) cnt = 0 while l != -1 and cnt < k: cnt += 1 temp = left[l] delete(l,grp) l = temp cnt = 0 while r != n and cnt < k: cnt += 1 temp = right[r] delete(r,grp) r = temp if grp == 1: grp = 2 else: grp = 1 print(*used,sep='') ``` Yes
96,166
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` def input_ints(): return [int(x) for x in input().split()] class Node: def __init__(self, val): self.prev = None self.next = None self.val = val self.team = None _, k = input_ints() nodes = [Node(x) for x in input_ints()] order = [i for i, x in sorted(enumerate(nodes), key=lambda x: x[1].val, reverse=True)] for a, b in zip(nodes, nodes[1:]): a.next = b b.prev = a team = 1 for i in order: node = nodes[i] if node.team: continue left = node for _ in range(k+1): if left: left.team = team left = left.prev else: break right = node for _ in range(k+1): if right: right.team = team right = right.next else: break if left: left.next = right if right: right.prev = left team = (team == 1) + 1 print(''.join(str(x.team) for x in nodes)) ``` Yes
96,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` '''input 5 1 2 4 5 3 1 ''' from sys import stdin import math from copy import deepcopy import collections # heap dict source code def doc(s): if hasattr(s, '__call__'): s = s.__doc__ def f(g): g.__doc__ = s return g return f class heapdict(collections.MutableMapping): __marker = object() @staticmethod def _parent(i): return ((i - 1) >> 1) @staticmethod def _left(i): return ((i << 1) + 1) @staticmethod def _right(i): return ((i+1) << 1) def __init__(self, *args, **kw): self.heap = [] self.d = {} self.update(*args, **kw) @doc(dict.clear) def clear(self): self.heap.clear() self.d.clear() @doc(dict.__setitem__) def __setitem__(self, key, value): if key in self.d: self.pop(key) wrapper = [value, key, len(self)] self.d[key] = wrapper self.heap.append(wrapper) self._decrease_key(len(self.heap)-1) def _min_heapify(self, i): l = self._left(i) r = self._right(i) n = len(self.heap) if l < n and self.heap[l][0] < self.heap[i][0]: low = l else: low = i if r < n and self.heap[r][0] < self.heap[low][0]: low = r if low != i: self._swap(i, low) self._min_heapify(low) def _decrease_key(self, i): while i: parent = self._parent(i) if self.heap[parent][0] < self.heap[i][0]: break self._swap(i, parent) i = parent def _swap(self, i, j): self.heap[i], self.heap[j] = self.heap[j], self.heap[i] self.heap[i][2] = i self.heap[j][2] = j @doc(dict.__delitem__) def __delitem__(self, key): wrapper = self.d[key] while wrapper[2]: parentpos = self._parent(wrapper[2]) parent = self.heap[parentpos] self._swap(wrapper[2], parent[2]) self.popitem() @doc(dict.__getitem__) def __getitem__(self, key): return self.d[key][0] @doc(dict.__iter__) def __iter__(self): return iter(self.d) def popitem(self): """D.popitem() -> (k, v), remove and return the (key, value) pair with lowest\nvalue; but raise KeyError if D is empty.""" wrapper = self.heap[0] if len(self.heap) == 1: self.heap.pop() else: self.heap[0] = self.heap.pop(-1) self.heap[0][2] = 0 self._min_heapify(0) del self.d[wrapper[1]] return wrapper[1], wrapper[0] @doc(dict.__len__) def __len__(self): return len(self.d) def peekitem(self): """D.peekitem() -> (k, v), return the (key, value) pair with lowest value;\n but raise KeyError if D is empty.""" return (self.heap[0][1], self.heap[0][0]) del doc __all__ = ['heapdict'] def heap_delete(mypq, index): if index in mypq: mypq[index] = -float('inf') mypq.popitem() def get_left_right(arr, n): aux = [] for i in range(n): aux.append([arr[i], i - 1, i + 1]) return aux def add_left(arr, mypq, myset, index, k): left = index count = 0 while left != -1 and count < k: left = arr[left][1] if left == -1: break myset.add(arr[left][0]) heap_delete(mypq, left) count += 1 if left == -1: arr[index][1] = -1 else: arr[index][1] = arr[left][1] arr[left][2] = index def add_right(arr, mypq, myset, index, k): right = index count = 0 while right != len(arr) and count < k: right = arr[right][2] if right == len(arr): break myset.add(arr[right][0]) heap_delete(mypq, right) count += 1 if right == len(arr): arr[index][2] = len(arr) else: arr[index][2] = arr[right][2] arr[right][1] = index # main starts n, k = list(map(int, stdin.readline().split())) arr = list(map(int, stdin.readline().split())) arr = get_left_right(arr, n) # making heap dict mypq = heapdict() for i in range(n): mypq[i] = -arr[i][0] # assigning team first = set() second = set() chance = 0 while len(mypq) > 0: if chance == 0: # process first index, value = mypq.popitem() value = abs(value) first.add(value) heap_delete(mypq, index) add_left(arr, mypq, first, index, k) add_right(arr, mypq, first, index, k) if arr[index][1] != -1: arr[arr[index][1]][2] = arr[index][2] if arr[index][2] != n: arr[arr[index][2]][1] = arr[index][1] chance = 1 else: # process second index, value = mypq.popitem() value = abs(value) second.add(value) heap_delete(mypq, index) add_left(arr, mypq, second, index, k) add_right(arr, mypq, second, index, k) if arr[index][1] != -1: arr[arr[index][1]][2] = arr[index][2] if arr[index][2] != n: arr[arr[index][2]][1] = arr[index][1] chance = 0 for i in arr: element = i[0] if element in first: print(1, end = '') else: print(2, end = '') ``` Yes
96,168
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` n, k = list(map(int, input().split())) a = list(map(int, input().split())) class Student: know: int team: int lock: bool num: int def __init__(self, know, team, num): self.know = know self.team = team self.lock = False self.num = num def set_team(self, team): if not self.lock: self.team = team self.lock = True def get_team(self): return str(self.team) c = [] for i in range(len(a)): c.append(Student(i, 0, i)) student_count = len(a) selected_people = [] students_sel = 0 team = 1 if k == 1: while a: ind = a.index(max(a)) c[ind].set_team(team) selected_people.append(c[ind]) c.pop(ind) a.pop(ind) #print(a) if team == 1: team = 2 else: team = 1 else: while a: ind = a.index(max(a)) #print(a, ind) arr_len = len(a) s, t = ind - k, ind + k + 1 if t > arr_len: t = arr_len if s < 0: s = 0 rg = list(range(s, t)) rg.reverse() #print(list(rg)) for i in rg: c[i].set_team(team) selected_people.append(c[i]) c.pop(i) a.pop(i) print(rg) if team == 1: team = 2 else: team = 1 ans = "" selected_people.sort(key=lambda x: x.num) for i in selected_people: ans += i.get_team() # print(selected_people) print(ans) ``` No
96,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [0] * n s = sorted(enumerate(a), key=lambda x: x[1], reverse=True) # print(s) p = 1 first = 0 last = n - 1 spaces = [] sn = 150 # print(s) for i in s: j = i[0] if b[j] > 0: continue # print(i[1]) jk = k + 1 g = 0 while j >= first and jk > 0: if b[j] == 0: b[j] = p jk -= 1 else: g += 1 if g > sn: for sp in spaces[::-1]: if sp[0] < j < sp[1]: j = sp[0] break # print(j, end=" ") j -= 1 if jk > 0: first = i[0] + k jf = j j = i[0] jk = k g = 0 while j <= last and jk > 0: if b[j] == 0: b[j] = p jk -= 1 else: g += 1 if g > sn: for sp in spaces[::-1]: if sp[0] < j < sp[1]: j = sp[1] break # print(j, end=" ") j += 1 if jk > 0: last = i[0] - k jl = j if jl - jf > sn * 3: spaces.append((jf + 1, jl - 1)) # print(i) # print(*b, sep="") # print(spaces) # print() p = 1 if p == 2 else 2 # print(*b) print(*b, sep="") # print(spaces) # print(len(spaces)) print(len(spaces)) ``` No
96,170
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` n, k = [int(i) for i in input().split()] l = [int(i) for i in input().split()] pos = sorted([(l[i], i) for i in range(n)], reverse = True) t = 1 for x in pos: p = x[1] if l[p] < 0: continue while p >= 0 and l[p] > 0 and x[1] - p <= k: l[p] = -t p -= 1 p = x[1] + 1 while p < n and l[p] > 0 and p - x[1] <= k: l[p] = -t p += 1 t += 1 if t == 1 else -1 print(''.join(str(-i) for i in l)) ``` No
96,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct. Output Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise. Examples Input 5 2 2 4 5 3 1 Output 11111 Input 5 1 2 1 3 5 4 Output 22111 Input 7 1 7 2 1 3 5 4 6 Output 1121122 Input 5 1 2 4 5 3 1 Output 21112 Note In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team). In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team). Submitted Solution: ``` n, k = map(int, input().split()) numbers = list(map(int, input().split())) myValues = {} teams = [0 for i in range(len(numbers))] import sys sys.setrecursionlimit(3500) class Value: def __init__(self, skill, index, previousVal = None, nextVal = None): self.skill = skill self.index = index self.previousVal = previousVal self.nextVal = nextVal def __gt__(self, other): return self.skill > other.skill def __repr__(self): return str(self) def __str__(self): return "(skill: "+str(self.skill)+",index: "+str(self.index)+")" def addPrevious(value, team, k): myValues.pop(value.index) teams[value.index] = team if value.nextVal: value.nextVal.previousVal = value.previousVal if value.previousVal: value.previousVal.nextVal = value.nextVal if k>0 and value.previousVal: addPrevious(value.previousVal, team, k-1) def addNext(value, team, k): myValues.pop(value.index) teams[value.index] = team if value.nextVal: value.nextVal.previousVal = value.previousVal if value.previousVal: value.previousVal.nextVal = value.nextVal if k>0 and value.nextVal: addNext(value.nextVal, team, k-1) def addToTeam(value, team, k): myValues.pop(value.index) teams[value.index] = team if value.nextVal: value.nextVal.previousVal = value.previousVal if value.previousVal: value.previousVal.nextVal = value.nextVal if k>0: if value.nextVal: addNext(value.nextVal, team, k-1) if value.previousVal: addPrevious(value.previousVal, team, k-1) def getValue(someObject): return someObject[1].skill try: currValue = Value(numbers[0], 0) myValues[0] = currValue for i in range(1,len(numbers)): newValue = Value(numbers[i], i, currValue) myValues[i] = newValue currValue = newValue while True: if currValue.previousVal: currValue.previousVal.nextVal = currValue currValue = currValue.previousVal else: break currTeam = 1 sortedList = sorted(myValues.items(), key = getValue, reverse = True) for i in sortedList: if i[0] in myValues: currTeam = (currTeam+1)%2 addToTeam(i[1], currTeam+1, k) teamString = "" for i in teams: teamString += str(i) print(teamString) except Exception as e: print(str(e)) ``` No
96,172
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` N=int(input()) l=list(map(int,input().split())) d=dict() d[4]=0 d[8]=0 d[15]=0 d[16]=0 d[23]=0 d[42]=0 l1=[4,8,15,16,23,42] for i in range(N): if l[i]==4: d[4]+=1 else: if l[i]==8: if d[4]>d[8]: d[8]+=1 elif l[i]==15: if d[8]>d[15]: d[15]+=1 elif l[i]==16: if d[15]>d[16]: d[16]+=1 elif l[i]==23: if d[16]>d[23]: d[23]+=1 elif l[i]==42: if d[23]>d[42]: d[42]+=1 print(N-d[42]*6) ```
96,173
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` import sys input = sys.stdin.readline def main(): n = int(input()) a = list(map(int, input().split())) x = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5} val = [4, 8, 15, 16, 23, 42] ptr = [-1, -1, -1, -1, -1, -1] done = False sets = 0 while not done: for p in range(6): if p == 0: while ptr[p] < n and (ptr[p] == -1 or a[ptr[p]] != val[p]): ptr[p] += 1 else: while ptr[p] < n and (ptr[p] == -1 or a[ptr[p]] != val[p] or ptr[p] <= ptr[p-1]): ptr[p] += 1 if all(ptr[i] < n for i in range(6)): sets += 1 for i in range(6): ptr[i] += 1 else: done = True print(n-6*sets) if __name__ == '__main__': main() ```
96,174
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` '''input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 ''' from sys import stdin,stdout read = lambda : map(int,stdin.readline().split()) I = lambda: stdin.readline() alias = {'4':0,'8':1,'15':2,'16':3,'23':4,'42':5} n = int(I()) counts = [0 for i in range(6)] for i in map(lambda x:alias[x],stdin.readline().split()): if i==0: counts[0]+=1 elif i>0 and counts[i]<counts[i-1]: counts[i]+=1 # print(arr,counts) print(n-counts[-1]*6) ```
96,175
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) ansl=[4,8,15,16,23,42] c4=0 c8=0 c15=0 c16=0 c23=0 c42=0 j=0 ans=0 for i in range(n): if l[i]==4: c4+=1 elif l[i]==8: if c8<c4: c8+=1 elif l[i]==15: if c15<c8: c15+=1 elif l[i]==16: if c16<c15: c16+=1 elif l[i]==23: if c23<c16: c23+=1 elif l[i]==42: if c42<c23: c42+=1 ans=n-c42*6 print(ans) ```
96,176
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` # cf 1176 C 1300 n = int(input()) A = [*map(int, input().split())] R = { 8: 4, 15: 8, 16: 15, 23: 16, 42: 23 } # set([4, 8, 15, 16, 23, 42]) P = { 4: [], 8: [], 15: [], 16: [], 23: [], 42: [] } ans = 0 for i, a in enumerate(A): if a == 4: P[4].append(a) elif a in R and R[a] in P: prev = R[a] if len(P[prev]) > 0: P[prev].pop() P[a].append(a) else: ans += 1 else: ans += 1 for i, n in enumerate([4, 8, 15, 16, 23]): if len(P[n]) > 0: ans += (len(P[n]) * (i + 1)) print(ans) ```
96,177
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` def get(n, a): state = [0] * 6 for ai in a: if ai == 0: state[0] += 1 continue if state[ai - 1] > 0: state[ai - 1] -= 1 state[ai] += 1 return n - 6 * state[5] s2i = {'4': 0, '8': 1, '15': 2, '16': 3, '23': 4, '42': 5} n = int(input()) a = [s2i[s] for s in input().split()] print(get(n, a)) ```
96,178
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` n=int(input()) arr=[x for x in input().split(' ')] myMap={ "4":0, "8":0, "15":0, "16":0, "23":0, "42":0 } bad=0 def doit(a,b): a,b=str(a),str(b) if myMap[a]>myMap[b]: myMap[b]+=1 else: global bad bad+=1 for item in arr: if item=="4": myMap[item]+=1 elif item=="8": doit(4,8) elif item=="15": doit(8,15) elif item=="16": doit(15,16) elif item=="23": doit(16,23) else: doit(23,42) temp=min(myMap.values()) bad = bad + (sum(myMap.values())-temp*6) print(bad) ```
96,179
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Tags: dp, greedy, implementation Correct Solution: ``` q= int (input()) a=0 b=0 c=0 d=0 e=0 f=0 for j in map(int,input().split()): if j==4 : a+=1 elif j==8 and b<a : b+=1 elif j==15 and c<b : c+=1 elif j==16 and d<c : d+=1 elif j==23 and e<d : e+=1 elif j==42 and f<e : f+=1 print(q-f*6) ```
96,180
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` n = int(input()) kol = [0, 0, 0, 0, 0, 0] ind = [4, 8, 15, 16, 23, 42] delete = 0 for i in map(int,input().split()): for j in range(6): if ind[j] == i: cur = j break if cur == 0: kol[0] += 1 else: if kol[cur-1] != 0: kol[cur-1] -= 1 kol[cur] += 1 else: delete += 1 print(delete + kol[0] + kol[1]*2 + kol[2]*3 + kol[3]*4 + kol[4]*5) ``` Yes
96,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` from bisect import bisect_left N = int(input()) ls = list(map(int, input().split())) d4 = [] d8 = [] d15 = [] d16 = [] d23 = [] d42 = [] for i in range(len(ls)): if ls[i]==4: d4.append(i) elif ls[i]==8: d8.append(i) elif ls[i]==15: d15.append(i) elif ls[i]==16: d16.append(i) elif ls[i]==23: d23.append(i) else: d42.append(i) cnt = 0 j = 0; k = 0; l = 0; m = 0; n = 0 for i in d4: pos = bisect_left(d8, i, lo=j) if pos==len(d8): break i = d8[pos] j = pos+1 pos = bisect_left(d15, i, lo=k) if pos==len(d15): break i = d15[pos] k = pos+1 pos = bisect_left(d16, i, lo=l) if pos==len(d16): break i = d16[pos] l = pos+1 pos = bisect_left(d23, i, lo=m) if pos==len(d23): break i = d23[pos] m = pos+1 pos = bisect_left(d42, i, lo=n) if pos==len(d42): break n = pos+1 cnt+=1 print(N-6*cnt) ``` Yes
96,182
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` n=int(input()) s=input() s1=s.split() l=[int(i) for i in s1] d={4:1,8:2,15:3,16:4,23:5,42:6} dp=[1e8,0,0,0,0,0,0] for i in range(len(l)): if l[i] in d and dp[d[l[i]]]<dp[d[l[i]]-1]: dp[d[l[i]]]=dp[d[l[i]]]+1 print(len(l)-dp[6]*6) ``` Yes
96,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` n = int(input()) s= list(map(int,input().split())) count = [0]*6 for temp in s: if temp==4: count[0]+=1 elif temp==8 and count[0]>count[1]: count[1]+=1 elif temp==15 and count[1]>count[2]: count[2]+=1 elif temp==16 and count[2]>count[3]: count[3]+=1 elif temp==23 and count[3]>count[4]: count[4]+=1 elif temp==42 and count[4]>count[5]: count[5]+=1 else: pass #print(count) out = n - 6*min(count) print(out) ``` Yes
96,184
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` from sys import stdin from bisect import bisect_right inp = lambda : stdin.readline().strip() n = int(inp()) a =[int(x) for x in inp().split()] v = {8:4,15:8,16:15,23:16,42:23} d = {4:0,8:0,15:0,16:0,23:0,42:0} for i in a: if i == 4 or d[v[i]] > 0: d[i] += 1 minimum = 10**9 for i in d.values(): minimum = min(i,minimum) print(len(a)-minimum*6) ``` No
96,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` # Aaditya Upadhyay # .............. # ╭━┳━╭━╭━╮╮ # ┃┈┈┈┣▅╋▅┫┃ # ┃┈┃┈╰━╰━━━━━━╮ # ╰┳╯┈┈┈┈┈┈┈┈┈◢▉◣ # ╲┃┈┈┈┈┈┈┈┈┈┈▉▉▉ # ╲┃┈┈┈┈┈┈┈┈┈┈◥▉◤ # ╲┃┈┈┈┈╭━┳━━━━╯ # ╲┣━━━━━━┫ # ………. # .……. /´¯/)………….(\¯`\ # …………/….//……….. …\….\ # ………/….//……………....\….\ # …./´¯/…./´¯\……/¯ `\…..\¯`\ # ././…/…/…./|_…|.\….\….\…\.\ # (.(….(….(…./.)..)...(.\.).).) # .\…………….\/../…....\….\/…………/ # ..\…………….. /……...\………………../ # …..\…………… (………....)……………./ from sys import stdin,stdout from collections import * from math import gcd,floor,ceil st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 INF=float('inf') def solve(): n=inp() count=0 l=li() d={4:0 , 8:0 , 15:0 , 16:0, 23:0 , 42:0} for i in range(n-1,-1,-1): d[l[i]]+=1 if l[i]==4: f=0 for j in [8,15,16,23,42]: if d[j]<=0: f=1 break if f==0: count+=1 for j in [8,15,16,23,42,4]: d[j]-=1 print(n - count*6) for _ in range(1): solve() ``` No
96,186
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` seq = (4,8,15,16,23,42) n = int(input()) a = list(map(int,input().split())) ans = 0 while True: temp = 0 for i in seq: try: awal = temp temp = a[awal:].index(i) a.pop(awal+temp) except: break else: ans += 6 continue break print(n-ans) ``` No
96,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42. Your task is to remove the minimum number of elements to make this array good. An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15, 16, 23, 42. Examples of good arrays: * [4, 8, 15, 16, 23, 42] (the whole array is a required sequence); * [4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); * [] (the empty array is good). Examples of bad arrays: * [4, 8, 15, 16, 42, 23] (the order of elements should be exactly 4, 8, 15, 16, 23, 42); * [4, 8, 15, 16, 23, 42, 4] (the length of the array is not divisible by 6); * [4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of elements in a. The second line of the input contains n integers a_1, a_2, ..., a_n (each a_i is one of the following numbers: 4, 8, 15, 16, 23, 42), where a_i is the i-th element of a. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 5 4 8 15 16 23 Output 5 Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Output 0 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42 Output 3 Submitted Solution: ``` ###################################################################### # Write your code here #import sys #import resource #resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY]) #sys.setrecursionlimit(0x100000) # Write your code here RI = lambda : [int(x) for x in input().strip().split()] rw = lambda : input().strip().split() from collections import defaultdict as df #import heapq #heapq.heapify(li) heappush(li,4) heappop(li) #import random #random.shuffle(list) #infinite = float('inf') #######################################################################) t=int(input()) l=RI() d=df(int) ans=0 for i in l: if(i not in [4,8,15,16,23,42]): ans+=1 else: d[i]+=1 mini=d[4] for j in [4,8,15,16,23,42]: mini=min(mini,d[j]) for j in [4,8,15,16,23,42]: ans+=(d[j]-mini) print(ans) ``` No
96,188
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` import math n,k=map(int,input().split()) print((3+2*n-int(math.sqrt(9+8*n+8*k)))//2) ```
96,189
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` n,k=map(int,input().split()) for r in range(1,10**5): if (r*(r+1))//2+r==k+n: print(n-r) exit() ```
96,190
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` import sys n, k = input().split() n = int(n) k = int(k) candisInBox = 0 multi = 0 movement = 0 theDiffrance = 0 reminingCandies = 0 while movement <= n: multi = multi + 1 movement = movement + 1 candisInBox = candisInBox + multi theDiffrance = n - movement reminingCandies = candisInBox - k if candisInBox >= k: if theDiffrance == reminingCandies: print(theDiffrance) sys.exit() ```
96,191
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` def main(): import sys input = sys.stdin.readline n, k = map(int, input().split()) l = 1 r = n + 1 while r - l != 1: m = l + r >> 1 candies = m * (m + 1) // 2 eat = n - m if candies - eat <= k: l = m else: r = m print(n - l) return 0 main() ```
96,192
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` n, k = [int(i) for i in input().split()] print((3 + 2 * n - int((8 * n + 8 * k + 9) ** 0.5)) // 2) ```
96,193
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` n, k = [int(item) for item in input().split()] candy = 0 add = 0 for i in range(0, 10**5): candy += add add += 1 if candy - k == n - i: print(n-i) exit() ```
96,194
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` n, k = map(int,input().split()) cnt = 0 c = 0 i = 0 while i != n: c = c + 1 cnt = c + cnt if(cnt - (n-c)) == k: break i = i + 1 print(n-c) ```
96,195
Provide tags and a correct Python 3 solution for this coding contest problem. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Tags: binary search, brute force, math Correct Solution: ``` import math n, k = map(int, input().split()) p = int((-3+int(math.sqrt(9+8*(n+k))))/2) print(int(p*(p+1)/2)-k) ```
96,196
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Submitted Solution: ``` n,k = list(map(int,input().split())) l = (-3+(9+(4*(2*(n+k))))**(.5))//2 print(int(n-l)) ``` Yes
96,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Submitted Solution: ``` n,k=input().split() n=int(n) k=int(k) i=1 flag=0 while (flag==0): put=(i*(i+1))/2 put=put-(n-i); if (put==k): print(n-i); flag=1; i+=1 ``` Yes
96,198
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: * the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 1; * the second option is to put candies in the box. In this case, Alya will put 1 more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option. For example, one possible sequence of Alya's actions look as follows: * put one candy into the box; * put two candies into the box; * eat one candy from the box; * eat one candy from the box; * put three candies into the box; * eat one candy from the box; * put four candies into the box; * eat one candy from the box; * put five candies into the box; This way she will perform 9 actions, the number of candies at the end will be 11, while Alya will eat 4 candies in total. You know the total number of actions n and the number of candies at the end k. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given n and k the answer always exists. Please note, that during an action of the first option, Alya takes out and eats exactly one candy. Input The first line contains two integers n and k (1 ≤ n ≤ 10^9; 0 ≤ k ≤ 10^9) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given n and k the answer exists. Output Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. Examples Input 1 1 Output 0 Input 9 11 Output 4 Input 5 0 Output 3 Input 3 2 Output 1 Note In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 0 candies. In the second example the possible sequence of Alya's actions looks as follows: * put 1 candy, * put 2 candies, * eat a candy, * eat a candy, * put 3 candies, * eat a candy, * put 4 candies, * eat a candy, * put 5 candies. This way, she will make exactly n=9 actions and in the end the box will contain 1+2-1-1+3-1+4-1+5=11 candies. The answer is 4, since she ate 4 candies in total. Submitted Solution: ``` from math import sqrt n,k = map(int,input().split()) a = n**2+n-2*k b = 2*n+3 d = sqrt(b**2-4*a) ans = (b-d)//2 print(int(ans)) ``` Yes
96,199