description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def erase_digits(n, remainder, count): cnt = 0 i = len(n) - 1 s = n while i >= 0 and cnt < count: digit = int(s[i]) if digit % 3 == remainder: cnt += 1 s = s[:i] + s[i + 1 :] i -= 1 if len(s) == len(n) or cnt < count: return "" while len(s)...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN STRING WHILE FUNC_CALL VAR V...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
import sys s = list(input()) digsum = 0 rem = [(0) for i in range(len(s))] for i in range(0, len(s)): dig = ord(s[i]) - ord("0") digsum += dig rem[i] = dig % 3 currem = digsum % 3 if currem == 0: print("".join(s)) sys.exit() if len(s) == 1: print(-1) sys.exit() inds1 = [] inds2 = [] for i i...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
n = input() if len(n) < 3: if len(n) == 1: if int(n) % 3 != 0: print(-1) else: print(n) if len(n) == 2: if (int(n[0]) + int(n[1])) % 3 == 0: print(n) elif int(n[0]) % 3 == 0: print(n[0]) elif int(n[1]) % 3 == 0: ...
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_C...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
import sys a = list(map(int, list(input()))) n = len(a) su = sum(a) l1 = [i for i in range(n) if a[i] % 3 == 1] l2 = [i for i in range(n) if a[i] % 3 == 2] def erase_leading_zeroes(li): i = 0 while i < n: if len(li) <= 1: return if li[i] == 0: li.pop(i) else: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CAL...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def f(n, r, k): tmp = n for t in range(k): for i in range(len(tmp) - 1, -1, -1): if int(tmp[i]) % 3 == r: tmp = tmp[:i] + tmp[i + 1 :] break for i in range(len(tmp)): if int(tmp[i]) != 0: return "".join(tmp[i:]) if len(tmp) == 0 or ...
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL STRING VAR VAR IF FUNC...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
import sys n = list(input("")) l = [(int(c) % 3) for c in n][::-1] d = sum(l) % 3 if len(n) == 1: if n == ["3"]: print(3) else: print(-1) sys.exit(0) def li(x): global n del n[len(n) - 1 - l.index(x)] del l[l.index(x)] def cond(x): x = x.lstrip("0") if len(x) == 0: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR LIST STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF VAR BIN_OP BIN_OP FUNC_CALL VAR ...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = input() l = [] n = len(s) ans = 0 r1, r2 = [], [] def red(l): for i in range(len(l)): if l[i] != 0: return l[i:] return l def pri(l): print("".join([str(k) for k in l])) exit() for i in range(n): l.append(int(s[i])) ans += l[-1] if l[-1] % 3 == 1 and len(r1) < 3...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN VAR VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VA...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
n = input() a = [0] * len(n) b1 = [0] * len(n) b2 = [0] * len(n) k = 0 c1 = 0 c2 = 0 ans = "" for i in range(len(n)): a[i] = int(n[i]) b1[i] = int(n[i]) b2[i] = int(n[i]) k += a[i] k %= 3 if k != 0: k1 = k for i in range(len(b1) - 1, -1, -1): if b1[i] == 1 or b1[i] == 4 or b1[i] == 7...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR AS...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
n = input() n = list(n[::-1]) ans1, ans2, ans3, ans4 = [], [], [], [] s = 0 for i in n: s += int(i) if s % 3 == 0: pass else: flag1 = flag2 = flag3 = flag4 = False if s % 3 == 1: ans1 = n[:] for i in n: if int(i) % 3 == 1: ans1.remove(i) flag1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def deleteD(n, num): rel = list(reversed(s)) for digit in reversed(s): if int(digit) % 3 == n: rel.remove(digit) num -= 1 if num == 0: if len(rel) == 0: return [] while rel[-1] == "0" and len(rel) > 1: rel.pop() ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN LIST WHILE VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR RETURN L...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = list(input()) def db3(n, sm): new = n.copy() sm %= 3 if sm == 0: return "".join(new) else: if sm == 2: for j in range(1, len(new)): if int(new[j]) % 3 == 2: new[j] = "" return "".join(new) for j in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL STRING VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CAL...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
import sys def lencheck(item1, item2): if len(item1) > len(item2): return True def leadingzero(string): while string[0:1] == "0" and len(string) != 1: string = string[1:] return string data = sys.stdin.read().strip() sumOfDigits = 0 for i in data: sumOfDigits += int(i) data2 = "" i...
IMPORT FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF WHILE VAR NUMBER NUMBER STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def checkBeauty(digi): total = 0 for i in range(0, len(digi)): total += int(digi[i]) return total % 3 def modThree(digi): one = [] two = [] for i in range(0, len(digi)): if int(digi[i]) % 3 == 1: one.insert(0, i) elif int(digi[i]) % 3 == 2: two.i...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR VAR...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
a = input() if len(a) == 1: if int(a) % 3 == 0: print(a) else: print(-1) exit(0) one = [] two = [] sum = 0 zs, zf = 0, 0 for i in range(len(a)): q = int(a[i]) sum += q if q == 0: if zs == 0: zs = i elif zs != 0 and zf == 0: zf = i if q % 3 == 1...
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VA...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = input().strip() m = {(0): 0, (1): 0, (2): 0} bol = [0] * len(s) two = [] one = [] i = 0 bc = 0 for a in s: m[int(a) % 3] = m[int(a) % 3] + 1 if int(a) % 3 == 0: bol[i] = 1 bc += 1 elif int(a) % 3 == 1: one.append(i) elif int(a) % 3 == 2: two.append(i) i += 1 out =...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = input() def rm(s, m): if s == None or len(s) == 1: return None i = len(s) - 1 while i >= 0: if int(s[i]) % 3 == m: break i -= 1 if i == -1: return None elif i == 0: k = i + 1 while k < len(s) and s[k] == "0": k += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NONE FUNC_CALL VAR VAR NUMBER RETURN NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN NONE IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
n = list(input()) leng = 0 mp = [0, 0, 0] for x in n: leng += 1 mp[int(x) % 3] += 1 tot = (mp[1] + 2 * mp[2]) % 3 if tot == 0: print("".join(n)) exit() if mp[tot] == 0: do = tot ^ 3 cnt = 2 elif mp[tot] == 1 and int(n[0]) % 3 == tot and n[1:3] == ["0", "0"]: do = tot ^ 3 cnt = 2 if m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER A...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = input() rem = 0 rems = [0] * len(s) one = [] two = [] for i in range(len(s)): rems[i] = int(s[i]) % 3 if rems[i] == 1: one.append(i) elif rems[i] == 2: two.append(i) rem += int(s[i]) rem %= 3 include = [1] * len(s) include1 = [1] * len(s) f = 0 if rem == 1: if len(one): ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VA...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def find1right(s, c, orig): r = s.rfind(c) if r != -1: res = orig[:r] + orig[r + 1 :] res_strip = res.lstrip("0") ans = len(orig) - len(res_strip), res_strip if "0" in res and res_strip == "": ans = len(s) - 1, "0" return ans return len(orig), "" def fin...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF STRING VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING RETURN VAR RETURN FUNC_CALL VAR VAR STRING FUNC_DEF ASS...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def clean_trailing_zeros(a): if not a: return a i = len(a) - 1 while i >= 1 and a[i] == 0: i -= 1 return a[: i + 1] def remove_digits(a, i1, i2): if i1: i1 = i1[0] result1 = clean_trailing_zeros(a[:i1] + a[i1 + 1 :]) else: result1 = [] if len(i2) >= ...
FUNC_DEF IF VAR RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN V...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def remove_1_remainder(num, num_sum): dig_idx = len(num) - 1 to_remove = [] found = True while num_sum % 3 != 0: if dig_idx < 0 or len(num) - len(to_remove) == 1: found = False break curr_num = int(num[dig_idx]) if curr_num % 3 == 1: to_remove....
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR FUN...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
num = list(map(int, list(input()))) num2 = sum(num) % 3 j = 0 for i in range(1, len(num)): if num[i] % 3 == num2: j = i num3 = 3 - num2 z = [] for i in range(1, len(num)): if num[i] % 3 == num3: z += [i] num4 = num[0] % 3 if num2 == 0: for i in range(len(num)): print(num[i], end="") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BI...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def countremove(n, mod): res = 0 for i in range(len(n)): if mod[len(n) - 1 - i] == 3: continue if n[i] == "0": res += 1 else: break return res def markremove(n): mod = [(int(x) % 3) for x in n][::-1] excess = sum(mod) % 3 ones = mod.c...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUN...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def func(t): an = "" l = len(t) for i in range(l): if t[i] != "0": break for j in range(i, l): an += t[j] return an for nitish in range(1): s = input() ss = 0 cnt = 10**20 cnt1 = 10**20 n = len(s) for i in range(n): ss += int(s[i]) if...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FO...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
import sys from itertools import compress s = input() n = len(s) mod = [0] * n for i, x in enumerate(map(int, s)): mod[i] = x % 3 total_mod = sum(mod) % 3 def remove_zeros(a): for i in range(n): if not a[i]: continue if s[i] == "0": a[i] = 0 else: r...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER RETURN IF VAR N...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
n = list(map(int, list(input()))) mds = [] for i in n: mds.append(i % 3) mod = sum(mds) % 3 try: if mod == 1: i = len(mds) - 1 nn = n[:] while i >= 0: if mds[i] == 1: del nn[i] break i -= 1 i = len(mds) - 1 count = [...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def find(s): if len(s) == 1: if int(s) % 3 == 0: return s return -1 digit = [[] for i in range(3)] zeros = [] for i in range(len(s)): digit[int(s[i]) % 3] += [i] if s[i] == "0": zeros += [i] total = (len(digit[1]) * 1 + len(digit[2]) * 2) % 3 ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER LIST VAR IF VAR VAR STRING VAR LIST VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CA...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
sn = input().strip() n = len(sn) def rem3(sn): return sum(map(int, sn)) % 3 def buildn(sn, com, start=0): return "".join(sn[start + i] for i in com) def subminbeau2(sn, start=0): n = len(sn) r3 = rem3(sn[start:]) sn3 = "".join(str(int(c) % 3) for c in sn) nums3 = set(sn3[1 + start :]) ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF NUMBER RETURN FUNC_CALL STRING VAR BIN_OP VAR VAR VAR VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR BIN...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def RemoveFirstZero(str): count = 0 for i in range(len(str)): if str[i] != "0": count = i break return str[count:] def RemainderOf3(str): sum = 0 for i in range(len(str)): sum += int(str[i]) return sum % 3 input1 = input() setofans = [] t = 0 p = True ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = input() L = len(s) S = 0 zero = [] one = [] two = [] for i in range(L): x = int(s[i]) S = (S + x) % 3 if x % 3 == 1: one.append(i) elif x % 3 == 2: two.append(i) elif x == 0: zero.append(i) if S == 0: print(s) elif S == 1: if len(one) >= 1 and (one[-1] > 0 or len(...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def erase(s, n, m): p = "147" if n == 1 else "258" if sum(s.count(c) for c in p) < m: return [] t = list(reversed(s)) for c in p: while t.count(c) > 0 and m > 0: t.remove(c) m -= 1 while len(t) > 1 and t[-1] == "0": t.pop() return list(reversed(t))...
FUNC_DEF ASSIGN VAR VAR NUMBER STRING STRING IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN FUNC_CALL ...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def n_by_deleting_r(n, r): if all(map(lambda x: int(x) % 3 != r, n)): return "" for idx in range(len(n) - 1, -1, -1): if r == int(n[idx]) % 3: return n[:idx] + n[idx + 1 :] def n_by_two_digit_remove(n, r): if sum(map(lambda x: int(x) % 3 == r, n)) < 2: return "" L =...
FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
digits = [int(d) for d in input()] remainder = sum(digits) % 3 def clip(digits): digits_copy = digits.copy() while len(digits_copy) > 0: if digits_copy[0] == 0 and len(digits_copy) > 1: del digits_copy[0] else: break if len(digits_copy) != 0: return "".join(...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NONE IF VAR NUMBER ...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
n = input() nums = [(int(i) % 3) for i in n] ones = nums.count(1) twos = nums.count(2) dis = (ones - twos) % 3 def solve(): global n global nums global dis if dis == 0: return n t = rfind(dis) if t > 0 or t == 0 and len(n) > 1 and nums[t + 1] != 0: return n[:t] + n[t + 1 :] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBE...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
m = list(input()) n = list(map(int, m)) s = sum(n) l = len(n) if s % 3 == 0: print("".join(m)) else: r = s % 3 for j in range(1, len(n)): if n[j] % 3 == r: n.pop(j) break if len(n) == l: flag = 0 if n[0] % 3 == r: if len(n) > 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR EXP...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
def f(x, y): global n if d[x] and (d[x][-1] != 0 or n[1] != "0"): n = n[: d[x][-1]] + n[d[x][-1] + 1 :] else: i = 0 if d[x]: for i in range(1, len(n)): if n[i] == "0": continue else: break if ...
FUNC_DEF IF VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER AS...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
s = input() n = len(s) dp, leadingzero, camefrom, erasepos = [], 0, [], [] for i in range(3): dp.append([int(1000000000.0)] * (n + 1)) camefrom.append([int(-1)] * (n + 1)) dp[0][n] = 0 for i in range(n - 1, -1, -1): for j in range(3): dp[j][i] = min( dp[j][i], min(1 + dp[j][i + 1], dp[(i...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR LIST NUMBER LIST LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR B...
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zer...
a = [int(x) for x in input()] n = len(a) rem = sum(a) % 3 a1 = a[:] r1 = rem i = n - 1 while r1 > 0 and i >= 0: if a1[i] % 3 == 2: if r1 == 1: a1[i] = -1 r1 = 2 else: a1[i] = -1 r1 = 0 i -= 1 cb = n + 1 ab = [] if r1 == 0: c1 = 0 i = 0 ...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera...
line = list(map(int, input().split(" "))) A, B, T = zip(line[::2], line[1::2]) n = int(input()) bottles = [tuple(map(int, input().split(" "))) for _ in range(n)] def dist(x, y): return abs(complex(*x) - complex(*y)) def keyFun(x, a): return dist(T, bottles[x]) - dist(a, bottles[x]) if n == 1: ret = mi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VA...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera...
ax, ay, bx, by, tx, ty = list(map(int, input().split())) od = [] co = [] objects = int(input()) for i in range(objects): x, y = list(map(int, input().split())) od.append(((tx - x) ** 2 + (ty - y) ** 2) ** 0.5) co.append([x, y]) asaved = [0, 0] asaved2 = [0, 0] ma = -(10**25) for i in range(objects): x =...
ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera...
import sys input = sys.stdin.readline def dist(x1, y1, x2, y2): return (abs(x1 - x2) ** 2 + abs(y1 - y2) ** 2) ** 0.5 ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) xy = [list(map(int, input().split())) for i in range(n)] s = 0 for i in range(n): x, y = xy[i] s += dist(tx, ty, x, y...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL ...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera...
import sys def calc_dist(x, y, x2, y2): return ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 inp = sys.stdin.read().splitlines() line0 = inp[0].split() Ax, Ay, Bx, By, Tx, Ty = ( int(line0[0]), int(line0[1]), int(line0[2]), int(line0[3]), int(line0[4]), int(line0[5]), ) totaldist = 0 Alst = [] ...
IMPORT FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NU...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera...
read = lambda: list(map(int, input().split())) def dis(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 ax, ay, bx, by, tx, ty = read() n = int(input()) a, b = [], [] sum = 0 for i in range(n): x, y = read() dist = dis(tx, ty, x, y) a.append((dis(ax, ay, x, y) - dist, i)) b.appen...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIG...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera...
ax, ay, bx, by, tx, ty = list(map(int, input().split())) n = int(input()) a, b = [], [] res = 0 for i in range(n): x, y = list(map(int, input().split())) lt = ((tx - x) * (tx - x) + (ty - y) * (ty - y)) ** 0.5 la = ((ax - x) * (ax - x) + (ay - y) * (ay - y)) ** 0.5 lb = ((bx - x) * (bx - x) + (by - y) *...
ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() lis = [0, -1, -1] sol = [0] r = 0 for i in range(len(s)): r = (r + int(s[i])) % 3 if lis[r] != -1: sol.append(max(sol[-1], 1 + sol[lis[r]])) else: sol.append(sol[-1]) lis[r] = i + 1 print(sol[-1])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER A...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = len(s) ans = 0 i = 0 while i < n: if int(s[i]) % 3 == 0: ans += 1 i += 1 continue if i != n - 1 and int(s[i]) % 3 == 1 and int(s[i + 1]) % 3 == 2: ans += 1 i += 2 continue if i != n - 1 and int(s[i]) % 3 == 2 and int(s[i + 1]) % 3 == 1: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER I...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = list(map(int, list(input()))) dp = [0] * len(s) t = [-1, -1, -1] k = 0 m = 0 for i in range(len(s)): k += s[i] r = -1 if t[k % 3] != -1: r = dp[t[k % 3]] elif k % 3 == 0: r = 0 dp[i] = max(m, r + 1) t[k % 3] = i m = max(m, dp[i]) print(dp[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
MOD = 1000000007 MOD2 = 998244353 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) let = "@abcdefghijklmnopqrstuvwxyz" s = si() n = len(s) l = [0] * n rem = [-1] * 3 rem[0], ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL 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 ASSI...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
dp = dict() dp[0] = 0 dp[1] = -1000000000.0 dp[2] = -1000000000.0 s = input() n = len(s) sum = 0 ans = 0 for i in range(n): v = ord(s[i]) - ord("0") sum += v sum %= 3 dp[sum] = max(dp[0], dp[1], dp[2], dp[sum] + 1) ans = max(ans, dp[sum]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = len(s) ss = 0 f = [1] * n rem = [] for i in range(n): rem.append(int(s[i]) % 3) ans = rem.count(0) i = 0 while i < n: if rem[i] == 1: if i + 1 < n and rem[i + 1] == 2: ans += 1 i += 2 elif i + 1 < n and rem[i + 1] == 1 and i + 2 < n and rem[i + 2] == 1: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input().strip() i = 0 ans = 0 while i < len(s): rem_digits = len(s) - i if rem_digits >= 3: if int(s[i]) % 3 == 0: i += 1 elif int(s[i : i + 2]) % 3 == 0: i += 2 elif int(s[i + 1]) % 3 == 0: i += 2 else: i += 3 ans += 1 ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() y = [] for i in s: y.append(int(i)) s = 0 dp = [] count = 0 for i in y: if i % 3 != 0: j = 0 dp.append(i) while j < len(dp) - 1: dp[j] = dp[j] + i if dp[j] % 3 == 0: dp = [] count += 1 break j...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUM...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
a = list(map(int, input())) for i in range(len(a)): a[i] = a[i] % 3 s = 0 ans = 0 for i in range(len(a)): s += a[i] if a[i] == 0: s = 0 ans += 1 elif s % 3 == 0: s = 0 ans += 1 elif s != a[i] and abs(a[i] - a[i - 1]) == 1: s = 0 ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR N...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = len(s) c = [0] * n r = [0] * n if s[0] in ["3", "6", "9"]: c[0] = 1 else: c[0] = 0 r[0] = int(s[0]) % 3 j = 1 while j < n: if int(s[j]) % 3 == 0: c[j] = c[j - 1] + 1 elif r[j - 1] == 4: r[j] = 0 c[j] = c[j - 1] + 1 elif int(s[j]) % 3 == r[j - 1]: r...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP FUNC_CALL...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
c = 0 f = [0, -1, -1] z = [0] for e, i in enumerate(input()): c = (c + int(i)) % 3 z.append(z[-1]) if f[c] != -1: z[-1] = max(z[-1], z[f[c]] + 1) f[c] = e + 1 print(z[-1])
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBE...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() count, ans, tmp = 0, 0, 0 for i in s: if int(i) % 3 == 0 or (tmp + int(i)) % 3 == 0 or count == 2: tmp = 0 ans += 1 count = 0 else: tmp += int(i) count += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
l = [*map(lambda x: int(x) % 3, input())] dp = [0, -float("inf"), -float("inf")] for d in l: new_dp = [-float("inf")] * 3 new_dp[d] = max(0, max(dp) + (d == 0)) new_dp[0] = max(new_dp[0], dp[-d % 3] + 1) for r in (1, 2): new_dp[r] = max(new_dp[r], dp[(r - d) % 3]) dp = new_dp print(max(dp))
ASSIGN VAR LIST FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR LIST NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER B...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() k = 0 ans = 0 vis = {0} for i, c in enumerate(s): k += int(c) k %= 3 if k in vis: ans += 1 k = 0 vis = {0} else: vis.add(k) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = 0 ans = 0 for k in s: t = int(k) n += t if n % 3 == 0 or t % 3 == 0 or n % 100 % 3 == 0: ans += 1 n = 0 else: n = n * 10 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = str(input()) prev_sum = 0 ans = 0 f_el = 0 need = True for el in s: el = int(el) if el % 3 == 0: ans += 1 prev_sum = 0 need = True continue if need: f_el = el need = False prev_sum = el continue prev_sum += el if prev_sum % 3 == 0 o...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BI...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input().strip() have_one = 0 have_two = 0 res = 0 for c in s: x = int(c) if x % 3 == 1: have_one += 1 elif x % 3 == 2: have_two += 1 else: res += 1 have_one = 0 have_two = 0 if have_one == 3 or have_two == 3 or have_one > 0 and have_two > 0: res +=...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = len(s) r = [0] * n for i in range(n): r[i] = int(s[i]) % 3 i = 0 c = 0 while i < n: if i + 2 < n and ( r[i] == r[i + 1] == r[i + 2] == 1 or r[i] == r[i + 1] == r[i + 2] == 2 ): c += 1 i += 3 elif i + 1 < n and (r[i] == 2 and r[i + 1] == 1 or r[i] == 1 and r[i + 1]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VA...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
import sys sys.setrecursionlimit(10000) t = 1 for _ in range(t): s = input() no = "" count = 0 for i in s: if int(i) % 3 == 0: count += 1 no = "" else: no += i if int(no) % 3 == 0: count += 1 no = "" ...
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING IF BIN_OP FUNC_CALL ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() ans = 0 r = 0 r1 = 0 r2 = 0 for i in s: n = ord(i) - 48 if n % 3 == 0: ans += 1 r = r1 = r2 = 0 else: r = r + n % 3 if r % 3 == 0: ans += 1 r = r1 = r2 = 0 elif r % 3 == 1: if r1 == 1: ans += 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBE...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() count = 0 i = 0 while i < len(s): if int(s[i]) % 3 == 0: count += 1 i += 1 elif i < len(s) - 1 and (int(s[i : i + 2]) % 3 == 0 or int(s[i + 1]) % 3 == 0): count += 1 i += 2 elif i < len(s) - 2 and ( int(s[i + 1 : i + 3]) % 3 == 0 or int(s[i : i + 3]) % 3 =...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NU...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
n = input() ans = 0 r, c = 0, 0 for i in n: r += int(i) c += 1 if int(i) % 3 == 0 or r % 3 == 0 or c == 3: ans += 1 r, c = 0, 0 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
a = input() su = 0 ans = 0 b = "" for i in range(len(a)): if int(a[i]) % 3 == 0: ans += 1 b += "9" else: b += str(int(a[i]) % 3) for i in range(len(b) - 2): if int(b[i]) + int(b[i + 1]) == 3: ans += 1 b = b[:i] + "99" + b[i + 2 :] if ( int(b[i]) + int(b[i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR V...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = str(input()) c = 0 cont = 0 su = 0 for i in range(len(s)): k = int(s[i]) % 3 if k == 0: c += 1 su = 0 cont = 0 else: if k == 1: su += 1 else: su += 2 cont += 1 if su % 3 == 0 or cont == 3: c += 1 cont...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
arr = input() count = 0 idex = -1 for i in range(len(arr)): for j in range(i, idex, -1): next = int(arr[j : i + 1]) if next % 3 == 0: idex = i count += 1 break print(count)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s, k, i = "".join([str(int(i) % 3) for i in input()]) + " ", 0, 0 while i < len(s): if s[i] == "0": k += 1 i += 1 elif s[i : i + 2] in "12.21": k += 1 i += 2 elif s[i : i + 3] in "111.222": k += 1 i += 3 else: i += 1 print(k)
ASSIGN VAR VAR VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR STRING NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMB...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() ans = 0 temp = "" for i in s: if int(i) == 0: ans += 1 temp = "" else: temp += i k = int(temp) if k % 3 == 0: ans += 1 temp = "" else: su = 0 for j in temp: su += int(j) for j ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = " " + input() dp = [0] * len(s) for i in range(1, len(s)): sum = 0 for j in range(i, 0, -1): sum += int(s[j]) if sum % 3 == 0: dp[i] = max(dp[j - 1] + 1, 1) break dp[i] = max(dp[i], dp[i - 1]) print(dp[-1])
ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER AS...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
def solve(digits): solutions = {} for index, digit in enumerate(digits): if digit % 3 == 0: solutions[index] = 1 + solutions.get(index - 1, 0) else: cand1 = solutions.get(index - 1, 0) cand2 = 0 for start_index in range(index - 1, -1, -1): ...
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMB...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s, r, fin = input(), 0, [0, -1, -1] n = len(s) z = [(0) for _ in range(n + 1)] for i, c in enumerate(s): r = (r + int(c)) % 3 z[i + 1] = z[i] if fin[r] != -1: z[i + 1] = max(z[i + 1], z[fin[r]] + 1) fin[r] = i + 1 print(z[n])
ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUN...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = list(map(lambda o: int(o), list(input()))) s.reverse() sm = c = cc = 0 for i in s: cc += 1 sm += i if not i % 3 or not sm % 3 or cc == 3: c += 1 sm = 0 cc = 0 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() z = 0 t = "" for i in range(len(s)): if s[i] == "0" or int(s[i]) % 3 == 0: z += 1 t += "0" else: t += s[i] a = t.split("0") num = 0 for i in range(len(a)): mod = -1 q = 0 for j in range(len(a[i])): k = int(a[i][j]) if mod == -1: mod = k...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() l = [0] * 200005 s = "#" + s for i in range(1, len(s)): l[i] = l[i - 1] if i == 1: if int(s[i]) % 3 == 0: l[i] = 1 elif i == 2: if int(s[i]) % 3 == 0: l[i] = max(l[i], l[i - 1] + 1) if int(s[i - 1 : i + 1]) % 3 == 0: l[i] = max(l[i], l[...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASS...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
c = 0 r = 0 b = 0 for i in input(): n = int(i) % 3 if n == 0 or (n + r) % 3 == 0 or b == 2: c += 1 r = 0 b = 0 else: r += n b += 1 print(c)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() i = 0 res = 0 while i < len(s): while i < len(s) and s[i] == "0": i += 1 res += 1 contains = [0, 0, 0] j = i for j in range(i, len(s)): val = int(s[j]) % 3 contains[val] += 1 if ( contains[0] or contains[1] and conta...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR N...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
def solve(digits): solutions = {} fin = {(0): 0} digit_sum = 0 for index, digit in enumerate(digits): digit_sum += digit solutions[index] = solutions.get(index - 1, 0) if digit_sum % 3 in fin: solutions[index] = max( solutions[index], solutions.get(fin...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR RET...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
import sys def main(): s = sys.stdin.readline().strip() N = len(s) dp = [0] * N dp[0] = 1 if int(s[0]) % 3 == 0 else 0 if len(s) == 1: print(dp[0]) return dp[1] = dp[0] if int(s[1]) % 3 == 0: dp[1] = dp[0] + 1 if (int(s[1]) + int(s[0])) % 3 == 0: dp[1] =...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() l = [] c = 0 for i in range(len(s)): if int(s[i]) % 3 == 0: c += 1 l = [] else: l.append(int(s[i])) for j in range(len(l) - 1): l[j] += int(s[i]) if l[j] % 3 == 0: c += 1 l = [] break print(c)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBE...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
a = input() l = len(a) count = 0 num = "" for i in range(l): b = int(a[i]) if b == 0: count += 1 num = "" elif b % 3 == 0: count += 1 num = "" else: num += str(b) if int(num) % 100 % 3 == 0 or int(num) % 3 == 0: count += 1 num = "" ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = len(s) ans = 0 c = 0 l = [] for i in range(n): a = int(s[i]) % 3 if a == 0: ans += 1 c = 0 l = [] elif c == 0: l.append(int(s[i])) c += 1 elif c == 1: if (a + l[0]) % 3 == 0: ans += 1 c = 0 l = [] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER IF...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
a = str(input()) a = "x" + a n = len(a) f = [(0) for i in range(0, 10**6)] k = 0 for i in range(1, n): if int(a[i]) % 3 == 0: f[i] = f[i - 1] + 1 k = i else: for j in range(i - 1, k, -1): if int(a[j : i + 1]) % 3 == 0: f[i] = f[k] + 1 k = i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() f = [0] * len(s) cnt = 0 for i in range(len(s)): a = int(s[i]) if a % 3 == 0: cnt += 1 f[i] = 1 for i in range(len(s) - 1): if f[i] == 0 and f[i + 1] == 0: a = int(s[i]) * 10 + int(s[i + 1]) if a % 3 == 0: cnt += 1 f[i] = f[i + 1] = 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER N...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() ost = [] for i in map(int, s): ost += [i % 3] now = 0 last = -1 answer = 0 for i in ost: if i == 0: now = [] answer += 1 elif now == 2: now = 0 answer += 1 elif now == 1: if last != i: answer += 1 now = 0 else: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR LIST VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() s = "#" + s res = 0 n = len(s) dp = [0] * n l = 0 for i in range(1, n): j = int(s[i : i + 1]) if j == 0 or j % 3 == 0: dp[i] = dp[i - 1] + 1 l = i continue dp[i] = dp[i - 1] t = j for k in range(i - 1, l, -1): t += int(s[k : k + 1]) if t % 3 == 0: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
a = [int(i) for i in list(input())] current = 0 l = len(a) for i in range(1, l): a[i] += a[i - 1] a = [0] + a ans = 0 for i in range(l + 1): for j in range(current, i): if (a[i] - a[j]) % 3 == 0: ans += 1 current = i break print(ans)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR 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 FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VA...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
n = input() buf = 0 c = 0 m = 0 for i in range(len(n)): buf += int(n[i]) m += 1 if int(n[i]) % 3 == 0 or buf % 3 == 0 or m >= 3: buf = 0 c += 1 m = 0 print(c)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
lst = map(int, input()) res, prev, length = 0, [], 0 for i, x in enumerate(lst): if x % 3 == 0: res += 1 prev, length = [], 0 else: k, item = 0, x % 3 for j in range(length - 1, -1, -1): item = (item + prev[j]) % 3 if item == 0: res, k, pre...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR LIST NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VA...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
def main(): a = [(int(i) % 3) for i in input()] d = [] k = 0 ans = 0 summ = 0 for i in a: if i == 0: ans += 1 k = 0 summ = 0 d = [] else: d += [i] k += 1 summ += i if k != 1: ...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR LIST VAR VAR NUMBER VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
u = "0" + input() n = len(u) - 1 d = [0] * (n + 1) def div3(k): if int(k) % 3 == 0: return 1 return 0 if div3(u[1]): d[1] = 1 else: d[1] = 0 for i in range(2, n + 1): a1 = d[i - 1] + div3(u[i]) a2 = d[i - 2] + div3(u[i] + u[i - 1]) if i > 2: a3 = d[i - 3] + div3(u[i] + u[...
ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
n = list(input()) cntr = 0 marks = [] for i in range(len(n)): marks.append(0) for i in range(len(n)): if int(n[i]) % 3 == 0: cntr += 1 marks[i] = 1 elif marks[i] == 0: marks[i] = 1 tmpcnt = int(n[i]) mrk = -1 for j in range(2): if i + j + 1 < len(n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL V...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = str(input()) n = len(s) l = [-1] * 3 a = [] pre = [0] dp = [int(0)] * n for i in range(len(s)): a.append(int(s[i])) pre.append((pre[i] + int(s[i])) % 3) dp[n - 1] = a[n - 1] % 3 == 0 l[pre[n - 1]] = n - 1 l[pre[n]] = n for i in range(n - 2, -1, -1): dp[i] = dp[i + 1] + int(a[i] % 3 == 0) if l[pre[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_C...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
a = input() s = 0 d = [0, 0, 0] for i in range(len(a) - 1, -1, -1): z = int(a[i]) % 3 if z == 0: d = [0, 0, 0] s += 1 continue d[z] += 1 if d[2] == 3: s += 1 d = [0, 0, 0] elif d[1] >= 1 and d[2] >= 1: s += 1 d = [0, 0, 0] elif d[1] == 3: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST ...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() n = len(s) d = [0] * (n + 1) f = [-1] * 3 r = 0 for i in range(1, n + 1): c = int(s[i - 1]) if c % 3 == 0: d[i] = d[i - 1] + 1 else: r = (r + c) % 3 t = f[r % 3] if t > -1 or r == 0: d[i] = max(d[t] + 1, d[i - 1]) else: d[i] = d[i -...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMB...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() cursum = 0 curstr = "" count = 0 for i in s: cursum += int(i) curstr += i if ( cursum % 3 == 0 or i in ["0", "3", "6", "9"] or len(curstr) > 1 and int(curstr[1:]) % 3 == 0 ): count += 1 cursum = 0 curstr = "" print(count)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR LIST STRING STRING STRING STRING FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL V...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = input() sumarr = [int(s[0])] for i in range(1, len(s)): sumarr.append(sumarr[i - 1] + int(s[i])) ansarr = [int(sumarr[0] % 3 == 0) for _ in range(len(s))] for i in range(1, len(s)): ansarr[i] = ansarr[i - 1] j = 1 while i >= j and (sumarr[i] - sumarr[i - j]) % 3: j += 1 if j <= i: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR V...
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
s = [int(i) for i in input()] ans = 0 last = 0 def check(x): Sum = 0 while x != 0: Sum += x % 10 x //= 10 if Sum % 3 == 0: return True return False for i in range(len(s)): if s[i] % 3 == 0: ans += 1 last = 0 else: last = last * 10 + s[i...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASS...