description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
def reverse(m): t = "" for i in m: if i == "1": t = t + "0" else: t = t + "1" return t class Solution: def findKthBit(self, n: int, k: int) -> str: s = "0" while n > 1: t = reverse(s) s = s + "1" + t[::-1] n -= 1 return s[k - 1]
FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING RETURN VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: s = "0" for i in range(2, n + 1): sRevInv = "".join([("1" if c == "0" else "0") for c in s[::-1]]) s = s + "1" + sRevInv if len(s) >= k: return s[k - 1] return s[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR STRING STRING STRING VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR IF FUNC_CALL VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: dp = [None] * n dp[0] = "0" for i in range(1, n): m = "" inv = self.invert(dp[i - 1], m) rev = self.reverse(inv) dp[i] = dp[i - 1] + "1" + rev return dp[-1][k - 1] def reverse(self, string): return string[::-1] def invert(self, string, m): for i in range(len(string)): if string[i] == "1": m += "0" else: m += "1" return m
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR RETURN VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING RETURN VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: switch = {"0": "1", "1": "0"} s = "0" while len(s) < k: s = s + "1" + "".join(switch[i] for i in reversed(s)) return s[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: def reverse(cur_s): return "".join([c for c in reversed(cur_s)]) def invert(cur_s): return "".join([("1" if c == "0" else "0") for c in cur_s]) S = "0" for i in range(1, n): S += "1" + reverse(invert(S)) return S[k - 1]
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR STRING STRING STRING VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: s = "0" inv = "1" rev_inv = "1" for i in range(n - 1): s = s + "1" + rev_inv inv = "" rev_inv = "" for j in range(len(s)): if s[j] == "0": inv += "1" else: inv += "0" rev_inv = inv[::-1] return s[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def invert(s): inv_s = "" for char in s: if char == "1": inv_s += "0" else: inv_s += "1" return inv_s answer = ["0"] for i in range(1, 21): prev_s = answer[i - 1] answer.append(prev_s + "1" + invert(prev_s)[::-1]) def findKthBit(self, n: int, k: int) -> str: return self.answer[n - 1][k - 1]
CLASS_DEF FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR NUMBER FUNC_DEF VAR VAR RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: if n == 1: return "0" def rev(s): return s[::-1] def invert(r): t = "" for i in r: if i == "1": t += "0" else: t += "1" return t z = "0" for i in range(2, n + 1): a = invert(z) b = rev(a) z += "1" + b return z[k - 1]
CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER RETURN STRING FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP STRING VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: s = ["0"] for _ in range(n - 1): s += ["1"] + [("1", "0")[int(x)] for x in reversed(s)] return s[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST STRING STRING STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: k -= 1 s = "0" i = 0 while i < n: inverted = "".join("1" if c == "0" else "0" for c in s)[::-1] s = s + "1" + inverted i += 1 return s[k]
CLASS_DEF FUNC_DEF VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL STRING VAR STRING STRING STRING VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR VAR NUMBER RETURN VAR VAR VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: def build_string(n): previous = "0" for i in range(1, n): invert = "" for c in previous: if c == "1": invert += "0" else: invert += "1" previous = previous + "1" + invert[::-1] return previous ans = build_string(n) return ans[k - 1]
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: S = [0] for i in range(2, n + 1): S += [1] + [(1 if i == 0 else 0) for i in S[::-1]] return str(S[k - 1])
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER VAR NUMBER NUMBER NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: s = ["0"] for i in range(n - 1): temp1 = s.copy() for i in range(len(temp1)): if temp1[i] == "0": temp1[i] = "1" elif temp1[i] == "1": temp1[i] = "0" temp1.reverse() temp = s + ["1"] + temp1 s = temp return s[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST STRING VAR ASSIGN VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: l = [0] for _ in range(n - 1): l = l + [1] + [(1 - b) for b in reversed(l)] if len(l) >= k: return str(l[k - 1]) return str(l[k - 1])
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: bits = [False] for i in range(1, n + 1): bits.extend([True] + [(j == False) for j in bits[::-1]]) return str(int(bits[k - 1]))
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: memo_table = [""] * n memo_table[0] = "0" for i in range(1, n): memo_table[i] = self.new_level(memo_table[i - 1]) return memo_table[n - 1][k - 1] def new_level(self, old_level: str): new_level = ["1"] * (len(old_level) * 2 + 1) left = 0 right = len(old_level) * 2 for c in old_level: new_level[left] = c if c == "0": new_level[right] = "1" else: new_level[right] = "0" left += 1 right -= 1 return "".join(new_level)
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER RETURN FUNC_CALL STRING VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: cache = [""] * n def gen_str(n): if n - 1 in cache: return cache[n - 1] if n == 1: s = "0" cache[0] = s return s prev = gen_str(n - 1) s = prev + "1" for c in reversed(prev): if c == "0": s += "1" else: s += "0" cache[n - 1] = s return s return gen_str(n)[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: s0 = "0" i = 1 while i <= n: s0 = s0 + "1" + self.reverse(s0) i = i + 1 return s0[k - 1] def reverse(self, s): mapp = {"1": "0", "0": "1"} ans = "" for x in s: ans = ans + mapp[x] return ans[::-1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR NUMBER
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: def invert(data): ans = "" for val in data: ans += "1" if val == "0" else "0" return ans output = "0" for i in range(1, n + 1): output += "1" + invert(output)[::-1] if len(output) >= k: break return output[k - 1]
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR VAR STRING STRING STRING RETURN VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: s = "0" for i in range(1, n): chars = [] for j in reversed(list(range(len(s)))): chars.append("1" if s[j] == "0" else "0") s += "1" + "".join(chars) return s[k - 1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING STRING VAR BIN_OP STRING FUNC_CALL STRING VAR RETURN VAR BIN_OP VAR NUMBER VAR
Given two positive integers n and k, the binary string  Sn is formed as follows: S1 = "0" Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1 Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0). For example, the first 4 strings in the above sequence are: S1 = "0" S2 = "011" S3 = "0111001" S4 = "011100110110001" Return the kth bit in Sn. It is guaranteed that k is valid for the given n.   Example 1: Input: n = 3, k = 1 Output: "0" Explanation: S3 is "0111001". The first bit is "0". Example 2: Input: n = 4, k = 11 Output: "1" Explanation: S4 is "011100110110001". The 11th bit is "1". Example 3: Input: n = 1, k = 1 Output: "0" Example 4: Input: n = 2, k = 3 Output: "1"   Constraints: 1 <= n <= 20 1 <= k <= 2n - 1
class Solution: def findKthBit(self, n: int, k: int) -> str: series = ["0"] for i in range(n - 1): series = self.getNext(series) return series[k - 1] def getNext(self, series): extension = series[::-1] for idx, c in enumerate(extension): if c == "0": extension[idx] = "1" else: extension[idx] = "0" return series + ["1"] + extension
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING RETURN BIN_OP BIN_OP VAR LIST STRING VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
def solution(): n = int(input()) s = input() ans = 0 for i in range(n): record = {"+": 0, "-": 0} for j in range(i, n): record[s[j]] += 1 dif = record["-"] - record["+"] ans += dif >= 0 and dif % 3 == 0 print(ans) t = int(input()) for _ in range(t): solution()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR STRING VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
for _ in range(int(input())): n = int(input()) s = input() ans = 0 for i in range(len(s)): p, m = 0, 0 for j in range(i, len(s)): if s[j] == "+": p = p + 1 elif s[j] == "-": m = m + 1 if m >= p and (m - p) % 3 == 0: ans = ans + 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
n = int(input()) for i in range(n): t = int(input()) l = input() m = 0 c = 0 R = [] for j, ch in enumerate(l): if ch == "-": a = 1 else: a = -1 f = [] if j == 0: f.append(a) if a < 0: a = 0 elif a == 0: m = m + 1 elif a % 3 == 0: m += 1 else: f.append(a) if a < 0: a = -1 elif a == 0: m = m + 1 elif a % 3 == 0: m += 1 for i in range(j): c = a + R[j - 1][i] f.append(c) if c < 0: c = 0 elif c == 0: m = m + 1 elif c % 3 == 0: m += 1 R.append(f) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
def promisingstring(s): n = len(s) presum = [0] * (n + 1) ans = 0 for i in range(1, n + 1): if s[i - 1] == "+": presum[i] = presum[i - 1] + 1 else: presum[i] = presum[i - 1] - 1 for i in range(1, n + 1): for j in range(i): if presum[i] - presum[j] <= 0 and (presum[i] - presum[j]) % 3 == 0: ans += 1 return ans t = int(input()) for _ in range(t): _ = input() s = input() print(promisingstring(s))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
def promising(x): if not x % 3 and x > -1: return 1 return 0 for tc in range(int(input())): count, n, balance = ( 0, int(input()), [(1 if char == "-" else -1) for char in input()], ) for i in range(n - 1): x = sum(balance[i : i + 2]) count += promising(x) for j in range(i + 2, n): x += balance[j] count += promising(x) print(count)
FUNC_DEF IF BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
t = int(input()) for i in range(t): n = int(input()) s = input() c = 0 se = set() lsta = [] for j in range(n - 1): p = 0 m = 0 for k in range(j, n): if s[k] == "+": p += 1 else: m += 1 if p == m: lsta.append(1) c += 1 elif m > p: if (m - p) % 3 == 0: lsta.append(1) print(len(lsta))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
ans = [] for i in range(int(input())): n = int(input()) inpstr = list(input().strip()) balance = [] bal = n balance.append(bal) cnt = 0 for _ in range(1, n + 1): if inpstr[_ - 1] == "+": bal += 1 else: bal -= 1 balance.append(bal) for __ in range(_): if (balance[__] >= balance[_]) & ((balance[__] - balance[_]) % 3 == 0): cnt += 1 ans.append(cnt) for answ in ans: print(answ)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
t = int(input()) for _ in range(t): n = int(input()) s = input() promising = 0 for i in range(n): plus = 0 minus = 0 for j in range(i, n): if s[j] == "+": plus += 1 elif s[j] == "-": minus += 1 if plus <= minus and (minus - plus) % 3 == 0: promising += 1 print(promising)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
for _ in range(int(input())): n = int(input()) temp = input() subl, plul = [(0) for i in range(n + 1)], [(0) for i in range(n + 1)] ans = 0 for i in range(n): if temp[i] == "+": plul[i + 1] = plul[i] + 1 subl[i + 1] = subl[i] else: subl[i + 1] = subl[i] + 1 plul[i + 1] = plul[i] for i in range(n): for j in range(i + 1, n): subcount = subl[j + 1] - subl[i] addcount = plul[j + 1] - plul[i] if (subcount - addcount) % 3 == 0 and subcount >= addcount: ans += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
tst = int(input()) for _ in range(tst): n = int(input()) s = input() f = [(0) for i in range(3)] cur_bal = n cnt_bal = [(0) for i in range(2 * n + 1)] cnt_bal[cur_bal] += 1 f[cur_bal % 3] += 1 ans = 0 for i in range(n): new_bal = cur_bal if s[i] == "-": new_bal -= 1 f[new_bal % 3] += cnt_bal[new_bal] ans += f[new_bal % 3] cnt_bal[new_bal] += 1 f[new_bal % 3] += 1 else: f[new_bal % 3] -= cnt_bal[new_bal] new_bal += 1 ans += f[new_bal % 3] cnt_bal[new_bal] += 1 f[new_bal % 3] += 1 cur_bal = new_bal print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
testcase = int(input()) for _ in range(testcase): ans = 0 length = int(input()) string = input() for i in range(length): plus = minus = 0 for j in range(i, length): if string[j] == "+": plus += 1 else: minus += 1 if minus < plus: continue if (plus - minus) * 2 % 3 == 0: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
tst = int(input()) for _ in range(tst): n = int(input()) s = input() b = [(0) for i in range(n + 1)] bal = n b[0] = bal ans = 0 for i in range(1, n + 1): if s[i - 1] == "+": bal += 1 else: bal -= 1 b[i] = bal for j in range(i): if b[j] >= b[i] and (b[j] - b[i]) % 3 == 0: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced. We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation: replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced. For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+". How many non-empty substrings of the given string $s$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++". -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 500$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $n$ ($1 \le n \le 3000$): the length of $s$. The second line of the test case contains the string $s$ of length $n$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $n$ over all test cases does not exceed $3000$. -----Output----- For each test case, print a single number: the number of the promising non-empty substrings of string $s$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $s$. -----Examples----- Input 5 3 +-+ 5 -+--- 4 ---- 7 --+---+ 6 +++--- Output 2 4 2 7 4 -----Note----- The following are the promising substrings for the first three test cases in the example: $s[1 \dots 2]$="+-", $s[2 \dots 3]$="-+"; $s[1 \dots 2]$="-+", $s[2 \dots 3]$="+-", $s[1 \dots 5]$="-+---", $s[3 \dots 5]$="---"; $s[1 \dots 3]$="---", $s[2 \dots 4]$="---".
t = int(input()) for _ in range(t): n = int(input()) s = input() pr = [(0) for i in range(n + 1)] for i in range(1, n + 1): if s[i - 1] == "-": pr[i] = pr[i - 1] + 1 else: pr[i] = pr[i - 1] - 1 c = 0 for r in range(n + 1): for l in range(r): if pr[r] - pr[l] >= 0 and (pr[r] - pr[l]) % 3 == 0: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
input() n = [int(x) for x in input().split()] a = -1 aa = 0 for i, x in enumerate(n): aaa = aa + len([x for x in n[i:] if x]) if aaa > a: a = aaa if not x: aa += 1 print(max(a, aa))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def solve(s): zeroes = accum(s, 0) ones = list(reversed(accum(reversed(s), 1))) return max(x + y for x, y in zip(zeroes, ones)) def accum(lst, value): counts = [0] for el in lst: if el == value: counts.append(counts[-1] + 1) else: counts.append(counts[-1]) return counts def main(): n = input() s = list(map(int, input().split())) print(solve(s)) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) t = list(map(int, input().split())) print(max([(i - sum(t[:i]) + sum(t[i:])) for i in range(n + 1)]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = [int(x) for x in input().split()] max_fails = [] fails = 0 for i in range(n): if s[i] == 0: fails += 1 max_fails.append(fails) max_successes = [] successes = 0 for i in range(n - 1, -1, -1): if s[i] == 1: successes += 1 max_successes.append(successes) max_successes = reversed(max_successes) print(max([(x + y) for x, y in zip(max_fails, max_successes)]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = input() def max_l(s): if len(s) <= 1: return len(s) lenE = 0 ind = 0 prev = -1 for i in range(len(s)): if s[i] == "1": lenE += 1 if s[i] == "1" and prev == "0": ind = i - 1 prev = s[i] lenZ = 0 for i in range(ind + 1): if s[i] == "0": lenZ += 1 return max(lenE, lenZ + max_l(s[ind + 1 :])) a = max_l(s) print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) k = -1 l = input() for i in range(len(l) + 1): s = l[:i].count("0") + l[i:].count("1") if s > k: k = s print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = list(map(int, input().split())) res = max([(i - sum(s[:i]) + 1 + sum(s[i + 1 :])) for i in range(n)]) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) lst = list(map(int, input().split())) l, r = 0, lst.count(0) res = r for i, x in enumerate(lst): if x == 0: r -= 1 else: l += 1 if l + r < res: res = l + r print(n - res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = list(map(int, input().split())) cnt = a.count(0) ans = 0 for i in range(cnt + 1): a1 = a[::-1] a2 = [] cnt1 = i index = 0 while cnt1: if not a1[index]: cnt1 -= 1 else: a2.append(a1[index]) index += 1 for j in range(index, n): a2.append(a1[j]) a2 = a2[::-1] index = len(a2) - 1 ansi = 0 while index > -1 and a2[index]: index -= 1 for o in range(index, -1, -1): if a2[o]: ansi += 1 ans = max(len(a2) - ansi, ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def list_input(): return list(map(int, input().split())) def map_input(): return map(int, input().split()) def map_string(): return input().split() n = int(input()) a = list_input() cur = 0 ans = 0 for i in range(n): if a[i] == 0: cur += 1 ans = max(ans, cur + a[i + 1 :].count(1)) print(max(ans, a.count(1)))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def test(i): answer = s[:i].count(0) + s[i:].count(1) return answer n = int(input()) s = list(map(int, input().split())) answer = [] for i in range(n + 1): answer.append(test(i)) print(max(answer))
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = [int(x) for x in input().split()] r = 0 for i in range(len(a) + 1): x = a[:i].count(0) y = a[i:].count(1) r = max(r, x + y) print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
N = 107 n = int(input()) a = list(map(int, input().split())) a.insert(0, 0) f = [[(0) for j in range(N)] for i in range(N)] f[0][0] = 0 f[1][0] = 0 f[1][1] = 1 for i in range(2, n + 1): for j in range(i): if a[j] == 0 or a[j] == 1 and a[i] == 1: f[i][i] = max(f[i][i], f[i - 1][j] + 1) f[i][j] = max(f[i][j], f[i - 1][j]) res = 0 for i in range(n + 1): res = max(res, f[n][i]) print(res)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
import sys input = sys.stdin.readline n = int(input()) s = list(map(int, input().split())) zc, res = [(0) for i in range(105)], 0 for i in range(1, n + 1): zc[i] = zc[i - 1] + (1 if s[i - 1] == 0 else 0) for i in range(1, n + 1): lzc = zc[i - 1] roc = n - i - (zc[n] - zc[i]) res = max(res, lzc + 1 + roc) print(res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = list(map(int, input().split(" "))) ones = sum(1 for v in s if v == 1) zeroes = sum(1 for v in s if v == 0) zero_ones = 0 loss = 0 for i in range(n): if s[i] == 1: loss += 1 continue loss_zeroes = 0 j = i + 1 while j < n: if s[j] == 0 and s[j - 1] == 1: while j < n and s[j] == 0: loss_zeroes += 1 j += 1 continue j += 1 zero_ones = max(zero_ones, n - loss - loss_zeroes) print(max(ones, zeroes, zero_ones))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) line = list(map(int, input().split())) ans = -1 for i in range(n + 1): ans1 = 0 for j in range(n): if j < i and line[j] == 0: ans1 += 1 elif j >= i and line[j] == 1: ans1 += 1 ans = max(ans, ans1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = input() a = [int(x) for x in input().split()] sum0 = 0 sum1 = 0 for i in a: if i == 1: sum1 = max(sum1 + 1, sum0 + 1) else: sum0 = sum0 + 1 print(max(sum1, sum0))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) l = input().split() z, o = 1, l.count("1") maxi = max(o, n - o) for i in l: if i == "1": o -= 1 if o + z > maxi: maxi = o + z else: z += 1 print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = list(map(int, input().split())) one = [] zero = 0 for i in range(n): if a[i] == 1: one.append(i) else: zero += 1 if len(one) == 0: print(zero) else: num = zero for i in range(len(one)): pre0 = 0 suf0 = 0 tmp1 = 0 for j in range(n): if j < one[i] and a[j] == 0: pre0 += 1 elif one[i] <= j and a[j] == 1: tmp1 += 1 num = max(pre0 + tmp1, num) print(num)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = list(map(int, input().split())) max_l = 0 z, o = 0, 0 for i in range(n): o = 0 if a[i] == 0: z += 1 for j in range(i, n): if a[j] == 1: o += 1 max_l = max(max_l, z + o) print(max_l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = [0] + list(map(int, input().split())) a, b = [0] * (n + 1), [0] * (n + 2) for i in range(n): a[i + 1] = a[i] if s[i + 1] else a[i] + 1 b[n - i] = b[n - i + 1] + 1 if s[n - i] else b[n - i + 1] ans = 0 for i in range(n + 1): ans = max(ans, a[i] + b[i + 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) games = list(map(int, input().split())) after = [0] * n if games[-1] == 1: after[-1] = 1 else: after[-1] = 0 for i in range(n - 2, -1, -1): if games[i] == 1: after[i] = after[i + 1] + 1 else: after[i] = after[i + 1] curnull = 0 ans = 0 for i in range(n): if games[i] == 0: curnull += 1 ans = max(ans, curnull + after[i]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = [int(i) for i in input().split()] answer = [0] * n answer[0] = 1 for i in range(1, n): if a[i] == 1: answer[i] = max(answer) + 1 else: temp_max = 0 for j in range(i): if a[j] == 0 and answer[j] > temp_max: temp_max = answer[j] answer[i] = temp_max + 1 print(max(answer))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
N = int(input()) A = list(map(int, input().split())) ans = sum(1 for x in A if x == 0) for i in range(N): if A[i] == 1: pref = sum(1 for x in A[:i] if x == 0) suff = sum(1 for x in A[i:] if x == 1) ans = max(ans, pref + suff) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) seq = list(input().split(" ")) totalzeroes = seq.count("0") ans = totalzeroes ones, zeroes = 0, 0 for s in seq[::-1]: if s == "1": ones += 1 else: zeroes += 1 ans = max(ans, totalzeroes + ones - zeroes) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = [int(i) for i in input().split()] ans = 0 for i in range(a.count(0) + 1): zc = 0 for j in range(n): if a[j] == 0: zc += 1 if zc == i: break ans = max(ans, i + a[j:].count(1)) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = [int(i) for i in input().split()] print(max([(s[:i].count(0) + s[i:].count(1)) for i in range(len(s) + 1)]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n): res = max(res, i - sum(a[:i]) + 1 + sum(a[i + 1 :])) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) t = -1 an = 0 a = list(map(int, input().split())) while a.count(1): an = max(a.index(1) + a.count(1), an) del a[a.index(1)] print(max(an, len(a)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) projects = input().split(" ") best = 0 for i in range(len(projects)): cur = 1 cur += projects[:i].count("0") cur += projects[i + 1 : n].count("1") best = max(best, cur) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
import sys sys.setrecursionlimit(100000) def parser(): while 1: data = list(input().split(" ")) for number in data: if len(number) > 0: yield number input_parser = parser() def get_word(): global input_parser return next(input_parser) def get_number(): data = get_word() try: return int(data) except ValueError: return float(data) ans = 0 a = input() st = input().split() m0 = 0 m1 = 0 ans = 0 for i in st: if int(i): m1 = max(m0, m1) + 1 else: m0 += 1 ans = max(m0, m1) print(ans)
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = list(map(int, input().split())) f0 = [0] * (n + 1) for i in range(n): if s[i] == 0: f0[i] = f0[i - 1] + 1 else: f0[i] = f0[i - 1] f1 = [0] * (n + 1) for i in range(n - 1, -1, -1): if s[i] == 1: f1[i] = f1[i + 1] + 1 else: f1[i] = f1[i + 1] ans = 0 for i in range(n): if ans < f0[i] + f1[i]: ans = f0[i] + f1[i] ans = max(f0[n - 1], f1[0], ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) def it(): A = list(map(int, input().split())) A.reverse() c1 = 0 r0 = len(A) - sum(A) yield r0 for a in A: if a == 1: c1 += 1 yield c1 + r0 else: r0 -= 1 print(max(it()))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def read_ints(): return [int(i) for i in input().split()] n = int(input()) s = read_ints() to_rem = n if sum(s) else 0 for i in range(n): to_rem = min(to_rem, s[:i].count(1) + (s[i:].count(0) if sum(s[i:]) else 0)) print(n - to_rem)
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = [int(i) for i in input().split()] ans = sum(a) for i in range(len(a) - 1, -1, -1): ans = min(ans, len(a) - i - sum(a[i:]) + sum(a[:i])) print(len(a) - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def procv(s, n): for i in range(n - 1): if s[i] == "1": for j in range(i, n - 1): if s[j + 1] == "0": s[j + 1] = "x" break f = list(filter(lambda v: v != "x", s)) return len(f) n = int(input()) s = list(input().split()) print(procv(s, n))
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) m = 0 ls = list(map(int, input().split())) for i in range(n + 1): s = 0 for j in range(i): s += not ls[j] for j in range(i, n): s += ls[j] m = max(s, m) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = list(map(int, input().split())) l = [(a[i + 1 :].count(0) + a[:i].count(1)) for i in range(n)] print(n - min(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
KoKoKo = int kudaxKudax = input kukareku = max kokokokoko = print kudkudax = range kokoko = KoKoKo(kudaxKudax()) ko = [KoKoKo(x) for x in kudaxKudax().split()] KO = KOKOKO = 0 for kok in kudkudax(kokoko - 1, -1, -1): KO += ko[kok] KOKOKO = kukareku(KOKOKO, KO + ko[: kok + 1].count(0)) kokokokoko(KOKOKO)
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) data = list(map(int, input().split())) data2 = [0] * n data2[0] = data[0] for i in range(1, n): if data[i]: data2[i] = data2[i - 1] + 1 else: data2[i] = data2[i - 1] data2 = [0] + data2 ma = -2 for i in range(n + 1): ma = max(ma, data2[-1] - data2[i] + i - data2[i]) print(ma)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
a = int(input()) b = list(map(int, input().split())) c = [] d = [] count = 0 for i in b: if i == 0: count += 1 c.append(count) count = 0 for i in b[::-1]: if i == 1: count += 1 d.append(count) d = d[::-1] x = [] for i in range(a): x.append(c[i] + d[i]) print(max(x))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
from sys import stdin, stdout n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) dp = [[0, 0] for i in range(n)] for i in range(n): if not values[i]: dp[i][0] = 1 for j in range(i - 1, -1, -1): dp[i][0] = max(dp[i][0], dp[j][0] + 1) else: dp[i][1] = 1 for j in range(i - 1, -1, -1): dp[i][1] = max(dp[i][1], max(dp[j]) + 1) ans = 0 for i in range(n): ans = max(ans, max(dp[i])) stdout.write(str(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
import sys cases = sys.stdin.readline() numbers = [int(x) for x in sys.stdin.readline().strip().split(" ")] my_sum = sum(numbers) answers = [] ones_so_far = 0 zeroes_so_far = 0 index = 0 for x in numbers: if x == 1: ones_so_far += 1 else: zeroes_so_far += 1 remaining_ones = my_sum - ones_so_far remaining_zeroes = len(numbers) - remaining_ones - index - 1 a = max(ones_so_far, zeroes_so_far) + remaining_ones b = zeroes_so_far + remaining_zeroes index += 1 answers.append(max(a, b)) print(max(answers))
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = list(map(int, input().split())) p = [0] * n p[0] = a[0] for i in range(1, n): p[i] = p[i - 1] + a[i] ans = min(n, n - p[n - 1]) for i in range(n): l = p[i] r = n - i - 1 - (p[n - 1] - p[i]) ans = min(ans, l + r) print(n - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
input() a = list(map(int, input().split())) f = 0 for i in range(len(a)): s = 0 for j in range(len(a)): if j <= i: if a[j] == 0: s += 1 if j >= i: if a[j] == 1: s += 1 if s > f: f = s print(f)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
length = int(input()) array = list(map(int, input().split())) count = [] total = 0 for k in range(length): if array[length - 1 - k] == 1: total += 1 count.append(total) count.reverse() total = 0 maximum = 0 for k in range(length): if array[k] == 0: total += 1 maximum = max(maximum, total + count[k]) print(maximum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) nums = list(map(int, input().split())) result = -1 for l in range(n): r = l + 1 tempresult = nums[: l + 1].count(0) + nums[r:].count(1) result = max(result, tempresult) result = max(result, nums.count(1)) result = max(result, nums.count(0)) print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) l = list(map(int, input().split())) max_games = [(1) for i in range(n)] if n > 1: if l[1] == 0: if l[0] == 1: max_games[1] = 1 else: max_games[1] = 2 else: max_games[1] = 2 t_max = max(max_games) if n > 2: for i in range(2, n): if l[i] == 0: j = i - 1 while j >= 0: if l[j] == 0: max_games[i] = max_games[j] + 1 t_max = max([t_max, max_games[i]]) break j -= 1 else: max_games[i] = t_max + 1 t_max += 1 print(t_max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) p = list(map(int, input().split())) ind_z = [] ind_o = [] for i in range(n): if p[i] == 0: ind_z.append(i) else: ind_o.append(i) z = [0] * len(ind_z) o = [0] * len(ind_o) for i in range(len(z)): z[i] = i + 1 for j in range(ind_z[i], n): if p[j] == 1: z[i] += 1 for i in range(len(o)): o[i] = len(o) - i for j in range(ind_o[i] - 1, -1, -1): if p[j] == 0: o[i] += 1 z = [0] + z o = [0] + o print(max(max(o), max(z)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
a = int(input()) b = input().split() zerocount = 0 zero = [] onecount = 0 one = [] maxi = 0 for i in range(a): if b[i] == "0": zerocount += 1 zero.append(zerocount) for i in range(a - 1, -1, -1): if b[i] == "1": onecount += 1 one.append(onecount) one.reverse() if maxi < one[0]: maxi = one[0] for i in range(a - 1): if maxi < zero[i] + one[i + 1]: maxi = zero[i] + one[i + 1] if maxi < zero[a - 1]: maxi = zero[a - 1] print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) m = list(map(int, input().split())) x = m.count(0) y = n - x a = 0 b = 0 l = max(x, y) for i in range(n): if m[i] == 1: a += 1 c = [] d = 0 e = 0 for j in range(i + 1): if m[j] == 1: d += 1 else: e += 1 c.append(e + a - d) l = max(l, max(c) + y - a) else: b += 1 print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = [int(x) for x in input().split(" ")] case1 = 0 for i in range(n): if a[i] == 0: case1 += 1 case2 = 0 for i in range(n): if a[i] == 1: case2 += 1 final = max(case1, case2) for i in range(n - 1): result = 0 s1 = a[: i + 1] s2 = a[i + 1 :] for j in s1: if j == 0: result += 1 for j in s2: if j == 1: result += 1 final = max(final, result) print(final)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def rezume(lst): ones, zeros = 0, 0 l, r = [0] * len(lst), [0] * len(lst) result = 0 for i in range(len(lst)): l[i] = ones if lst[i]: ones += 1 r[len(lst) - i - 1] = zeros if not lst[len(lst) - i - 1]: zeros += 1 for i in range(len(lst)): result = max(result, len(lst) - l[i] - r[i]) return result n = int(input()) c = [int(j) for j in input().split()] print(rezume(c))
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) m = list(map(int, input().split())) maxi = 0 for i in range(n + 1): cur = m[:i].count(0) + m[i:].count(1) if cur > maxi: maxi = cur print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def main(): n = int(input()) a = list(map(int, input().split())) ans = max(sum(a), n - sum(a)) for i in range(n): ans = max(ans, sum(a[i:]) + i - sum(a[:i])) print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
a = int(input()) b = [int(i) for i in input().split()] c = b.copy() ans = 0 for i in range(a): if b[i] == 1: ans += b[i:].count(1) break ans += 1 ans1 = 0 for i in range(a): if b[i] == 1: ans1 = max(ans1, b[:i].count(0) + b[i:a].count(1)) print(max(ans, ans1, b.count(0), b.count(1)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) A = input().split() count_0 = 0 count_1 = 0 i = 0 if n == 1: print(n) else: for i in range(0, n): if A[i] == "0": count_0 += 1 if A[i] == "1": count_1 += 1 maxm = max(count_0, count_1) for i in range(0, n): max_now = 0 for j in range(0, i + 1): if A[j] == "0": max_now += 1 for j in range(i + 1, n): if A[j] == "1": max_now += 1 if max_now > maxm: maxm = max_now print(maxm)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) games = list(map(int, input().split())) strike = [0] * n for i in range(n): strike[i] = 1 for j in range(i): if games[j] <= games[i]: strike[i] = max(strike[i], strike[j] + 1) print(max(strike))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
INF = 10**9 + 7 def cutoff(games, pos): leave = 0 for i, g in enumerate(games): if i < pos: if g == 0: leave += 1 elif g == 1: leave += 1 return leave def main(): n = int(input()) games = [int(x) for x in input().split()] max_leave = -INF for i in range(n + 1): max_leave = max(max_leave, cutoff(games, i)) print(max_leave) def __starting_point(): main() __starting_point()
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) arr = list(map(int, input().split())) pref1 = [0] for i in arr: pref1.append(pref1[-1] + i) suf0 = [0] for i in arr[::-1]: suf0.append(suf0[-1] + (i + 1) % 2) ans = [] for i in range(n + 1): ans.append(n - (suf0[::-1][i] + pref1[i])) print(max(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = list(map(int, input().split())) ans = 0 x0 = 0 x1 = 0 for i in range(n): if s[i] == 1: x1 = max(x0, x1) + 1 else: x0 = x0 + 1 ans = max(x0, x1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) arr = input() arr = arr.split(" ") arr = list(map(int, arr)) maxi = -1 ones = list(range(n + 1)) ones[n] = 0 for j in range(1, n): if arr[n - j] == 1: ones[n - j] = ones[n - j + 1] + 1 else: ones[n - j] = ones[n - j + 1] if arr[0] == 1: ones[0] = ones[1] + 1 else: ones[0] = ones[1] counter = 0 if arr[0] == 1: maxi = ones[0] for i in range(0, n): if arr[i] == 0: counter = counter + 1 if i < n - 1: if maxi < counter + ones[i + 1]: maxi = counter + ones[i + 1] elif i == n - 1: if maxi < counter: maxi = counter print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = list(map(int, input().split())) c = [] t = 0 while s[t] == 0 and t < n - 1: t += 1 for i in range(t, n): if s[i] == 1: k = 0 for j in range(i): if s[j] == 1: k += 1 for j in range(i + 1, n): if s[j] == 0: k += 1 c.append(k) else: k = 0 for j in range(i): if s[j] == 1: k += 1 for j in range(i + 1, n): if s[j] == 0: k += 1 c.append(k) print(n - min(c))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) string = "".join(map(str, input().split())) maxx = 0 for i in range(n + 1): maxx = max(maxx, string[:i].count("0") + string[i:].count("1")) print(maxx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) lis = [int(e) for e in input().split()] ct = [] c0 = 0 c1 = 0 for i in range(len(lis)): if lis[i] == 0: c0 += 1 if lis[i] == 1: c1 += 1 ct.append(c0) ct.append(c1) for i in range(1, len(lis)): c0 = 0 c1 = 0 for j in range(i - 1, -1, -1): if lis[j] == 0: c0 += 1 for j in range(i, len(lis)): if lis[j] == 1: c1 += 1 ct.append(c0 + c1) print(max(ct))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≤ n ≤ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≤ s_{i} ≤ 1). 0 corresponds to an unsuccessful game, 1 — to a successful one. -----Output----- Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def main(): n = int(input()) games = list(map(int, input().split(" "))) result = max([(games[:i].count(0) + games[i:].count(1)) for i in range(n + 1)]) print(result) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR