description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | x = input()
lol = ""
c = 0
yo = []
while int(x) > 0:
if int(x) < 10:
c += int(x)
yo = yo + [1] * int(x)
x = 0
else:
for i in x:
if int(i) >= 1:
lol += "1"
else:
lol += "0"
x = str(int(x) - int(lol))
yo.append(lol)
lol = ""
c += 1
print(c)
print(*yo) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | quasiNumbers = []
num = input()
l = len(num)
m = n = int(num)
x = max(num)
maxi = int(x)
print(x)
for i in range(maxi):
j = l - 1
s = 0
while j >= 0:
k = n // 10**j
n = n % 10**j
if k > 0:
s = s * 10 + 1
else:
s = s * 10
j -= 1
f = str(s)
quasiNumbers.append(f)
n = m - s
m = n
T = " ".join(quasiNumbers)
print(T) | ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | def solve1(n):
r = []
while n > 0:
t = int("".join([("0" if x == "0" else "1") for x in str(n)]))
n -= int(t)
r.append(t)
print(len(r))
print(" ".join(map(str, r)))
num = int(input())
solve1(num) | FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR STRING STRING STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
s = ""
ans = 0
while n > 0:
m = int("".join([("1" if d != "0" else "0") for d in str(n)]))
n -= m
if n >= 0:
ans += 1
s += str(m) + " "
print(ans, s, sep="\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR STRING STRING STRING VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
a = [(0) for i in range(0, 100)]
m = 0
t = 1
while n > 0:
b = int(n % 10)
m = max(m, b)
for i in range(0, b):
a[i] = a[i] + t
t = t * 10
n = n / 10
print(m)
for i in range(0, m):
print(a[i], end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = list(input())
digits = []
numbers = []
for i in range(len(n)):
digits.append(int(n[i]))
for i in range(max(digits)):
numbers.append(0)
for i in range(len(n)):
for j in range(digits[i]):
numbers[j] += 10 ** (len(n) - 1 - i)
print(max(digits))
for num in numbers:
print(num, end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
res = []
digit = dict.fromkeys(map(ord, "123456789"), "1")
while n:
val = str(n).translate(digit)
n -= int(val)
res.append(val)
print(len(res))
print(*res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | l = list(map(int, list(input())))
print(max(l))
ans = []
while l.count(0) != len(l):
k = ["0" for i in range(len(l))]
for i in range(len(l)):
if l[i] != 0:
l[i] -= 1
k[i] = "1"
ans.append(str(int("".join(k))))
print(" ".join(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | from sys import stdout
n = input()
num = int(n)
c = 0
v = []
while num > 0:
l = len(n)
if n.count("1") + n.count("0") == l:
c += 1
v.append(n)
break
else:
s = ""
if "0" in n:
for i in n:
if i == "0":
s += "0"
else:
s += "1"
num -= int(s)
v.append(s)
c += 1
n = str(num)
else:
c += 1
v.append("1" * l)
num -= int("1" * l)
n = str(num)
print(c)
for i in v:
stdout.write(i)
print(end=" ") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF STRING VAR FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | s = input()
q = [int(x) for x in s]
def a(i):
r = ""
for x in q:
if x >= i:
r += "1"
elif len(r):
r += "0"
return r
mx = 0
for x in q:
mx = max(mx, x)
print(mx)
kek = [a(x) for x in range(1, mx + 1)]
s = ""
for x in kek:
s += x
s += " "
print(s) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR STRING RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | a = input()
count = 0
mass = []
for i in range(len(a)):
mass.append(a[i])
strings = []
def number(mass):
string = ""
for i in range(len(mass)):
join = "".join
if mass[i] != "0":
mass[i] = str(int(mass[i]) - 1)
string = join([string, "1"])
else:
string = join([string, "0"])
return string, mass
for i in range(max(list(map(int, mass)))):
new_mass = mass
temp, new_mass = number(new_mass)
strings.append(temp)
count += 1
print(count)
if not strings:
strings.append(0)
strings = list(map(int, strings))
print(" ".join(map(str, strings))) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR STRING ASSIGN VAR FUNC_CALL VAR LIST VAR STRING RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
if 1 <= n < 9:
print(n)
for i in range(n):
print(1, end=" ")
else:
x = str(n)
x = list(x)
cnt = 0
res = []
while n > 0:
tem = ""
for i in range(len(x)):
if x[i] != "1" and x[i] != "0":
x[i] = "1"
tem += x[i]
else:
tem += x[i]
tem = int(tem)
n = n - tem
cnt = cnt + 1
x = str(n)
x = list(x)
res.append(tem)
res = reversed(res)
print(cnt)
print(*res, sep=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | num = input()
le = len(num)
num2 = [0] * le
for i in range(le):
num2[i] = int(num[i])
print(max(num2))
for i in range(le):
while num2[i] > 0:
print(1, end="")
for j in range(i + 1, le):
if num2[j] > 0:
num2[j] -= 1
print(1, end="")
else:
print(0, end="")
print(" ", end="")
num2[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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING VAR VAR NUMBER |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | a = input()
n = [q for q in a]
s = []
t = ["0"] * len(n)
while n != t:
d = ""
for i in range(len(n)):
if n[i] == "0":
d += "0"
else:
d += "1"
n[i] = str(int(n[i]) - 1)
s.append(int(d))
print(len(s))
print(" ".join(map(str, s))) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
arr = []
while n > 0:
x = [int(i) for i in str(n)]
q = [min(i, 1) for i in x]
q = "".join([str(i) for i in q])
q = int(q)
arr.append(q)
n -= q
print(len(arr))
print(*arr) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
l = []
ans = []
cur = n
while cur > 0:
l.insert(0, cur % 10)
cur = cur // 10
f = 0
f1 = 0
while f1 == 0:
s = ""
for i in range(0, len(l)):
if l[i] != 0:
l[i] -= 1
s += "1"
f = 1
elif l[i] == 0 and f == 1:
s += "0"
ans.append(int(s))
if l.count(0) == len(l):
f1 = 1
print(len(ans))
for ele in ans:
print(ele, end=" ") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = int(input())
def iskvazi(x):
while x > 0:
cur = x % 10
if cur != 0 and cur != 1:
return False
x = x // 10
return True
kvazi = []
p = [0] * (n + 1)
add = [0] * (n + 1)
ans = [0] * (n + 1)
for i in range(1, n + 1):
if iskvazi(i):
kvazi.append(i)
for i in range(1, n + 1):
for to in kvazi:
if to > i:
break
if ans[i] == 0 or ans[i - to] + 1 < ans[i]:
ans[i] = ans[i - to] + 1
p[i] = i - to
add[i] = to
print(ans[n])
k = n
while k > 0:
print(add[k], end=" ")
k = p[k] | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = list(map(int, input()))
m = max(n)
print(m)
for j in range(m):
l = []
for i in n:
if i > j:
l.append(str(1))
else:
l.append(str(0))
print(int("".join(l))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | s = input()
n = int(s)
cont = []
while n > 0:
res = ""
for i in s:
if i != "0":
res += "1"
else:
res += "0"
n -= int(res)
cont.append(res)
s = str(n)
print(len(cont))
for i in cont:
print(i, end=" ") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = list(map(int, list(input())))
ans = int(max(n))
print(ans)
s = ""
while ans:
for i in range(len(n)):
if n[i] >= 1:
s += "1"
n[i] -= 1
else:
s += str(n[i])
print(int(s), end=" ")
s = ""
ans -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR STRING VAR NUMBER |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | def psuedoBinary(n, l):
while n > 0:
temp = n
m = 0
p = 1
while temp:
rem = temp % 10
temp = int(temp / 10)
if rem != 0:
m += p
p *= 10
l.append(m)
n = n - m
n = int(input())
l = []
psuedoBinary(n, l)
print(len(l))
print(*l[::-1]) | FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = [int(i) for i in input()]
n_sorted = list(map(lambda x: list(x), list(enumerate(n.copy()))))
n_sorted.sort(key=lambda x: x[1])
estado = ["1" for i in range(len(n))]
numeros = []
for k in n_sorted:
numeros += k[1] * [int("".join(estado))]
sub = k[1]
for i in n_sorted:
i[1] -= sub
estado[k[0]] = "0"
print(len(numeros))
print(*numeros) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR BIN_OP VAR NUMBER LIST FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | ans = []
def minQuasi(n):
if n <= 0:
return
m = "".join(min(i, "1") for i in str(n))
minQuasi(n - int(m))
ans.append(m)
n = int(input())
minQuasi(n)
print(len(ans))
print(*ans) | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = input()
answer = []
for j in range(int(n[0])):
answer.append(10 ** (len(n) - 1))
for i in range(1, len(n)):
j = 0
while j < len(answer) and j < int(n[i]):
answer[j] += 10 ** (len(n) - i - 1)
j += 1
if j < int(n[i]):
while j < int(n[i]):
answer.append(10 ** (len(n) - i - 1))
j += 1
print(len(answer))
print(*answer) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | a = list(map(int, list(input())))
r = []
while True:
ok = False
p = 0
for i in range(len(a)):
p = p * 10 + (a[i] > 0)
if a[i]:
ok = True
a[i] -= 1
if not ok:
break
else:
r.append(p)
print(len(r))
print(*r) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | s = input()
mas = []
res = 0
for i, x in enumerate(s):
x = int(x)
for j, y in enumerate(mas):
if x == 0:
mas[j] += "0"
else:
mas[j] += "1"
x -= 1
for i in range(x):
res += 1
mas.append("1")
print(res)
print(*mas) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | a = input()
inputList = [int(x) for x in reversed(a)]
outputList = []
listItem = 0
while sum(inputList) != 0:
listItem = 0
for i in range(0, len(inputList)):
if inputList[i] != 0:
listItem += 10**i
inputList[i] -= 1
outputList.append(listItem)
print(len(outputList))
for i in reversed(outputList):
print(i, end=" ") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | n = list(map(lambda x: int(x), list(input())))
maxval = max(n)
ans = [""] * maxval
ns = len(n)
for c in n:
for i in range(maxval):
if i < c:
ans[i] += "1"
else:
ans[i] += "0"
ans = list(map(lambda x: str(int(x)), ans))
print(maxval)
print(" ".join(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^6).
-----Output-----
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
-----Examples-----
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11 | def main():
n = input()
prob = [int(digit) for digit in n][::-1]
res = []
for i in range(max(prob)):
num = 0
for index, number in enumerate(prob):
if number >= i + 1:
num += 10**index
res.append(num)
print(len(res))
print(" ".join([str(number) for number in res]))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | import itertools
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
acc = [0] + list(itertools.accumulate(A))
rsum = lambda i, j: acc[j + 1] - acc[i]
dp = [0] * n
ans = 0
for i, a in enumerate(A):
if i >= m:
dp[i] = max(dp[i], dp[i - m] + rsum(i - m + 1, i) - k)
for j in range(i, max(-1, i - m), -1):
dp[i] = max(dp[i], rsum(j, i) - k)
ans = max(ans, dp[i])
print(ans) | IMPORT ASSIGN VAR VAR 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 BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | from itertools import accumulate
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
als = []
for i in range(m):
ls = a[:]
for j in range(n):
if j % m == i:
ls[j] -= k
als.append(list(accumulate(ls)))
ans = 0
for i in range(m):
ls = als[i]
mn = 0
anstmp = 0
for j in range(n):
if mn > ls[j]:
mn = ls[j]
if j % m == i:
anstmp = max(anstmp, ls[j] - mn)
ans = max(ans, anstmp)
print(ans) | ASSIGN VAR VAR 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | def getBestWindow(N, M, K, a):
dp, ans = [], 0
for i in range(0, N):
dp.append(a[i] - K)
sum, x = a[i], max(0, i - M)
for j in range(i - 1, x - 1, -1):
dp[i] = max(dp[i], dp[j] + sum - K)
sum += a[j]
if i < M:
dp[i] = max(dp[i], sum - K)
dp[i] = max(dp[i], 0)
ans = max(ans, dp[i])
return ans
N, M, K = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
ans = getBestWindow(N, M, K, arr)
print(ans) | FUNC_DEF ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = map(int, input().split())
a = list(map(int, input().split()))
best = 0
dp = [0] * (n + 1)
for i in range(n):
b2 = 0
for j in range(max(-1, i - m), i + 1):
b2 = max(b2, dp[j] - k + sum(a[j + 1 : i + 1]))
dp[i] = max(b2, a[i] - k)
best = max(best, dp[i])
print(best) | ASSIGN VAR VAR 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | def max_subarray(A):
max_ending_here = max_so_far = A[0]
for x in A[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
ans = 0
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
li = a[0:i] + [-k]
s = 0
while True:
li += a[i + s : min(i + m + s, len(a))]
li += [-k]
if i + m + s >= len(a):
break
s += m
ans = max(max_subarray(li) - k, ans)
print(ans) | FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR LIST VAR ASSIGN VAR NUMBER WHILE NUMBER VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR LIST VAR IF BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | def maxsum(a):
best = 0
cur = 0
for e in a:
cur = max(cur, 0) + e
best = max(best, cur)
return best
def solve(m, k, a):
if m == 1:
return maxsum([(e - k) for e in a])
best = 0
cur = [-k] * m
for e in a:
new_cur = [
(max(0, cur[0]) + e - k if i == 1 else cur[(i - 1) % m] + e)
for i in range(m)
]
best = max(best, max(new_cur))
cur = new_cur
return best
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(m, k, a)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = map(int, input().split())
(*a,) = map(int, input().split())
dp = [-1] * (n + 15)
for i in range(n):
s, mx = a[i], max(0, a[i])
for j in range(i - 1, max(-1, i - m), -1):
s += a[j]
mx = max(mx, s)
dp[i] = max(0, dp[i - m] + s - k, mx - k)
print(max(dp)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = [int(w) for w in input().split()]
a = [int(w) for w in input().split()]
def f(o):
r = e = 0
for i, x in enumerate(a):
if i < o:
continue
if i % m == o:
e -= k
if e < -k:
e = -k
e += x
if e > r:
r = e
return r
print(max(f(o) for o in range(m))) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | from sys import exit, stdin, stdout
n, m, k = list(map(int, stdin.readline().split()))
a = list(map(int, stdin.readline().split()))
def bf(a):
best = 0
best_arg = -1, -1
for i in range(n):
for j in range(i, n):
cur = sum(a[i : j + 1]) - k * ((j - i) // m + 1)
if cur > best:
best = max(best, cur)
best_arg = i, j
return best, best_arg
def max_sum(a):
if len(a) == 0:
return 0
elif len(a) == 1:
return max(0, a[0] - k)
mid = len(a) // 2
l_rec = max_sum(a[:mid])
r_rec = max_sum(a[mid:])
l_bests = [0] * m
r_bests = [0] * m
l_sum = 0
for idx in range(1, mid + 1):
l_sum += a[mid - idx]
if idx % m == 0:
l_sum -= k
l_bests[idx % m] = max(l_bests[idx % m], l_sum)
r_sum = 0
for idx in range(0, len(a) - mid):
r_sum += a[idx + mid]
if (idx + 1) % m == 0:
r_sum -= k
r_bests[(idx + 1) % m] = max(r_bests[(idx + 1) % m], r_sum)
best_acr = 0
for i in range(m):
for j in range(m):
best_acr = max(
best_acr,
l_bests[i]
+ r_bests[j]
- (k if i + j > 0 else 0)
- (k if i + j > m else 0),
)
ans = max(l_rec, r_rec, best_acr)
return ans
ans = max_sum(a)
stdout.write(str(ans) + "\n") | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
if n <= m:
AA = [0] * (n + 1)
for i in range(n):
AA[i + 1] = AA[i] + A[i]
mm = 0
for i in range(n + 1):
for j in range(i + 1, n + 1):
mm = max(mm, AA[j] - AA[i] - k)
else:
DP = [([0] * (m + 1)) for _ in range(n + 1)]
for i in range(n):
a = A[i]
DP[i + 1][0] = max([DP[i][0], DP[i][m], DP[i][m] + a - k, DP[i][1]])
DP[i + 1][1] = max(a - k, DP[i][m] + a - k)
for j in range(2, m + 1):
DP[i + 1][0] = max(DP[i + 1][0], DP[i][j])
if j > i + 1:
continue
else:
DP[i + 1][j] = max(DP[i][j - 1] + a, DP[i][m] + a - k)
print(max(A[0] - k, 0) if n == 1 else mm if n <= m else max(0, max(DP[n]))) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = map(int, input().split())
A = list(map(int, input().split()))
glans = 0
for s in range(m):
B = []
f = s
su = 0
sus = 0
for i in range(s, n):
su += A[i]
sus = max(sus, su)
if (i + 1) % m == s:
B.append(sus - k)
B.append(su - sus)
su = 0
sus = 0
f = i + 1
dob = 0
klol = 0
for j in range(f, n):
dob += A[j]
klol = max(klol, dob - k)
B = [0] + B + [klol]
for i in range(1, len(B)):
B[i] += B[i - 1]
cnt = -(10**10)
ans = [0, 0]
minsum = 10**10
candidat = 0
for i in range(len(B)):
if B[i] - minsum > cnt:
cnt = B[i] - minsum
ans[1] = i
ans[0] = candidat
if B[i] <= minsum:
minsum = B[i]
candidat = i
glans = max(glans, B[ans[1]] - B[ans[0]])
print(glans) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | import sys
def input():
return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]
def main():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for mod in range(m):
b = [0] + a.copy()
for i in range(1, n + 1):
if i % m == mod:
b[i] += -k
for i in range(1, n + 1):
b[i] += b[i - 1]
for i in reversed(range(1, n + 1)):
if i + 1 <= n:
b[i] = max(b[i], b[i + 1])
if i % m != mod:
continue
ans = max(ans, b[i] - b[i - 1])
print(ans)
return 0
main() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a = [0] + a
dp = [0] * 300005
ans = 0
for i in range(1, n + 1):
a[i] += a[i - 1]
for j in range(1, m + 1):
if i - j >= 0:
dp[i] = max(dp[i], a[i] - a[i - j] - k)
if i - m >= 0:
dp[i] = max(dp[i], a[i] - a[i - m] + dp[i - m] - k)
ans = max(ans, dp[i])
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | N, M, K = list(map(int, input().split()))
A = [int(a) for a in input().split()]
S = [0]
for a in A:
S.append(S[-1] + M * a - K)
MI = [10**50] * M
ans = 0
for i in range(N + 1):
MI[i % M] = min(MI[i % M], S[i])
for j in range(M):
ans = max(ans, (S[i] - MI[(i - j) % M] - K * (-j % M)) // M)
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | import sys
n, m, k = list(map(int, sys.stdin.readline().strip().split()))
a = list(map(int, sys.stdin.readline().strip().split()))
b = [0] * (n + 1)
for i in range(1, n + 1):
b[i] = b[i - 1] + m * a[i - 1] - k
M = [10**20] * m
ans = 0
for i in range(0, n + 1):
M[i % m] = min([M[i % m], b[i]])
for j in range(0, m):
if i > j:
ans = max([ans, b[i] - M[j] - k * ((m * i + m - (i - j)) % m)])
print(ans // m) | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = map(int, input().split())
a = list(map(int, input().split()))
sa = [0] * n
ans = 0
for i in range(n):
sa[i] = a[i] - k
s = a[i]
for j in range(i - 1, max(-1, i - m - 1), -1):
sa[i] = max(sa[i], sa[j] + s - k)
s += a[j]
if i < m:
sa[i] = max(sa[i], s - k)
sa[i] = max(sa[i], 0)
ans = max(ans, sa[i])
print(ans) | ASSIGN VAR VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = map(int, input().split())
b = [0] + list(map(int, input().split()))
rem = [float("inf") for i in range(m)]
rem[0] = k
curr = 0
ans = 0
for i in range(1, n + 1):
curr += b[i]
ans = max(ans, curr - min(rem))
rem[i % m] = min(rem[i % m], curr)
rem[i % m] += k
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | import sys
def eprint(*args):
print(*args, file=sys.stderr)
zz = 1
if zz:
input = sys.stdin.readline
else:
sys.stdin = open("input.txt", "r")
sys.stdout = open("all.txt", "w")
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]
def string(s):
return "".join(s)
def fori(n):
return [fi() for i in range(n)]
def inc(d, c, x=1):
d[c] = d[c] + x if c in d else x
def bo(i):
return ord(i) - ord("A")
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a, b):
if a > b:
return 2
return 2 if a == b else 0
def gi():
return [xx for xx in input().split()]
def cil(n, m):
return n // m + int(n % m > 0)
def fi():
return int(input())
def pro(a):
return reduce(lambda a, b: a * b, a)
def swap(a, i, j):
a[i], a[j] = a[j], a[i]
def si():
return list(input().rstrip())
def mi():
return map(int, input().split())
def gh():
sys.stdout.flush()
def isvalid(i, j):
return 0 <= i < n and 0 <= j < m and a[i][j] != "."
def bo(i):
return ord(i) - ord("a")
def graph(n, m):
for i in range(m):
x, y = mi()
a[x].append(y)
a[y].append(x)
t = 1
while t > 0:
t -= 1
n, m, k = mi()
a = li()
d = [[] for i in range(m + 1)]
pre = [a[0]]
for i in range(1, n):
pre.append(pre[-1] + a[i])
pre.append(0)
l = [[] for i in range(m + 1)]
for i in range(m):
maxi = -(10**18)
for j in range(i, n):
if j > i and (j - i) % m == 0:
d[i].append(maxi - (j - i) // m * k)
l[i].append(maxi)
maxi = -(10**18)
maxi = max(maxi, pre[j])
if maxi != -(10**18):
d[i].append(maxi - ((j - i) // m + 1) * k)
l[i].append(maxi)
for i in range(m):
for j in range(len(d[i]) - 2, -1, -1):
d[i][j] = max(d[i][j + 1], d[i][j])
maxi = 0
for i in range(n):
c = d[i % m][i // m] + i // m * k - pre[i - 1]
maxi = max(maxi, c)
print(maxi) | IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR STRING FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | base = 1000000007
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
mx = 0
s = 0
dp = []
dd = []
for j in range(m):
for i in range(n + 1):
dp.append(base)
dd.append(0)
for i in range(n):
dd[i + 1] = dd[i] + a[i] - k * (i % m == j)
dp[i + 1] = min(dd[i], dp[i])
if i % m == j:
mx = max(mx, dd[i + 1] - dp[i + 1])
print(mx) | ASSIGN VAR NUMBER ASSIGN VAR VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
bv = 0
for ms in range(M):
cv = 0
for i in range(ms, N):
v = A[i]
if i % M == ms:
v -= K
cv = max(0, cv)
cv += v
bv = max(bv, cv)
print(bv) | ASSIGN VAR VAR VAR FUNC_CALL 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
bestbest = 0
def brute(n, m, k, A):
ans = 0
val = 0, 0
for i in range(n):
for j in range(i, n):
if ans < sum(A[i : j + 1]) - k * ceil((j - i + 1) / m):
ans = sum(A[i : j + 1]) - k * ceil((j - i + 1) / m)
val = i, j
return val, ans
for off in range(m):
B = A[off:]
C = []
canstart = []
for i in range(len(B)):
if i % m == 0:
C.append(-k)
canstart.append(1)
canstart.append(0)
C.append(B[i])
best = 0
run = 0
for i in range(len(C)):
run += C[i]
if run < -k:
run = -k
best = max(best, run)
bestbest = max(bestbest, best)
print(bestbest) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
values = list()
for j in range(n):
result = a[j]
sum1 = 0
for i in range(m):
if j - i >= 0:
sum1 = sum1 + a[j - i]
if sum1 > result:
result = sum1
else:
continue
if j - m >= 0:
result = max(result, sum1 + values[j - m])
values.append(max(0, result - k))
print(max(values)) | ASSIGN VAR VAR VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [([float("-inf")] * m) for i in range(n)]
dp[0][0] = a[0]
for i in range(1, n):
for j in range(1, m):
dp[i][j] = dp[i - 1][j - 1] + a[i]
dp[i][0] = max(dp[i - 1][m - 1] - k, 0) + a[i]
print(max(max([max(x) for x in dp]) - k, 0)) | ASSIGN VAR VAR VAR FUNC_CALL 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 BIN_OP LIST FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER |
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0 | import sys
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
cs = [0] * (N + 1)
mi = [10**10] * M
mi[0] = 0
ans = 0
for i, a in enumerate(A):
cs[i + 1] = cs[i] + (a - K / M)
mi[(i + 1) % M] = min(mi[(i + 1) % M], cs[i + 1])
for j in range(M):
ans = max(ans, cs[i + 1] - mi[(i + 1 + j) % M] - K / M * j)
print(max(int(ans + 0.5), 0))
main() | IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | n, m = map(int, input().split())
S = [input() for i in range(n)]
mod = 998244353
ans = 0
count = 0
for i in range(n):
for j in range(m):
if S[i][j] == "o":
count += 1
pow2 = 1
N = [0]
for i in range(n):
N.append((pow2 - N[-1]) % mod)
pow2 *= 2
pow2 %= mod
pow2 = 1
M = [0]
for i in range(m):
M.append((pow2 - M[-1]) % mod)
pow2 *= 2
pow2 %= mod
for i in range(n):
c = 0
for j in range(m):
if S[i][j] != "o":
c = 0
continue
if j != m - 1 and S[i][j + 1] == "o":
ans += pow(2, count - c - 2, mod) * M[c + 1]
ans %= mod
c += 1
for i in range(m):
c = 0
for j in range(n):
if S[j][i] != "o":
c = 0
continue
if j != n - 1 and S[j + 1][i] == "o":
ans += pow(2, count - c - 2, mod) * N[c + 1]
ans %= mod
c += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | from sys import stdin
input = stdin.readline
def A():
t = int(input())
for _ in range(t):
n = int(input())
r = list(map(int, input().split()))
s = 0
for i in r:
if i == 1 or i == 3:
s += 1
print(s)
def B():
t = int(input())
for _ in range(t):
a, b, c = map(int, input().split())
a1, b1, c1 = 1, 1, 1
while len(str(c1)) < c:
c1 *= 2
b1 *= 2
a1 *= 2
while len(str(b1)) < b:
b1 *= 3
while len(str(a1)) < a:
a1 *= 5
print(a1, b1)
def C():
n, q = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = [0] * q
c = [n + 2] * 51
for i in range(n):
if c[a[i]] == n + 2:
c[a[i]] = i
for ind in range(q):
i = t[ind]
x = c[i]
for y in range(len(c)):
if c[y] < x:
c[y] += 1
ans[ind] = x + 1
c[i] = 0
print(*ans)
def D():
n, k = map(int, input().split())
z = [chr(ord("a") + x) for x in range(26)]
s = []
for a in range(k):
s.append(z[a])
for b in range(a + 1, k):
s.append(z[a] + z[b])
s = "".join(s)
while len(s) < n:
s *= 2
print(s[:n])
def E():
n, m = map(int, input().split())
g = [(0) for i in range(n)]
s = 0
for i in range(n):
g[i] = list(input().rstrip())
for j in g[i]:
if j == "o":
s += 1
mod = 998244353
if s == 0:
print(0)
return
q = [0] * (s + 1)
q[0] = 0
q[1] = 0
for i in range(2, s + 1):
q[i] = (q[i - 1] + 2 * q[i - 2] + pow(2, i - 2, mod)) % mod
seqs = [0] * (s + 1)
seq = 0
for i in range(n):
for j in range(m):
if g[i][j] == "o":
seq += 1
elif seq > 0:
seqs[seq] += 1
seq = 0
if seq > 0:
seqs[seq] += 1
seq = 0
seq = 0
for j in range(m):
for i in range(n):
if g[i][j] == "o":
seq += 1
elif seq > 0:
seqs[seq] += 1
seq = 0
if seq > 0:
seqs[seq] += 1
seq = 0
tot = 0
for i in range(1, s + 1):
prod = seqs[i] * q[i] % mod
prod = prod * pow(2, s - i, mod) % mod
tot += prod
print(tot % mod)
E() | ASSIGN VAR VAR FUNC_DEF 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | from sys import stdin, stdout
mod = 998244353
d = {}
def power(x, y):
if y < 0:
return 0
s = str(x) + "$" + str(y)
if d.get(s, -1) != -1:
return d[s]
f = 1
y1 = y
while y:
if y % 2 == 1:
f *= x
x = x * x
y //= 2
x %= mod
f %= mod
d[s] = f
return f
ct = 0
n, m = [int(i) for i in stdin.readline().split()]
a = [[i for i in stdin.readline()] for j in range(n)]
dp = [[[0, 0] for i in range(m)] for j in range(n)]
c1 = 0
for i in range(n):
for j in range(m):
if a[i][j] == "o":
dp[i][j] = [1, 1]
if i > 0:
dp[i][j][0] += dp[i - 1][j][0]
if j > 0:
dp[i][j][1] += dp[i][j - 1][1]
c1 += 1
for i in range(n):
for j in range(m):
if a[i][j] == "o":
if i > 0 and a[i - 1][j] == "o":
val = dp[i][j][0]
if val == 2:
ct += power(2, c1 - 2)
else:
no = (val - 1) // 2
if val % 2 == 0:
ct += (
power(2, c1 - val + 1)
* (power(4, no) - 1)
* power(3, mod - 2)
% mod
)
ct += power(2, c1 - val)
ct %= mod
else:
ct += (
power(2, c1 - val)
* (power(4, no) - 1)
* power(3, mod - 2)
% mod
)
if j > 0 and a[i][j - 1] == "o":
val = dp[i][j][1]
if val == 2:
ct += power(2, c1 - 2)
else:
no = (val - 1) // 2
if val % 2 == 0:
ct += (
power(2, c1 - val + 1)
* (power(4, no) - 1)
* power(3, mod - 2)
% mod
)
ct += power(2, c1 - val)
else:
ct += (
power(2, c1 - val)
* (power(4, no) - 1)
* power(3, mod - 2)
% mod
)
ct %= mod
ct %= mod
stdout.write(str(ct) + "\n") | ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR LIST NUMBER NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return map(int, sys.stdin.readline().rstrip().split())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI2():
return list(map(int, sys.stdin.readline().rstrip()))
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split())
def LS2():
return list(sys.stdin.readline().rstrip())
n, m = MI()
board = [S() for _ in range(n)]
mod = 998244353
power = [1]
for _ in range(n * m + 10):
power.append(2 * power[-1] % mod)
M = max(n, m)
X = [0] * (M + 1)
A = [0] * (M + 1)
A[1] = 1
for i in range(2, M + 1):
a = -A[i - 1] + power[i - 1]
a %= mod
A[i] = a
for i in range(2, M + 1):
x = 2 * X[i - 1] + A[i - 1]
x %= mod
X[i] = x
red = []
blue = []
white = 0
for i in range(n):
count = 0
for j in range(m):
if board[i][j] == "o":
count += 1
white += 1
else:
if count >= 2:
red.append(count)
count = 0
if count >= 2:
red.append(count)
for j in range(m):
count = 0
for i in range(n):
if board[i][j] == "o":
count += 1
else:
if count >= 2:
blue.append(count)
count = 0
if count >= 2:
blue.append(count)
ans = 0
for i in red + blue:
ans += X[i] * power[white - i]
ans %= mod
print(ans) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
input = sys.stdin.readline
mod = 998244353
n, m = map(int, input().split())
board = [input().strip() for i in range(n)]
ans = 0
tot_c = 0
tot_h = []
tot_v = []
for i in range(n):
for j in range(m):
if board[i][j] == "o":
tot_c += 1
for i in range(n):
for j in range(m):
if board[i][j] == "o" and (j == 0 or board[i][j - 1] == "*"):
tot_h.append(1)
elif board[i][j] == "o":
tot_h[-1] += 1
for j in range(m):
for i in range(n):
if board[i][j] == "o" and (i == 0 or board[i - 1][j] == "*"):
tot_v.append(1)
elif board[i][j] == "o":
tot_v[-1] += 1
paired = [([0] * (max(n, m) + 1)) for i in range(2)]
paired[0][1] = paired[1][1] = 1
for i in range(2, max(n, m) + 1):
paired[0][i] = (2 * paired[1][i - 1] + paired[0][i - 1]) % mod
paired[1][i] = paired[0][i - 1]
dp = [0] * (max(n, m) + 1)
for i in range(2, max(n, m) + 1):
dp[i] = (2 * dp[i - 1] + paired[1][i - 1]) % mod
for num_consec in tot_h + tot_v:
ans = (ans + dp[num_consec] * pow(2, tot_c - num_consec, mod)) % mod
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | n, m = map(int, input().split())
g = [input() for _ in range(n)]
mod = 998244353
two = [1, 2, 4, 8]
dp = [0, 0, 1, 3]
ct = 8
for i in range(4, n * m + 1):
ct *= 2
ct %= mod
two.append(ct)
dp.append((dp[i - 1] + 2 * dp[i - 2] + two[i - 2]) % mod)
white = 0
ans = 0
for i in range(n):
for j in range(m):
if g[i][j] == "o":
white += 1
for i in range(n):
mid = 0
for j in range(m):
if g[i][j] == "o":
mid += 1
else:
ans += dp[mid] * two[white - mid]
ans %= mod
mid = 0
ans += dp[mid] * two[white - mid]
ans %= mod
for j in range(m):
mid = 0
for i in range(n):
if g[i][j] == "o":
mid += 1
else:
ans += dp[mid] * two[white - mid]
ans %= mod
mid = 0
ans += dp[mid] * two[white - mid]
ans %= mod
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
input = sys.stdin.readline
MOD = 998244353
def solve(N, M, B):
pow2 = [1] * (3 * 10**5 + 10)
for i in range(1, len(pow2)):
pow2[i] = pow2[i - 1] * 2 % MOD
dp = [0] * (3 * 10**5 + 10)
for i in range(2, len(dp)):
dp[i] = 2 * dp[i - 2] + pow2[i - 2] + dp[i - 1]
dp[i] %= MOD
w_count = sum(sum(b) for b in B)
ans = 0
for n in range(N):
current = 0
for m in range(M):
if B[n][m]:
current += 1
continue
r = w_count - current
ans += dp[current] * pow2[r] % MOD
ans %= MOD
current = 0
for m in range(M):
current = 0
for n in range(N):
if B[n][m]:
current += 1
continue
r = w_count - current
ans += dp[current] * pow2[r] % MOD
ans %= MOD
current = 0
return ans
def main():
N, M = map(int, input().split())
B = [[] for _ in range(N)]
for i in range(N):
B[i] = [(c == "o") for c in input()] + [0]
B.append([0] * (M + 1))
ans = solve(N + 1, M + 1, B)
print(ans)
main() | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR STRING VAR FUNC_CALL VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | pow2 = [(0) for i in range(300005)]
pow2[0] = 1
for i in range(1, 300005):
pow2[i] = pow2[i - 1] * 2
pow2[i] %= 998244353
dp = [(0) for i in range(300005)]
dp[2] = 1
for i in range(3, 300005):
dp[i] = dp[i - 1] + 2 * dp[i - 2] + pow2[i - 2]
dp[i] %= 998244353
l = input().split()
n = int(l[0])
m = int(l[1])
a = []
for i in range(n):
s = input()
a.append(s)
counter = 0
s = a
mod = 998244353
for i in range(n):
for j in range(m):
if s[i][j] == "o":
counter += 1
ans = 0
for i in range(n):
start = 0
end = 0
done = 0
for j in range(m):
if s[i][j] == "o":
if done == 0:
done = 1
start = j
end = j
else:
end += 1
elif done == 1:
length = end - start + 1
z = dp[length]
z = z * pow2[counter - length]
z %= mod
ans += z
ans %= mod
done = 0
if done:
length = end - start + 1
z = dp[length]
z = z * pow2[counter - length]
z %= mod
ans += z
ans %= mod
done = 0
for i in range(m):
start = 0
end = 0
done = 0
for j in range(n):
if s[j][i] == "o":
if done == 0:
done = 1
start = j
end = j
else:
end += 1
elif done == 1:
length = end - start + 1
z = dp[length]
z = z * pow2[counter - length]
z %= mod
ans += z
ans %= mod
done = 0
if done:
length = end - start + 1
z = dp[length]
z = z * pow2[counter - length]
z %= mod
ans += z
ans %= mod
done = 0
print(ans) | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | n, m = map(int, input().split())
s = [(input() + "*") for _ in range(n)] + ["*" * (m + 1)]
cnt = sum(i.count("o") for i in s)
MOD = 998244353
ans = 0
inv4 = pow(4, MOD - 2, MOD)
inv2 = pow(2, MOD - 2, MOD)
v = pow(2, cnt, MOD)
for i in range(n + 1):
cnt = 0
for j in range(m + 1):
if s[i][j] == "o":
cnt += 1
else:
for k in range(cnt - 1):
ans += inv4 * pow(inv2, k, MOD) * (cnt - 1 - k) * pow(-1, k, MOD)
ans %= MOD
cnt = 0
for j in range(m + 1):
cnt = 0
for i in range(n + 1):
if s[i][j] == "o":
cnt += 1
else:
for k in range(cnt - 1):
ans += inv4 * pow(inv2, k, MOD) * (cnt - 1 - k) * pow(-1, k, MOD)
ans %= MOD
cnt = 0
print(ans * v % MOD) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR LIST BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
inf = 10**16
md = 998244353
h, w = MI()
ss = [[(c == "o") for c in SI()] for _ in range(h)]
inv4 = pow(4, md - 2, md)
inv8 = pow(8, md - 2, md)
mx = max(h, w) + 5
pp = [0] * mx
pp[0] = inv4
pp[1] = inv8
for i in range(2, mx):
pp[i] = (pp[i - 2] * inv4 + inv8) % md
ev = [0] * mx
for i in range(2, mx):
ev[i] = (ev[i - 1] + pp[i - 2]) % md
def RLE(s):
cw = []
pc = s[0]
w = 0
for c in s:
if c == pc:
w += 1
else:
cw.append((pc, w))
w = 1
pc = c
cw.append((pc, w))
return cw
def cal(row):
global ans
kv = RLE(row)
for k, v in kv:
if k:
ans += ev[v]
ans %= md
ans = 0
for row in ss:
cal(row)
for col in zip(*ss):
cal(col)
s = sum(sum(row) for row in ss)
ans = ans * pow(2, s, md) % md
print(ans) | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR STRING VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
s = [input() for i in range(n)]
mod = 998244353
inv = 499122177
w, res = 0, 0
for i in range(n):
even, odd = 0, 1
for j in range(m):
if s[i][j] == "*":
even, odd = 0, 1
else:
res += even * inv
even, odd = odd * inv, even * inv + inv
even %= mod
odd %= mod
res %= mod
w += 1
for j in range(m):
even, odd = 0, 1
for i in range(n):
if s[i][j] == "*":
even, odd = 0, 1
else:
res += even * inv
even, odd = odd * inv, even * inv + inv
even %= mod
odd %= mod
res %= mod
for i in range(w):
res = 2 * res % mod
print(res) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | mod = 998244353
def qpow(n, k):
res = 1
while k:
if k & 1:
res = res * n % mod
n = n * n % mod
k >>= 1
return res
n, m = map(int, input().split())
mp = []
cnt = 0
for i in range(n):
mp.append(input())
for j in mp[-1]:
if j == "o":
cnt += 1
half = qpow(2, mod - 2)
dp = [0, 0]
now = half * half % mod
piece = 0
for i in range(1, cnt + 1):
piece = (piece + now + mod) % mod
dp.append((dp[-1] + piece) % mod)
now = now * half % mod * -1
ans = 0
for i in range(n):
now = 0
for j in mp[i]:
if j == "o":
now += 1
else:
ans += dp[now]
now = 0
ans = (ans + dp[now]) % mod
for i in range(m):
now = 0
for j in range(n):
if mp[j][i] == "o":
now += 1
else:
ans += dp[now]
now = 0
ans = (ans + dp[now]) % mod
ans = ans * qpow(2, cnt) % mod
print(ans) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR STRING VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | mod = 998244353
n, m = map(int, input().split())
a = [0] * n
dp = [0] * n
dp2 = [0] * n
P = [0] * 300005
for i in range(n):
dp[i] = [0] * m
dp2[i] = [0] * m
for i in range(n):
a[i] = list(input())
cnt = 0
for i in range(n):
for j in range(m):
if a[i][j] == "o":
cnt += 1
ans = 0
P[2] = pow(2, cnt - 2, mod)
P[3] = pow(2, cnt - 3, mod)
for i in range(3, max(m, n) + 1):
P[i] = (P[3] + pow(4, -1, mod) * P[i - 2]) % mod
for i in range(n):
for j in range(m):
if a[i][j] == "o":
dp[i][j] = dp[i][j - 1] + 1
if dp[i][j] >= 2:
ans = (ans + P[dp[i][j]]) % mod
for i in range(m):
for j in range(n):
if a[j][i] == "o":
dp2[j][i] = dp2[j - 1][i] + 1
if dp2[j][i] >= 2:
ans = (ans + P[dp2[j][i]]) % mod
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
grid = []
for i in range(n):
grid.append(input())
ans = 0
MOD = 998244353
count = 0
for i in range(n):
for j in range(m):
if grid[i][j] == "o":
count += 1
if count < 2:
print(0)
exit()
s = pow(2, count - 2, MOD)
inv3 = pow(3, MOD - 2, MOD)
inv4 = pow(4, MOD - 2, MOD)
for i in range(n):
tmp = 0
for j in range(m):
if grid[i][j] == "o":
tmp += 1
else:
tmp = 0
if tmp >= 2:
if tmp == 2:
ans = (ans + s) % MOD
elif tmp % 2 == 0:
n1 = tmp // 2 - 1
n4 = pow(4, n1, MOD)
n4inv = pow(n4, MOD - 2, MOD)
ans = (ans + s - (n4 - 1) * n4inv % MOD * inv3 % MOD * s) % MOD
else:
n1 = tmp // 2
n4 = pow(4, n1, MOD)
n4inv = pow(n4, MOD - 2, MOD)
ans = (ans + s - (n4 - 1) * n4inv % MOD * inv3 % MOD * s) % MOD
ans = (ans - s * n4inv) % MOD
for i in range(m):
tmp = 0
for j in range(n):
if grid[j][i] == "o":
tmp += 1
else:
tmp = 0
if tmp >= 2:
if tmp == 2:
ans = (ans + s) % MOD
elif tmp % 2 == 0:
n1 = tmp // 2 - 1
n4 = pow(4, n1, MOD)
n4inv = pow(n4, MOD - 2, MOD)
ans = (ans + s - (n4 - 1) * n4inv % MOD * inv3 % MOD * s) % MOD
else:
n1 = tmp // 2
n4 = pow(4, n1, MOD)
n4inv = pow(n4, MOD - 2, MOD)
ans = (ans + s - (n4 - 1) * n4inv % MOD * inv3 % MOD * s) % MOD
ans = (ans - s * n4inv) % MOD
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | MOD = 998244353
ninv = pow(9, MOD - 2, MOD)
def f(n):
return ((3 * n + 1) * pow(2, n, MOD) - (1 if n % 2 == 0 else -1)) * ninv
h, w = map(int, input().split())
s = ["*" * (w + 2)] + [("*" + input() + "*") for _ in range(h)] + ["*" * (w + 2)]
c = 0
for i in range(h + 2):
c += s[i].count("o")
ans = 0
for i in range(1, h + 1):
l = []
for j in range(w + 1):
if s[i][j] != s[i][j + 1]:
l.append(j)
for j in range(1, len(l), 2):
ans += f(l[j] - l[j - 1] - 1) * pow(2, c - l[j] + l[j - 1], MOD)
for i in range(1, w + 1):
l = []
for j in range(h + 1):
if s[j][i] != s[j + 1][i]:
l.append(j)
for j in range(1, len(l), 2):
ans += f(l[j] - l[j - 1] - 1) * pow(2, c - l[j] + l[j - 1], MOD)
print(ans % MOD) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP STRING FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR LIST BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
from sys import stdin
mod = 998244353
H, W = map(int, stdin.readline().split())
s = [list(stdin.readline()[:-1]) for i in range(H)]
ans = 0
onum = 0
for i in range(H):
for j in range(W):
if s[i][j] == "o":
onum += 1
for i in range(H):
to = onum
dp = [1, 0]
for j in range(W):
if s[i][j] == "*":
dp = [sum(dp) % mod, 0]
else:
to -= 1
ans += pow(2, to, mod) * dp[1]
ans %= mod
dp = [(dp[0] + 2 * dp[1]) % mod, dp[0]]
for j in range(W):
to = onum
dp = [1, 0]
for i in range(H):
if s[i][j] == "*":
dp = [sum(dp) % mod, 0]
else:
to -= 1
ans += pow(2, to, mod) * dp[1]
ans %= mod
dp = [(dp[0] + 2 * dp[1]) % mod, dp[0]]
print(ans % mod) | IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | p = 998244353
pow = [1]
for i in range(1, 3 * 10**5 + 1):
pow.append(2 * pow[-1] % p)
dp = [0] * (3 * 10**5 + 1)
dp[2] = 1
for i in range(3, 3 * 10**5 + 1):
dp[i] = (pow[i - 2] + dp[i - 1] + 2 * dp[i - 2]) % p
n, m = map(int, input().split())
b = []
for i in range(n):
b.append(input())
res = []
cnt = 0
for i in range(n):
res.append(0)
for j in range(m):
if b[i][j] == "*":
res.append(0)
else:
cnt += 1
res[-1] += 1
for j in range(m):
res.append(0)
for i in range(n):
if b[i][j] == "*":
res.append(0)
else:
res[-1] += 1
ans = 0
for j in res:
if j == 0:
pass
else:
ans = (ans + dp[j] * pow[cnt - j] % p) % p
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
input = sys.stdin.readline
MOD = 998244353
n, m = map(int, input().rstrip().split())
mapp = [list(input().rstrip()) for _ in range(n)]
dp = [0, 0, 1]
for i in range(3, max(n, m) + 1):
dp.append((dp[-1] + 2 * dp[-2] + pow(2, i - 2, MOD)) % MOD)
white_lst = []
w = 0
for i in range(n):
flag = False
for j in range(m):
if mapp[i][j] == "o":
w += 1
if not flag:
flag = True
white_lst.append(1)
else:
white_lst[-1] += 1
else:
flag = False
for j in range(m):
flag = False
for i in range(n):
if mapp[i][j] == "o":
if not flag:
flag = True
white_lst.append(1)
else:
white_lst[-1] += 1
else:
flag = False
ans = 0
for white_element in white_lst:
ans = (ans + dp[white_element] * pow(2, w - white_element, MOD)) % MOD
print(ans % MOD) | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | from sys import stdin, stdout
MOD = 998244353
b1 = 0
b2 = 0
b3 = 0
def colorings_and_dominoes(n, m, s_a):
r = 0
c = sum(s.count("o") for s in s_a)
b_a = [(1) for _ in range(c + 1)]
if c >= 2:
b_a[2] = bpow(c - 2)
if c >= 3:
b_a[3] = bpow(c - 3)
for i in range(4, c + 1, 1):
if i % 2 == 0:
b_a[i] = b_a[i - 1] + bpow(c - i)
else:
b_a[i] = b_a[i - 2] + bpow(c - i)
b_a[i] %= MOD
for i in range(n):
uc = 0
for j in range(m):
if s_a[i][j] == "o":
uc += 1
else:
uc = 0
if uc >= 2:
r += b_a[uc]
r %= MOD
for j in range(m):
uc = 0
for i in range(n):
if s_a[i][j] == "o":
uc += 1
else:
uc = 0
if uc >= 2:
r += b_a[uc]
r %= MOD
return r
def bpow(c):
if c == 0:
return 1
r = bpow(c // 2)
r *= r
r %= MOD
if c % 2 == 1:
r *= 2
r %= MOD
return r
n, m = map(int, stdin.readline().split())
s_a = []
for _ in range(n):
s_a.append(stdin.readline().strip())
r = colorings_and_dominoes(n, m, s_a)
stdout.write(str(r) + "\n") | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | def pot2mod(blancos, memo=[1]):
if blancos < 0:
return 0.5
if blancos < len(memo):
return memo[blancos]
global NUMMOD
for i in range(len(memo), blancos + 1):
memo.append(memo[i - 1] * 2 % NUMMOD)
return memo[blancos]
NUMMOD = 998244353 * 8
n, m = map(int, input().split())
esblanco = [[(False) for x in range(m + 1)]]
for y in range(n):
esblanco.append([False] + [(x != "*") for x in input()])
blancos = 0
for renglon in esblanco:
for x in renglon:
if x:
blancos += 1
blancos -= 2
suma = 0
nume = [[(0) for x in range(m + 1)] for y in range(n + 1)]
numeren = 0
denoren = 0
for y in range(1, n + 1):
for x in range(1, m + 1):
if esblanco[y][x] and esblanco[y][x - 1]:
denoren += 1
numeren = (pot2mod(denoren) - numeren) % NUMMOD
suma += numeren * pot2mod(blancos - denoren) % NUMMOD
else:
denoren = 0
numeren = 0
nume[y][x] = numeren / pot2mod(denoren)
for x in range(1, m + 1):
for y in range(1, n + 1):
if esblanco[y][x] and esblanco[y - 1][x]:
denoren += 1
numeren = (pot2mod(denoren) - numeren) % NUMMOD
suma += numeren * pot2mod(blancos - denoren) % NUMMOD
else:
denoren = 0
numeren = 0
nume[y][x] = numeren / pot2mod(denoren)
print(int(suma % (NUMMOD / 8))) | FUNC_DEF LIST NUMBER IF VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR STRING VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | import sys
def putin():
return map(int, sys.stdin.readline().split())
def f(n):
return ((3 * n + 1) * 2**n - (-1) ** n) // 9
def sol():
n, k = putin()
A = []
for i in range(n):
A.append(list(sys.stdin.readline()))
O_number = 0
for i in range(n):
for j in range(k):
O_number += A[i][j] == "o"
Red = {}
for i in range(n):
cur = int(A[i][0] == "o")
for j in range(1, k):
if A[i][j] == "o":
if cur > 0:
cur += 1
else:
cur += 1
elif cur > 0:
if cur in Red:
Red[cur] += 1
else:
Red[cur] = 1
cur = 0
if cur > 0:
if cur in Red:
Red[cur] += 1
else:
Red[cur] = 1
Blue = {}
for i in range(k):
cur = int(A[0][i] == "o")
for j in range(1, n):
if A[j][i] == "o":
if cur > 0:
cur += 1
else:
cur += 1
elif cur > 0:
if cur in Blue:
Blue[cur] += 1
else:
Blue[cur] = 1
cur = 0
if cur > 0:
if cur in Blue:
Blue[cur] += 1
else:
Blue[cur] = 1
answer = 0
for elem in Red:
answer += f(elem - 1) * Red[elem] * 2 ** (O_number - elem)
for elem in Blue:
answer += f(elem - 1) * Blue[elem] * 2 ** (O_number - elem)
sys.stdout.write(str(answer % 998244353))
sol() | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR VAR FOR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | MOD = 998244353
N, M = map(int, input().split())
S = [input() for _ in range(N)]
L = max(N, M)
imos = [0] * (L + 2)
for i in range(N):
cnt = 0
for j in range(M):
if S[i][j] == "*":
cnt = 0
else:
cnt += 1
imos[1] += 1
imos[cnt + 1] -= 1
for j in range(M):
cnt = 0
for i in range(N):
if S[i][j] == "*":
cnt = 0
else:
cnt += 1
imos[1] += 1
imos[cnt + 1] -= 1
ans = 0
for i in range(2, min(L, imos[1] // 2) + 1):
imos[i] += imos[i - 1]
ans += imos[i] * pow(2, imos[1] // 2 - i, MOD) * (-1) ** (i % 2) % MOD
ans %= MOD
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | MOD = 998244353
def power(a, b):
res = 1
while b > 0:
if b % 2 == 1:
res = res * a % MOD
a = a * a % MOD
b //= 2
return res
def inverse(n):
return power(n, MOD - 2)
h, w = map(int, input().split())
grid = [input() for _ in range(h)]
prob = [0, 0]
for c in range(2, max(h, w) + 1):
prob.append(prob[-1] + (-1) ** c * inverse(power(2, c)))
prob[-1] %= MOD
res = 0
for r in range(h):
cnt = 0
for c in range(w):
if grid[r][c] == "o":
cnt += 1
else:
cnt = 0
res += prob[cnt]
res %= MOD
for c in range(w):
cnt = 0
for r in range(h):
if grid[r][c] == "o":
cnt += 1
else:
cnt = 0
res += prob[cnt]
res %= MOD
for r in range(h):
for c in range(w):
if grid[r][c] == "o":
res *= 2
res %= MOD
print(res) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black.
You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $2^w$, where $w$ is the number of white cells.
After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:
each domino covers two adjacent cells;
each cell is covered by at most one domino;
if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;
if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells.
Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $2^w$ possible ways to paint it. Since it can be huge, print it modulo $998\,244\,353$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 3 \cdot 10^5$; $nm \le 3 \cdot 10^5$) — the number of rows and columns, respectively.
Then $n$ lines follow, each line contains a string of $m$ characters. The $j$-th character in the $i$-th string is * if the $j$-th cell in the $i$-th row is black; otherwise, that character is o.
-----Output-----
Print one integer — the sum of values of the board over all $2^w$ possible ways to paint it, taken modulo $998\,244\,353$.
-----Examples-----
Input
3 4
**oo
oo*o
**oo
Output
144
Input
3 4
**oo
oo**
**oo
Output
48
Input
2 2
oo
o*
Output
4
Input
1 4
oooo
Output
9
-----Note-----
None | n, m = map(int, input().split())
maze = []
for i in range(n):
maze.append(input())
tot = 0
for i in range(n):
for j in range(m):
if maze[i][j] == "o":
tot += 1
lis = [(0) for i in range(max(n, m) + 1)]
for i in range(n):
j = 0
while j < m:
p = j
while p < m and maze[i][j] == maze[i][p]:
p += 1
leng = p - j
j = p
if maze[i][j - 1] == "*":
continue
if leng > 1:
lis[leng] += 1
for j in range(m):
i = 0
while i < n:
p = i
while p < n and maze[i][j] == maze[p][j]:
p += 1
leng = p - i
i = p
if maze[i - 1][j] == "*":
continue
if leng > 1:
lis[leng] += 1
pre = [(0) for i in range(max(n, m) + 1)]
ans = 0
mod = 998244353
for i in range(2, min(max(n, m), tot) + 1):
pre[i] = (((i - 1) * pow(2, i - 2, mod) - pre[i - 1]) % mod + mod) % mod
ans += pre[i] * lis[i] % mod * pow(2, tot - i, mod) % mod
ans %= mod
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR STRING IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n, k, A, B = [int(input()) for _ in range(4)]
s = 0
if k == 1:
print(A * (n - 1))
exit()
while n > 1:
t = n % k
d = n // k
if not d:
s += (n - 1) * A
print(s)
exit()
s += A * t if t else min(A * (n - d), B)
n = k * d if t else d
print(s) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if k == 1:
ans = (n - 1) * a
else:
while n != 1:
if n % k == 0:
t = n // k
ta = min(b, (n - t) * a)
ans += ta
n = t
else:
t = n % k if n // k else n - 1
ans += t * a
n -= t
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | number = int(input())
divisor = int(input())
decrement_cost = int(input())
division_cost = int(input())
final_cost = 0
while number != 1:
remainder = number % divisor
if remainder != 0:
final_cost += decrement_cost * remainder
number -= remainder
jump = number - number // divisor
if division_cost < jump * decrement_cost:
final_cost += division_cost
number //= divisor
else:
final_cost += decrement_cost * (number - 1)
number = 1
print(final_cost) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | import sys
n = int(input())
divisor = int(input())
price_sub = int(input())
price_div = int(input())
x = n
cost = 0
if divisor == 1:
cost += (x - 1) * price_sub
print(int(cost))
sys.exit(0)
num_subs = divisor - 1
while x > 1:
if x % divisor != 0:
mod = x % divisor
cost += price_sub * mod
x -= mod
if x < 1:
cost -= price_sub
continue
points = x - x // divisor
if price_div < points * price_sub:
cost += price_div
x = x // divisor
continue
cost += (x - 1) * price_sub
print(int(cost))
sys.exit(0)
print(int(cost)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n - 1) * a)
else:
x = n
count = 0
while x > 1:
if x >= k:
if x % k == 0:
if (x - x // k) * a > b:
count += b
else:
count += (x - x // k) * a
x = x // k
else:
r = x % k
count += r * a
x = x - r
else:
count += (x - 1) * a
x = 1
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | def dp(x, k, a, b):
if x < k or k == 1:
return (x - 1) * a
if x % k == 0:
return dp(x // k, k, a, b) + min(b, a * (x - x // k))
else:
return dp(x - x % k, k, a, b) + x % k * a
n = int(input())
k = int(input())
a = int(input())
b = int(input())
print(dp(n, k, a, b)) | FUNC_DEF IF VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | import sys
n = int(input())
k = int(input())
A = int(input())
B = int(input())
x = n
cst = 0
if k == 1:
print((x - 1) * A)
sys.exit(0)
while x != 1:
if x % k == 0:
cst += min((x - x // k) * A, B)
x = x // k
elif x < k:
cst += (x - 1) * A
x = 1
else:
cst += x % k * A
x -= x % k
print(cst) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if n == 1:
print(0)
exit()
if k > n or k == 1:
print(a * (n - 1))
exit()
mn = a * (n - 1)
ans = 0
while n // k >= 1:
x = n % k
y = n // k
ans += min(a * (n - y), x * a + b)
n = n // k
if n:
ans += (n - 1) * a
print(min(ans, mn)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
anw = 0
if k == 1:
print(a * (n - 1))
exit(0)
while n > 1:
if n % k != 0:
if n < k:
n -= 1
anw += a * (n % k)
n -= n % k
else:
toMinus = (n - n // k) * a
anw += min(toMinus, b)
n //= k
print(anw) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | class COL:
def main(self):
n = int(input())
k = int(input())
a = int(input())
b = int(input())
x = n
count = 0
if k == 1:
print(str((x - 1) * a))
return
while x > 1:
if x < k:
count = count + a * (x - 1)
break
if x % k == 0:
if (x - x / k) * a < b:
count = count + (x - x / k) * a
else:
count = count + b
x = x / k
else:
count = count + x % k * a
x = x - x % k
print(str(int(count)))
c = COL()
c.main() | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | def main():
n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
if k == 1:
print((n - 1) * A)
exit(0)
if n == 1:
print(0)
exit(0)
while n > 1:
if n % k != 0:
mul = n - k * (n // k)
cost += A * mul
n -= mul
else:
subCost = A * (n - n // k)
cost += min(subCost, B)
n //= k
if n == 0:
cost -= A
print(cost)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | import sys
n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n - 1) * a)
sys.exit()
s = 0
while n > 1:
if n % k == 0:
d = n - n // k
if b > a * d:
n -= d
s += a * d
else:
n //= k
s += b
elif n // k == 0:
s += (n % k - 1) * a
n -= n % k - 1
else:
s += n % k * a
n -= n % k
print(s) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
cost = 0
if k > 1:
while n > 1:
if n >= k and n % k == 0:
q = n // k
cost += min((n - q) * a, b)
n = q
elif n >= k and n % k != 0:
q = n // k
l = q * k
cost += (n - l) * a
n = l
else:
cost += (n - 1) * a
n = 1
cost += (n - 1) * a
print(cost) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n, k, A, B, v = int(input()), int(input()), int(input()), int(input()), 0
while n > 1:
if k == 1 or n < k:
v += A * (n - 1)
n = 1
elif n % k:
v += A * (n % k)
n -= n % k
else:
v += min(A * (n - n // k), B)
n //= k
print(v) | ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if k == 1:
print((n - 1) * a)
else:
while n > 1:
if n % k == 0:
ans += min(b, a * (n - n // k))
n //= k
elif n > k:
ans += n % k * a
n -= n % k
else:
ans += (n % k - 1) * a
n = 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
if k == 1:
cost += (n - 1) * A
else:
while n > 1:
r = n % k
q = n // k
if n < k:
cost += (n - 1) * A
n = 1
elif r != 0:
cost += r * A
n -= r
else:
cost += min(B, (n - q) * A)
n = q
print(cost) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
cn = 0
if k == 1:
print((n - 1) * a)
exit(0)
while n >= 1:
x = n % k
cn += a * x
n -= x
if n == 0:
cn -= a
break
nn = n // k
cn += min(b, (n - nn) * a)
n = nn
print(cn) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
x = n
cost = 0
if k == 1:
cost = (x - 1) * a
else:
while x != 1:
r = x % k
cost += a * r
x -= r
if x == k:
if (x - x // k) * a > b:
cost += b
x = x // k
else:
cost += a * (x - x // k)
x = x // k
break
elif x < k:
cost += (x - 1) * a
break
if (x - x // k) * a > b:
cost += b
x = x // k
else:
cost += a * (x - x // k)
x = x // k
print(cost) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if ((k == 1) | (k > n)) & (n != 1):
ans = n * a - a
n = 1
while n != 1:
if n % k == 0:
t = n // k
y = n - t
if y * a <= b:
ans += n * a - a
n = 1
else:
ans += b
n = t
else:
ans += n % k * a
n -= n % k
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if k != 1:
while n != 1:
if n % k != 0:
ans = ans + n % k * a
n = n - n % k
if n == 0:
ans = ans - a
n = 1
else:
f = n // k
if b > (n - f) * a:
ans = ans + (n - f) * a
else:
ans = ans + b
n = f
else:
ans = (n - 1) * a
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
x = n
y = 0
while x > 1:
c = x / k
if x % k == 0 and (x - int(c)) * a >= b and k != 1:
x = c
y = y + b
elif x % k == 0 and (x - int(c)) * a < b:
y = y + a * (x - 1)
x = 1
elif x % k == 0 and (x - int(c)) * a >= b and k == 1:
y = y + a * (x - 1)
x = 1
elif x % k != 0 and x > k:
y = y + (x - int(c) * k) * a
x = int(c) * k
elif x < k:
y = y + a * (x - 1)
x = 1
print(int(y)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
div = int(input())
minusCost = int(input())
divCost = int(int(input()))
if div == 1:
print((n - 1) * minusCost)
exit()
ret = 0
cur = n
while cur > 1:
if cur < div:
ret += (cur - 1) * minusCost
cur = 1
elif cur % div != 0:
ret += cur % div * minusCost
cur -= cur % div
else:
ret += min(divCost, (cur - cur // div) * minusCost)
cur //= div
print(ret) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total. | n = int(input())
k = int(input())
a = int(input())
b = int(input())
m = n
ans = 0
if n >= k and k > 1:
while n != 1:
ans += n % k * a
n -= n % k
ans += min(b, (n - n // k) * a)
n //= k
if n < k:
ans += (n - 1) * a
break
print(min(ans, (m - 1) * a))
else:
print((n - 1) * a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.