text
stringlengths
198
433k
conversation_id
int64
0
109k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook. Input The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 100) — the number of participants, the number of pens, and the number of notebooks respectively. Output Print "Yes" if it possible to reward all the participants. Otherwise, print "No". You can print each letter in any case (upper or lower). Examples Input 5 8 6 Output Yes Input 3 9 3 Output Yes Input 8 5 20 Output No Note In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks. In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks. In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No". Submitted Solution: ``` string = input() li = string.split(" ") n = int(li[0]) m = int(li[1]) k = int(li[2]) #print(n,m,k) if (k>=n) and (m>=n): print("Yes") else: print("No") ``` Yes
106,200
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook. Input The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 100) — the number of participants, the number of pens, and the number of notebooks respectively. Output Print "Yes" if it possible to reward all the participants. Otherwise, print "No". You can print each letter in any case (upper or lower). Examples Input 5 8 6 Output Yes Input 3 9 3 Output Yes Input 8 5 20 Output No Note In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks. In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks. In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No". Submitted Solution: ``` n,p,m=map(int,input().split()) if p>=n and m>=p: print('Yes') else: print('No') ``` No
106,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook. Input The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 100) — the number of participants, the number of pens, and the number of notebooks respectively. Output Print "Yes" if it possible to reward all the participants. Otherwise, print "No". You can print each letter in any case (upper or lower). Examples Input 5 8 6 Output Yes Input 3 9 3 Output Yes Input 8 5 20 Output No Note In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks. In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks. In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No". Submitted Solution: ``` string = input() li = string.split(" ") n = li[0] m = li[1] k = li[2] if (k>=n) and (m>=n): print("Yes") else: print("No") ``` No
106,202
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook. Input The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 100) — the number of participants, the number of pens, and the number of notebooks respectively. Output Print "Yes" if it possible to reward all the participants. Otherwise, print "No". You can print each letter in any case (upper or lower). Examples Input 5 8 6 Output Yes Input 3 9 3 Output Yes Input 8 5 20 Output No Note In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks. In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks. In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No". Submitted Solution: ``` q,w,e = input().split() q = int(q) w = int(w) e = int(e) def check(a,s,d): if a/s >= 1 : if a/d >= 1 : print("yes") else: print("no") else: print("no") check(q,w,e) ``` No
106,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook. Input The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 100) — the number of participants, the number of pens, and the number of notebooks respectively. Output Print "Yes" if it possible to reward all the participants. Otherwise, print "No". You can print each letter in any case (upper or lower). Examples Input 5 8 6 Output Yes Input 3 9 3 Output Yes Input 8 5 20 Output No Note In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks. In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks. In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No". Submitted Solution: ``` j=input().split() n,m,k=j[0],j[1],j[2] if n<=m or n<=k: print("Yes") else: print("No") ``` No
106,204
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` n=int(input()) if n%2: print("YES") ls=[0]*2*n c=1 i=-1 while c<=2*n: i=i+1 ls[i]=c i=(i+n)%(2*n) ls[i]=c+1 c=c+2 print(*ls) else: print("NO") ```
106,205
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` def almost_equal(n): if n%2==0: return None else: r = [1] r2 = [2] m = 1 while m<n: m += 2 r += [2*m,2*m -3] r2 += [2*m-1,2*m-2] return r+r2 n = int(input().strip()) r = almost_equal(n) if r: print("YES") print(' '.join([str(x) for x in r])) else: print("NO") ```
106,206
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` n = int(input()) a = [0] * (2*n) curr = 1 for i in range(n): if i%2 == 0: a[i] = curr curr += 1 a[i+n] = curr curr += 1 else: a[i+n] = curr curr += 1 a[i] = curr curr += 1 arr = a + a[:n-1] s = set() window = sum(a[:n]) s.add(window) for i in range(n, 3*n-1): window += arr[i] window -= arr[i-n] s.add(window) if len(s) > 2: print("NO") else: print("YES") print(*a) ```
106,207
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` n = int(input()) n2 = 2 * n if n == 1: print('YES\n1 2') else: a = [None] * n2 now = n2 flag = True for i in range(n): if flag: a[i] = now a[n + i] = now - 1 else: a[i] = now - 1 a[n + i] = now flag = 1 - flag now -= 2 min_ans = sum(a[:n]) max_ans = min_ans now = min_ans for i in range(n2): now -= a[i] now += a[(n + i) % n2] min_ans = min(min_ans, now) max_ans = max(max_ans, now) if max_ans - min_ans > 1: print('NO') else: print('YES') print(' '.join(list(map(str, a)))) ```
106,208
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` n=int(input()) if(n%2!=0): a=[0]*(2*n+1) for i in range(1,n+1): if(i%2==1): a[i]=2*i a[n+i]=2*i-1 else: a[i]=2*i-1 a[n+i]=2*i print("YES") for i in range(1,2*n+1): print(a[i],end=' ') else: print("NO") ```
106,209
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` n = int(input()) a = [1] b = [] counter = 2 for i in range(2, 2*n + 1): if counter < 2: a.append(i) else: b.append(i) counter = (counter + 1) % 4 c = a + b sums = [] sum = 0 for i in range(n): sum += c[i] sums.append(sum) for i in range(len(c) - n): sum = sum - c[i] + c[i + n] sums.append(sum) sum = sum - c[len(c) - n] + c[0] sums.append(sum) answer = True comp = sorted(sums)[-1] for i in sums: if(abs(i - comp) > 1): answer = False #print(sums) if(answer): print('YES') print(*a, *b) else: print('NO') ```
106,210
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` def divisors(M): d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d def popcount(x): x = x - ((x >> 1) & 0x55555555) x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x = (x + (x >> 4)) & 0x0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) return x & 0x0000007f def eratosthenes(n): res=[0 for i in range(n+1)] prime=set([]) for i in range(2,n+1): if not res[i]: prime.add(i) for j in range(1,n//i+1): res[i*j]=1 return prime def factorization(n): res=[] for p in prime: if n%p==0: while n%p==0: n//=p res.append(p) if n!=1: res.append(n) return res def euler_phi(n): res = n for x in range(2,n+1): if x ** 2 > n: break if n%x==0: res = res//x * (x-1) while n%x==0: n //= x if n!=1: res = res//n * (n-1) return res def ind(b,n): res=0 while n%b==0: res+=1 n//=b return res def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [2, 3, 5, 7, 11, 13, 17] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): from math import gcd m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2 ** 20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret def divisors(n): res = [1] prime = primeFactor(n) for p in prime: newres = [] for d in res: for j in range(prime[p]+1): newres.append(d*p**j) res = newres res.sort() return res def xorfactorial(num): if num==0: return 0 elif num==1: return 1 elif num==2: return 3 elif num==3: return 0 else: x=baseorder(num) return (2**x)*((num-2**x+1)%2)+function(num-2**x) def xorconv(n,X,Y): if n==0: res=[(X[0]*Y[0])%mod] return res x=[X[i]+X[i+2**(n-1)] for i in range(2**(n-1))] y=[Y[i]+Y[i+2**(n-1)] for i in range(2**(n-1))] z=[X[i]-X[i+2**(n-1)] for i in range(2**(n-1))] w=[Y[i]-Y[i+2**(n-1)] for i in range(2**(n-1))] res1=xorconv(n-1,x,y) res2=xorconv(n-1,z,w) former=[(res1[i]+res2[i])*inv for i in range(2**(n-1))] latter=[(res1[i]-res2[i])*inv for i in range(2**(n-1))] former=list(map(lambda x:x%mod,former)) latter=list(map(lambda x:x%mod,latter)) return former+latter def merge_sort(A,B): pos_A,pos_B = 0,0 n,m = len(A),len(B) res = [] while pos_A < n and pos_B < m: a,b = A[pos_A],B[pos_B] if a < b: res.append(a) pos_A += 1 else: res.append(b) pos_B += 1 res += A[pos_A:] res += B[pos_B:] return res class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N self.group = N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) stack = [x] while self._parent[stack[-1]]!=stack[-1]: stack.append(self._parent[stack[-1]]) for v in stack: self._parent[v] = stack[-1] return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] < self._size[gy]: self._parent[gx] = gy self._size[gy] += self._size[gx] else: self._parent[gy] = gx self._size[gx] += self._size[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) class WeightedUnionFind(): def __init__(self,N): self.parent = [i for i in range(N)] self.size = [1 for i in range(N)] self.val = [0 for i in range(N)] self.flag = True self.edge = [[] for i in range(N)] def dfs(self,v,pv): stack = [(v,pv)] new_parent = self.parent[pv] while stack: v,pv = stack.pop() self.parent[v] = new_parent for nv,w in self.edge[v]: if nv!=pv: self.val[nv] = self.val[v] + w stack.append((nv,v)) def unite(self,x,y,w): if not self.flag: return if self.parent[x]==self.parent[y]: self.flag = (self.val[x] - self.val[y] == w) return if self.size[self.parent[x]]>self.size[self.parent[y]]: self.edge[x].append((y,-w)) self.edge[y].append((x,w)) self.size[x] += self.size[y] self.val[y] = self.val[x] - w self.dfs(y,x) else: self.edge[x].append((y,-w)) self.edge[y].append((x,w)) self.size[y] += self.size[x] self.val[x] = self.val[y] + w self.dfs(x,y) class Dijkstra(): class Edge(): def __init__(self, _to, _cost): self.to = _to self.cost = _cost def __init__(self, V): self.G = [[] for i in range(V)] self._E = 0 self._V = V @property def E(self): return self._E @property def V(self): return self._V def add_edge(self, _from, _to, _cost): self.G[_from].append(self.Edge(_to, _cost)) self._E += 1 def shortest_path(self, s): import heapq que = [] d = [10**15] * self.V d[s] = 0 heapq.heappush(que, (0, s)) while len(que) != 0: cost, v = heapq.heappop(que) if d[v] < cost: continue for i in range(len(self.G[v])): e = self.G[v][i] if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost heapq.heappush(que, (d[e.to], e.to)) return d #Z[i]:length of the longest list starting from S[i] which is also a prefix of S #O(|S|) def Z_algorithm(s): N = len(s) Z_alg = [0]*N Z_alg[0] = N i = 1 j = 0 while i < N: while i+j < N and s[j] == s[i+j]: j += 1 Z_alg[i] = j if j == 0: i += 1 continue k = 1 while i+k < N and k + Z_alg[k]<j: Z_alg[i+k] = Z_alg[k] k += 1 i += k j -= k return Z_alg class BIT(): def __init__(self,n,mod=0): self.BIT = [0]*(n+1) self.num = n self.mod = mod def query(self,idx): res_sum = 0 mod = self.mod while idx > 0: res_sum += self.BIT[idx] if mod: res_sum %= mod idx -= idx&(-idx) return res_sum #Ai += x O(logN) def update(self,idx,x): mod = self.mod while idx <= self.num: self.BIT[idx] += x if mod: self.BIT[idx] %= mod idx += idx&(-idx) return class dancinglink(): def __init__(self,n,debug=False): self.n = n self.debug = debug self._left = [i-1 for i in range(n)] self._right = [i+1 for i in range(n)] self.exist = [True for i in range(n)] def pop(self,k): if self.debug: assert self.exist[k] L = self._left[k] R = self._right[k] if L!=-1: if R!=self.n: self._right[L],self._left[R] = R,L else: self._right[L] = self.n elif R!=self.n: self._left[R] = -1 self.exist[k] = False def left(self,idx,k=1): if self.debug: assert self.exist[idx] res = idx while k: res = self._left[res] if res==-1: break k -= 1 return res def right(self,idx,k=1): if self.debug: assert self.exist[idx] res = idx while k: res = self._right[res] if res==self.n: break k -= 1 return res class SparseTable(): def __init__(self,A,merge_func,ide_ele): N=len(A) n=N.bit_length() self.table=[[ide_ele for i in range(n)] for i in range(N)] self.merge_func=merge_func for i in range(N): self.table[i][0]=A[i] for j in range(1,n): for i in range(0,N-2**j+1): f=self.table[i][j-1] s=self.table[i+2**(j-1)][j-1] self.table[i][j]=self.merge_func(f,s) def query(self,s,t): b=t-s+1 m=b.bit_length()-1 return self.merge_func(self.table[s][m],self.table[t-2**m+1][m]) class BinaryTrie: class node: def __init__(self,val): self.left = None self.right = None self.max = val def __init__(self): self.root = self.node(-10**15) def append(self,key,val): pos = self.root for i in range(29,-1,-1): pos.max = max(pos.max,val) if key>>i & 1: if pos.right is None: pos.right = self.node(val) pos = pos.right else: pos = pos.right else: if pos.left is None: pos.left = self.node(val) pos = pos.left else: pos = pos.left pos.max = max(pos.max,val) def search(self,M,xor): res = -10**15 pos = self.root for i in range(29,-1,-1): if pos is None: break if M>>i & 1: if xor>>i & 1: if pos.right: res = max(res,pos.right.max) pos = pos.left else: if pos.left: res = max(res,pos.left.max) pos = pos.right else: if xor>>i & 1: pos = pos.right else: pos = pos.left if pos: res = max(res,pos.max) return res def solveequation(edge,ans,n,m): #edge=[[to,dire,id]...] x=[0]*m used=[False]*n for v in range(n): if used[v]: continue y = dfs(v) if y!=0: return False return x def dfs(v): used[v]=True r=ans[v] for to,dire,id in edge[v]: if used[to]: continue y=dfs(to) if dire==-1: x[id]=y else: x[id]=-y r+=y return r class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.size = n for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): if r==self.size: r = self.num res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res def bisect_l(self,l,r,x): l += self.num r += self.num Lmin = -1 Rmin = -1 while l<r: if l & 1: if self.tree[l] <= x and Lmin==-1: Lmin = l l += 1 if r & 1: if self.tree[r-1] <=x: Rmin = r-1 l >>= 1 r >>= 1 if Lmin != -1: pos = Lmin while pos<self.num: if self.tree[2 * pos] <=x: pos = 2 * pos else: pos = 2 * pos +1 return pos-self.num elif Rmin != -1: pos = Rmin while pos<self.num: if self.tree[2 * pos] <=x: pos = 2 * pos else: pos = 2 * pos +1 return pos-self.num else: return -1 import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) n = int(input()) if n%2==0: print("NO") else: print("YES") ans = [0 for i in range(2*n)] for i in range(n): if i%2==0: ans[i] = 2*i + 1 ans[i+n] = 2*i + 2 else: ans[i] = 2*i + 2 ans[i+n] = 2*i + 1 print(*ans) ```
106,211
Provide tags and a correct Python 3 solution for this coding contest problem. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys readline = sys.stdin.readline N = int(readline()) if N & 1: print('YES') Ans = list(range(1, 1+2*N, 2)) + list(range(2, 1+2*N, 2)) for i in range(0, N, 2): Ans[i], Ans[i+N] = Ans[i+N], Ans[i] print(*Ans) else: print('NO') ```
106,212
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` def solve(): arange=int(input()) if(arange%2==0): print("NO") return diapasone=list(range(1,(arange*2)+1)) answer=[] i=0 j=len(diapasone)-1 while(len(answer)<len(diapasone)): temp_i=i temp_j=j counter=arange while(counter>0): answer.append(diapasone[temp_i]) counter-=1 if(counter>0): answer.append(diapasone[temp_j]) counter-=1 temp_i+=2 temp_j-=2 i+=1 j-=1 answer_final='' for i in answer: answer_final+=str(i) answer_final+=' ' print("YES") print(answer_final[:-1]) solve() ``` Yes
106,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` n = int(input()) if n % 2 == 0: print("NO") elif n == 1: print("YES") print("1 2") else: print("YES") circleTop = [] circleBottom = [] for x in range(n): if x % 2 == 0: circleTop.append(x*2+1) circleBottom.append(x*2+2) else: circleTop.append(x*2+2) circleBottom.append(x*2+1) # works print(" ".join(map(str, circleTop+circleBottom))) ``` Yes
106,214
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` def find(n): ans=[0]*(2*n) if n%2==0: return [] temp=0 for i in range(1,n+1): left=2*i-1 right=2*i if temp%2==0: ans[i-1]=left ans[i+n-1]=right else: ans[i-1]=right ans[i+n-1]=left temp+=1 return ans n=int(input()) ans=find(n) if ans==[]: print("NO") else: print("YES") print(*ans) ``` Yes
106,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` size1=int(input()) ar1=[] ar2=[] count=1 if size1%2==0: print('NO') else: for i in range((size1)): if i%2==0: ar1.append(count) count+=1 ar2.append(count) count+=1 else: ar2.append(count) count += 1 ar1.append(count) count+=1 print('YES') ar1=ar1+ar2 for i in ar1: print(i, end=" ") print() ``` Yes
106,216
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` n = int(input()) if n&1 == 0: print("NO") else: j = [1] for y in range(n+1,2*n): j.append(y) for y in range(2,n+1): j.append(y) j.append(2*n) print("YES") print(*j) ``` No
106,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` n=int(input()) if(n%2==1): print("YES") else: print("NO") ``` No
106,218
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` n = int(input()) c = 2*n res = list(range(1,c+1)) res2=[] print(res) for i in range(1,int(len(res)/2)): b = res[i] res[i] = res[i+2] res[i+2] = b print(res) for i in range(0,len(res)-2): d = res[i]+res[i+1]+res[i+2] res2.append(d) for i in range(0,2): d = res[i-2]+res[i-1]+res[i] res2.append(d) for i in range(0,len(res2)//n,2): e = res2[i] -res2[i+1] if e == -1 or e == 1: f = 'True' else: print('NO') quit() print('YES') print(res) ``` No
106,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1. For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1. <image> Input The first and the only line contain one integer n (1 ≤ n ≤ 10^5). Output If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them. Examples Input 3 Output YES 1 4 5 2 3 6 Input 4 Output NO Note Example from the statement is shown for the first example. It can be proved that there is no solution in the second example. Submitted Solution: ``` n = int(input()); if n % 2 == 0: print("NO"); else: ans = []; for i in range(2*n): ans.append(0); current = 1; for i in range(n): ans[i] = current if i % 2 == 0 else current+1; ans[n+i] = current+1 if i % 2 == 0 else current; current += 2; print("YES"); print(ans); ``` No
106,220
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` import sys input = sys.stdin.readline t = int(input()) for _ in range(t): a,b = map(int,input().split()) s = input() n = len(s) ls = [] if s[0] == ".": cnt = 1 else: cnt = 0 for i in range(1,n+1): if i < n and s[i] == ".": cnt += 1 else: if cnt >= b: ls.append(cnt) cnt = 0 if not ls: print("NO") continue ls.sort() if a >= 2*b: if len(ls) >= 2 or ls[0] > a+(b-1)*2 or ls[0] < a: print("NO") else: print("YES") else: if ls[0] < a:# or ls[-1] > a+(2*b-1)*2: print("NO") elif len(ls) >= 2 and ls[-2] >= 2*b: print("NO") else: l = len(ls)-1 t = ls[-1] for i in range(t): if i+a <= t: p,q = i,t-(i+a) if not (b<=p<a or b<=q<a or p>=2*b or q>=2*b): x = l+(a<=p<2*b)+(a<=q<2*b) if x%2 == 0: print("YES") break else: print("NO") ```
106,221
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` import sys from itertools import groupby readline = sys.stdin.readline t = int(input()) for _ in range(t): a, b = map(int, readline().split()) dots = [len(list(v)) for k, v in groupby(readline().rstrip()) if k == '.'] lose = 0 med = 0 long = 0 longest = 0 for x in dots: if x < b: continue if b <= x < a: lose = 1 elif 2*b <= x: long += 1 if longest < x: longest = x elif a <= x < 2*b: med += 1 if lose or long > 1: print("NO") continue if long: for left, right in zip(range(longest), range(longest-a, -1, -1)): if (left < b or a <= left < 2*b) and (right < b or a <= right < 2*b): if (((med + (1 if a <= left else 0) + (1 if a <= right else 0)) & 1) == 0): print("YES") break else: print("NO") else: print("YES" if med & 1 else "NO") ```
106,222
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` # import sys # input = sys.stdin.readline Q = int(input()) for _ in range(Q): a, b = map(int, input().split()) S = input() + "X" s = 0 x = x1 = x2 = x3 = xx = 0 for i in range(len(S)): if S[i] == "X": if s < b: pass elif a <= s < 2*b: x += 1 elif a < 2*b and (3*a <= s < a+3*b-1 or 2*a <= s < a+2*b-1): xx += 1 elif a < 2*b and 3*a <= s < a+4*b-1: x3 += 1 elif a < 2*b and 2*a <= s < a+3*b-1: x2 += 1 elif a <= s < a+2*b-1: x1 += 1 else: # print("a, b, s =", a, b, s) print("NO") break s = 0 else: s += 1 else: # print("x, x1, x2, x3 =", x, x1, x2, x3) if xx+x1+x2+x3 >= 2: print("NO") elif xx: print("YES") elif (x + x1 + x2*2 + x3*3) % 2 == 0: print("NO") else: print("YES") ```
106,223
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` import os, sys # zeilen = [l.strip() for l in sys.stdin.readlines()] q = int(sys.stdin.readline().strip()) for _ in range(q): a, b = map(int, sys.stdin.readline().strip().split()) word = sys.stdin.readline().strip() gaps = sorted([len(gap) for gap in word.split('X') if len(gap)>= b]) if len(gaps) == 0: print('NO') elif gaps[0] < a: print('NO') elif len(gaps) > 1 and gaps[-2] >= 2*b: print('NO') elif gaps[-1] < 2*b: # no problematic, need only count print('YES' if (len(gaps) % 2) else 'NO') else: # exactly one problematic gap p = gaps[-1] if (len(gaps) % 2): # A tries to make this gap into zero or two if p <= (a + 2*b - 2): # short enough for 0 print('YES') elif p < 3*a: # we have to try two print('NO') # not long enough elif p > (a + 4*b - 2): # too long print('NO') else: print('YES') else: # A tries to make this gap into one if p < 2*a: # too short print('NO') elif p > (a + 3*b - 2):# too long print('NO') else: print('YES') ```
106,224
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` import sys input = sys.stdin.readline q=int(input()) for testcases in range(q): a,b=map(int,input().split()) S=input().strip() S+="X" T=[] NOW=0 for s in S: if s==".": NOW+=1 else: if NOW!=0: T.append(NOW) NOW=0 count=0 noflag=0 other=[] for t in T: if b<=t<a: noflag=1 break if a<=t<2*b: count+=1 elif t>=2*b: other.append(t) if len(other)>=2: noflag=1 if noflag==1: print("NO") continue if len(other)==0: if count%2==1: print("YES") else: print("NO") continue OTHER=other[0] for left in range(OTHER-a+1): right=OTHER-a-left if left>=2*b or right>=2*b or b<=left<a or b<=right<a: continue count2=count if left>=a: count2+=1 if right>=a: count2+=1 if count2%2==0: print("YES") break else: print("NO") ```
106,225
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` def sol(): a, b = map(int, input().split()) s = input().replace("X", " ") small_segs = 0 critical_region = -1 for p in map(len, s.split()): if p < b: continue if p < a and p >= b: return False if ((p - a) % 2 == 0 and (p >= a + 4 * b)) or ((p - a) % 2 == 1 and p >= a + 4 * b - 1): return False if p >= 2*b: if critical_region != -1: return False critical_region = p elif p >= a: small_segs += 1 if critical_region == -1: return small_segs % 2 == 1 can = [0] * 3 for l in range(critical_region+1-a): r = critical_region - l - a if (l >= b and l < a) or l >= 2 * b: continue if (r >= b and r < a) or r >= 2 * b: continue canl = int(l >= a) canr = int(r >= a) can[canl + canr] = 1 for choice, val in enumerate(can): if val and (small_segs + choice) % 2 == 0: return True return False n = int(input()) for _ in range(n): print("YES" if sol() else "NO") ```
106,226
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` q = int(input()) for rwer in range(q): a, b = map(int,input().split()) s = input() tab = [] count = 0 for i in range(len(s)): if s[i] == '.': count += 1 if s[i] == 'X': if count > 0: tab.append(count) count = 0 if count > 0: tab.append(count) #print(tab) bat = [j for j in tab if j >= b] tab = bat.copy() if len(tab) == 0: print("no") else: roomb = 0 for i in tab: if i >= 2*b: roomb += 1 if roomb > 1: print("no") else: alice = 1 for i in tab: if i < a: alice = 0 break if alice == 0: print("no") else: if roomb == 0: if len(tab) % 2 == 1: print("yes") else: print("no") if roomb == 1: jednostrzaly = len(tab) - 1 duzy = max(tab) #alice gra w duzym i co ona tam moze zrobic? if duzy >= (a + 4*b - 1): print("no") else: if jednostrzaly % 2 == 0: #jesli alice da rade zostawic 0 albo 2 sloty to wygrala if duzy <= a + 2 * b - 2: ########poprawka z -1 print("yes") elif duzy >= 3 * a: print("yes") else: print("no") if jednostrzaly % 2 == 1: #alice musi zostawic 1 slota if duzy >= 2*a and duzy <= (a + 3*b-2): print("yes") else: print("no") ```
106,227
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Tags: games Correct Solution: ``` def removeX(s,p): if (p==len(s)): return s while s[p]!='X': p+=1 if (p==len(s)): return s j=0 while s[p+j]=='X': j+=1 if (p+j==len(s)): break return removeX(s[0:p+1]+s[p+j:],p+1) def doable(lenght,a,b,parity): for x in range((lenght-a)//2+1): y=lenght-a-x #print(x,y) if ((not((x>=b) & (x<a)))&(not(x>=2*b))&(not((y>=b) & (y<a)))&(not(y>=2*b))): e=0 #print('oui') if((x>=a)&(x<2*b)): e+=1 if((y>=a)&(y<2*b)): e+=1 if((parity+e)%2==0): return 1 return 0 for i in range(int(input())): a,b=[int(x) for x in input().split()] v=[0,0,0] s=removeX(input(),0) for y in s.split('X'): k=len(y) if ((k>=b) & (k<a)): v[0]+=1 elif ((k>=a) & (k<2*b)): v[1]+=1 elif (k>=2*b): v[2]+=1 lenght=k #print(v) if ((v[0]>0) | (v[2]>1)): print('NO') elif (v[2]==1): if (lenght-a>=4*b): print('NO') else: if (doable(lenght,a,b,v[1]%2)==1): print('YES') else: print('NO') else: if (v[1]%2==0): print('NO') else: print('YES') ```
106,228
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() Q = int(input()) for _ in range(Q): a, b = map(int, input().split()) S = input() + "X" s = 0 x = x1 = x2 = x3 = xx = 0 for i in range(len(S)): if S[i] == "X": if s < b: pass elif a <= s < 2*b: x += 1 elif a < 2*b and (3*a <= s < a+3*b-1 or 2*a <= s < a+2*b-1): xx += 1 elif a < 2*b and 3*a <= s < a+4*b-1: x3 += 1 elif a < 2*b and 2*a <= s < a+3*b-1: x2 += 1 elif a <= s < a+2*b-1: x1 += 1 else: # print("a, b, s =", a, b, s) print("NO") break s = 0 else: s += 1 else: # print("x, x1, x2, x3 =", x, x1, x2, x3) if xx+x1+x2+x3 >= 2: print("NO") elif xx: print("YES") elif (x + x1 + x2*2 + x3*3) % 2 == 0: print("NO") else: print("YES") ``` Yes
106,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` def solve(a, b, s): l = map(lambda x: len(x), s.split('X')) tot = 0 mx = 0 for j in l: if j < b: continue if j < a: return 'NO' if j >= 2 * b: if mx > 0: return 'NO' mx = j tot += 1 if mx > 0: if a < 2 * b: one = mx >= a and mx <= a + 2 * b - 2 two = mx >= 2 * a and mx <= a + 3 * b - 2 three = mx >= 3 * a and mx <= a + 4 * b - 2 if not (one or two or three): return 'NO' if (one and two) or (two and three): return 'YES' if two: tot += 1 if a >= 2 * b: if not (mx >= a and mx <= a + 2 * b - 2): return 'NO' if tot % 2 == 1: return 'YES' else: return 'NO' q = int(input()) for i in range(q): a, b = map(int, input().split()) s = input() print(solve(a, b, s)) ``` Yes
106,230
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` def main(): import sys input = sys.stdin.readline q = int(input()) for _ in range(q): a, b = map(int, input().split()) S = input().rstrip('\n') S += '!' win = 1 cnt = 0 flg = 0 num = 0 for s in S: if s == '.': cnt += 1 else: if cnt: if b <= cnt < a: win = 0 break elif cnt < b: pass elif cnt < 2*b: num += 1 else: num += 1 if flg: flg = 2 win = 0 break else: flg = 1 tmp = cnt cnt = 0 if flg == 1: if num % 2 == 0: if a >= 2*b: win = 0 else: if not 2*a <= tmp <= a+3*b-2: win = 0 else: if tmp <= a+2*b-2: pass elif 3*a <= tmp <= a+4*b-2: pass else: win = 0 elif flg == 0: if num % 2 == 0: win = 0 if win: print('Yes') else: print('No') if __name__ == '__main__': main() ``` Yes
106,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` q = int(input()) for i in range(q): a, b = [int(item) for item in input().split()] s = input().rstrip() + "#" cnt = 0 bob_world = 0 alice_world = 0 length = 0 bob_winning = False for ch in s: if ch == ".": cnt += 1 else: if cnt < b: pass elif b <= cnt < a: bob_winning = True break elif a <= cnt < b * 2: alice_world += 1 elif cnt >= b * 2: length = cnt bob_world += 1 if bob_world >= 2: bob_winning = True break cnt = 0 if bob_winning: print("No") else: if length == 0: if alice_world % 2 == 1: print("Yes") else: print("No") continue possibility = set() for i in range(length - a + 1): l = i; r = length - a - i if b <= l < a or b <= r < a: continue if l >= b * 2 or r >= b * 2: continue val = 0 if a <= l < b * 2: val += 1 if a <= r < b * 2: val += 1 possibility.add(val + 1) alice_win = False for item in possibility: if (alice_world + item) % 2 == 1: alice_win = True if alice_win: print("Yes") else: print("No") ``` Yes
106,232
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` import sys input = sys.stdin.readline q=int(input()) for testcases in range(q): a,b=map(int,input().split()) S=input().strip() T=[] NOW=0 for s in S: if s==".": NOW+=1 else: if NOW!=0: T.append(NOW) NOW=0 T.sort() LA=[] LB=[] flag=0 SP=0 for t in T: LA.append(t//a) LB.append(t//b) SP+=t//b-t//a if sum(LA)%2==1 and SP<=1: print("YES") else: print("NO") ``` No
106,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` T = int(input()) for i in range(T): [a, b] = [int(i) for i in input().split()] game = input() length = 0 spaces = [] aspace = 0 bspace = 0 for g in game: if(g=='.'):length+=1 else: if(length>=b): spaces.append(length) length = 0 for s in spaces: if(s >= a): aspace+=s//a bspace+=int((s%a+1)//2 >= b) elif(s >= b): bspace+=1 if(bspace>1 or aspace%3==2): print("NO") else: print("YES") ``` No
106,234
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` def main(): import sys input = sys.stdin.readline q = int(input()) for _ in range(q): a, b = map(int, input().split()) S = input().rstrip('\n') S += '!' win = 1 cnt = 0 flg = 0 num = 0 for s in S: if s == '.': cnt += 1 else: if cnt: if b <= cnt < a: win = 0 break elif cnt < b: pass elif cnt < 2*b: num += 1 else: num += 1 if flg: flg = 2 win = 0 break else: flg = 1 tmp = cnt cnt = 0 if flg == 1: if num % 2 == 0: if a >= 2*b: win = 0 else: if not 2*a <= tmp <= a+3*b-2: win = 0 else: if tmp > a+2*b-2: win = 0 elif flg == 0: if num % 2 == 0: win = 0 if win: print('Yes') else: print('No') if __name__ == '__main__': main() ``` No
106,235
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length a, and Bob must select a substring of length b. It is guaranteed that a > b. For example, if s = ...X.. and a = 3, b = 2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s = ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX. Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally. You have to answer q independent queries. Input The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries. The first line of each query contains two integers a and b (1 ≤ b < a ≤ 3 ⋅ 10^5). The second line of each query contains the string s (1 ≤ |s| ≤ 3 ⋅ 10^5), consisting of only characters . and X. It is guaranteed that sum of all |s| over all queries not exceed 3 ⋅ 10^5. Output For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). Example Input 3 3 2 XX......XX...X 4 2 X...X.X..X 5 3 .......X..X Output YES NO YES Note In the first query Alice can select substring s_3 ... s_5. After that s turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move. In the second query Alice can not win because she cannot even make one move. In the third query Alice can choose substring s_2 ... s_6. After that s turns into .XXXXX.X..X, and Bob can't make a move after that. Submitted Solution: ``` Q = int(input()) for q in range(Q): a, b = tuple(map(int, input().split())) s = input() ones = [] count = 0 flag = False for i in s: if i == "X": if a > count >= b: print('NO') flag = True break elif count >= b: ones.append(count) count = 0 else: count += 1 if count != 0: ones.append(count) if a > count >= b: print('NO') continue if flag: continue if len(ones) == 0: print('NO') continue count_more2b = 0 more2b = 0 for one in ones: if one >= 2 * b: count_more2b += 1 more2b = one if count_more2b >= 2: print('NO') flag = True break if flag: continue if count_more2b == 0: if len(ones) % 2 == 0: print('NO') else: print('YES') continue elif more2b - a >= 2 * b: print('NO') continue else: if a > more2b - a >= b: print('NO') continue if more2b - a < b: ones.pop() if len(ones) % 2 == 0: print('YES') else: print('NO') ``` No
106,236
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` x = int(input()) y = list(map(int, input().split())) a = int(x/2) b = 0 c = 0 y.sort() for i in range(a, x): b+=y[i] for i in range(a): c+=y[i] print(b**2+c**2) ```
106,237
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def li(): return list(mi()) n=ii() a=li() a.sort() x=y=0 for i in range(n//2): x+=a[i] y+=a[n-i-1] if n%2: y+=a[n//2] print(x*x+y*y) ```
106,238
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) a.sort() mp = n // 2 sl = sum(a[:mp]) sm = sum(a[mp:]) smd = sl**2 + sm**2 print(smd) ```
106,239
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) ar = list(map(int, input().split())) ar.sort() x, y = 0, 0 for i in range((n + 1) // 2): if i * 2 == n - 1: y += ar[i] else: x += ar[i] y += ar[n - i - 1] print(x * x + y * y) ```
106,240
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) a.sort() if n%2==0: d=(n//2) else: d=((n//2)+1)-1 b=sum(a[0:d]) c=sum(a[d:n]) print((b*b)+(c*c)) ```
106,241
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` from collections import deque n = int(input()) a = deque(sorted(map(int, input().split()))) up = 0 right = 0 for i in range(n): if i % 2: up += a.popleft() else: right += a.pop() print(up * up + right * right) ```
106,242
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split(" "))) a.sort() sum1=0 sum2=0 for i in range (n): if(i<int(n/2)): sum1+=a[i] else: sum2+=a[i] print(sum1*sum1+sum2*sum2) ```
106,243
Provide tags and a correct Python 3 solution for this coding contest problem. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Tags: greedy, math, sortings Correct Solution: ``` n = int(input()) u = list(map(int, input().split())) u.sort() a = sum(u[:n // 2]) b = sum(u) - a print(a * a + b * b) ```
106,244
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) l.sort() v=n//2 s1=sum(l[:v]) s=sum(l) s2=s-s1 print(pow(s2,2)+pow(s1,2)) ``` Yes
106,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` a = int(input()) b = list(map(int, input().split())) X = 0 Y = 0 b.sort() for i in range(0,len(b)): if (i < len(b) // 2): Y += b[i]; else: X += b[i]; print(Y**2 + X**2) ``` Yes
106,246
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> 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() l=li() l.sort() i,j=0,n-1 x,y =0,0 c=1 while i<=j: if c: x+=l[j] c=0 j-=1 else: y+=l[i] c=1 i+=1 pr(x*x + y*y) for _ in range(1): solve() ``` Yes
106,247
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` #設定 import sys input = sys.stdin.buffer.readline #ライブラリインポート from collections import defaultdict INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): n = int(input()) a = getlist() a = sorted(a) x = 0 y = 0 for i in range(int(n // 2)): x += a[i] y = sum(a) - x ans = (x ** 2) + (y ** 2) print(ans) if __name__ == '__main__': main() ``` Yes
106,248
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` n = int(input('')) a = list(map(int,input('').split(' '))) a.sort() r = n//2 t = sum(a) s = 0 for i in range(n//2): s = s + a[i]**2 t = t-s print(t**2 + s**2) ``` No
106,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` import math n = int(input()) ar = list(sorted(list(map(int, input().split(' '))))) x = n//2 a, b = (0, 0) for idx, num in enumerate(ar): if idx < x: a += num else: b += num print(int(math.pow(a, 2) + math.pow(b, 2))) ``` No
106,250
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` # cf 1248 B 900 import math n = int(input()) A = [*map(int, input().split())] A.sort(reverse=True) w, h = 0, 0 i, j = 0, len(A) - 1 while i < j: w += A[i] i += 1 h += A[j] j -= 1 if i == j: w += A[i] print(w, h) print(w*w + h*h) ``` No
106,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point (0, 0). While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to OX or OY axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from (0, 0). Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. Input The first line contains an integer n (1 ≤ n ≤ 100 000) — the number of sticks Alexey got as a present. The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10 000) — the lengths of the sticks. Output Print one integer — the square of the largest possible distance from (0, 0) to the tree end. Examples Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 Note The following pictures show optimal trees for example tests. The squared distance in the first example equals 5 ⋅ 5 + 1 ⋅ 1 = 26, and in the second example 4 ⋅ 4 + 2 ⋅ 2 = 20. <image> <image> Submitted Solution: ``` # B. Выращивание дерева a = int(input()) b = input().split() X = 0 Y = 0 b.sort() for i in range(0,len(b)): if (i < a / 2): Y += int(b[i]); else: X += int(b[i]); print(Y**2 + X**2) ``` No
106,252
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You are given a tree on n vertices. For each i between 1 and n, find the maximum size of an almost-i-uniform set. Input The first line contains a single integer n (2 ≤ n ≤ 5 ⋅ 10^5) – the number of vertices of the tree. Then n-1 lines follows, the i-th of which consisting of two space separated integers u_i, v_i (1 ≤ u_i, v_i ≤ n) meaning that there is an edge between vertices u_i and v_i. It is guaranteed that the given graph is tree. Output Output a single line containing n space separated integers a_i, where a_i is the maximum size of an almost-i-uniform set. Examples Input 5 1 2 1 3 1 4 4 5 Output 4 3 2 1 1 Input 6 1 2 1 3 1 4 4 5 4 6 Output 4 4 2 1 1 1 Note Consider the first example. * The only maximum almost-1-uniform set is \{1, 2, 3, 4\}. * One of the maximum almost-2-uniform sets is or \{2, 3, 5\}, another one is \{2, 3, 4\}. * A maximum almost-3-uniform set is any pair of vertices on distance 3. * Any single vertex is an almost-k-uniform set for k ≥ 1. In the second sample there is an almost-2-uniform set of size 4, and that is \{2, 3, 5, 6\}. Submitted Solution: ``` def almost_same_distance(n,adj,edges): max_deg =max_degree(adj) result = [max_deg+1] for k in range(2,n+1): max = find_almost_k_uniform(n,k,adj,edges) result.append(max) return result def find_almost_k_uniform(n,k,adj,edges): max_len = 0 if k % 2 == 1: max_len = find_k_odd(n,k,adj,edges) else: max_len = find_k_even(n,k,adj,edges) return max_len def find_k_odd(n,k,adj,edges): d_s = {} max_len = 0 for v in range(1,n+1): d_s[v] = bfs(n,v,adj) l = k//2 for v in range(1,n+1): r = {i:-1 for i in range(1,n+1)} #buscar un vertice de longitud l o l+1 por subarbol depth,subtree = d_s[v] for w in range(1,n+1): if depth[w] == l+1: r[subtree[w]] = l+1 if depth[w] == l and r[subtree[w]] == -1: r[subtree[w]] = l len_r = 0 found_l = False for t in r.values(): if t != -1: if t == l and not found_l: len_r += 1 found_l =True elif t== l+1: len_r += 1 if len_r > max_len: max_len = len_r return max_len def find_k_even(n,k,adj,edges): d_s = {} for v in range(1,n+1): d_s[v] = bfs(n,v,adj) max_len = 0 l = k/2 for v in range(1,n+1): depth,subtree = d_s[v] r = {} for w in range(1,n+1): if depth[w] == l: r[subtree[w]] = w if len(r) > max_len: max_len = len(r) #print("max_lena vert--", max_len) for e in edges:#O(n-1) u = e[0] v = e[1] r_u = {} r_v = {} depth_u,subtree_u = bfs(n,u,adj,v)#O(n-1) depth_v,subtree_v = bfs(n,v,adj,u) #print(e) #print("u--",depth_u,"--",subtree_u) #print("v--",depth_v,"--",subtree_v) for w in range(1,n+1):#O(n-1) if depth_u[w] == l: r_u[subtree_u[w]] = w for w in range(1,n+1):#O(n-1) if depth_v[w] == l: r_v[subtree_v[w]] = w t = len(r_u) + len(r_v) if t > max_len: max_len = t #print("edge",e,"---",max_len) #print("max_lena vert--", max_len) return max_len def bfs(n,x,adj,y=-1): #depth[x]: longitud camino entre el vertice inicial y x visited = [False for i in range(n+1)] visited [x] = True depth = [-1 for _ in range(n+1)] subtree = [-1 for _ in range(n+1)] if y!=-1: visited[y] =True q = [x] depth[x] = 0 for w in adj[x]: subtree[w] = w while len(q) > 0: v = q[0] q.remove(v) for w in adj[v]: if not visited[w]: q.append(w) depth[w] = depth[v] + 1 if v!= x: subtree[w] = subtree[v] visited[w] = True return depth,subtree def max_degree(adj): m_d = 0 for x in adj: x_degree = len(x) if m_d < x_degree: m_d = x_degree return m_d def main(): n= int(input()) adj = [[]for i in range(n+1)] edges = [] for _ in range(n-1): x,y = [ int(i) for i in input().split()] edges.append((x,y)) adj[x].append(y) adj[y].append(x) max_len = almost_same_distance(n,adj,edges) print(' '.join(str(i) for i in max_len)) main() ``` No
106,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You are given a tree on n vertices. For each i between 1 and n, find the maximum size of an almost-i-uniform set. Input The first line contains a single integer n (2 ≤ n ≤ 5 ⋅ 10^5) – the number of vertices of the tree. Then n-1 lines follows, the i-th of which consisting of two space separated integers u_i, v_i (1 ≤ u_i, v_i ≤ n) meaning that there is an edge between vertices u_i and v_i. It is guaranteed that the given graph is tree. Output Output a single line containing n space separated integers a_i, where a_i is the maximum size of an almost-i-uniform set. Examples Input 5 1 2 1 3 1 4 4 5 Output 4 3 2 1 1 Input 6 1 2 1 3 1 4 4 5 4 6 Output 4 4 2 1 1 1 Note Consider the first example. * The only maximum almost-1-uniform set is \{1, 2, 3, 4\}. * One of the maximum almost-2-uniform sets is or \{2, 3, 5\}, another one is \{2, 3, 4\}. * A maximum almost-3-uniform set is any pair of vertices on distance 3. * Any single vertex is an almost-k-uniform set for k ≥ 1. In the second sample there is an almost-2-uniform set of size 4, and that is \{2, 3, 5, 6\}. Submitted Solution: ``` v = int(input()) graph = dict.fromkeys(range(1, v+1)) for _ in range(v-1): key, value = map(int, input().split()) try: graph[key].append(value) except AttributeError: graph[key] = [value] try: graph[value].append(key) except AttributeError: graph[value] = [key] def dfs(graph, key, search_level): stack = [(key, 0)] vertex_set = set() vertex_set.add(key) visited = set() visited.add(key) while len(stack) > 0: current, level = stack.pop() if level == search_level or level == search_level+1: vertex_set.add(current) for i in graph[current]: if i not in visited: stack.append((i, level+1)) visited.add(i) return vertex_set n = 1 from functools import reduce from itertools import combinations redu = reduce comb = combinations for i in range(v): current_result = {} max_set_len = 0 for j in graph.keys(): current_result[j] = dfs(graph, j, n) for key in graph.keys(): sizes = len(current_result[key])+1 for size in range(2, sizes): for c in comb(current_result[key], size): length = len(redu(set.intersection, [current_result[j] for j in c])) if length > max_set_len and length == len(c): max_set_len = length n += 1 print(max_set_len if max_set_len > 0 else 1, end=' ') ``` No
106,254
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You are given a tree on n vertices. For each i between 1 and n, find the maximum size of an almost-i-uniform set. Input The first line contains a single integer n (2 ≤ n ≤ 5 ⋅ 10^5) – the number of vertices of the tree. Then n-1 lines follows, the i-th of which consisting of two space separated integers u_i, v_i (1 ≤ u_i, v_i ≤ n) meaning that there is an edge between vertices u_i and v_i. It is guaranteed that the given graph is tree. Output Output a single line containing n space separated integers a_i, where a_i is the maximum size of an almost-i-uniform set. Examples Input 5 1 2 1 3 1 4 4 5 Output 4 3 2 1 1 Input 6 1 2 1 3 1 4 4 5 4 6 Output 4 4 2 1 1 1 Note Consider the first example. * The only maximum almost-1-uniform set is \{1, 2, 3, 4\}. * One of the maximum almost-2-uniform sets is or \{2, 3, 5\}, another one is \{2, 3, 4\}. * A maximum almost-3-uniform set is any pair of vertices on distance 3. * Any single vertex is an almost-k-uniform set for k ≥ 1. In the second sample there is an almost-2-uniform set of size 4, and that is \{2, 3, 5, 6\}. Submitted Solution: ``` def almost_same_distance(n,adj,edges): max_deg =max_degree(adj) result = [max_deg+1] #max = find_almost_k_uniform(n,3,adj,edges) #print(4,"--->",max) for k in range(2,n+1): max = find_almost_k_uniform(n,k,adj,edges) result.append(max) return result def find_almost_k_uniform(n,k,adj,edges): max_len = 0 if k % 2 == 1: max_len = find_k_odd(n,k,adj,edges) else: max_len = find_k_even(n,k,adj,edges) return max_len def find_k_odd(n,k,adj,edges): d_s = {} max_len = 0 for v in range(1,n+1): d_s[v] = bfs(n,v,adj) l = k//2 for v in range(1,n+1): r = {i:-1 for i in range(1,n+1)} #buscar un vertice de longitud l o l+1 por subarbol depth,subtree = d_s[v] for w in range(1,n+1): if depth[w] == l+1: r[subtree[w]] = l+1 if depth[w] == l and r[subtree[w]] == -1: r[subtree[w]] = l len_r = 0 found_l = False for t in r.values(): if t != -1: if t == l and not found_l: len_r += 1 found_l =True elif t== l+1: len_r += 1 if len_r > max_len: max_len = len_r return max_len def find_k_even(n,k,adj,edges): d_s = {} for v in range(1,n+1): d_s[v] = bfs(n,v,adj) max_len = 0 l = k/2 for v in range(1,n+1): depth,subtree = d_s[v] r = {} for w in range(1,n+1): if depth[w] == l: r[subtree[w]] = w if len(r) > max_len: max_len = len(r) #print("max_lena vert--", max_len) for e in edges:#O(n-1) u = e[0] v = e[1] r_u = {} r_v = {} depth_u,subtree_u = bfs(n,u,adj,v)#O(n-1) depth_v,subtree_v = bfs(n,v,adj,u) #print(e) #print("u--",depth_u,"--",subtree_u) #print("v--",depth_v,"--",subtree_v) for w in range(1,n+1):#O(n-1) if depth_u[w] == l: r_u[subtree_u[w]] = w for w in range(1,n+1):#O(n-1) if depth_v[w] == l: r_v[subtree_v[w]] = w t = len(r_u) + len(r_v) if t > max_len: max_len = t #print("edge",e,"---",max_len) #print("max_lena vert--", max_len) return max_len def bfs(n,x,adj,y=-1): #depth[x]: longitud camino entre el vertice inicial y x visited = [False for i in range(n+1)] visited [x] = True depth = [-1 for _ in range(n+1)] subtree = [-1 for _ in range(n+1)] if y!=-1: visited[y] =True q = [x] depth[x] = 0 for w in adj[x]: subtree[w] = w while len(q) > 0: v = q[0] q.remove(v) for w in adj[v]: if not visited[w]: q.append(w) depth[w] = depth[v] + 1 if v!= x: subtree[w] = subtree[v] visited[w] = True return depth,subtree def max_degree(adj): m_d = 0 for x in adj: x_degree = len(x) if m_d < x_degree: m_d = x_degree return m_d def main(): n= int(input()) adj = [[]for i in range(n+1)] edges = [] for _ in range(n-1): x,y = [ int(i) for i in input().split()] edges.append((x,y)) adj[x].append(y) adj[y].append(x) max_len = almost_same_distance(n,adj,edges) print(' '.join(str(i) for i in max_len)) main() ``` No
106,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You are given a tree on n vertices. For each i between 1 and n, find the maximum size of an almost-i-uniform set. Input The first line contains a single integer n (2 ≤ n ≤ 5 ⋅ 10^5) – the number of vertices of the tree. Then n-1 lines follows, the i-th of which consisting of two space separated integers u_i, v_i (1 ≤ u_i, v_i ≤ n) meaning that there is an edge between vertices u_i and v_i. It is guaranteed that the given graph is tree. Output Output a single line containing n space separated integers a_i, where a_i is the maximum size of an almost-i-uniform set. Examples Input 5 1 2 1 3 1 4 4 5 Output 4 3 2 1 1 Input 6 1 2 1 3 1 4 4 5 4 6 Output 4 4 2 1 1 1 Note Consider the first example. * The only maximum almost-1-uniform set is \{1, 2, 3, 4\}. * One of the maximum almost-2-uniform sets is or \{2, 3, 5\}, another one is \{2, 3, 4\}. * A maximum almost-3-uniform set is any pair of vertices on distance 3. * Any single vertex is an almost-k-uniform set for k ≥ 1. In the second sample there is an almost-2-uniform set of size 4, and that is \{2, 3, 5, 6\}. Submitted Solution: ``` def almost_same_distance(n,adj,edges): max_deg =max_degree(adj) result = [max_deg+1] for k in range(2,n+1): max = find_almost_k_uniform(n,k,adj,edges) result.append(max) return result def find_almost_k_uniform(n,k,adj,edges): max_len = 0 if k % 2 == 1: max_len = find_k_odd(n,k,adj,edges) else: max_len = find_k_even(n,k,adj,edges) return max_len def find_k_odd(n,k,adj,edges): d_s = {} max_len = 0 for v in range(1,n+1): d_s[v] = bfs(n,v,adj) l = k//2 for v in range(1,n+1): r = {i:-1 for i in range(1,n+1)} #buscar un vertice de longitud l o l+1 por subarbol depth,subtree = d_s[v] for w in range(1,n+1): if depth[w] == l+1: r[subtree[w]] = l+1 if depth[w] == l and r[subtree[w]] == -1: r[subtree[w]] = l len_r = 0 found_l = False for t in r.values(): if t != -1: if t == l and not found_l: len_r += 1 found_l =True elif t== l+1: len_r += 1 if len_r > max_len: max_len = len_r print(r) return max_len def find_k_even(n,k,adj,edges): d_s = {} for v in range(1,n+1): d_s[v] = bfs(n,v,adj) max_len = 0 l = k/2 for v in range(1,n+1): depth,subtree = d_s[v] r = {} for w in range(1,n+1): if depth[w] == l: r[subtree[w]] = w if len(r) > max_len: max_len = len(r) #print("max_lena vert--", max_len) for e in edges:#O(n-1) u = e[0] v = e[1] r_u = {} r_v = {} depth_u,subtree_u = bfs(n,u,adj,v)#O(n-1) depth_v,subtree_v = bfs(n,v,adj,u) #print(e) #print("u--",depth_u,"--",subtree_u) #print("v--",depth_v,"--",subtree_v) for w in range(1,n+1):#O(n-1) if depth_u[w] == l: r_u[subtree_u[w]] = w for w in range(1,n+1):#O(n-1) if depth_v[w] == l: r_v[subtree_v[w]] = w t = len(r_u) + len(r_v) if t > max_len: max_len = t #print("edge",e,"---",max_len) #print("max_lena vert--", max_len) return max_len def bfs(n,x,adj,y=-1): #depth[x]: longitud camino entre el vertice inicial y x visited = [False for i in range(n+1)] visited [x] = True depth = [-1 for _ in range(n+1)] subtree = [-1 for _ in range(n+1)] if y!=-1: visited[y] =True q = [x] depth[x] = 0 for w in adj[x]: subtree[w] = w while len(q) > 0: v = q[0] q.remove(v) for w in adj[v]: if not visited[w]: q.append(w) depth[w] = depth[v] + 1 if v!= x: subtree[w] = subtree[v] visited[w] = True return depth,subtree def max_degree(adj): m_d = 0 for x in adj: x_degree = len(x) if m_d < x_degree: m_d = x_degree return m_d def main(): n= int(input()) adj = [[]for i in range(n+1)] edges = [] for _ in range(n-1): x,y = [ int(i) for i in input().split()] edges.append((x,y)) adj[x].append(y) adj[y].append(x) max_len = almost_same_distance(n,adj,edges) print(' '.join(str(i) for i in max_len)) main() ``` No
106,256
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` from math import ceil a = int(input()) for i in range(a): # n - days before deadline, d - days for the program to work n, d = map(int, input().split()) if d <= n: print("YES") else: counter = 1 current_n_of_days = counter + (ceil(d / (counter + 1))) previous_result = current_n_of_days + 1 while current_n_of_days <= previous_result: if current_n_of_days <= n: print("YES") break else: counter += 1 previous_result = current_n_of_days current_n_of_days = counter + (ceil(d / (counter + 1))) else: print("NO") ```
106,257
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` import os,sys from io import BytesIO, IOBase def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def li(): return list(mi()) import math for i in range(ii()): n,d=mi() if d<=n: print("YES") else: a=math.ceil(d/(n//2+1)) a+=n//2 if a<=n: print("YES") else: print("NO") ```
106,258
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` def arr_inp(): return [int(x) for x in stdin.readline().split()] from sys import stdin from math import ceil for i in range(int(input())): n, d = arr_inp() if n == d: print('YES') else: a, b, c, mi = 0, d, 2, d while (b >= a): b, a = ceil(d / c), a + 1 mi = min(mi, a + b) c += 1 print('YES' if n >= mi else 'NO') ```
106,259
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` import math #print(math.ceil(4.0)) t = int(input()) for i in range(0, t): n, d = map(int, input().split()) k = int(math.sqrt(d)) x = d #print("k=",k) if n <= k: x = min(x, int(n + 1 + math.ceil(d / (n + 1))-1) ) # print("x=",x) if k <= n: x = min(x, k + 1 + math.ceil(d / (k + 1))- 1) # print("x=", x) if k <= n + 1: x = min(x, k + math.ceil(d / k) -1) # print("x=", x) #print("n=",n) if x <= n: print("YES") else: print("NO") ```
106,260
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` import collections import math local = False if local: file = open("A.txt", "r") def inp(): if local: return file.readline().rstrip() else: return input().rstrip() def ints(): return [int(_) for _ in inp().split()] t = int(inp()) for _ in range(t): n, d = ints() if d<=n: print("YES") else: found = False for i in range(n): if i+math.ceil(d/(i+1))<=n: found=True break if found: print("YES") else: print("NO") ```
106,261
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` import io import os from collections import Counter, defaultdict, deque def solve(N, D): x = int((D + 0.25) ** 0.5 - 0.5) for i in range(max(0, x - 10), x + 10): days = i + D // (i + 1) if D % (i + 1) != 0: days += 1 if days <= N: return "YES" return "NO" if __name__ == "__main__": input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline T = int(input()) for t in range(T): N, D = [int(x) for x in input().split()] ans = solve(N, D) print(ans) ```
106,262
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` import math T=int(input()) for iT in range(T): n,d=[int(i) for i in input().split()] x=int(math.sqrt(d))-1 temp=x+math.ceil(d/(x+1)) print("YES" if (temp<=n or d==1 )else "NO") ```
106,263
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Tags: binary search, brute force, math, ternary search Correct Solution: ``` '''input 3 1 1 4 5 5 11 ''' # A coding delight from sys import stdin, stdout import gc gc.disable() input = stdin.readline import math def check(num): return num + math.ceil(d/(num + 1)) <= n # main starts t = int(input().strip()) for _ in range(t): n, d = list(map(int, input().split())) x = math.ceil(math.sqrt(d) - 1) if x + math.ceil(d/(x + 1)) <= n: print("YES") elif x - 1 >= 1 and x - 1 + math.ceil(d/x) <= n: print("YES") elif x + 1 + math.ceil(d/(x + 2)) <= n: print("YES") else: print("NO") ```
106,264
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` import sys from math import ceil tests = int(input()) for _ in range(tests): n, d = list(map(int, sys.stdin.readline().split())) ok = False for i in range(n, -1 ,-1): result = i + ceil(d/(i + 1)) if result <= n: print("YES") ok = True break if not ok: print("NO") ``` Yes
106,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` def func(x, d): #d_div_x = d // (x + 1) if d % (x + 1) == 0 else d // (x + 1) + 1 return x + d / (x + 1) # 14 def ternary_search_min(l, r, d): while r - l >= 3: m1 = int(r - 2 * (r - l) / 3) m2 = int(r - (r - l) / 3) if func(m1, d) <= func(m2, d): r = m2 else: l = m1 remain_args = [i for i in range(l, r + 1)] func_values = list(map(lambda x: func(x, d), remain_args)) return min(func_values) test_size = int(input()) for i in range(test_size): n, d = map(int, input().split()) min_days = ternary_search_min(0, n, d) if min_days <= n or d <= n: print("YES") else: print("NO") ``` Yes
106,266
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` from math import sqrt for w in range(int(input())): n,d = map(int,input().split()) print('yes') if 2*sqrt(d) <= n+1 else print('no') ``` Yes
106,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` import math t=int(input()) for _ in range(t): n,d=map(int,input().split()) x=n//2 y=math.ceil(d/(x+1)) if(x+y<=n): print('YES') else: print('NO') ``` Yes
106,268
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` for t in range(int(input())): n, d = [int(i) for i in input().split()] if d <= n: print("YES") elif (n-1)**2 + 4*(n-d) > 0: print("YES") else: print("NO") ``` No
106,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` import math t=int(input()) for i in range(t): n,d=map(int,input().split()) if d<=n: print("YES") else: m=int(pow(d,0.5)) z=m+math.ceil(d/(m+1)) #print(m) if z<=n: print("YES") else: print("NO") ``` No
106,270
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` import math for _ in range(int(input())): n,d=map(int,input().split()) if n>=d: print("YES") else: g=1 for i in range(1,n+1): if math.ceil((d/(i+1)))+i<=n: k=0 print("YES") break if g==1: print("NO") ``` No
106,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉. Will Adilbek be able to provide the generated results in no more than n days? Input The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases. The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs. Output Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise. Example Input 3 1 1 4 5 5 11 Output YES YES NO Note In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n. In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit. In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. Submitted Solution: ``` import math t = int(input()) while t: t-=1 n,d = map(int,input().split()) if d<=n or 1+math.ceil(d/(2))<=n or 2+math.ceil(d/3)<=n: print("YES") else: print("NO") ``` No
106,272
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` k=input().lower() h=int(k,16) print(h%2) ```
106,273
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` # d = {'0':0, '1': 1, '2':1, '3':2, '4':1,'5':2, '6':2,'7':3,'8':1,'9':2,'A':2} s = input() # count = 0 # for i in s: # count+=d[i] count = int(s[-1]) if(count%2==0): print('0') else: print('1') ```
106,274
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` if int(input(),16)%2==0: print(0) else: print(1) ```
106,275
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` n=input() if(int(n[len(n)-1])%2==0): print("0") else: print("1") ```
106,276
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` N = int(input()[-1]) print(N%2) ```
106,277
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` ans = int(input(), 16) if ans%2 == 0: print(0) else: print(1) ```
106,278
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` import math # Initialising hex string ini_string = input() # Code to convert hex to binary n = int(ini_string, 16) bStr = '' while n > 0: bStr = str(n % 2) + bStr n = n >> 1 res = bStr # Print the resultant string print(res[len(res) - 1]) ```
106,279
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Tags: *special, implementation Correct Solution: ``` str = input() res = int(str, 16) if res & 1 == 0: print(0) else: print(1) ```
106,280
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` # your code goes here a=input() if int(a[6])%2==0: print('0') else: print('1') ``` Yes
106,281
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` s=str(input()) t=0 if(int(s[len(s)-1])%2==0): print(0) else: print(1) ``` Yes
106,282
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` s = str(input()) a = int(s[-1]) if a % 2 == 0: print("0") else: print("1") ``` Yes
106,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` x = input() x = int(x,16) print(x % 2) ``` Yes
106,284
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` import random a=input() print(random.randrange(0,2,1)) ``` No
106,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` print("1") ``` No
106,286
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) s = input() s = s[1:] sum = 0 for x in s: sum += int(x) if sum % 10 == 8: print(1) else: print(0) ``` No
106,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A144045 Output 1 Submitted Solution: ``` inp = input() import random random.seed(inp) print(random.randint(0, 1)) ``` No
106,288
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` t = int(input()) for _ in range(t): a1, b1 = map(int, input().split()) a2, b2 = map(int, input().split()) x1 = min(a1, b1) + min(a2, b2) if max(a1, b1) == max(a2, b2): if x1 == max(a1, b1): print("YES") else: print("NO") else: print("NO") ```
106,289
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` for _ in range(int(input())): a = list(map(int,input().split())) b = list(map(int,input().split())) print('YES') if min(a)==(abs(b[1]-b[0])) and max(a)==max(b) else print('NO') ```
106,290
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() def test(): r1 = sorted(map(int, input().split())) r2 = sorted(map(int, input().split())) return ['No', 'Yes'][r1[0] + r2[0] == r1[1] == r2[1]] t = int(input()) for _ in range(t): print(test()) ```
106,291
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` num = int(input()) results = [] for T in range(num): x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] """ x[0] y[1] |--- | --| x[1] | | | y[0] |___ | __| x[0] x[1] |--------| |--------| y[0] |________| y[1] x[0] y[0] |--- | --| x[1] | | | y[1] |___ | __| x[1] y[1] |--- | --| x[0] | | | y[0] |___ | __| x[1] y[0] |--- | --| x[0] | | | y[1] |___ | __| """ result = \ ((x[1] == y[0]) and (x[1] == x[0] + y[1])) or \ ((x[1] == y[1]) and (x[1] == x[0] + y[0])) or \ ((x[0] == y[0]) and (x[0] == x[1] + y[1])) or \ ((x[0] == y[1]) and (x[0] == x[1] + y[0])) or \ ((y[1] == x[0]) and (y[1] == y[0] + x[1])) or \ ((y[1] == x[1]) and (y[1] == y[0] + x[0])) or \ ((y[0] == x[0]) and (y[0] == y[1] + x[1])) or \ ((y[0] == x[1]) and (y[0] == y[1] + x[0])) results.append(result) for result in results: print("Yes" if result else "No") ```
106,292
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` import math n=int(input()) for i in range(n): a=list(map(int,input().split())) b=list(map(int,input().split())) if(a[0]==b[0] and a[1]+b[1]==a[0]): print("Yes") elif(a[0]==b[1] and a[1]+b[0]==a[0]): print("Yes") elif(a[1]==b[0] and a[0]+b[1]==a[1]): print("Yes") elif(a[1]==b[1] and a[0]+b[0]==a[1]): print("Yes") else: print("No") ```
106,293
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` from itertools import combinations t = int(input()) for i in range(t): a1, b1 = input().split() a2, b2 = input().split() f = 0 if a1 == a2: if int(a1) == int(b1) + int(b2): print("YES") f = 1 if a1 == b2: if int(a1) == int(a2) + int(b1): print("YES") f = 1 if b1 == a2: if int(b1) == int(a1) + int(b2): print("YES") f = 1 if b1 == b2: if int(b1) == int(a2) + int(a1): print("YES") f = 1 if f == 0: print("NO") ```
106,294
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` t=int(input()) for _ in range(t): arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) arr3=[i for i in arr1 for j in arr2 if i==j] c1=0 c2=0 if(len(arr3)==0): print("No") continue #print(arr3) arr3[0]=max(arr3) for i in arr1: if arr3[0]!=i: c1=i for i in arr2: if arr3[0]!=i: c2=i #print(c1,c2) if arr3[0]==c1+c2: print("Yes") else: print("No") ```
106,295
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Tags: brute force, implementation, math Correct Solution: ``` # Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. # Input # The first line contains an integer t # (1≤t≤104) — the number of test cases in the input. Then t # test cases follow. # Each test case is given in two lines. # The first line contains two integers a1 # and b1 (1≤a1,b1≤100 # ) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). # The second line contains two integers a2 # and b2 (1≤a2,b2≤100 # ) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). # Output # Print t # answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). def fun(a,b,c,d): if a ==b or c==d: return False if max(a,b)==max(c,d) and min(a,b) + min(c,d) == max(a,b): return True return False for _ in range(int(input())): a,b = list(map(int,input().split())) c,d = list(map(int,input().split())) if fun(a,b,c,d): print("Yes") else: print("No") ```
106,296
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` t = int(input()) for _ in range(t) : n = [ int(i) for i in input().split() ] m = [ int(i) for i in input().split() ] ans = False if ( n[0] == m[0] and n[1]+m[1] == n[0] ) : ans = True elif ( n[0] == m[1] and n[1]+m[0] == n[0] ) : ans = True elif ( n[1] == m[0] and n[0]+m[1] == n[1] ) : ans = True elif ( n[1] == m[1] and n[0]+m[0] == n[1] ) : ans = True if ( ans ) : print("Yes") else : print("No") ``` Yes
106,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` def sqr(a,b): if max(sq1)==max(sq2): if min(sq1)+min(sq2)==max(sq1): return 'YES' return 'NO' n=int(input()) ans=[] for i in range(n): sq1=list(map(int,input().split())) sq2 = list(map(int, input().split())) ans.append(sqr(sq1,sq2)) for i in ans: print(i) ``` Yes
106,298
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given in two lines. The first line contains two integers a_1 and b_1 (1 ≤ a_1, b_1 ≤ 100) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers a_2 and b_2 (1 ≤ a_2, b_2 ≤ 100) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). Output Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). Example Input 3 2 3 3 1 3 2 1 3 3 3 1 3 Output Yes Yes No Submitted Solution: ``` t=int(input()) for i in range(t): a, b=map(int,input().split()) c, d=map(int,input().split()) if a==d and a == b+c: print("YES") elif a==c and a==b+d: print("YES") elif b==d and b==a+c: print("YES") elif b==c and b==a+d: print("YES") else: print("NO") ``` Yes
106,299