text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` import os,io from sys import stdout import collections # import random # import math # from operator import itemgetter input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import Counter # import heapq # from functools import lru_cache # import sys # sys.setrecursionlimit(10**6) # from functools import lru_cache # @lru_cache(maxsize=None) def primes(n): sieve = [True] * n for i in range(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,n,2) if sieve[i]] def binomial_coefficient(n, k): if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 def powerOfK(k, max): if k == 1: return [1] if k == -1: return [-1, 1] result = [] n = 1 while n <= max: result.append(n) n *= k return result def prefixSum(arr): for i in range(1, len(arr)): arr[i] = arr[i] + arr[i-1] return arr def divisors(n): i = 1 result = [] while i*i <= n: if n%i == 0: if n/i == i: result.append(i) else: result.append(i) result.append(n/i) i+=1 return result def kadane(a,size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if max_ending_here < 0: max_ending_here = 0 return max_so_far # @lru_cache(maxsize=None) def digitsSum(n): if n == 0: return 0 r = 0 while n > 0: r += n % 10 n //= 10 return r # INPUTS -------------------------- # s = input().decode('utf-8').strip() # n = int(input()) # l = list(map(int, input().split())) # t = int(input()) # for _ in range(t): n, m, k = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) if len(a) > len(b): print("YES") exit() if a[-1] > b[-1]: print("YES") exit() i = 0 j = 0 while i < len(a) and j < len(b): while j < len(b) and b[j] < a[i]: j += 1 if len(a) - i > len(b) - j: print("YES") exit() while i < len(a) and a[i] <= b[j]: i += 1 print("NO") exit() ```
97,300
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if (len(a) > len(b)) or (max(a) > max(b)): print("YES") else: a = sorted(a) b = sorted(b) ans = "NO" aa, bb = 0, 0 while (ans != "YES" and aa < len(a) and bb < len(b)): temp = a[aa] while (b[bb] < temp and bb < len(b)): bb += 1 if (bb == len(b)): ans = "YES" bb += 1 aa += 1 if (bb == len(b) and aa < len(a)): ans = "YES" print(ans) ```
97,301
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` rd = lambda: list(map(int, input().split())) rd() a = sorted(rd(), reverse=True) b = sorted(rd(), reverse=True) if len(a) > len(b): print("YES"); exit() for i in range(len(a)): if a[i] > b[i]: print("YES"); exit() print("NO") ```
97,302
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` import sys from math import gcd,sqrt,ceil from collections import defaultdict,Counter,deque from bisect import bisect_left,bisect_right import math from itertools import permutations # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # import sys # import io, os # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def get_sum(bit,i): s = 0 i+=1 while i>0: s+=bit[i] i-=i&(-i) return s def update(bit,n,i,v): i+=1 while i<=n: bit[i]+=v i+=i&(-i) def modInverse(b,m): g = math.gcd(b, m) if (g != 1): return -1 else: return pow(b, m - 2, m) def primeFactors(n): sa = set() sa.add(n) while n % 2 == 0: sa.add(2) n = n // 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: sa.add(i) n = n // i # sa.add(n) return sa def seive(n): pri = [True]*(n+1) p = 2 while p*p<=n: if pri[p] == True: for i in range(p*p,n+1,p): pri[i] = False p+=1 return pri def check_prim(n): if n<0: return False for i in range(2,int(sqrt(n))+1): if n%i == 0: return False return True n,m,k = map(int,input().split()) hash1 = defaultdict(int) hash2 = defaultdict(int) l1 = list(map(int,input().split())) l2 = list(map(int,input().split())) w = defaultdict(lambda : 1) ha = set() for i in l1: hash1[i]+=1 ha.add(i) for i in l2: hash2[i]+=1 ha.add(i) w1,w2 = 0,0 ha = list(ha) ha.sort() prev = 1 for i in ha: z1,z2 = hash1[i],hash2[i] if hash2[i]>=hash1[i]: w[i] = prev else: if w1>=w2: w[i] = prev+1 else: w[i] = w2-w1 + 2 w1+=hash1[i]*w[i] w2+=hash2[i]*w[i] prev = w[i] if w1>w2: print('YES') else: print('NO') ```
97,303
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` a, b, _c = map(int, input().split()) af = list(map(int, input().split())) bf = list(map(int, input().split())) af.sort(reverse = True) bf.sort(reverse = True) aflen = len(af) bflen = len(bf) i = 0 j = 0 cnt = 0 while i < aflen and j < bflen: if af[i] > bf[j]: cnt += 1 i += 1 elif af[i] < bf[j]: cnt -= 1 j += 1 else: i += 1 j += 1 if cnt > 0: print("YES") break else: cnt += aflen - i if cnt > 0: print("YES") else: print("NO") ```
97,304
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` n,m,k=map(int,input().split()) Alice=list(map(int,input().split())) Bob=list(map(int,input().split())) SA={} SB={} for item in Alice: if(item in SA): SA[item]+=1 continue SA[item]=1 SB[item]=0 for item in Bob: if(item in SB): SB[item]+=1 continue SB[item]=1 SA[item]=0 x=sorted(list(set(Alice+Bob)),reverse=True) n=len(x) done=False i=0 needed=0 while(i<n): if(SA[x[i]]-SB[x[i]]>needed): print("YES") done=True break needed+=SB[x[i]]-SA[x[i]] i+=1 if(not done): print("NO") ```
97,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n > m: print('YES') else: a.sort() b.sort() b = b[-n:] ans = 'NO' for i in range(n): if a[i] > b[i]: ans = 'YES' print(ans) ``` Yes
97,306
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` from collections import defaultdict n, k, p = 0, 0, defaultdict(int) input() for i in map(int, input().split()): p[i] += 1 for i in map(int, input().split()): p[i] -= 1 r = sorted(list(p.keys()), reverse = True) for i in r: n += p[i] if n > 0: break print('YES' if n > 0 else 'NO') ``` Yes
97,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) ans = 'NO' if n > m: ans = 'YES' else: for i in range(n): if a[i] > b[i]: ans = 'YES' print(ans) ``` Yes
97,308
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort(key=lambda x:-x) b.sort(key=lambda x: -x) t=False n1=min(m,n) if n>m: t=True else: for i in range (n1): if a[i]>b[i]: t=True if t: print('YES') else: print('NO') ``` Yes
97,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` a, b, _c = map(int, input().split()) af = list(map(int, input().split())) bf = list(map(int, input().split())) af.sort(reverse = True) bf.sort(reverse = True) aflen = len(af) bflen = len(bf) i = 0 j = 0 cnt = 0 while i < aflen and j < bflen: if af[i] > bf[j]: cnt += 1 i += 1 elif af[i] < bf[j]: cnt -= 1 j += 1 else: i += 1 j += 1 if cnt > 0: print("YES") break else: print("NO") ``` No
97,310
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` import sys def intersect(a, b): new_a, new_b = [], [] while len(a) != 0 and len(b) != 0: if a[0] == b[0]: a = a[1:] b = b[1:] continue if a[0] < b[0]: new_a.append(a[0]) a = a[1:] else: new_b.append(b[0]) b = b[1:] if len(a) != 0: new_a += a if len(b) != 0: new_b += b return new_a, new_b num_alice, num_bob, n_types = tuple(int(x) for x in sys.stdin.readline().split()) alice = sorted([int(x) for x in sys.stdin.readline().split()]) bob = sorted([int(x) for x in sys.stdin.readline().split()]) a, b = intersect(alice, bob) if len(a) == 0: print("NO") sys.exit(0) max_a = a[-1] b = [x for x in b if x >= max_a] if len(a) <= len(b): print("NO") else: print("YES") ``` No
97,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up down """ n, m, k = I() a = I() b = I() s = sorted(set(a + b), reverse = True) A = dd(int) ans = 'NO' for i in a: A[i] += 1 for i in b: A[i] -= 1 for i in s: if A[i] == 0: continue if A[i] > 0: ans = 'YES' if n > m: ans = 'YES' print(ans) ``` No
97,312
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Submitted Solution: ``` class CodeforcesTask297BSolution: def __init__(self): self.result = '' self.n_m_k = [] self.alice = [] self.bob = [] def read_input(self): self.n_m_k = [int(x) for x in input().split(" ")] self.alice = [int(x) for x in input().split(" ")] self.bob = [int(x) for x in input().split(" ")] def process_task(self): if self.n_m_k[0] > self.n_m_k[1]: self.result = "YES" elif self.n_m_k[0] == self.n_m_k[1]: if abs(max(self.bob) - max(self.alice)) <= 1: self.result = "YES" elif max(self.alice) >= max(self.bob): self.result = "YES" else: self.result = "NO" else: if max(self.alice) > max(self.bob): self.result = "YES" else: self.result = "NO" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask297BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ``` No
97,313
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` n, m = map(int, input().split()) (a, d) = ([], []) for i in range(n): t, val = input().split() (a if t == 'ATK' else d).append(int(val)) my = sorted([int(input()) for i in range(m)]) a.sort() d.sort() def solve1(): ret = 0 used = [False] * m for val in d: for i in range(m): if not used[i] and my[i] > val: used[i] = True break else: return 0 for val in a: for i in range(m): if not used[i] and my[i] >= val: used[i] = True ret += my[i] - val break else: return 0 return ret + sum([my[i] for i in range(m) if not used[i]]) def solve2(): ret = 0 for k in range(min(len(a), m)): if my[-k-1] >= a[k]: ret += my[-k-1] - a[k] else: break return ret print(max(solve1(), solve2())) ```
97,314
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` import sys n, m = map(int, input().split()) atk = [] dfs = [] for _ in range(n): t, s = input().split() (atk if t == "ATK" else dfs).append(int(s)) atk = sorted(atk) dfs = sorted(dfs) mine = sorted([int(input()) for _ in range(m)]) def s1(): ret = 0 done = [False] * m for s in dfs: check = False for i in range(m): if not done[i] and mine[i] > s: check = True done[i] = True break if not check: return 0 for s in atk: check = False for i in range(m): if not done[i] and mine[i] >= s: check = True done[i] = True ret += mine[i] - s break if not check: return 0 for i in range(m): if not done[i]: ret += mine[i] return ret def s2(): ret = 0 for i in range(m): alc = 0 for j in range(min(m - i, len(atk))): if mine[i + j] < atk[j]: break else: alc += mine[i + j] - atk[j] ret = max(ret, alc) return ret print(max(s1(), s2())) ```
97,315
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` n, m = map(int, input().split()) u = [[], []] for q in range(n): p, s = input().split() u[p == 'ATK'].append(int(s)) d, a = [sorted(q) for q in u] v = sorted(int(input()) for q in range(m)) k, s = 0, sum(v) i = j = 0 for q in v: if i < len(d) and q > d[i]: s -= q i += 1 elif j < len(a) and q >= a[j]: s -= a[j] j += 1 if i + j - len(a) - len(d): s = 0 for q in v: if k < len(a) and q >= a[k]: k += 1 x = y = 0 v.reverse() for i in range(k): x += a[i] y += v[i] s = max(s, y - x) print(s) ```
97,316
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` n , m = map(int , input().split()) a , d = [1e9] , [1e9] for x in range(n) : p , s = input().split() [d , a][p < 'B'].append(int(s)) v = [int(input()) for y in range(m) ] for q in [a , d , v] : q.sort() s = sum(v) i = j = 0 for t in v : if t > d[i] : s , i = s - t , i + 1 elif t >= a[j] : s , j = s - a[j] , j + 1 if i + j - n : s = 0 print(max(s , sum(max(0 , y - x) for x , y in zip(a, v[::-1])))) ```
97,317
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` n, m = map(int, input().split()) (a, d) = ([], []) for i in range(n): t, val = input().split() (a if t == 'ATK' else d).append(int(val)) my = sorted([int(input()) for i in range(m)]) a.sort() d.sort() def solve1(): ret = 0 used = [False] * m for val in d: for i in range(m): if not used[i] and my[i] > val: used[i] = True break else: return 0 for val in a: for i in range(m): if not used[i] and my[i] >= val: used[i] = True ret += my[i] - val break else: return 0 return ret + sum([my[i] for i in range(m) if not used[i]]) def solve2(): ret = 0 my.reverse() for k in range(min(len(a), m)): if my[k] >= a[k]: ret += my[k] - a[k] else: break return ret print(max(solve1(), solve2())) ```
97,318
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` n, m = map(int, input().split()) (a, d, my) = ([], [], []) for i in range(n): t, val = input().split() (a if t == 'ATK' else d).append(int(val)) my = sorted([int(input()) for i in range(m)]) a.sort() d.sort() def solve1(): ret = 0 used = [False] * m for val in d: for i in range(m): if not used[i] and my[i] > val: used[i] = True break else: return 0 for val in a: for i in range(m): if not used[i] and my[i] >= val: used[i] = True ret += my[i] - val break else: return 0 ret += sum([my[i] for i in range(m) if not used[i]]) return ret def solve2(): ret = 0 my.reverse() for k in range(0, min(len(a), m)): if my[k] >= a[k]: ret += my[k] - a[k] else: break return ret print(max(solve1(), solve2())) ```
97,319
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` n, m = map(int, input().split()) (a, d) = ([], []) for i in range(n): t, val = input().split() (a if t == 'ATK' else d).append(int(val)) my = sorted([int(input()) for i in range(m)]) a.sort() d.sort() def solve1(): ret = 0 used = [False] * m for val in d: for i in range(m): if not used[i] and my[i] > val: used[i] = True break else: return 0 for val in a: for i in range(m): if not used[i] and my[i] >= val: used[i] = True ret += my[i] - val break else: return 0 return ret + sum([my[i] for i in range(m) if not used[i]]) def solve2(): ret = 0 for k in range(min(len(a), m)): if my[-k-1] >= a[k]: ret += my[-k-1] - a[k] else: break return ret print(max(solve1(), solve2())) # Made By Mostafa_Khaled ```
97,320
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Tags: dp, flows, greedy Correct Solution: ``` def avoiddef(a,b): b.reverse() x = 0 i = 0 n = min(len(a),len(b)) while i<n and b[i]>a[i]: x += b[i]-a[i] i += 1 return x def killdefs(d,a,b): i = 0 n = len(b) b2 = [bb for bb in b] for dd in d: while i<n and b2[i]<=dd: i += 1 if i==n: return -1 #fail to kill all defs! b2[i]= 0 i += 1 b2.sort() x = 0 i = 0 for aa in a: while i<n and b2[i]<aa: i += 1 if i==n: return -1 #failed to kill all atks! i += 1 return sum(b2)-sum(a) def f(a,bl): al = [int(c[1]) for c in a if c[0]=='ATK'] dl = [int(c[1]) for c in a if c[0]=='DEF'] al.sort() dl.sort() bl.sort() return max(killdefs(dl,al,bl),avoiddef(al,bl)) n,m = list(map(int,input().split())) a = [input().split() for _ in range(n)] b = [int(input()) for _ in range(m)] print(f(a,b)) ```
97,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Submitted Solution: ``` n,m = map(int,input().split()) jiro = [] for i in range(n): tmp=input().split() tmp[1]=int(tmp[1]) jiro.append(tmp) ciel = [] for i in range(m): ciel.append(int(input())) a,b,c=0,0,0 #case #1: All-in ciel.sort(reverse=True) jiro.sort(key=lambda x:x[0]) jiro.sort(key=lambda x:x[1]) sm = 0 ji = 0 for i in ciel: if i > jiro[ji][1]: sm += i - jiro[ji][1] else: break ji += 1 if ji >= len(jiro) or jiro[ji][0] == 'DEF': break a=(sm) #case #1.5: Defeat all jiro.sort(key=lambda x:x[1],reverse=True) sm = 0 ji = 0 for i in (i for i in jiro if i[0] != 'DEF'): if i[1] < ciel[ji]: sm += ciel[ji] - i[1] else: break ji += 1 if ji >= len(ciel): break b=(sm) #case #2: Defeat all sm = 0 ji = 0 fst =0 for i in (i for i in jiro if i[0] == 'DEF'): x=-1 for j in range(len(ciel)): if ciel[j] > i[1]: x=j break if x==-1: fst=1 break del ciel[x] if fst ==0: for i in (i for i in jiro if i[0] != 'DEF'): if i[1] < ciel[ji]: sm += ciel[ji] - i[1] del ciel[ji] else: fst=1 break if len(ciel)<=0: fst=1 break if fst ==0: sm += sum(ciel) c=(sm) print(max(a,b,c)) ``` No
97,322
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Submitted Solution: ``` n,m=map(int,input().split()) ja=list() jd=list() for i in range(n): p,s=input().split() s=int(s) if(p=="ATK"): ja.append(s) else: jd.append(s) ca=list(int(input()) for i in range(m)) ja.sort() jd.sort() ca.sort() ca2=ca[:] w=False for i in jd: for j in range(len(ca)): if(ca[j]>i): ca.pop(j) w=True break if not w: break d=0 if(w): ja.reverse() ca.reverse() for i in range(len(ja)): if(ja[i]>ca[i]): w=False break if(w): print(sum(ca)-sum(ja)) else: ca=ca2[:] ca2.reverse() d=0 n=0 for i in range(len(ca2)): if(ca2[i]>=ja[i]): d+=ca2[i]-ja[i] n+=1 else: break if(n==len(ja)): d=sum(ca2)-sum(ja) print(d) ``` No
97,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Submitted Solution: ``` n, m = map(int, input().split()) u = [[], []] for i in range(n): p, s = input().split() u[p == 'ATK'].append(int(s)) d, a = [sorted(q) for q in u] v = sorted(int(input()) for q in range(m)) s = k = 0 for q in v: if k < len(a) and q >= a[k]: k += 1 x = y = 0 v.reverse() for i in range(k): x += a[i] y += v[i] s = max(s, y - x) t = sum(v) i = j = 0 for q in v: if i < len(d) and q > d[i]: t -= q i += 1 elif j < len(a) and q >= a[j]: t -= a[j] j += 1 if i + j - len(a) - len(d): t = 0 print(max(s, t)) ``` No
97,324
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards X. This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: * If Y's position is Attack, then (X's strength) ≥ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). * If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get. Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card. Output Output an integer: the maximal damage Jiro can get. Examples Input 2 3 ATK 2000 DEF 1700 2500 2500 2500 Output 3000 Input 3 4 ATK 10 ATK 100 ATK 1000 1 11 101 1001 Output 992 Input 2 4 DEF 0 ATK 0 0 0 1 1 Output 1 Note In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000. In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992. In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. Submitted Solution: ``` class KM: def __init__(self, n, graph): self.n = n self.graph = graph # adjacent matrix self.Lx = [max(self.graph[i]) for i in range(self.n)] self.Ly = [0] * n self.slack = None self.S = None self.T = None self.matched = [-1] * n def match(self, u): self.S[u] = True for v in range(self.n): # v is already in the cross road if self.T[v]: continue t = self.Lx[u] + self.Ly[v] - self.graph[u][v] if not t: self.T[v] = True if self.matched[v] == -1 or self.match(self.matched[v]): self.matched[v] = u return True else: self.slack[v] = min(self.slack[v], t) return False def update(self): d = min(self.slack[i] for i in range(self.n) if not self.T[i]) for i in range(self.n): if self.S[i]: self.Lx[i] -= d for i in range(self.n): if self.T[i]: self.Ly[i] += d else: self.slack[i] -= d def km(self): for i in range(self.n): self.slack = [0x7fffffff] * self.n while True: self.S = [False] * self.n self.T = [False] * self.n if self.match(i): break else: self.update() return sum(self.graph[self.matched[i]][i] for i in range(self.n) if self.matched[i] != -1) # http://codeforces.com/contest/321/problem/B if __name__ == '__main__': inf = 0x7fffffff maxn = 500 graph = [] for i in range(maxn): graph.append([0] * maxn) n, m = [int(x) for x in input().split()] jiro = [input().split() for i in range(n)] ciel = [int(input()) for i in range(m)] for i in range(m): for j in range(n): if jiro[j][0] == 'ATK': if ciel[i] >= int(jiro[j][1]): graph[i][j] = ciel[i] - int(jiro[j][1]) ans = KM(m, graph).km() if m > n: for i in range(m): for j in range(n, m): graph[i][j] = ciel[i] for i in range(m): for j in range(n): if jiro[j][0] == 'ATK': if ciel[i] >= int(jiro[j][1]): graph[i][j] = ciel[i] - int(jiro[j][1]) else: graph[i][j] = -inf else: if ciel[i] > int(jiro[j][1]): graph[i][j] = 0 else: graph[i][j] = -inf ans = max(ans, KM(m, graph).km()) print(ans) ``` No
97,325
Provide tags and a correct Python 3 solution for this coding contest problem. This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points. Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort. After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n + 1 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here. Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible. Input The first line contains a pair of integers n and k (1 ≤ k ≤ n + 1). The i-th of the following n lines contains two integers separated by a single space — pi and ei (0 ≤ pi, ei ≤ 200000). The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. * In subproblem C1 (4 points), the constraint 1 ≤ n ≤ 15 will hold. * In subproblem C2 (4 points), the constraint 1 ≤ n ≤ 100 will hold. * In subproblem C3 (8 points), the constraint 1 ≤ n ≤ 200000 will hold. Output Print a single number in a single line — the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1. Examples Input 3 2 1 1 1 4 2 2 Output 3 Input 2 1 3 2 4 0 Output -1 Input 5 2 2 10 2 10 1 1 3 1 3 1 Output 12 Note Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place. Consider the second test case. Even if Manao wins against both opponents, he will still rank third. Tags: brute force Correct Solution: ``` m = 301000 ns = [0] * m es = [0] * m c = [0] * m b = [0] * m t = [0] * m P = 0 def add(b, k): k = t[k] while k: e = es[k] if b[-1] > e: b[-1] = e b[e] += 1 k = ns[k] def delete(b): for i in range(b[m - 1], m + 1): if b[i]: b[i] -= 1 b[-1] = i return i def calc(k): global b q = 0 b = [0] * m b[-1] = m take = rank - dn if take < 0: take = 0 add(b, k) add(b, k - 1) for i in range(1, take + 1): q += delete(b) for i in range(k - 1): add(b, i) for i in range(k + 1, P + 1): add(b, i) for i in range(1, k - take + 1): q += delete(b) return q n, k = map(int, input().split()) rank = n - k + 1 if rank == 0: print('0') exit(0) for i in range(1, n + 1): p, e = map(int, input().split()) if p > P: P = p c[p] += 1 es[i], ns[i] = e, t[p] t[p] = i dn = 0 for i in range(1, n + 1): if i > 1: dn += c[i - 2] if c[i] + c[i - 1] + dn >= rank and rank <= i + dn: u = calc(i) if i < n: dn += c[i - 1] v = calc(i + 1) if u > v: u = v if i < n - 1: dn += c[i] v = calc(i + 2) if u > v: u = v print(u) exit(0) print('-1') ```
97,326
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programmers from the R2 company love playing 2048. One day, they decided to invent their own simplified version of this game — 2k on a stripe. Imagine an infinite in one direction stripe, consisting of unit squares (the side of each square is equal to the height of the stripe). Each square can either be empty or contain some number. Initially, all squares are empty. Then at infinity one of the unit squares number 2 or 4 appears. Then the player presses a button once, and the appeared number begins to move towards the beginning of the stripe. Let's assume that some number x moves to the beginning of the stripe, then it will stop if: 1. it either gets in the first square of the stripe; 2. or it is in the square that is preceded by a square with number y (y ≠ x). But if number x at some point of time gets to the square with the same number then both numbers add to each other and result in 2x. The new number 2x continues moving to the beginning of the stripe by the same rules. After the final stop of the number moving process, the infinity gets a new number 2 or 4 and the process repeats. Read the notes to the test samples to better understand the moving strategy. I guess you've understood that the game progress fully depends on the order in which numbers 2 and 4 appear. Let's look at some sequence of numbers 2 and 4 in the game. We assume that the sequence is winning if it results in at least one square getting the number greater or equal than 2k. The goal of the game is to make up a winning sequence of n numbers. But not everything is so simple, some numbers in the sequence are identified beforehand. You are given a sequence consisting of numbers 0, 2, 4. Count how many ways there are to replace each 0 of the sequence with 2 or 4 to get a winning sequence. Input The first line contains two integers n and k (1 ≤ n ≤ 2000; 3 ≤ k ≤ 11). The next line contains sequence of n integers, each of them is either 0, or 2, or 4. Output Print a single integer — the number of ways to replace zeroes by numbers 2 or 4 to get a winning sequence. As this number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 7 4 2 2 4 2 2 2 2 Output 1 Input 1 3 0 Output 0 Input 2 3 0 4 Output 1 Input 5 4 2 0 0 4 4 Output 2 Note Consider the first example. The beginning of the strip will look as follows: 2 → 4 → 8 → 8 2 → 8 4 → 8 4 2 → 16. To better understand the game, you can see the original game on http://gabrielecirulli.github.io/2048/. Please note that the game that is described on the strip is slightly different from the original game (when the two numbers add up in the original game, they do not keep moving). Be careful, the game is addictive, there isn't much time for the contest! Submitted Solution: ``` n, k = map(int, input().split()) seq = list(map(int, input().split())) tmp = [0] for x in seq: if x == 2: tmp[-1] += 1 elif x == 4: tmp[-1] += 2 else: tmp.append(0) need = (1 << k - 1) - sum(tmp) - len(tmp) + 1 if need <= 0: print((1 << len(tmp) - 1) % 1000000007) elif need <= len(tmp) - 1: print((1 << len(tmp) - 1 - need) % 1000000007) else: print(0) ``` No
97,327
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programmers from the R2 company love playing 2048. One day, they decided to invent their own simplified version of this game — 2k on a stripe. Imagine an infinite in one direction stripe, consisting of unit squares (the side of each square is equal to the height of the stripe). Each square can either be empty or contain some number. Initially, all squares are empty. Then at infinity one of the unit squares number 2 or 4 appears. Then the player presses a button once, and the appeared number begins to move towards the beginning of the stripe. Let's assume that some number x moves to the beginning of the stripe, then it will stop if: 1. it either gets in the first square of the stripe; 2. or it is in the square that is preceded by a square with number y (y ≠ x). But if number x at some point of time gets to the square with the same number then both numbers add to each other and result in 2x. The new number 2x continues moving to the beginning of the stripe by the same rules. After the final stop of the number moving process, the infinity gets a new number 2 or 4 and the process repeats. Read the notes to the test samples to better understand the moving strategy. I guess you've understood that the game progress fully depends on the order in which numbers 2 and 4 appear. Let's look at some sequence of numbers 2 and 4 in the game. We assume that the sequence is winning if it results in at least one square getting the number greater or equal than 2k. The goal of the game is to make up a winning sequence of n numbers. But not everything is so simple, some numbers in the sequence are identified beforehand. You are given a sequence consisting of numbers 0, 2, 4. Count how many ways there are to replace each 0 of the sequence with 2 or 4 to get a winning sequence. Input The first line contains two integers n and k (1 ≤ n ≤ 2000; 3 ≤ k ≤ 11). The next line contains sequence of n integers, each of them is either 0, or 2, or 4. Output Print a single integer — the number of ways to replace zeroes by numbers 2 or 4 to get a winning sequence. As this number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 7 4 2 2 4 2 2 2 2 Output 1 Input 1 3 0 Output 0 Input 2 3 0 4 Output 1 Input 5 4 2 0 0 4 4 Output 2 Note Consider the first example. The beginning of the strip will look as follows: 2 → 4 → 8 → 8 2 → 8 4 → 8 4 2 → 16. To better understand the game, you can see the original game on http://gabrielecirulli.github.io/2048/. Please note that the game that is described on the strip is slightly different from the original game (when the two numbers add up in the original game, they do not keep moving). Be careful, the game is addictive, there isn't much time for the contest! Submitted Solution: ``` s = input() if s == 'FCF': print('Yes') elif 'C' in s and 'F' in s and s.index('C') < s.index('F'): print("Yes") else: print("No") ``` No
97,328
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n=int(input()) movie=list(map(int,input().strip().split())) movie.sort() for i in range(1,n+1): if(i in movie): movie.remove(i) #print(i) else: print(i) break ```
97,329
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n-1): if a[0]!=1: print(1) break elif a[i]==n-1: print(n) break elif a[i]+1!=a[i+1]: print(a[i]+1) break ```
97,330
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n=int(input()) a=list(range(1,n+1)) s=list(map(int,input().split())) a=set(a) s=set(s) p=a.difference(s) p=list(p) print(p[0]) ```
97,331
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n = int(input()) array = input().split(" ") nar = [] for i in range(len(array)): nar.append(int(array[i])) nar.sort() for i in range(n-2): if nar[i+1]-nar[i]>1: print(i+2) exit() if nar[0] == 2: print(1) exit() print(n) ```
97,332
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n=int(input()) arr=list(map(int,input().split())) print(int((n*(n+1))/2)-sum(arr)) ```
97,333
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` #!/usr/bin/python3 n = int(input()) s = [int(v) for v in input().split()] t = sum(range(1, n+1)) for i in s: t -= i print(t) ```
97,334
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n = int(input()); print(int((1+n)/2*n-sum(list(map(int,input().split()))))) ```
97,335
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Tags: implementation Correct Solution: ``` n = int(input()) e = list(map(int,input().split())) print(int(n*(n+1)/2)-sum(e)) ```
97,336
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` import sys input=sys.stdin.buffer.readline n=int(input()) arr=list(map(int,input().split())) arr.sort() z=0 for i in range(0,n-1): if arr[i]==i+1: continue else: print(i+1) z=1 break if z==0: print(n) ``` Yes
97,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n = int(input()) sum = n * (n + 1) // 2 for x in map(int, input().split()): sum -= x print(sum) ``` Yes
97,338
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n=int(input()); l=list(map(int,input().split())) l.sort() for i in range(1,n+1): if i==n:print(n); break if l[i-1]!=i :print(i);break ``` Yes
97,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) l=set(l) l1=[i for i in range(1,n+1)] l1=set(l1) l1=l1-l l1=list(l1) l1 = [str(i) for i in l1] print(" ".join(l1)) ``` Yes
97,340
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n = int(input()) arr = sum(map(int, input().split())) print(((n*n+1)//2)-arr) ``` No
97,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n = int(input()) l = list(map(int,input().split())) l.sort() flag = 0 for i in range(1,n-1): if i == l[i-1]: continue else: flag = 1 print(i) break if flag == 0: print(n) ``` No
97,342
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n = int (input()) m=map(int,input().split()[:n]) m = sorted(m) k=0 for i in range(n-2): if m[i]+1 != m[i+1]: print (m[i]+1) break else: k+=1 #print(k) if k==n-2: print(n) if m[0]!=1: print(1) elif k==n-2: print(n) ``` No
97,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct. Output Print the number of the episode that Polycarpus hasn't watched. Examples Input 10 3 8 10 1 7 9 6 5 2 Output 4 Submitted Solution: ``` n=int(input()) lst1=[int(i) for i in input().split()] lst2=list(range(1,n+1)) lst1.sort() for i in range(0,n): if lst2[i]!=lst1[i]: print(i) break ``` No
97,344
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` # -*- coding: utf-8 -*- import sys from heapq import heappush, heappop, heapify def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 N = INT() A = LIST() A = [-a for a in A] heapify(A) ans = 0 while len(A) > 1: a = heappop(A) b = heappop(A) ans += -(a+b) heappush(A, a+b) ans += -A[0] print(ans) ```
97,345
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` N = int(input()) ints = list(map(int, input().split())) ints = sorted(ints) cum_sum = [0] * (N+1) for i in range(N): cum_sum[i+1] = cum_sum[i] + ints[i] res = sum(ints) for i in range(1,N): res += ints[i-1] + (cum_sum[-1]-cum_sum[i]) print(res) ```
97,346
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` from collections import Counter import string import bisect #import random import math import sys # sys.setrecursionlimit(10**6) from fractions import Fraction def array_int(): return [int(i) for i in sys.stdin.readline().split()] def vary(arrber_of_variables): if arrber_of_variables==1: return int(sys.stdin.readline()) if arrber_of_variables>=2: return map(int,sys.stdin.readline().split()) def makedict(var): return dict(Counter(var)) testcases=1 for _ in range(testcases): n=vary(1) num=array_int() num.sort() sumt=0 for i in range(n-1): sumt+=num[i]*(i+2) print(sumt+n*num[-1]) ```
97,347
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` import itertools input() a = list(map(int, str.split(input()))) a.sort(reverse=True) print(sum(itertools.accumulate(a)) + sum(a) - max(a)) ```
97,348
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) a.sort() ans = n*a[-1] for i in range(n-1): ans += (i+2)*a[i] print(ans) ```
97,349
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` n = int(input()) num = list(map(int, input().split())) num.sort(reverse=True) psum = [0]*n psum[0] = num[0] for i in range(1, n): psum[i] = psum[i-1]+num[i] print(sum(psum[1:])+psum[n-1]) ```
97,350
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` def main(): n = int(input()) seq = [int(c) for c in input().split()] if n == 1: print(seq[0]) return seq.sort() s = sum(seq) ans = 2 * s for i in range(n-2): s -= seq[i] ans += s print(ans) if __name__ == "__main__": main() ```
97,351
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Tags: greedy, sortings Correct Solution: ``` from heapq import * def main(): n = int(input()) s = [int(a) for a in map(int, input().split())] heapify(s) res = sum(s) ans = res for i in range(n - 1): x = heappop(s) res -= x ans += x + res print(ans) if __name__ == '__main__': main() ```
97,352
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` n = int(input()) nums = list( map(int,input().split(" "))) nums.sort() ans = 0 l = len(nums) if l == 1: print(nums[0]) else: for i in range(l - 2): ans += (i + 2) * nums[i] ans += (nums[-1] + nums[-2]) * l print(ans) ``` Yes
97,353
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` #!/usr/bin/env python3 n = int(input()) a = sorted(int(x) for x in input().split()) count = 0 for i in range(n): count += (i+2) * a[i] print(count - a[-1]) ``` Yes
97,354
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` n=int(input()) lis=sorted(list(map(int,input().split()))) ans=0 for i in range(n):ans+=(i+2)*lis[i] ans-=lis[-1] print(ans) ``` Yes
97,355
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` from heapq import heappush, heappop """ でかい数を後に残した方がいいに決まってる """ n = int(input()) v = [int(i) for i in input().split()] ans = sum(v) s = ans q = [] for i in range(n): heappush(q, v[i]) v = None while len(q) > 1: t = heappop(q) s -= t ans += t ans += s print(ans) ``` Yes
97,356
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` from collections import deque # N = 3 # L = [3, 1, 5] N = int(input()) L = list(map(int,input().split())) ans = sum(L) L.sort() queue = deque([L[0], L[1:]]) while queue: a = queue.popleft() b = queue.popleft() if a: ans += a if b: ans += sum(b) b.sort() queue.append(b[0]) queue.append(b[1:]) print(ans) ``` No
97,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` N = int(input()) ints = list(map(int, input().split())) def T(large, small): if len(large) == 0: return 0 s = min(large) return sum(large) + sum(small) + T( [i for i in large if i != s], [s]) small = min(ints) print(sum(ints) + T([i for i in ints if i != small], [small])) ``` No
97,358
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` #!/snap/bin/pypy3 def main(): n = int(input()) numbers = set(map(int, input().split())) ans = 0 while len(numbers) > 1: print(numbers) a = max(numbers) numbers.remove(a) b = max(numbers) numbers.remove(b) ans += a + b numbers.add(a + b) print(ans + sum(numbers)) if __name__ == '__main__': main() ``` No
97,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman. Output Print a single integer — the largest possible score. Examples Input 3 3 1 5 Output 26 Input 1 10 Output 10 Note Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. Submitted Solution: ``` def main(): n = int(input()) seq = [int(c) for c in input().split()] seq.sort() s = sum(seq) ans = 2 * s for i in range(n-2): s -= seq[i] ans += s print(ans) if __name__ == "__main__": main() ``` No
97,360
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` (m, n) = map(int, input().split(' ')) B = [] for i in range(0,m): row = [int(x) for x in input().split(' ')] B.append(row) B_ = [] for j in range(0,n): col = [B[i][j] for i in range(0,m)] B_.append(col) for row in B: if 1 in row: if 0 in row: for j in range(0,n): col = [B[i][j] for i in range(0,m)] if (row[j]==1 and 0 in col): print("NO") exit() for col in B_: if 1 in col: if 0 in col: for i in range(0,m): row = [B[i][j] for j in range(0,n)] if (col[i]==1 and 0 in row): print("NO") exit() only1 = False only0 = False for row in B: if 1 not in row: only0 = True if 0 not in row: only1 = True if only1 and only0: print("NO") exit() only1 = False only0 = False for col in B_: if 1 not in col: only0 = True if 0 not in col: only1 = True if only1 and only0: print("NO") exit() A = [[0 for col in range(0,n)] for row in range(0,m)] R = [] for i in range(0,m): flg = 1 for j in range(0,n): if B[i][j] == 0: flg = 0 break if flg == 1: R.append(i) C = [] for j in range(0,n): flg = 1 for i in range(0,m): if B[i][j] == 0: flg = 0 break if flg == 1: C.append(j) for r in R: for c in C: A[r][c] = 1 print("YES") for i in range(0,m): s = ""+str(A[i][0]) for j in range(1,n): s += " "+str(A[i][j]) print(s) ```
97,361
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` # cook your dish here m,n=map(int,input().split()) l=[] for i in range(m) : l.append(list(map(int,input().split()))) r=[] c=[] f=0 for i in range(m) : for j in range(n) : if l[i][j]==1 : x=1 for k in range(m) : if l[k][j]==0 : x=0 break if x==1 : c.append(j) for k in range(n) : if l[i][k]==0 : x=0 break if x==1 : r.append(i) else : for k in range(n) : if l[i][k]==0 : x=1 break if x==0 : r.append(i) else : f=1 break if f==1 or (len(r)==0 and len(c)!=0) or (len(c)==0 and len(r)!=0): print("NO") else : print("YES") for i in range(m) : for j in range(n) : if i in r and j in c : print(1,end=" ") else : print(0,end=" ") print() ```
97,362
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` n,m= map(int,input().split()) b=[] a=[m*[1] for _ in range(n)] for i in range(n): b+=[list(map(int,input().split()))] for k in range(m): if b[i][k]==0: a[i]=m*[0] for j in range(n): a[j][k]=0 stop=0 i=0 while not stop and i<n: for j in range(m): s=0 for k in range(n): s+=a[k][j] if b[i][j]!=min(1,s+sum(a[i])): stop=1 break i+=1 if stop: print("NO") else: print("YES") for i in range(n): print(*a[i]) ```
97,363
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` a, b = map(int, input().split(' ')) array = [[1] * b for i in range(a)] orig = [list(map(int, input().split(' '))) for i in range(a)] matrix = [] for i in orig: matrix.append(i[:]) row0 = [] col0 = [] for i in range(a): for j in range(b): if matrix[i][j] == 0: row0.append(i) col0.append(j) row0 = list(set(row0)) col0 = list(set(col0)) for i in row0: matrix[i] = [0] * b for ele in col0: for i in range(a): matrix[i][ele] = 0 match = [[0] * b for i in range(a)] for i in range(len(matrix)): if 1 in matrix[i]: match[i] = [1] * len(matrix[0]) jlist = [] for i in range(a): for j in range(b): if matrix[i][j] == 1: jlist.append(j) for i in jlist: for bad in range(len(match)): match[bad][i] = 1 if match == orig: print("YES") for i in matrix: print(' '.join([str(j) for j in i])) else: print("NO") ```
97,364
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` m, n = [int(s) for s in input().split(' ')] B = [[] for _ in range(m)] A = [[1 for _ in range(n)] for _ in range(m)] ARow = [n for _ in range(m)] ACol = [m for _ in range(n)] for i in range(m): B[i] = [int(s) for s in input().split(' ')] for j in range(n): if B[i][j] == 0: for x in range(m): A[x][j] = 0 if ACol[j] > 0: ARow[x] = max(ARow[x]-1, 0) for y in range(n): A[i][y] = 0 if ARow[i] > 0: ACol[y] = max(ACol[y]-1, 0) ARow[i] = 0 ACol[j] = 0 contradiction = False for i in range(m): if contradiction: break for j in range(n): if B[i][j] == 1: contradiction = ARow[i] == 0 and ACol[j] == 0 if contradiction: break if contradiction: print('NO') else: print('YES') for i in range(m): print(' '.join(map(str, A[i]))) ```
97,365
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` import sys import string import math from collections import defaultdict from functools import lru_cache from collections import Counter def mi(s): return map(int, s.strip().split()) def lmi(s): return list(mi(s)) def tmi(s): return tuple(mi(s)) def mf(f, s): return map(f, s) def lmf(f, s): return list(mf(f, s)) def js(lst): return " ".join(str(d) for d in lst) def line(): return sys.stdin.readline().strip() def linesp(): return line().split() def iline(): return int(line()) def mat(n): matr = [] for _ in range(n): matr.append(linesp()) return matr def mati(n): mat = [] for _ in range(n): mat.append(lmi(line())) return mat def pmat(mat): for row in mat: print(js(row)) def dist(x, y): return ((x[0] - y[0])**2 + (x[1] - y[1])**2)**0.5 def fast_exp(x, n): if n == 0: return 1 elif n % 2 == 1: return x * fast_exp(x, (n - 1) // 2)**2 else: return fast_exp(x, n // 2)**2 def main(mat): z_col = set() z_row = set() for i in range(len(mat)): for j in range(len(mat[i])): if mat[i][j] == 0: # Implies that the row and col # must both be 0. z_row.add(i) z_col.add(j) ans = [[0 for _ in range(len(mat[i]))] for i in range(len(mat))] row_done = set() col_done = set() pending_row = set() pending_col = set() for i in range(len(mat)): for j in range(len(mat[i])): if mat[i][j] == 1: if i not in z_row and j not in z_col: ans[i][j] = 1 row_done.add(i) col_done.add(j) if i in pending_row: pending_row.remove(i) if j in pending_col: pending_col.remove(j) elif i not in z_row and j in z_col: # Current column must be a 0. # So this row must have a one. if i not in row_done: # Need to do i. pending_row.add(i) elif i in z_row and j not in z_col: if j not in col_done: pending_col.add(j) else: print("NO") return # Try and complete the pending row. for i in pending_row: done = False for j in range(len(mat[i])): if j not in z_col: ans[i][j] = 1 if j in pending_col: pending_col.remove(j) done = True if not done: print("NO") return for j in pending_col: done = False for i in range(len(mat)): if i not in z_row: ans[i][j] = 1 done = True if not done: print("NO") return print("YES") pmat(ans) def main(mat): # Million times better solution. A = [[1 for _ in range(len(mat[i]))] for i in range(len(mat))] z_row = set() z_col = set() for i in range(len(mat)): for j in range(len(mat[i])): if mat[i][j] == 0: # Make row/col 0. z_row.add(i) z_col.add(j) for row in z_row: for j in range(len(mat[0])): A[row][j] = 0 for col in z_col: for i in range(len(mat)): A[i][col] = 0 # Use A to get mat. B = [[1 for _ in range(len(mat[i]))] for i in range(len(mat))] for i in range(len(A)): for j in range(len(A[i])): B[i][j] = 0 for k in range(len(A)): B[i][j] |= A[k][j] for k in range(len(A[0])): B[i][j] |= A[i][k] if B[i][j] != mat[i][j]: print("NO") return print("YES") pmat(A) if __name__ == "__main__": n, _ = mi(line()) mat = mati(n) main(mat) ```
97,366
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` n,m=list(map(int,input().split())) l=[] for i in range(n): l.append(list(map(int,input().split()))) a=[] for i in range(n+1): a.append([None for j in range(m+1)]) for i in range(n): for j in range(m): if l[i][j]==0: for x in range(m): a[i][x]=0 for x in range(n): a[x][j]=0 else: if a[i][j]!=0: a[i][j]=1 for i in range(n): c=0 for j in range(m): if a[i][j]==1: c=c+1 a[i][m]=c for j in range(m): c=0 for i in range(n): if a[i][j]==1: c=c+1 a[n][j]=c b=[] for i in range(n): b.append([None for j in range(m)]) for i in range(n): for j in range(m): if a[i][j]==1: for x in range(n): b[x][j]=1 for x in range(m): b[i][x]=1 else: if b[i][j]!=1: b[i][j]=0 if b==l: print('YES') for i in range(n): for j in range(m-1): print(a[i][j],end=' ') print(a[i][m-1]) else: print('NO') ```
97,367
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Tags: greedy, hashing, implementation Correct Solution: ``` m,n=list(map(int,input().split())) grid = [list(map(int,input().split())) for i in range(m)] def ANDrow(grid,i): ans = 1 for j in range(n): ans = ans and grid[i][j] return ans def ANDcol(grid,j): ans = 1 for i in range(m): ans = ans and grid[i][j] return ans gridA = [] for i in range(m): temp= [] for j in range(n): temp.append(0) gridA.append(temp) # gridA= [[0]*n]*m flag = True countR = 0 countC = 0 for i in range(m): if not flag: break for j in range(n): androw = ANDrow(grid[::],i) countR+=androw andcol = ANDcol(grid[::],j) countC+=andcol # print(grid[i][j],androw,andcol,grid[i][j] and androw and andcol) gridA[i][j] = int(bool(grid[i][j]) and bool(androw) and bool(andcol)) # print(i,j,int(bool(grid[i][j]) and bool(androw) and bool(andcol)),gridA) flag2 = (grid[i][j] and (not (androw or andcol))) if flag2: flag = False break if flag and not((countC==0) ^ (countR==0)): print("YES") for i in gridA: print(*i) else: print("NO") ```
97,368
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` m,n=map(int,input().split()) l=[] ind=[] out=[[1]*n for i in range(m)] def check(b): for i in range(m): if out[i][b]==1: return True return False for i in range(m): k=list(map(int,input().split())) for j in range(len(k)): if k[j]==0: for h in range(m): out[h][j]=0 for t in range(n): out[i][t]=0 if k[j]==1: ind.append((i,j)) flag=True for i in ind: if 1 in out[i[0]] or check(i[1]): pass else: print('NO') flag=False break if flag: print('YES') for i in range(m): for j in range(n): print(out[i][j],end=' ') print() ``` Yes
97,369
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` m,n=list(map(int,input().split(" "))) a=[] b=[] for i in range(m): a.append([1 for i in range(n)]) for i in range(m): b.append([int(y) for y in input().split()]) for i in range(m): for j in range(n): if b[i][j]==0: for k in range(m): a[k][j]=0 for z in range(n): a[i][z]=0 finalmatrix=[] for i in range(m): finalmatrix.append([0 for i in range(n)]) for i in range(m): for j in range(n): rvalue=0 cvalue=0 for k in range(m): rvalue=rvalue or a[k][j] for z in range(n): cvalue=cvalue or a[i][z] finalmatrix[i][j]=cvalue or rvalue flag=True for i in range(m): for j in range(n): if finalmatrix[i][j]!=b[i][j]: flag=False break if flag: print("YES") for i in range(m): for j in range(n): print(a[i][j],end=" ") print(end="\n") else: print("NO") ``` Yes
97,370
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` from array import * m, n = list(map(int, input().split())) A = [] for i in range(m): k = list(map(int, input().split())) A.append(k) ans = [[-1 for x in range(n)] for y in range(m)] flag = 0 for i in range(m): if flag: break for j in range(n): if A[i][j] == 0: # print() # print(i, j) for a in range(n): # print(i, a) if ans[i][a] == -1 or ans[i][a] == 0: # print(i, a) # print(ans) ans[i][a] = 0 # print(ans) # print() else: print("NO") flag = 1 break if flag: break for b in range(m): if ans[b][j] == -1 or ans[b][j] == 0: # print(b, j) # print(ans) ans[b][j] = 0 # print(ans) # print() # print(ans) else: print("NO") flag = 1 break for i in range(m): if flag: break for j in range(n): if ans[i][j] == -1: if A[i][j] == 1: ans[i][j] = 1 else: print("NO") flag = 1 break """""" for i in range(m): check = 0 if flag: break for j in range(n): check = 0 if A[i][j] == 1: #print() #print(i,j) for a in range(n): if ans[i][a] == 1: check = 1 #print("check = 1 : " + str(i) + " , " + str(a)) for b in range(m): if ans[b][j] == 1: check = 1 #print("check = 1" + str(b) +" , "+ str(j)) if check: continue else: flag = 1 print("NO") break if flag == 0: print("YES") for i in ans: for j in i: print(j, end=" ") print() """ 2 3 0 1 0 1 1 1 """ ``` Yes
97,371
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` import sys m, n = map(int, sys.stdin.readline().split()) mat = [] ans = [] for i in range(m): a = list(map(int, sys.stdin.readline().split())) mat.append(a) ans.append([-1] * n) for i in range(m): for j in range(n): if mat[i][j] == 0: for k in range(n): ans[i][k] = 0 for k in range(m): ans[k][j] = 0 for i in range(m): for j in range(n): if ans[i][j] == -1: ans[i][j] = 1 row = [0] * m col = [0] * n for i in range(m): for j in range(n): row[i] |= ans[i][j] for i in range(n): for j in range(m): col[i] |= ans[j][i] has = True for i in range(m): for j in range(n): if mat[i][j] != (row[i] | col[j]): has = False break if has == False: break if has == False: print("NO") else: print("YES") for i in range(m): print(' '.join(map(str, ans[i]))) print() ``` Yes
97,372
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` read = lambda: map(int, input().split()) n, m = read() a = [list(read()) for i in range(n)] pi = [1] * m; pj = [1] * n ai = []; aj = [] flag = 0 for i in range(n): if a[i][0] and a[i] != pi: flag = 1 break elif a[i][0]: ai.append(i) for i in range(m): if a[0][i] and [a[j][i] for j in range(n)] != pj: flag = 1 break elif a[0][i]: aj.append(i) if flag: print('NO') exit() print('YES') A = [[0] * m for i in range(n)] for i in ai: for j in aj: A[i][j] = 1 [print(*i) for i in A] ``` No
97,373
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` __author__ = "runekri3" def get_answer(): m, n = list(map(int, input().split())) total_rows, total_cols = m, n rows = [] for row_i in range(total_rows): row = list(map(int, input().split())) rows.append(row) cols = [[row[col_i] for row in rows] for col_i in range(total_cols)] filled_rows = [] must_be_filled_cols = set() for row_i, row in enumerate(rows): ones = row.count(1) if ones != 0: if ones != total_cols: [must_be_filled_cols.add(col_i) for col_i in range(total_cols) if row[col_i] == 1] else: filled_rows.append(row_i) for must_be_filled_col_i in must_be_filled_cols: col = cols[must_be_filled_col_i] ones = col.count(1) if ones != total_rows: print("NO") return solution_matrix = [[0 for _ in range(total_cols)] for _ in range(total_rows)] for row_i in filled_rows: if len(must_be_filled_cols) == 0: solution_matrix[row_i] = [1] * total_cols for col_i in must_be_filled_cols: solution_matrix[row_i][col_i] = 1 print("YES") [print(" ".join(map(str, row))) for row in solution_matrix] get_answer() ``` No
97,374
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` __author__ = '-' l1 = input().strip().split(" ") m = int(l1[0]) n = int(l1[1]) B = [] for i in range(m): line = input().strip().split(" ") row = [] for p in line: row.append(int(p)) B.append(row) A = [[0 for x in range(n)] for y in range(m)] def transferA(B,m,n): A = [[0 for x in range(n)] for y in range(m)] for i in range(m): rida1 = True for j in range(n): if B[i][j] == 0: rida1 = False break if rida1: for j in range(n): veerg1 = True for r in range(m): if B[r][j] == 0: veerg1 = False break if veerg1 and rida1: A[i][j] = 1 return A A = transferA(B,m,n) def transfer(A,m,n): C = [[0 for x in range(n)] for y in range(m)] for i in range(len(A)): for j in range(len(A[i])): if A[i][j] == 1: for k in range(n): C[i][k] = 1 for l in range(m): C[l][j] = 1 return C C = transfer(A,m,n) if C == B: print("YES") for i in range(len(C)): for j in range(len(C[i])): print(C[i][j],end = " ") print() else: print("NO") ``` No
97,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ai = 1, otherwise it is equal to 0. Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula: <image>. (Bij is OR of all elements in row i and column j of matrix A) Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. Input The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). Output In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. Examples Input 2 2 1 0 0 0 Output NO Input 2 3 1 1 1 1 1 1 Output YES 1 1 1 1 1 1 Input 2 3 0 1 0 1 1 1 Output YES 0 0 0 0 1 0 Submitted Solution: ``` def solve(a,b,m,n): for i in range(m): for j in range(n): x=b[i][j] if x==0: if 1 in a[i]: return False else: a[i]=[0 for i in range(n)] for k in range(i,-1,-1): if a[k][j]==1: return False for k in range(i,m): a[k][j]=0 elif b[i][j]==1: if a[i][j]==-1: a[i][j]=1 return True m,n=map(int,input().split()) b=[] for i in range(m): x=[int(i) for i in input().split()] b.append(x) a=[[-1 for i in range(n)]for i in range(m)] ans=solve(a,b,m,n) if ans==True: print("YES") for i in range(len(a)): print(*a[i]) else: print("NO") ``` No
97,376
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` m, n = list(map(int, input().split())) print((m * n) // 2) # S_of_deck / S_of_domino ```
97,377
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` a,b=map(int,input().split()) c=(int(a*b)) d=2 maximum1=(int(c/d)) print(round(maximum1)) ```
97,378
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` m,n=[int(x) for x in input().split()] if(m%2==0 or n%2==0): if(m%2==0): ans=n*(int(m/2)) else: ans=m*(int(n/2)) else: ans=int((m*n)/2) print(ans) ```
97,379
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` s= input().split(' ') m = int(s[0]) n = int(s[1]) if m == n == 1: print(0) elif m == 1 or n == 1: print(int(round(m*n/2-0.2))) else: if m%2 == 0 or n%2 == 0: print(int(m*n/2)) else: #m,n le if m>n: m=m-1 print(int(m*n/2+ round(n/2-0.2))) else: n=n-1 print(int(m*n/2+ round(m/2-0.2))) ```
97,380
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` def domino(): m,n=map(int,input().split()) return m*n//2 print (domino()) ```
97,381
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` a = map(int, input().split()) result = 1 for x in a: result *= x print(int(result/2)) ```
97,382
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` m,n=map(int,input().split()) if n*m %2==0: x=n*m/2 elif m*n%2==1: x=((n*m)-1)/2 print(int(x)) ```
97,383
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Tags: greedy, math Correct Solution: ``` m, n = [int(x) for x in input().strip().split(' ')] print(m * n // 2) ```
97,384
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` m,n=[int(i) for i in input().split()] a=m*n//2 print(a) ``` Yes
97,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` import math lineArr = [] def intInput(): global lineArr lineArr = input().split(' ') for i in range(len(lineArr)): lineArr[i]=int(lineArr[i]) intInput() m = lineArr[0] n = lineArr[1] 2 if n%2 == 0: d = (n/2)*m elif m%2 == 0: d = (m/2)*n else: d = math.floor((m*n)/2) d = int(d) print(d) ``` Yes
97,386
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` n, k = map(int, input().split()) if (n*k)%2==0: print(int((n*k)/2)) else: print(int(n*k)//2) ``` Yes
97,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` import sys m,n = [int(x) for x in sys.stdin.readline().split()] if m % 2 == 1 and n % 2 == 1: print((m*n-1) // 2) else: print(m*n // 2) ``` Yes
97,388
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` m,n = map(int,input().split()) a = 2 # площадь одной доминошки if n * m % a == 0: k = n * m / a else: k = m * n // a print(k) ``` No
97,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` def main(): m, n = [int(x) for x in input().strip().split()] print(m,n) if m%2==0 and n%2==0: print(int((m*n)/2)) elif m%2==0 and n%2!=0: print(int((m*n)/2)) elif n%2==0 and m%2!=0: print(int((m*n)/2)) else: print(int(((m-1)/2)+((m*(n-1))/2))) main() ``` No
97,390
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` a,b=list(map(int,input().split(' '))) print((a*b-1)//2) ``` No
97,391
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16). Output Output one number — the maximal number of dominoes, which can be placed. Examples Input 2 4 Output 4 Input 3 3 Output 4 Submitted Solution: ``` a = input() print(int(a[0]) * int(a[0]) // 2) ``` No
97,392
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` [n, A] = [int(x) for x in input().split()] d = [0] + [int(x) for x in input().split()] sigma = sum(d) ans = [0] * (n + 1) for i in range(1, n + 1): at_least = A - sigma + d[i] - 1 at_least = max(at_least, 0) ans[i] += at_least at_most = d[i] - A + n - 1 at_most = max(at_most, 0) ans[i] += at_most ans = ans[1:] ans = [str(x) for x in ans] print(" ".join(ans)) ```
97,393
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` n , m = map(int,input().split()) lis = list(map(int,input().split())) s = sum(lis) for i in range(n): t = s-lis[i] z=n-1 ans = max(0,m-t-1) ans+=max(0,lis[i]-m+z) print(ans,end=' ') ```
97,394
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` n, k = map(int, input().split()) d = list(map(int, input().split())) tot, res = sum(d), [] for i in range(n): x = max(0, k + d[i] - tot - 1) y = max(0, -k + d[i] + n - 1) res.append(x+y) print(*res) ```
97,395
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` n, A = map(int, input().split()) d = list(map(int, input().split())) sum = 0 for i in range(n): sum += d[i] for i in range(n): left = max(1, A - (sum - d[i])) right = min(d[i], A - (n - 1)) ans = d[i] - (right - left + 1) print(ans) ```
97,396
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` n, a = map(int, str.split(input())) ns = tuple(map(int, str.split(input()))) s = sum(ns) res = [] for x in ns: low = max(0, a - (s - x) - 1) high = min(x, a - (n - 1)) res.append(low + x - high) print(str.join(" ", map(str, res))) ```
97,397
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` n, a = map(int, input().split()) b = list(map(int, input().split())) ans = [0] * n k = a - (n - 1) if n == 1: print(b[0] - 1) exit() elif a % n == 0: d = a // n if b.count(d) == n: ans = [d - 1] * n print(*ans) exit() s = sum(b) for i in range(n): if k < b[i]: ans[i] += (b[i] - k) if (s - a) < b[i]: ans[i] += a - (s - b[i]) - 1 print(*ans) ```
97,398
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A. Input The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show. Output Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them. Examples Input 2 8 4 4 Output 3 3 Input 1 3 5 Output 4 Input 2 3 2 3 Output 0 1 Note In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. Tags: math Correct Solution: ``` #! /usr/bin/python3 #http://codeforces.com/contest/534/problem/C n, sum = map(int, input().split()) t = input().split() array = [0] * n for i in range(0, n): array[i] = int(t[i]) total = 0 for i in range(0, n): total = total + array[i] for i in range(0, n): k = total - array[i] top = sum - (n - 1) below = sum - k if below <= 0: below = 1 if top > array[i]: top = array[i] print(array[i] - top + below - 1, end=' ') print() ```
97,399