text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` import os, sys from io import BytesIO, IOBase from math import ceil 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") mod = 998244353 def pw(x, y): ans = 1 while y: if y % 2: ans *= x y -= 1 ans %= mod else: x *= x y //= 2 x %= mod return ans def ncr(n, r): ans = 1 for i in range(r): ans *= (n - i) ans *= pw(i + 1, mod - 2) ans %= mod return ans % mod def solve(): n = len(a) if n == 0: return 0 a1 = [0 for i in range(n + 1)] for i in range(n): a1[1 + i] = a[i] p = [0 for i in range(n + 1)] for i in range(n + 1): p[a1[i]] = i k = 1 for i in range(n, 1, -1): if p[a1[i] + 1] <= p[a1[i - 1] + 1]: k += 1 return k n, m = map(int, input().split()) a = list(map(int, input().split())) t = solve() if m < t: print(0) else: c = m - t ans = ncr(n + c, c) % mod print(ans) ```
1,100
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` m = 998244353 n,k = [ int(d) for d in input().split()] a = [ int(d) for d in input().split()] d = {} for i in range(n): d[a[i]] = i e = 0 d[n] = -1 for i in range(n-1): if (d[a[i]+1] < d[a[i+1]+1]): e = e + 1 if (k+e < n): print(0) else: num = 1 den = 1 for i in range(1,n+1): num = (num*(k+e-n+i))%m den = (den*i)%m x = pow(den,m-2,m) print((num*x)%m) ```
1,101
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` import sys input = sys.stdin.buffer.readline mod = 998244353 n,k = map(int,input().split()) s = list(map(int,input().split())) pos = [-1]*(n+1) for i in range(n): pos[s[i]] = i increases = 0 for i in range(n-1): increases += pos[s[i]+1] > pos[s[i+1]+1] # k-1-increases+n choose n # ways to choose n numbers from 1 to k given that the difference between # variable(increases) of them = 1 is the same as ordering n bars and # k-1-increases stars (ways to choose the n+1 spaces between numbers and we # add back 1 to each difference included in increases numerator = denominator = 1 for i in range(1,n+1): numerator = numerator * (k-1-increases+i) % mod denominator = denominator * i % mod # if k-1 < increases, the answer is 0 and this is automatically account for # because k-1-increases <= -1 and that k-1-increase >= -(n-1) # Then, the numerator will be multiplied by 0 at some point during calculation print(numerator*pow(denominator,mod-2,mod)%mod) ```
1,102
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` MOD=998244353;n,k=map(int,input().split());arr=list(map(int,input().split()));pos=[0]*(n+1) for i in range(n):pos[arr[i]]=i pos[n]=-1;cnt=0;num,denom=1,1 for i in range(n-1): if (pos[arr[i]+1]>pos[arr[i+1]+1]): cnt+=1 for i in range(n):num=num*(k-cnt+n-1-i)%MOD;denom=denom*(i+1)%MOD print(num*pow(denom,MOD-2,MOD)%MOD) ```
1,103
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` import sys from sys import stdin mod = 998244353 def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs def modnCr(n,r): return fac[n] * inv[n-r] * inv[r] % mod fac,inv = modfac(300000,mod) n,k = map(int,stdin.readline().split()) s = list(map(int,stdin.readline().split())) ra = [None] * n for i in range(n): ra[s[i]] = i eq = 0 for i in range(n-1): if s[i] + 1 == n: eq += 1 elif s[i+1]+1 == n: pass elif ra[s[i]+1] < ra[s[i+1]+1]: eq += 1 print (eq,file=sys.stderr) ans = 0 for neq in range(eq+1): usealp = n - neq if usealp > k: continue else: ans += modnCr(eq,neq) * modnCr(k,usealp) ans %= mod print (ans) ```
1,104
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() P = 998244353 nn = 404040 fa = [1] * (nn+1) fainv = [1] * (nn+1) for i in range(nn): fa[i+1] = fa[i] * (i+1) % P fainv[-1] = pow(fa[-1], P-2, P) for i in range(nn)[::-1]: fainv[i] = fainv[i+1] * (i+1) % P C = lambda a, b: fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0 N, K = map(int, input().split()) A = [int(a) for a in input().split()] B = [-1] * (N + 1) for i, a in enumerate(A): B[a] = i c = 0 for i in range(1, N): if B[A[i]+1] < B[A[i-1]+1]: c += 1 print(C(N + K - c - 1, N)) ```
1,105
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Tags: combinatorics, constructive algorithms, math Correct Solution: ``` MOD = 998244353 n, k = map(int, input().split()) arr = list(map(int, input().split())) pos = [-1] * (n+1) for i, a in enumerate(arr): pos[a] = i pos[-1] = -1 for i in range(n-1): if pos[arr[i]+1] < pos[arr[i+1]+1]: k += 1 if k < n: print(0) else: fact = [1] for i in range(1, k+1): fact.append(fact[-1]*i%MOD) print(fact[k]*pow(fact[n], MOD-2, MOD)*pow(fact[k-n], MOD-2, MOD)%MOD) ```
1,106
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Submitted Solution: ``` MOD=998244353 n,k=map(int,input().split()) arr=list(map(int,input().split())) pos=[0]*(n+1) for i in range(n): pos[arr[i]]=i pos[n]=-1 cnt=0 for i in range(n-1): if (pos[arr[i]+1]>pos[arr[i+1]+1]): cnt+=1 #k-cnt+n-1 choose n num,denom=1,1 for i in range(n): num=num*(k-cnt+n-1-i)%MOD denom=denom*(i+1)%MOD print(num*pow(denom,MOD-2,MOD)%MOD) ``` Yes
1,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Submitted Solution: ``` import sys input = sys.stdin.readline n,k=map(int,input().split()) S=list(map(int,input().split())) mod=998244353 FACT=[1] for i in range(1,5*10**5+1): FACT.append(FACT[-1]*i%mod) FACT_INV=[pow(FACT[-1],mod-2,mod)] for i in range(5*10**5,0,-1): FACT_INV.append(FACT_INV[-1]*i%mod) FACT_INV.reverse() def Combi(a,b): if 0<=b<=a: return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod else: return 0 S_INV=[0]*n for i in range(n): S_INV[S[i]]=i #print(S_INV) S_INV.append(-1) B=[0]*n BX=0 for i in range(1,n): if S_INV[S[i]+1]<S_INV[S[i-1]+1]: B[i]+=1 BX+=1 if k-1<BX: print(0) else: c=k-1-BX print(Combi(n+c,c)) ``` Yes
1,108
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Submitted Solution: ``` n, k = map(int, input().split()) p = list(map(int, input().split())) pos = [-1] * (n + 1) for i, x in enumerate(p): pos[x] = i d = 0 for i in range(n - 1): if pos[p[i + 1] + 1] < pos[p[i] + 1]: d += 1 if k <= d: print(0) exit() mod = 998244353 def modpow(x, p): res = 1 while p: if p % 2: res = res * x % mod x = x * x % mod p //= 2 return res def C(N, K): num = 1 den = 1 for j in range(K): num *= N - j num %= mod den *= K - j den %= mod return num * modpow(den, mod - 2) % mod k -= 1 ans = C(n + k - d, n) print(ans) ``` Yes
1,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array. More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix array. Let s be a string of length n. Then the i-th suffix of s is the substring s[i … n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y]. A string x is lexicographically smaller than string y, if either x is a prefix of y (and x≠ y), or there exists such i that x_i < y_i, and for any 1≤ j < i , x_j = y_j. Input The first line contain 2 integers n and k (1 ≤ n ≤ 200000,1 ≤ k ≤ 200000) — the length of the suffix array and the alphabet size respectively. The second line contains n integers s_0, s_1, s_2, …, s_{n-1} (0 ≤ s_i ≤ n-1) where s_i is the i-th element of the suffix array i.e. the starting position of the i-th lexicographically smallest suffix. It is guaranteed that for all 0 ≤ i< j ≤ n-1, s_i ≠ s_j. Output Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353. Examples Input 3 2 0 2 1 Output 1 Input 5 1 0 1 2 3 4 Output 0 Input 6 200000 0 1 2 3 4 5 Output 822243495 Input 7 6 3 2 4 1 0 5 6 Output 36 Note In the first test case, "abb" is the only possible solution. In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal. In the fourth test case, one possible string is "ddbacef". Please remember to print your answers modulo 998244353. Submitted Solution: ``` import sys import heapq input = sys.stdin.readline def mod_exp(b,e,mod): r = 1 while e > 0: if (e&1) == 1: r = (r*b)%mod b = (b*b)%mod e >>= 1 return r def comb(n,k,p): if k > n: return 0 num = 1 for i in range(n,n-k,-1): num = (num*i)%p denom = 1 for i in range(1,k+1): denom = (denom*i)%p return (num * mod_exp(denom,p-2,p))%p n,k = map(int,input().split()) MOD_NUM = 998244353 P = list(map(int,input().split())) R = [-1]*n for i in range(n): R[P[i]] = i R.append(0) Rp = [R[P[i] + 1] for i in range(n)] d = 0 for i in range(n-1): if Rp[i] > Rp[i+1]: d += 1 if k-d-1 < 0 or n+k-d-1 < 0: print(0) exit() ans = comb(n+k-d-1, k-d-1,MOD_NUM) ans %= MOD_NUM print(ans) ``` No
1,110
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` def cd(where): for s in where: if s == "..": directories.pop() else: directories.append(s) def pwd(): print("/", end="") for s in directories: print(s, "/", sep="", end="") print() n = int(input()) directories = [] #храним текущий путь от корня for i in range(n): com = input() if com[0] == "p": pwd() else: com, where = com.split() where = where.split("/") if (where[0] == ''): directories = [] where = where[1:] cd(where) ```
1,111
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) cur = list() for i in range(0,n): st = str(input()) if st.startswith('pwd'): ans = '/' for s in cur : ans = ans + s ans = ans + '/' print(ans) else : st = st.strip() temp = st.split('/') for s in temp: if s == '' :continue elif s == 'cd ': cur.clear() elif s == '..' or s == 'cd ..' : cur.pop() else : if s.startswith('cd') : t = s.split() if len(t) > 1 : cur.append(t[1]) else : cur.append(s) ```
1,112
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) dir = [] def pwd(dir): if len(dir) == 0: print("/") else: for i in dir: print("/"+i, end="") print("/") for i in range(n): line = input() #print("##"+line+"##") if line.startswith("cd"): dir_line = line.split()[1].strip() if dir_line[0] == '/': dir = [] for i in dir_line[1:].split("/"): if i == "..": dir.pop() else: dir.append(i) else: for i in dir_line.split("/"): if i == "..": dir.pop() else: dir.append(i) else: pwd(dir) ```
1,113
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` def printPath(path): print('/', end='') if len(path): for dir in path: print(dir + '/', end='') print() # Get input data num_commands = int(input()) commands = [] for i in range(0, num_commands): commands.append(input()) current_path = [] for command in commands: if command == 'pwd': printPath(current_path) else: path = command.split()[1] if path[0] == '/': current_path = [] path = path[1:] for directory in path.split('/'): if directory == '..': current_path = current_path[:-1] else: current_path.append(directory) ```
1,114
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) path = [] for _ in range(n): s = input().strip() if s == 'pwd': print('/' + '/'.join(path) + ['', '/'][bool(path)]) else: s = s.split(' ')[1] if s[0] == '/': s = s.lstrip('/') path = [] if s: for p in s.split('/'): if p == '..': if path: path.pop() else: path.append(p) ```
1,115
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) stacc = ["/"] while n > 0: line = input() linesplit = line.split() if len(linesplit) == 2: command = linesplit[0] parameter = linesplit[1] else: command = linesplit[0] if command == "pwd": print("".join(stacc)) elif command == "cd": directory = parameter.split("/") if not directory[0]: stacc = ["/"] for folders in directory: if folders == "..": stacc.pop() else: if folders: stacc.append(folders + "/") n = n - 1 ```
1,116
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) dirs = ['/'] def ins_split(command): command = command.split('/') command[:] = [i for i in command if i != ""] command[:] = [i+'/' for i in command] return command def display(): # indexes to remove count = dirs.count('../') for _ in range(count): j = dirs.index('../') dirs.remove(dirs[j]) dirs.remove(dirs[j-1]) print(''.join(dirs)) while n: command = input() if command == 'pwd': display() else: # removing cd part command = command[3:] # handling absolute path if command[0] == '/': command = ins_split(command) dirs[1:] = command # handling relative else: command = ins_split(command) dirs += command n -= 1 ```
1,117
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Tags: *special, data structures, implementation Correct Solution: ``` def getNext(s): return s[3:] lines = int(input()) stack = ["/"] for x in range(lines): command = input() start = command[0] if start == "p": print("".join(stack)) elif start == "c": folders = getNext(command).split("/") if not folders[0]: stack = ["/"] for folder in folders: if folder == "..": stack.pop() else: if folder: stack.append(folder + "/") ```
1,118
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` n = int(input()) stack = [] for i in range(n): u = input() if u == "pwd": if stack: print("/"+"/".join(stack)+"/") else: print("/") else: _, d = u.split() dirs = d.split('/') if dirs[0] == "": stack = [] dirs = dirs[1:] for d in dirs: if d == "..": stack.pop() else: stack.append(d) ``` Yes
1,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` # cd-pwd # http://codeforces.com/contest/158/problem/C class Stack: def __init__(self): self.dirs = [] def isEmpty(self): return self.dirs == [] def push(self, item): return self.dirs.append(item) def pop(self): return self.dirs.pop() def peek(self): return self.dirs[len(self.dirs)-1] def size(self): return len(self.dirs) def show(self): if self.dirs==[] or self.dirs[0]!='/': print('/', end='') for i in range(len(self.dirs)): if self.dirs[i]!='': print(self.dirs[i]+'/', end='') print() def pwd(self): print(self.dirs) def clear(self): self.dirs = [] def working(inp): new = inp.split(' ') #print("new>>", new) if new[0] == 'cd': commands = new[1].split('/') #print("commands>>", commands) if commands[0]=='': directories.clear() for i in range (len(commands)): if commands[i]!='': if commands[i] == '..': directories.pop() else: directories.push(commands[i]) #directories.show() else: directories.show() directories = Stack() #directories.clear() numberOfCmds = int(input()) for i in range(numberOfCmds): working(input()) ``` Yes
1,120
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` n = int(input()) path = [] for i in range(0,n): c = input().split() if c[0] == 'cd': s = c[1].split('/') if s[0] == '': path.clear() s.pop(0) for d in s: if d == '..': path.pop() else: path.append(d) else: print('/', end='') for d in path: print(d, '/', sep='', end='') print() ``` Yes
1,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` res = [] for _ in range(int(input())): comando = input().split() # print(comando) if(len(comando) == 1): aux = "" for k in res: aux += "/" + k aux += "/" print(aux) else: caminho = comando[1].split('/') for merda in caminho: if len(merda) == 0: res = [] elif merda == "..": if(len(res) > 0): res.pop() else: res.append(merda) ``` Yes
1,122
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` #codeforces gi = lambda : list(map(int,input().strip().split())) st = [] for k in range(gi()[0]): l = input() if l == "/": st = [] if l == "pwd": if st: print("/" + "/".join(st) + "/") else: print("/") else: l = l[3:].split("/") if l[0] == "": l = l[1:] for e in l: if e == "..": st.pop() else: st.append(e) ``` No
1,123
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` amount = int(input()) current_dir = '/' for x in range(amount): command = input() if command == 'pwd': print(current_dir) continue cd, new_dir_command = command.split() splitted_dir = new_dir_command.split("/") if new_dir_command[0] == "/": current_dir = '' splitted_dir.pop(0) for dir_part in splitted_dir: if dir_part == '..': current_dir = current_dir[:current_dir.rfind('/')] else: current_dir += "/" + dir_part ``` No
1,124
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 12/30/19 """ import collections import time import os import sys import bisect import heapq from typing import List d = [] N = int(input()) for i in range(N): s = input() if s == 'pwd': print('/'.join(d) + '/') else: s = s.split(' ')[1] if s.startswith('/'): d = [] for v in s.split('/'): if v == '..': d.pop() elif v == '.': pass else: d.append(v) ``` No
1,125
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. Input The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. Output For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. Examples Input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd Output / /home/vasya/ /home/ /home/petya/ Input 4 cd /a/b pwd cd ../a/b pwd Output /a/b/ /a/a/b/ Submitted Solution: ``` n = int(input()) cur = [] for _ in range(n): s = input() if s[:3] == 'cd ' : _, path = s.split() paths = path.split('/') for direct in paths: if direct == '': continue elif direct == '..': cur.pop() else: cur += [direct] else: print('/' + '/'.join(cur)) ``` No
1,126
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined up to the box office, each person wants to buy exactly one ticket for his own entertainment. Before the box office started selling tickets, each person found the seat that seemed best for him and remembered it as a pair of coordinates (xi, yi), where xi is the row number, and yi is the seat number in this row. It is possible that some people have chosen the same place, then when some people see their favorite seat taken in the plan of empty seats in the theater, they choose and buy a ticket to another place. Each of them has the following logic: let's assume that he originally wanted to buy a ticket to seat (x1, y1), then when he comes to the box office, he chooses such empty seat (x2, y2), which satisfies the following conditions: * the value of |x1 - x2| + |y1 - y2| is minimum * if the choice is not unique, then among the seats that satisfy the first condition, this person selects the one for which the value of x2 is minimum * if the choice is still not unique, among the seats that satisfy the first and second conditions, this person selects the one for which the value of y2 is minimum Your task is to find the coordinates of a seat for each person. Input The first input line contains three integers n, m, k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ min(n·m, 105) — the number of rows in the room, the number of seats in each row and the number of people in the line, correspondingly. Each of the next k lines contains two integers xi, yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) — the coordinates of the seat each person has chosen. Numbers on the same line are separated by a space. The pairs of coordinates are located in the order, in which people stand in the line, starting from the head (the first person in the line who stands in front of the box office) to the tail (the last person in the line). Output Print k lines, each containing a pair of integers. Print on the i-th line xi, yi — the coordinates of the seat, for which the person who stands i-th in the line will buy the ticket. Examples Input 3 4 6 1 1 1 1 1 1 1 2 1 3 1 3 Output 1 1 1 2 2 1 1 3 1 4 2 3 Input 4 3 12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Output 2 2 1 2 2 1 2 3 3 2 1 1 1 3 3 1 3 3 4 2 4 1 4 3 Submitted Solution: ``` from datetime import * time1 = datetime.now() import sys try: file = open('test.in');fin=file.readline except: fin = sys.stdin.readline n,m,k=map(int,fin().split()) dis=[0]*(m+2)*(n+2) mulm=[(m+2)*i for i in range(n+2)] f1=dict() f2=dict() ansx,ansy=0,0 rangeIJ=((i,j) for j in range(-1,2) for i in range(-1,2)) def renew(x,y,d,i): global ansx,ansy yy = i%(m+2); xx = i//(m+2) if (xx<=n)and(yy>0)and(yy<=m)and(abs(xx-x)+abs(yy-y)<=d): if (xx<ansx)or(xx==ansx)and(yy<ansy): ansx, ansy = xx, yy def findset1(x): if x in f1:f1[x]=findset1(f1[x]) return f1[x] if (x in f1) else x def findset2(x): if x in f2:f2[x]=findset2(f2[x]) return f2[x] if (x in f2) else x def check(x,y,d): global ansx,ansy ansx,ansy=3000,3000 x0 = max(1,x-d);y0 = x-x0+y-d if(y0>0):renew(x,y,d,findset1(mulm[x0]+y0)) y0 = d-x+x0+y if(y0<=m):renew(x,y,d,findset2(mulm[x0]+y0)) if ansx<3000: #print(ansx,ansy) ind=mulm[ansx]+ansy ind1=mulm[ansx+1]+ansy f1[ind] = ind1-1 f2[ind] = ind1+1 return 1 y0 = max(y-d,1); x0 = d+x-y+y0 if(x0<=n):renew(x,y,d,findset2(mulm[x0]+y0)) y0 = min(y+d,m); x0 = d+x-y0+y if(x0<=n):renew(x,y,d,findset1(mulm[x0]+y0)) if ansx<3000: #print(ansx,ansy) ind=mulm[ansx]+ansy ind1=mulm[ansx+1]+ansy f1[ind] = ind1-1 f2[ind] = ind1+1 return 1 return 0 for _ in range(k): x,y=map(int,fin().split()) ind0=mulm[x]+y for i,j in rangeIJ: dis[ind0]=max(dis[ind0],dis[mulm[x+i]+y+j]-abs(i)-abs(j)) while 1: if(check(x,y,dis[ind0])):break dis[ind0]+=1 print(datetime.now()-time1) try:file.close() except:pass ''' import sys import random fout=open('test.in','w') fout.write('2000 2000 100000\n') for i in range(100000): fout.write(str(random.randint(417,419))+' '+str(random.randint(1306,1308))+'\n') ''' ``` No
1,127
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined up to the box office, each person wants to buy exactly one ticket for his own entertainment. Before the box office started selling tickets, each person found the seat that seemed best for him and remembered it as a pair of coordinates (xi, yi), where xi is the row number, and yi is the seat number in this row. It is possible that some people have chosen the same place, then when some people see their favorite seat taken in the plan of empty seats in the theater, they choose and buy a ticket to another place. Each of them has the following logic: let's assume that he originally wanted to buy a ticket to seat (x1, y1), then when he comes to the box office, he chooses such empty seat (x2, y2), which satisfies the following conditions: * the value of |x1 - x2| + |y1 - y2| is minimum * if the choice is not unique, then among the seats that satisfy the first condition, this person selects the one for which the value of x2 is minimum * if the choice is still not unique, among the seats that satisfy the first and second conditions, this person selects the one for which the value of y2 is minimum Your task is to find the coordinates of a seat for each person. Input The first input line contains three integers n, m, k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ min(n·m, 105) — the number of rows in the room, the number of seats in each row and the number of people in the line, correspondingly. Each of the next k lines contains two integers xi, yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) — the coordinates of the seat each person has chosen. Numbers on the same line are separated by a space. The pairs of coordinates are located in the order, in which people stand in the line, starting from the head (the first person in the line who stands in front of the box office) to the tail (the last person in the line). Output Print k lines, each containing a pair of integers. Print on the i-th line xi, yi — the coordinates of the seat, for which the person who stands i-th in the line will buy the ticket. Examples Input 3 4 6 1 1 1 1 1 1 1 2 1 3 1 3 Output 1 1 1 2 2 1 1 3 1 4 2 3 Input 4 3 12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Output 2 2 1 2 2 1 2 3 3 2 1 1 1 3 3 1 3 3 4 2 4 1 4 3 Submitted Solution: ``` n, m, k = map(int, input().split()) step = {} seki = set() an = [] def walk(x, y): i, j, k = step.get((x, y), (0, 0, 1)) if k==1: k += 1 else: k -= 1 j += 1 if j>2*i: i += 1 j = 0 while True: while j<=2*i: n_x = j-i m_x = n_x+x if n>=m_x>0: while k<=2: if n_x<0: if k==1: m_y = -n_x-i+y else: m_y = n_x+i+y else: if k==1: m_y = n_x-i+y else: m_y = i-n_x+y if m>=m_y>0 and (m_x, m_y) not in seki: step[(x, y)] = (i, j, k) seki.add((m_x, m_y)) return m_x, m_y k += 1 k = 1 j += 1 j = 0 i += 1 ''' x, y = map(int, input().split()) inps = [[x, y, 1]] for i in range(k-1): x, y = map(int, input().split()) if x!=inps[-1][0] or y!=inps[-1][1]: inps.append([x, y, 1]) else: inps[-1][2]+=1 for i in inps: for j in range(i[2]): an.append(walk(i[0], i[1])) ''' x, y = map(int, input().split()) if x==552 and y==1028: for i in range(60000): an.append(walk(552, 1028)) for i in range(k-60000): x, y = map(int, input().split()) an.append(walk(x, y)) else: an.append(walk(x, y)) for i in range(k-1): x, y = map(int, input().split()) an.append(walk(x, y)) for a in an: print(a[0], a[1]) ``` No
1,128
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined up to the box office, each person wants to buy exactly one ticket for his own entertainment. Before the box office started selling tickets, each person found the seat that seemed best for him and remembered it as a pair of coordinates (xi, yi), where xi is the row number, and yi is the seat number in this row. It is possible that some people have chosen the same place, then when some people see their favorite seat taken in the plan of empty seats in the theater, they choose and buy a ticket to another place. Each of them has the following logic: let's assume that he originally wanted to buy a ticket to seat (x1, y1), then when he comes to the box office, he chooses such empty seat (x2, y2), which satisfies the following conditions: * the value of |x1 - x2| + |y1 - y2| is minimum * if the choice is not unique, then among the seats that satisfy the first condition, this person selects the one for which the value of x2 is minimum * if the choice is still not unique, among the seats that satisfy the first and second conditions, this person selects the one for which the value of y2 is minimum Your task is to find the coordinates of a seat for each person. Input The first input line contains three integers n, m, k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ min(n·m, 105) — the number of rows in the room, the number of seats in each row and the number of people in the line, correspondingly. Each of the next k lines contains two integers xi, yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) — the coordinates of the seat each person has chosen. Numbers on the same line are separated by a space. The pairs of coordinates are located in the order, in which people stand in the line, starting from the head (the first person in the line who stands in front of the box office) to the tail (the last person in the line). Output Print k lines, each containing a pair of integers. Print on the i-th line xi, yi — the coordinates of the seat, for which the person who stands i-th in the line will buy the ticket. Examples Input 3 4 6 1 1 1 1 1 1 1 2 1 3 1 3 Output 1 1 1 2 2 1 1 3 1 4 2 3 Input 4 3 12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Output 2 2 1 2 2 1 2 3 3 2 1 1 1 3 3 1 3 3 4 2 4 1 4 3 Submitted Solution: ``` n, m, k = map(int, input().split()) step = {} seki = set() an = [] def walk(x, y): i, j, k = step.get((x, y), (0, 0, 1)) if k==1: k += 1 else: k -= 1 j += 1 if j>2*i: i += 1 j = 0 while True: while j<=2*i: n_x = j-i m_x = n_x+x if n>=m_x>0: while k<=2: if n_x<0: if k==1: m_y = -n_x-i+y else: m_y = n_x+i+y else: if k==1: m_y = n_x-i+y else: m_y = i-n_x+y if m>=m_y>0 and (m_x, m_y) not in seki: step[(x, y)] = (i, j, k) seki.add((m_x, m_y)) return m_x, m_y k += 1 k = 1 j += 1 j = 0 i += 1 for i in range(k): x, y = map(int, input().split()) if x==552 and y==1028: for i in range(k): an.append(walk(552, 1028)) break an.append(walk(x, y)) for a in an: print(a[0], a[1]) ``` No
1,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined up to the box office, each person wants to buy exactly one ticket for his own entertainment. Before the box office started selling tickets, each person found the seat that seemed best for him and remembered it as a pair of coordinates (xi, yi), where xi is the row number, and yi is the seat number in this row. It is possible that some people have chosen the same place, then when some people see their favorite seat taken in the plan of empty seats in the theater, they choose and buy a ticket to another place. Each of them has the following logic: let's assume that he originally wanted to buy a ticket to seat (x1, y1), then when he comes to the box office, he chooses such empty seat (x2, y2), which satisfies the following conditions: * the value of |x1 - x2| + |y1 - y2| is minimum * if the choice is not unique, then among the seats that satisfy the first condition, this person selects the one for which the value of x2 is minimum * if the choice is still not unique, among the seats that satisfy the first and second conditions, this person selects the one for which the value of y2 is minimum Your task is to find the coordinates of a seat for each person. Input The first input line contains three integers n, m, k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ min(n·m, 105) — the number of rows in the room, the number of seats in each row and the number of people in the line, correspondingly. Each of the next k lines contains two integers xi, yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) — the coordinates of the seat each person has chosen. Numbers on the same line are separated by a space. The pairs of coordinates are located in the order, in which people stand in the line, starting from the head (the first person in the line who stands in front of the box office) to the tail (the last person in the line). Output Print k lines, each containing a pair of integers. Print on the i-th line xi, yi — the coordinates of the seat, for which the person who stands i-th in the line will buy the ticket. Examples Input 3 4 6 1 1 1 1 1 1 1 2 1 3 1 3 Output 1 1 1 2 2 1 1 3 1 4 2 3 Input 4 3 12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Output 2 2 1 2 2 1 2 3 3 2 1 1 1 3 3 1 3 3 4 2 4 1 4 3 Submitted Solution: ``` n,m,k = list(map(int,input().split())) booked_seats = [] for i in range(k): x,y = list(map(int,input().split())) booked_seat = [] if [x,y] not in booked_seats: booked_seat = [x,y] else: delta = 0 while(booked_seat == []): delta += 1 delta_x = delta+1 delta_y = -1 available_seats = [] while((delta_y <= delta) and (delta_x >= 0)): delta_x -= 1 delta_y += 1 x_new = x-delta_x y_new = y-delta_y if ([x_new,y_new] not in booked_seats) and (x_new * y_new > 0) and (x_new <= n) and (y_new <= m): if [x_new,y_new] not in available_seats: available_seats.append([x_new,y_new]) continue x_new = x-delta_x y_new = y+delta_y if ([x_new,y_new] not in booked_seats) and (x_new * y_new > 0) and (x_new <= n) and (y_new <= m): if [x_new,y_new] not in available_seats: available_seats.append([x_new,y_new]) continue x_new = x+delta_x y_new = y-delta_y if ([x_new,y_new] not in booked_seats) and (x_new * y_new > 0) and (x_new <= n) and (y_new <= m): if [x_new,y_new] not in available_seats: available_seats.append([x_new,y_new]) continue x_new = x+delta_x y_new = y+delta_y if ([x_new,y_new] not in booked_seats) and (x_new * y_new > 0) and (x_new <= n) and (y_new <= m): if [x_new,y_new] not in available_seats: available_seats.append([x_new,y_new]) continue if(available_seats != []): booked_seat = min(available_seats) booked_seats.append(booked_seat) print(booked_seat[0],booked_seat[1]) ``` No
1,130
Provide tags and a correct Python 3 solution for this coding contest problem. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Tags: combinatorics, math, number theory Correct Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) m = 1000000007 r = [ 0, 1 ] for i in range(2, n+1): r.append( (- (m // i) * r[m % i]) % m ) c = [ 1 ] for i in range(1, n): c.append((c[i-1] * (k+i-1) * r[i]) % m) ans = [] for i in range(n): t = 0 for j in range(i+1): t = (t + a[j] * c[i-j]) % m ans.append(t) for i in range(n): print(ans[i], end=' ') ```
1,131
Provide tags and a correct Python 3 solution for this coding contest problem. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Tags: combinatorics, math, number theory Correct Solution: ``` def ncr(n, r, p): # initialize numerator # and denominator num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p p=10**9+7 n,k=map(int,input().split()) b=list(map(int,input().split())) if k==0: print(*b) else: k-=1 res=[] for r in range(1,n+1): res.append(ncr(r+k-1,r-1,p)) ans=[] for i in range(n): j=i val=0 while(j>=0): val+=res[j]*b[i-j] j+=-1 ans.append(val%p) print(*ans) ```
1,132
Provide tags and a correct Python 3 solution for this coding contest problem. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Tags: combinatorics, math, number theory Correct Solution: ``` leng, repeat=list(map(int,input().split())) Lis = list(map(int,input().split())) mod = 10**9 + 7 cum = [1] ans = [0]*leng for i in range(1, 2001): cum.append((cum[-1] * (repeat + i - 1) * pow(i, mod-2, mod)) % mod) for i in range(leng): for j in range(i + 1): ans[i] = (ans[i] + cum[i-j] * Lis[j]) % mod print(*ans) ```
1,133
Provide tags and a correct Python 3 solution for this coding contest problem. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Tags: combinatorics, math, number theory Correct Solution: ``` n, k = map(int, input().split()) num = list(map(int, input().split())) MOD = 10 ** 9 + 7 cf = [1] for i in range(1, 2020): cf.append((cf[-1] * (k + i - 1) * pow(i, MOD - 2, MOD)) % MOD) ans = [0 for i in range(n)] for i in range(n): for j in range(i + 1): ans[i] = (ans[i] + cf[i - j] * num[j]) % MOD print(' '.join(map(str, ans))) ```
1,134
Provide tags and a correct Python 3 solution for this coding contest problem. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Tags: combinatorics, math, number theory Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): mod = 10**9+7 n,k = map(int,input().split()) a = list(map(int,input().split())) coeff = [1] for i in range(n): coeff.append((coeff[-1]*(k+i)*pow(i+1,mod-2,mod))%mod) ans = [] for i in range(n): x = 0 for j in range(i,-1,-1): x = (x+a[j]*coeff[i-j])%mod ans.append(x) print(*ans) # Fast IO Region 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") if __name__ == "__main__": main() ```
1,135
Provide tags and a correct Python 3 solution for this coding contest problem. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Tags: combinatorics, math, number theory Correct Solution: ``` n, k = map(int, input().split()) num = list(map(int, input().split())) MOD = 10 ** 9 + 7 cf = [1] for i in range(1, 2020): cf.append((cf[-1] * (k + i - 1) * pow(i, MOD - 2, MOD)) % MOD) ans = [0 for i in range(n)] for i in range(n): for j in range(i + 1): ans[i] = (ans[i] + cf[i - j] * num[j]) % MOD print(' '.join(map(str, ans))) # Made By Mostafa_Khaled ```
1,136
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Submitted Solution: ``` mod=1000000007 n,k=map(int,input().split()) arr=list(map(int,input().split())) arrx=[] arr1=[] for i in range(n): arr1.append(arr[i]) sum1=0 if(k==0): print(*arr) else: j=1 sumx=0 for i in range(n): sumx=(j*(j+1))//2 arrx.append(sumx) j+=1 #print(*arrx) for i in range(n): sum1=0 val=min(k,i) for j in range(i): sum1+=((val)*(val+1)*arr1[j])//2 val=max(val-1,1) #print(sum1,i) arr[i]=((arr[i]%mod)+(sum1%mod))%mod print(*arr) ``` No
1,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Submitted Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1]*k print(a[i-1], end=" ") print(a[-1]) ``` No
1,138
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Submitted Solution: ``` leng, repeat=list(map(int,input().split())) Lis = list(map(int,input().split())) temp=Lis.copy() for rep in range(repeat): for i in range(len(Lis)-1): temp[i+1]=temp[i]+Lis[i+1] Lis= temp.copy() print(*temp) ``` No
1,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals <image>. The operation x mod y means that we take the remainder of the division of number x by number y. 2. Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si). You task is to find array a after exactly k described operations are applied. Input The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109). Output Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 Submitted Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1]*k print(a[i-1]) print(a[-1]) ``` No
1,140
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` a, b = input(), input() ca = a.count('1') cb = b.count('1') if ca + ca % 2 >= cb: print('YES') else: print('NO') ```
1,141
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` ax, bx = 0, 0 for c in input(): if c == '1': ax += 1 for c in input(): if c == '1': bx += 1 print("YES" if bx <= ax + ax % 2 else "NO") ```
1,142
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` a, b = input(), input() ax = sum([ord(c) - ord('0') for c in a]) bx = sum([ord(c) - ord('0') for c in b]) print("YES" if bx <= ax + ax % 2 else "NO") ```
1,143
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` a=input() b=input() coa=0 cob=0 for i in a: if i=='1': coa+=1 for i in b: if i=='1': cob+=1 if coa+(coa&1)>=cob:print('YES') else:print('NO') ```
1,144
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` def play(s, t): count1, count2 = 0, 0 for elem in s: if elem == '1': count1 += 1 for elem in t: if elem == '1': count2 += 1 if count2 - count1 > 1 or (count2 - count1 == 1 and count1 % 2 == 0): return "NO" return "YES" a = input() b = input() print(play(a, b)) ```
1,145
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO') ```
1,146
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` a = input() b = input() if ((a.count('1') + 1) // 2 * 2) >= b.count('1'): print("YES") else: print("NO") ```
1,147
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Tags: constructive algorithms Correct Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") 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 Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10**9+7 Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() a = ri() b = ri() cnt1, cnt2 = 0,0 cnt1= a.count('1') cnt2 = b.count('1') if cnt1%2 == 1: cnt1+=1 if cnt1 < cnt2: NO() else: YES() ```
1,148
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` alice = input() bob = input() a = alice.count('1') b = bob.count('1') a += (a%2) # if it is odd, then add another one. print("YES" if a >= b else "NO") ``` Yes
1,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): a,b = input().strip(),input().strip() x,y = a.count('1'),b.count('1') if y > x+(x&1): print('NO') else: print('YES') # Fast IO Region 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") if __name__ == "__main__": main() ``` Yes
1,150
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` a=input() print('YES'if a.count('1')+(a.count('1')&1)>=input().count('1')else'NO') ``` Yes
1,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` a = list(input()) b = list(input()) print(['NO', 'YES'][a.count('1')+a.count('1')%2 >= b.count('1')]) ``` Yes
1,152
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` a=input() b=input() coa=0 cob=0 for i in a: if i=='1': coa+=1 for i in b: if i=='1': cob+=1 if coa%2==1: print('YES') else: if cob>coa: print('NO') else: print('YES') ``` No
1,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` def play(s, t): count1, count2 = 0, 0 for elem in s: if elem == '1': count1 += 1 for elem in t: if elem == '1': count2 += 1 if count2 - count1 > 1 or (count2 - count1 == 0 and count1 % 2 == 0): return "NO" return "YES" a = input() b = input() print(play(a, b)) ``` No
1,154
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` a=input() b=input() coa=0 cob=0 for i in a: if i=='1': coa+=1 for i in b: if i=='1': cob+=1 if coa+(coa&1)>cob:print('YES') else:print('NO') ``` No
1,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: * Write parity(a) to the end of a. For example, <image>. * Remove the first character of a. For example, <image>. You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b? The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. Input The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. Output Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. Examples Input 01011 0110 Output YES Input 0011 1110 Output NO Note In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 Submitted Solution: ``` print('YES' if (int(input()) + 1) // 2 >= (int(input()) + 1) // 2 else 'NO') ``` No
1,156
Provide tags and a correct Python 3 solution for this coding contest problem. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Tags: dfs and similar, implementation Correct Solution: ``` w,h,n=list(map(int,input().split())) a=[[0 for i in range(2*w-1)] for j in range(2*h-1)] for i in range(1,2*h-1,2): for j in range(1,2*w-1,2): a[i][j]=' ' for i in range(n): x1,y1,x2,y2=list(map(int,input().split())) if x1==x2: if x1!=0 and x1!=w: for j in range(min(y1,y2),max(y1,y2)): a[2*h-2-2*(j)][2*x1-1]=' ' else: if y1!=0 and y1!=h: for j in range(min(x1,x2),max(x1,x2)): a[2*h-1-2*y1][2*j]=' ' b=[] c=1 for i in range(0,2*h-1,2): for j in range(0,2*w-1,2): if a[i][j]==0: d=i e=j while d<2*h-1 and a[d][e]==0 and a[d-1][e]!=' ' or d==i: d+=2 d-=2 while e<2*w-1 and a[d][e]==0 and a[d][e-1]!=' ' or e==j: e+=2 e-=2 b.append(((e-j)//2+1)*((d-i)//2+1)) for k in range(i,d+1,2): for l in range(j,e+1,2): a[k][l]=c c+=1 b+=[0]*(n+1-len(b)) print(*sorted(b)) ```
1,157
Provide tags and a correct Python 3 solution for this coding contest problem. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Tags: dfs and similar, implementation Correct Solution: ``` w, h, n = map(int, input().split(' ')) hblock = [[False for i in range(w)] for i in range(h)] vblock = [[False for i in range(w)] for i in range(h)] for i in range(n): x1, y1, x2, y2 = map(int, input().split(' ')) if x1 == x2: for j in range(y1, y2): hblock[j][x1-1] = True else: for j in range(x1, x2): vblock[y1-1][j] = True areas = [] vis = [[False for i in range(w)] for i in range(h)] for i in range(h): for j in range(w): if vis[i][j]: continue width = j while width < w and not hblock[i][width]: width += 1 height = i while height < h and not vblock[height][j]: height += 1 width = min(w - 1, width) - j + 1 height = min(h - 1, height) - i + 1 areas.append(width * height) for p in range(height): for q in range(width): vis[i + p][j + q] = True areas.sort() print(' '.join(map(str, areas))) ```
1,158
Provide tags and a correct Python 3 solution for this coding contest problem. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Tags: dfs and similar, implementation Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') w, h, n = map(int, input().split()) mat = [[0] * (2 * w) for _ in range(2 * h)] for x1, y1, x2, y2 in (map(int, input().split()) for _ in range(n)): if x1 == x2: for y in range(2 * y1, 2 * y2): mat[y][2 * x1 - 1] = 1 else: for x in range(2 * x1, 2 * x2): mat[2 * y1 - 1][x] = 1 ans = [] for i in range(0, 2 * h, 2): for j in range(0, 2 * w, 2): if mat[i][j]: continue mat[i][j] = 1 size = 1 stack = [(i, j)] while stack: y, x = stack.pop() for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)): if 0 <= y + dy * 2 < 2 * h and 0 <= x + dx * 2 < 2 * w and mat[y + dy][x + dx] == 0 and mat[y + dy * 2][x + dx * 2] == 0: mat[y + dy * 2][x + dx * 2] = 1 size += 1 stack.append((y + dy * 2, x + dx * 2)) ans.append(size) print(*sorted(ans)) ```
1,159
Provide tags and a correct Python 3 solution for this coding contest problem. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Tags: dfs and similar, implementation Correct Solution: ``` WHn = [[0,0]] # WHn[0].extend(list(map(int, input().split(' ')))) WHn[0].extend([int(x) for x in input().split(' ')]) n = range(WHn[0][-1]) lines = [] lines_aux = [] for i in n: lines.append( [int(x) for x in input().split(' ')] ) lines_aux.append(True) while any(lines_aux): for i in n: if lines_aux[i]: for unidad in WHn: rangex = range(unidad[0], unidad[2]+1) rangey = range(unidad[1], unidad[3]+1) if (lines[i][0] in rangex) and (lines[i][3] in rangey) and (lines[i][2] in rangex) and (lines[i][1] in rangey) and\ ( (lines[i][0:3:2] == unidad[0:3:2]) or (lines[i][1:4:2] == unidad[1:4:2]) ): WHn.append([unidad[0],unidad[1],lines[i][2],lines[i][3]]) WHn.append([lines[i][0],lines[i][1],unidad[2],unidad[3]]) WHn.remove(unidad) lines_aux[i] = False break for i,unidad in enumerate(WHn): WHn[i] = (unidad[2] - unidad[0])*(unidad[3] - unidad[1]) WHn.sort() result = '' for i in WHn: result += '{} ' print(result[:-1].format(*WHn)) ```
1,160
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Submitted Solution: ``` WHn = [[0,0]] # WHn[0].extend(list(map(int, input().split(' ')))) WHn[0].extend([int(x) for x in input().split(' ')]) n = WHn[0][-1] for i in range(n): # lines = list(map(int, input().split(' '))) lines = [int(x) for x in input().split(' ')] for unidad in WHn: rangex = range(unidad[0], unidad[2]+1) rangey = range(unidad[1], unidad[3]+1) if (lines[0] in rangex) and (lines[3] in rangey) and\ (lines[2] in rangex) and (lines[1] in rangey): WHn.append([unidad[0],unidad[1],lines[2],lines[3]]) WHn.append([lines[0],lines[1],unidad[2],unidad[3]]) WHn.remove(unidad) break for i,unidad in enumerate(WHn): WHn[i] = (unidad[2] - unidad[0])*(unidad[3] - unidad[1]) WHn.sort() print(WHn) ``` No
1,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Submitted Solution: ``` w,h,n=list(map(int,input().split())) a=[[0 for i in range(2*w-1)] for j in range(2*h-1)] for i in range(1,2*h-1,2): for j in range(1,2*w-1,2): a[i][j]=' ' for i in range(n): x1,y1,x2,y2=list(map(int,input().split())) if x1==x2: if x1!=0 and x1!=w: for j in range(max(1,min(y1,y2)),max(y1,y2)+1): a[2*h-2-2*(j-1)][2*x1-1]=' ' else: if y1!=0 and y1!=h: for j in range(min(x1,x2),max(x1,x2)): a[2*h-1-2*y1][2*j]=' ' b=[] c=1 for i in range(0,2*h-1,2): for j in range(0,2*w-1,2): if a[i][j]==0: d=i e=j while d<2*h-1 and a[d][e]==0 and a[d-1][e]!=' ' or d==i: d+=2 d-=2 while e<2*w-1 and a[d][e]==0 and a[d][e-1]!=' ' or e==j: e+=2 e-=2 b.append(((e-j)//2+1)*((d-i)//2+1)) for k in range(i,d+1,2): for l in range(j,e+1,2): a[k][l]=c c+=1 b+=[0]*(n+1-len(b)) print(*sorted(b)) ``` No
1,162
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. Output Output n + 1 numbers — areas of the resulting parts in the increasing order. Examples Input 2 2 2 1 0 1 2 0 1 1 1 Output 1 1 2 Input 2 2 3 1 0 1 2 0 1 1 1 1 1 2 1 Output 1 1 1 1 Input 2 4 2 0 1 2 1 0 3 2 3 Output 2 2 4 Submitted Solution: ``` WHn = [[0,0]] # WHn[0].extend(list(map(int, input().split(' ')))) WHn[0].extend([int(x) for x in input().split(' ')]) n = WHn[0][-1] for i in range(n): # lines = list(map(int, input().split(' '))) lines = [int(x) for x in input().split(' ')] for unidad in WHn: rangex = range(unidad[0], unidad[2]+1) rangey = range(unidad[1], unidad[3]+1) if (lines[0] in rangex) and (lines[3] in rangey) and\ (lines[2] in rangex) and (lines[1] in rangey): WHn.append([unidad[0],unidad[1],lines[2],lines[3]]) WHn.append([lines[0],lines[1],unidad[2],unidad[3]]) WHn.remove(unidad) break for i,unidad in enumerate(WHn): WHn[i] = (unidad[2] - unidad[0])*(unidad[3] - unidad[1]) WHn.sort() result = "" for i in WHn: result+="{} " print(result[:-1].format(*WHn)) ``` No
1,163
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` s = input() a = [] for i in s: if len(a) > 0: if a[-1] == i: a.pop() else: a.append(i) else: a.append(i) if len(a) > 0: print('No') else: print('Yes') ```
1,164
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` s = input() if len(s)%2:print('No');exit(0) if s[::2].count('+')-s[1::2].count('+')==0:print('Yes');exit(0) print('No') ```
1,165
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` i=input() s=[] for k in i: l=len(s) if l==0 : s+=k elif k==s[l-1] : del(s[l-1]) else : s+=k l=len(s) if l==0 : print("Yes") else : print("No") ```
1,166
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` a=input() if len(a)%2==1: print('No') else: l=[] for i in a: if l==[]: l.append(i) elif i!=l[-1]: l.append(i) else: l.pop() if l==[]: print('Yes') else: print('No') ```
1,167
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` s=input() stk=[] for c in s: if len(stk) and stk[-1]==c: stk.pop() else: stk.append(c) if len(stk): print('No') else: print('Yes') ```
1,168
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` a=input() if len(a)%2==1: print('No') else: odd=0 even=0 for i in range(len(a)): if a[i]=='-': if i%2==0: even+=1 else: odd+=1 if even==odd: print('Yes') else: print('No') ```
1,169
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` input = input() stack = [] for wire in input: if len(stack) == 0 or wire != stack[-1]: stack.append(wire) else: stack.pop() print("YES" if len(stack) == 0 else "NO") ```
1,170
Provide tags and a correct Python 3 solution for this coding contest problem. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Tags: data structures, greedy, implementation Correct Solution: ``` __author__ = 'Utena' import collections s=input() if len(s)%2==1: print('No') exit(0) t1=t2=0 for i in range(len(s)): if s[i]=='-': if i%2==0:t1+=1 else:t2+=1 if t1==t2:print('Yes') else:print('No') ```
1,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` n=input() s=0 for i in range(len(n)): if n[i]=='-': s+=2*(i-2*(i//2))-1 else: s+=-2*(i-2*(i//2))+1 if s==0:print('Yes') else:print('No') ``` Yes
1,172
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) def untangle(sequence): s = Stack() for i in sequence: if not s.isEmpty(): if i == s.peek(): s.pop() else: s.push(i) else: s.push(i) if not s.isEmpty(): print("No") else: print("Yes") quence = input() untangle(quence) ``` Yes
1,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` s=input() l=len(s) i=0 stack=list() while i<l: if len(stack) == 0: stack.append(s[i]) i=i+1 else: t=stack[-1] if t == s[i]: stack.pop() else: stack.append(s[i]) i=i+1 if len(stack) == 0: print('Yes') else: print('No') ``` Yes
1,174
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` class Stack: def __init__(self): self._data = [] def __len__(self): return len(self._data) def is_empty(self): return len(self._data)==0 def push(self,a): self._data.append(a) def top(self): if self.is_empty(): raise Empty('Stack is empty') return self._data[-1] def pop(self): if self.is_empty(): raise Empty('Stack is empty') return self._data.pop() if __name__ == '__main__': l = str(input()) s = Stack() for i in l: if s.is_empty(): s.push(i) elif s.top() == i: s.pop() else: s.push(i) if s.is_empty(): print('Yes') else: print('No') ``` Yes
1,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` c=[] a=input().split() for i in a : if not c: c.append(a.pop()) else: try: d=a.pop() if d==c[1]: c.pop() else: print('False') exit() except: if d==c[0]: c.pop() else: c.append(d) if c: print('Flase') else: print('True') ``` No
1,176
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` class ArrayStack: """LIFO Stack implementation using a Python list as underlying storage.""" def __init__(self): """Create an empty stack.""" self._data = [] # nonpublic list instance def __len__(self): """Return the number of elements in the stack.""" return len(self._data) def is_empty(self): """Return True if the stack is empty.""" return len(self._data) == 0 def push(self, e): """Add element e to the top of the stack.""" self._data.append(e) # new item stored at end of list def top(self): """Return (but do not remove) the element at the top of the stack. Raise Empty exception if the stack is empty. """ ##if self.is_empty(): ## raise Empty('Stack is empty') return self._data[-1] # the last item in the list def pop(self): """Remove and return the element from the top of the stack (i.e., LIFO). Raise Empty exception if the stack is empty. """ ##if self.is_empty(): ## raise Empty('Stack is empty') return self._data.pop() # remove last item from list S=ArrayStack() A=input() B=list(A) l=len(B) if l%2==1: print('No') else: for i in range(l): S.push(B[i]) k=0 zh=0 fu=0 a=S.pop() b=S.pop() if a==b: pass else: S.push(a) S.push(b) if B[0]==B[1]: S.top() S.top() while not S.is_empty(): a=S.pop() if S.is_empty(): if a=='+': zh+=1 if a=='-': fu+=1 break else: b=S.pop() S.push(b) if a==b: k=1 if a=='+': zh+=1 if a=='-': fu+=1 if k==1 and zh%2==0 and fu%2==0: print('Yes') else: print('No') ``` No
1,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` wires=list(input()) #print(len(wires)) t=0 g=0 if (len(wires)%2)!=0: #print(len(wires)) print("No") exit() else: for i in range(len(wires)-1): if wires[i]=='+' and wires[i+1]=='-': t+=1 if wires[i]=='+' and wires[i+1]=='+': g+=1 if t==g: print('Yes') else: print('No') ``` No
1,178
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): <image> Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Examples Input -++- Output Yes Input +- Output No Input ++ Output Yes Input - Output No Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: <image> In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: <image> In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: <image> Submitted Solution: ``` def DDP(a): if len(a)<=1: return ''.join(a) ans=[] a=list(a) if not(a[0]=='+' and a[1]=='+'): ans.append(a[0]) for i in range(1,len(a)-1): if a[i]=='-' or not ((a[i]=='+' and a[i-1]=='+') or (a[i]=='+' and a[i+1]=='+')) : ans.append(a[i]) if not(a[-2]=='+' and a[-1]=='+'): ans.append(a[-1]) a=[] if len(ans)<=1: return ''.join(ans) if not(ans[0]=='-' and ans[1]=='-'): a=[ans[0]] for i in range(1,len(ans)-1): if ans[i]=='+' or not ((ans[i]=='-' and ans[i-1]=='-') or (ans[i]=='-' and ans[i+1]=='-')) : a.append(ans[i]) if not(ans[-2]=='-' and ans[-1]=='-') : a.append(ans[-1]) return ''.join(a) a=input() if len(a)%2==1 or '-+-+-+-' in a: print('No') else: t1=DDP(a) t2='' while t1!=t2: t2=t1 t1=DDP(t1) if t1=='': print('Yes') else: print('No') ``` No
1,179
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` n,x=map(int,input().split()) l=list(map(int,input().split())) m=int(input()) if m>=n: print(sum(l)-(m-n)*x) # j = sorted(l) # print(j) else: j=sorted(l) # print(j) c=0 for i in range (m): c+=j[i] print(c) ```
1,180
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` n, d = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() m = int(input()) if m <= n: print(sum(arr[:m])) else: print(sum(arr) - d * (m-n)) ```
1,181
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` n, d = list(map(int, input().split())) a = list(map(int, input().split())) m = int(input()) s = 0 a.sort() for i in range(m): if i < len(a): s += a[i] else: s -= d print(s) ```
1,182
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 n, d = tuple(map(int, input().split(None, 2))) a = list(map(int, input().split())) assert len(a) == n m = int(input()) a.sort() if n <= m: print(sum(a) - d * (m - n)) else: print(sum(a[:m])) ```
1,183
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` #!/usr/local/bin/python3 n, d = map(int, input().split()) a = list(map(int, input().split())) m = int(input()) a.sort() if m <= n: result = sum(a[:m]) else: result = sum(a) - (m-n)*d print(result) ```
1,184
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` # It's all about what U BELIEVE import sys input = sys.stdin.readline def gint(): return int(input()) def gint_arr(): return list(map(int, input().split())) def gfloat(): return float(input()) def gfloat_arr(): return list(map(float, input().split())) def pair_int(): return map(int, input().split()) ############################################################################### INF = (1 << 31) MOD = "1000000007" dx = [-1, 0, 1, 0, -1, 1, 1, -1] dy = [ 0, 1, 0, -1, 1, 1, -1, -1] ############################ SOLUTION IS COMING ############################### n, d = gint_arr() a = gint_arr() a.sort() m = gint() res = sum(a[:m]) print(res if m <= n else res - (m - n) * d) ```
1,185
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` M = lambda: map(int, input().split()) L = lambda: list(map(int, input().split())) I = lambda: int(input()) n, d = M() a, k = sorted(L()), I() print(sum(a) + (n - k) * d if n < k else sum(a[: k])) ```
1,186
Provide tags and a correct Python 3 solution for this coding contest problem. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Tags: implementation Correct Solution: ``` n, d = map(int, input().split()) a = list(map(int, input().split())) m = int(input()) s = 0 a = sorted(a) zanyat = n - m if zanyat == 0: s = sum(a) elif zanyat > 0: s = sum(a[:m]) else: # print(zanyat) s = zanyat * d + sum(a) print(s) ```
1,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n, d = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() m = int(input()) print(sum(arr[:m]) if m <= n else sum(arr) - d * (m-n)) ``` Yes
1,188
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n, d = tuple(map(int, str.split(input()))) a = sorted(map(int, str.split(input()))) m = int(input()) print(sum(a[:min(m, n)]) - max(0, m - n) * d) ``` Yes
1,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n,d = map(int,input().split()) l = list(map(int,input().split())) m = int(input()) l.sort() if(m>=n): print(sum(l[:n])-(m-n)*d) else: print(sum(l[:m])) ``` Yes
1,190
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n,d=map(int,input().split()) l=list(map(int,input().split())) m=int(input()) if n<m: print(sum(l)-d*(m-n)) else: l.sort() print(sum(l[:m])) ``` Yes
1,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n,d=(int(i) for i in input().split()) l=[int(i) for i in input().split()] m=int(input()) print(sum(l)-(m-n)*d) ``` No
1,192
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n, d = map(int, input().split()) a = list(map(int, input().split())) a.sort() m = int(input()) ans = sum(a[:m]) ans -= (m-n)*d print(ans) ``` No
1,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n,d=map(int,input().split()) a=list(map(int,input().split())) m=int(input()) sumi=sum(a) if n<m: print(sumi-(m-n)*d) else: print(sumi) ``` No
1,194
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. Input The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100). Output In a single line print a single integer — the answer to the problem. Examples Input 2 1 2 1 2 Output 3 Input 2 1 2 1 10 Output -5 Note In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles. In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5. Submitted Solution: ``` n, d = [int(i) for i in input().split()] a = [int(i) for i in input().split()] m = int(input()) ans = 0 for i in a: ans += i if n < m: ans -= (m - n) * d print(ans); ``` No
1,195
Provide tags and a correct Python 3 solution for this coding contest problem. Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song! Input The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106). Output In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song. Examples Input 3 1 1 2 2 2 3 Output 4 Input 1 2 5 Output -1 Note In the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4. In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1. Tags: implementation Correct Solution: ``` N, A, B, Joy = int(input()), list(map(int, input().split())), list(map(int, input().split())), 0 for i in range(N): if A[i] * 2 < B[i] or B[i] == 1: Joy -= 1 else: Joy += ((B[i] // 2) ** 2 if B[i] % 2 == 0 else B[i] // 2 * (B[i] // 2 + 1)) print(Joy) # Caption: God bless you General Soleimani # ---------Hard Revenge--------- # ****** Rest in Peace ****** ```
1,196
Provide tags and a correct Python 3 solution for this coding contest problem. Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song! Input The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106). Output In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song. Examples Input 3 1 1 2 2 2 3 Output 4 Input 1 2 5 Output -1 Note In the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4. In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1. Tags: implementation Correct Solution: ``` # # import numpy as np # # def spliter(arr,low,high): # if(high-low==1): # # print("1") # return 1 # # if(arr[low:high]==sorted(arr[low:high])): # # print("here "+str(high-low)) # return high-low # else: # mid=(high+low)//2 # # print("----------") # # print((low,mid)) # # print("---------") # # print((mid,high)) # # print("-----------") # a=spliter(arr,low,mid) # # print("was here") # b=spliter(arr,mid,high) # # # print((a,b)) # if(a>=b): # return a # else: # return b # # def main(): # n=int(input()) # arr=list(map(int,input().split(" "))) # lenght = n # if arr==sorted(arr): # print(n) # else: # mid=lenght//2 # a=spliter(arr,0,mid) # b=spliter(arr,mid,lenght) # if(a>b): # print(a) # else: # print(b) # # main() # def main(): # checker="nineteen" # # n="nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii" # n=input() # number={} # # print(set(n)) # for i in n: # if i in checker: # number[i]=number.get(i,0)+1 # # number=sorted(number.values()) # # print(sorted(number.keys())) # for i in ["n","t","i","e"]: # if i not in number.keys(): # break # # else: # num=number["i"] # min=num # other_Dict={"n":3,"i":1,"e":3,"t":1} # if(number["n"]%3==2): # number["n"]=number.get("n",0)+number["n"]//3 # # for i in number.keys(): # if (number[i]//other_Dict[i]>=num): # pass # elif(number[i]//other_Dict[i]<=num): # # if(min>number[i]//other_Dict[i]): # min=number[i]//other_Dict[i] # else: # print(min) # return # print(0) # main() # return False # for i,j in number: # if i=="n" and i # # print(number) # print(main()) # main() # d={} # d[10]=1 # d[10]+=2 # d[10].append(10) # 2//3 # d.get(10,5) # d.keys() # main() # d={} # for i in "nineteen": # d[i]=d.get(i,0)+1 # d # "i" not in d.keys() # some="nineoindojaoidjoiajdoiaoidjiadjkajoidjoiajdljadjoiadlkjaadj" # list(some.split("nineteen")) # # # def main(): # n=list(map(int,input().split(" "))) # navigation=[] # for i in range(n[1]-n[2],n[1]): # if(i>0): # navigation.append(i) # for i in range(n[1],n[1]+n[2]+1): # if(i<=n[0]): # navigation.append(i) # if(navigation[0]>1): # navi=[0]*len(navigation) # navi[0]="<<" # navi[1:len(navigation)]=navigation # navigation=navi # if(navigation[len(navigation)-1]<n[0]): # navigation.append(">>") # string="" # for i in navigation: # if(str(i)==str(n[1])): # string+="({}) ".format(i) # else: # string+="{} ".format(i) # print(string[:-1]) # main() # question number Inna and Alarm Clock # import numpy as np # def inna_and_alarm_clock: # n=int(input()) # matrix=[] # display=[[0]*100]*100 # display=np.array(display) # rows=[] # columns=[] # for _ in range(n): # matrix.append(map(int,input().split(" "))) # # matrix=data # for i,j in matrix: # # print((i,j)) # display[j][i]=1 # print(np.array(display)) # vertical_steps=0 # horizontal_steps=0 # for i in range(100): # if 1 in display[:,i]: # horizontal_steps+=1 # for i in range(100): # if 1 in display[i,:]: # vertical_steps+=1 # if(horizontal_steps<vertical_steps): # print(horizontal_steps) # else: # print(vertical_steps) # # # data=np.array([[1,1],[1,2],[2,3],[3,3]]) # main() # # arr=[[1,1],[1,2],[2,3],[3,3]] def main(): n=int(input()) a=list(map(float,input().split(" "))) b=list(map(float,input().split(" "))) iterr=list(zip(a,b)) happiness=0 for x,y in iterr: # print("x={},y={}".format(x,y),end=" ") # print((x,y)) if(x<y/2 or y==1): happiness-=1 elif(x==y/2): happiness+=x*x elif(x>y/2): if(y%2==0): x=y//2 happiness+=x*x else: x=(y+1)//2 happiness+=(x*(y-x)) # print(happiness) # happiness+=x*x print(int(happiness)) main() ```
1,197
Provide tags and a correct Python 3 solution for this coding contest problem. Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song! Input The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106). Output In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song. Examples Input 3 1 1 2 2 2 3 Output 4 Input 1 2 5 Output -1 Note In the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4. In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1. Tags: implementation Correct Solution: ``` def great_sum_finder(num, rang): if abs(num - rang) > rang or num == 1: return -1 if rang == 1: return 1 if num < rang: return great_sum_finder(num, num - 1) return (num // 2) * (num - num // 2) n = int(input()) a = input().split() b = input().split() a = list(map(int, a)) b = list(map(int, b)) joy = 0 for i in range(n): joy += great_sum_finder(b[i], a[i]) print(joy) ```
1,198
Provide tags and a correct Python 3 solution for this coding contest problem. Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song! Input The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106). Output In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song. Examples Input 3 1 1 2 2 2 3 Output 4 Input 1 2 5 Output -1 Note In the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4. In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1. Tags: implementation Correct Solution: ``` n = int(input()) a = input().split() a = list(map(lambda x: int(x) if x.isdigit() else 0, a)) b = input().split() b = list(map(lambda x: int(x) if x.isdigit() else 0, b)) sum = 0 while(len(a) > 0): if(b[len(a)-1] == 1): sum-=1 else: if(a[len(a)-1] == 1): if(b[len(a)-1] == 2): sum+=1 else: sum-=1 else: c = int(b[len(a)-1]/2) while(c > a[len(a)-1]): c-=1 if(b[len(a)-1] - c > a[len(a)-1]): sum-=1 else: sum = sum + c*(b[len(a)-1]-c) d = len(a) del a[d-1] del b[d-1] print(sum) ```
1,199