description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split() if i != "\n"]
prefev = [0]
prefod = [0]
for i in range(n):
if not i & 1:
prefod.append(prefod[-1] + a[i])
prefev.append(prefev[-1])
else:
prefev.append(prefev[-1] + a[i])
prefod.append(prefod[-1])
prefev = prefev[1:]
prefod = prefod[1:]
best1, best2 = 0, 0
for i in range(n):
best1 = max(best1, prefev[i] + (prefod[-1] - prefod[i]))
best2 = max(best2, prefod[i] + (prefev[-1] - prefev[i]))
print(max(best1, best2)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | import sys
def solve(ls):
n = len(ls)
k = (n - 1) // 2
s = 0
for i in range(k + 1):
s += ls[2 * i]
s_max = s
for i in range(n):
s -= ls[2 * i % n]
s += ls[(2 * i + 1) % n]
s_max = max(s_max, s)
return s_max
def main(istr, ostr):
n = int(istr.readline())
ls = list(map(int, istr.readline().split()))
print(solve(ls), file=ostr)
main(sys.stdin, sys.stdout) | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
a = list(map(int, input().split()))
a0 = [a[i] for i in range(n) if i % 2 == 0]
a1 = [a[i] for i in range(n) if i % 2 == 1]
a = a0 + a1
l = n // 2 + 1
ans = sum(a[:l])
ans_sub = sum(a[:l])
for i in range(n):
ans_sub -= a[i]
ans_sub += a[(i + l) % n]
ans = max(ans, ans_sub)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
l = [int(x) for x in input().split()] * 2
for i in range(2, 2 * n):
l[i] += l[i - 2]
s = 0
for i in range(n):
if i >= 2:
a = l[n + i - 1] - l[i - 2]
else:
a = l[n + i - 1]
s = max(s, a)
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(0, n, 2):
b.append(a[i])
else:
ind = len(b)
for i in range(1, n, 2):
b.append(a[i])
b.extend(b)
ans = sum(b[:ind])
lsum = ans
for i in range(ind, len(b)):
lsum -= b[i - ind]
lsum += b[i]
ans = max(ans, lsum)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
m = (n + 1) // 2
a = list(map(int, input().split()))
curr = 0
for i in range(m):
curr += a[2 * i]
answer = curr
for j in range(n - 1):
curr -= a[2 * j % n]
curr += a[2 * (j + m) % n]
answer = max(answer, curr)
print(answer) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
exit(0)
v = [sum(a[i] for i in range(j, n, 2)) for j in range(2, 4)]
u = [0, 0]
ans = 0
for i in range(n):
w = u[(i - 2) % 2] + a[i] + a[(i + 1) % n] + v[(i + 3) % 2]
ans = max(ans, w)
u[i % 2] += a[i]
v[(i + 2) % 2] -= a[(i + 2) % n]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | for _ in range(1):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0, n, 2):
b += [a[i]]
for i in range(1, n, 2):
b += [a[i]]
b += b
size = (n + 1) // 2
ans = 0
total = 0
for i in range(size):
total += b[i]
ans = total
for i in range(size, len(b)):
total += b[i] - b[i - size]
ans = max(ans, total)
print(ans) | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR LIST VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | from sys import stdin, stdout
int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))
def solve(n, a):
if n == 1:
return a[0]
arr = []
for i in range(0, len(a), 2):
arr.append(a[i])
for i in range(1, len(a), 2):
arr.append(a[i])
arr += arr
need = (n + 1) // 2
curr = 0
for i in range(need):
curr += arr[i]
best = curr
for i in range(1, len(arr) - need):
curr -= arr[i - 1]
curr += arr[need + i - 1]
best = max(best, curr)
return best
n = int_in()
a = arr_in()
out(solve(n, a)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
arr = list(map(int, input().split()))
lis = []
for i in range(n + (n - 1) // 2):
lis.append(arr[2 * i % n])
ans = sum(lis[: (n + 1) // 2])
temp = ans
for i in range(1, n):
temp -= lis[i - 1]
temp += lis[(n + 1) // 2 + i - 1]
ans = max(ans, temp)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | def solve(n, arr):
ans = m = sum(arr[:n:2])
for i in range(0, n - 1, 2):
m += arr[i + 1] - arr[i]
ans = max(m, ans)
m = arr[0] + sum(arr[1:n:2])
ans = max(m, ans)
for i in range(2, n - 1, 2):
m += arr[i] - arr[i - 1]
ans = max(m, ans)
return ans
n = int(input())
arr = list(map(int, input().split()))
print(solve(n, arr)) | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
a = list(map(int, input().split()))
b = [a[i] for i in range(0, n, 2)] + [a[i] for i in range(1, n, 2)]
b = b + b
m = n // 2 + 1
total = sum(b[0:m])
ans = total
for i in range(0, n + n - m):
total += b[i + m] - b[i]
ans = max(ans, total)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!
You are given $n$ nonnegative integers $a_1, a_2, \dots, a_n$ arranged in a circle, where $n$ must be odd (ie. $n-1$ is divisible by $2$). Formally, for all $i$ such that $2 \leq i \leq n$, the elements $a_{i - 1}$ and $a_i$ are considered to be adjacent, and $a_n$ and $a_1$ are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.
Help Danny find the maximum possible circular value after some sequences of operations.
-----Input-----
The first line contains one odd integer $n$ ($1 \leq n < 2 \cdot 10^5$, $n$ is odd) Β β the initial size of the circle.
The second line contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($0 \leq a_{i} \leq 10^9$) Β β the initial numbers in the circle.
-----Output-----
Output the maximum possible circular value after applying some sequence of operations to the given circle.
-----Examples-----
Input
3
7 10 2
Output
17
Input
1
4
Output
4
-----Note-----
For the first test case, here's how a circular value of $17$ is obtained:
Pick the number at index $3$. The sum of adjacent elements equals $17$. Delete $7$ and $10$ from the circle and replace $2$ with $17$.
Note that the answer may not fit in a $32$-bit integer. | n = int(input())
a = [int(x) for x in input().split()]
if n == 1:
print(a[0])
exit()
evens = [a[0]]
odds = [a[1]]
for i in range(2, n):
if i % 2 == 0:
evens.append(evens[-1] + a[i])
else:
odds.append(odds[-1] + a[i])
maxi = 0
for i in range(len(evens)):
score = evens[i]
if i == 0:
score += odds[-1]
else:
score += odds[-1] - odds[i - 1]
if score > maxi:
maxi = score
for i in range(len(odds)):
score = odds[i]
score += evens[-1] - evens[i]
if score > maxi:
maxi = score
print(maxi) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
i = s.find("1")
if i == -1:
print(0)
else:
s1 = s[i:]
j = s1.find("0")
if j == -1:
print(s1)
else:
s2 = s1[j:]
s3 = s1[:j] + "".join(str(int(a) or int(b)) for a, b in zip(s1, s2))
s2 = s1[1:]
s4 = s1[:1] + "".join(str(int(a) or int(b)) for a, b in zip(s1, s2))
print(max(s3, s4)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
binary = input()
binary = binary.lstrip("0")
n = len(binary)
p_zero = []
p_one = []
for i in range(n):
if binary[i] == "0":
p_zero.append(i)
else:
p_one.append(i)
if len(p_one) == 0:
print(0)
elif len(p_zero) == 0:
print(binary)
else:
size = n - p_zero[0]
max_sub = ""
seq = ""
for i in p_one:
if n - i < size:
break
sub = binary[i : i + size]
if i == p_one[0]:
for j in p_zero:
if sub[j - p_zero[0]] == "1":
seq += "1"
else:
seq += "0"
max_sub = sub
else:
p = 0
c_seq = ""
flag = True
for j in p_zero:
if sub[j - p_zero[0]] == "1":
c_seq += "1"
else:
c_seq += "0"
if seq[p] < c_seq[-1]:
break
if seq[p] > c_seq[-1]:
flag = False
break
p += 1
if flag:
seq = c_seq
max_sub = sub
max_sub = "0" * (n - size) + max_sub
for i in range(n):
print("1" if binary[i] == "1" or max_sub[i] == "1" else "0", end="")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR NUMBER STRING VAR STRING VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR NUMBER STRING VAR STRING VAR STRING IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR VAR STRING STRING STRING STRING EXPR FUNC_CALL VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
b = int(s, 2)
a = b
mx = a | b
for i in range(0, 7):
a = a >> 1
m = a | b
if m > mx:
mx = m
st = format(mx, "b")
print(st) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
ind = []
index = 0
flag = 0
len_index = 0
ed = 0
for i in range(n):
if flag:
index += 1
if s[i] == "1":
ed = 1
if s[i] == "0" and ed != 0:
ind.append(index)
flag = 1
len_index += 1
if flag == 0:
print(0)
exit(0)
ln = index
mx_s = ""
for i in range(ln, n):
new_s = ""
for j in ind:
new_s += s[i - (ln - j)]
if new_s > mx_s:
mx_s = new_s
ans = ["0"] * (ln + 1)
for i in range(len_index):
ans[ind[i]] = mx_s[i]
ans = "".join(ans)
ans = int(ans, 2) | int(s, 2)
print(bin(ans)[2:]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | import sys
input = sys.stdin.readline
def solve():
n = int(input())
S = input().strip()
if S == "1" * n:
return S
elif S == "0" * n:
return "0"
m = st1 = 0
ans = 0
for i in range(n - 1):
if st1 == 0 and S[i] == "1":
st1 = S[i:]
st1 = int(st1, 2)
if S[i] == "1" and S[i + 1] == "0":
k = n - (i + 1)
for j in range(i, -1, -1):
if S[j] == "0":
continue
st2 = S[j:]
st2 = st2[:k]
ans = max(ans, st1 | int(st2, 2))
return bin(ans)[2:]
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP STRING VAR RETURN VAR IF VAR BIN_OP STRING VAR RETURN STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
first1 = n
for i in range(len(s)):
if s[i] == "1":
first1 = i
break
s = s[first1:]
if s == "":
print(0)
else:
first0 = n
for i in range(len(s)):
if s[i] == "0":
first0 = i
break
if first0 == n:
print(s)
else:
n = int(s, 2)
best = n
for i in range(first0 + 1):
best = max(best, n | n >> i)
print(bin(best)[2:])
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
if s.count("0") == n:
print("0")
elif s.count("1") == n:
print(s)
else:
s = s.lstrip("0")
n = len(s)
a = int(s, 2)
p = s.index("0")
k = n - p
ans = 0
for i in range(n - k):
sk = s[i : i + k]
b = int(sk, 2)
ans = max(a | b, ans)
ans = bin(ans)
ans = ans[2:]
ans = ans.lstrip("0")
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = int(input(), 2)
ans = 0
for i in range(20):
ans = max(ans, s | s >> i)
ans = bin(ans)
ans = ans[2:]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | def valOf(inp):
return int(inp, base=2)
def mainFunc():
n = int(input())
s = input()
s = s.lstrip("0")
if not s:
print(0)
return
zeroPos = -1
for index, value in enumerate(s):
if value == "0":
zeroPos = index
break
if zeroPos == -1:
print(s)
return
expectedS2Size = len(s) - zeroPos
maxOrPossible = valOf(s)
for i in range(0, len(s) - expectedS2Size):
maxOrPossible = max(maxOrPossible, valOf(s[i : i + expectedS2Size]) | valOf(s))
print(bin(maxOrPossible).replace("0b", ""))
return
t = 1
for testcase in range(t):
mainFunc() | FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | def update(s, i, j, n, mx):
while j >= i:
s[n - 1] |= s[j]
j -= 1
n -= 1
mx = max(mx, s)
return mx
def solve():
n = int(input())
s = input().strip()
s = [int(el) for el in s]
i = 0
while i < n and s[i] == 0:
i += 1
if i == n:
print(0)
return
s = s[i:]
n = len(s)
i = 0
while i < n and s[i] == 1:
i += 1
if i == n:
print(*s, sep="")
return
nt = n - i
i = 0
mx = [0] * nt
while i + nt <= n:
j = i + nt - 1
mx = update(s.copy(), i, j, n, mx)
i += 1
i = 0
while i < len(mx) - 1 and mx[i] == 0:
i += 1
print(*mx[i:], sep="")
solve() | FUNC_DEF WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING RETURN ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | import sys
input = sys.stdin.readline
def pobit(s, s2):
i = len(s) - 1
l = len(s2) - 1
ans = []
while l >= 0:
if s[i] == "1" or s2[l] == "1":
ans.append("1")
else:
ans.append("0")
i -= 1
l -= 1
while i >= 0:
ans.append(str(s[i]))
i -= 1
stroka = ""
i = len(s) - 1
while ans[i] == "0":
i -= 1
if i == 0:
break
while i >= 0:
stroka += ans[i]
i -= 1
return stroka
def solve():
n = int(input())
s = input()
s = s[0:n]
x = 0
i = 0
while s[i] == "0":
i += 1
if i == n:
return "0"
while i < n:
if s[i] == "1":
x += 1
else:
break
i += 1
ans = "0"
for i in range(n - x, n):
y = pobit(s, s[0:i])
if y > ans:
ans = y
return ans
ans = solve()
print(ans) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR RETURN STRING WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
s = list(s)
i = 0
while s[i] == "0":
i += 1
if i == n:
break
if i == n:
print(0)
else:
s = s[i:]
n = len(s)
ans = [i for i in s]
i = 0
o = 0
while s[i] == "1":
o += 1
i += 1
if o == 0:
print("0")
else:
ones = [j for j in range(1, o + 1)]
while i < n and len(ones) > 0:
if s[i] == "0":
tmp = []
for j in ones:
if s[i - j] == "1":
tmp.append(j)
if len(tmp) > 0:
ans[i] = "1"
ones = tmp
i += 1
anss = ""
for i in ans:
anss += i
print(anss) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | from sys import exit
n = int(input())
s = input()
f1 = s.find("1")
if f1 == -1:
print(0)
exit()
ln = 0
for i in range(f1, n):
if s[i] == "1":
ln += 1
else:
break
sb = int(s, 2)
res = sb
for i in range(ln):
res = max(res, sb | int(s[: -(i + 1)], 2))
print(bin(res)[2:]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | def main():
n = int(input())
s = list(input())
i = 0
while i < n and s[i] == "0":
i += 1
if i == n:
s = "0"
else:
s = s[i:]
n = len(s)
pos = -1
for i in range(n):
if s[i] == "0":
pos = i
break
if pos == -1:
print("".join(s))
return
if pos == 0:
print(0)
return
ans = []
for i in range(pos):
t = s[i : i + (n - pos)]
j, k = len(s) - 1, len(t) - 1
res = []
while j >= 0 and k >= 0:
res.append("1" if s[j] == "1" or t[k] == "1" else "0")
j -= 1
k -= 1
while j >= 0:
res.append(s[j])
j -= 1
res.reverse()
ans.append("".join(res))
ans.sort(reverse=True)
i = 0
while i < n and ans[0][i] == "0":
i += 1
if i == n:
print(0)
return
print(ans[0][i:])
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR VAR STRING STRING STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | input()
ash = int(input(), 2)
m = ash
for i in range(1, 100):
m = max(m, ash | ash >> i)
print("{0:b}".format(m)) | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
ss = input()
def cal(s):
if "1" not in s:
return "0"
s = s[s.index("1") :]
if "0" not in s:
return s[:-1] + "0"
t = s[s.index("0") :]
k = len(t)
re = t
for i in range(len(s) - k + 1):
if s[i] != "1":
continue
p = s[i : i + k]
c = [max(p[j], t[j]) for j in range(k)]
ck = "".join(c)
if ck == "1" * k:
return "1" * len(s)
re = max(re, ck)
return s[:-k] + re
print(cal(ss)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF STRING VAR RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR STRING IF STRING VAR RETURN BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR BIN_OP STRING VAR RETURN BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | len_1 = int(input())
str_1 = input()
msb = -1
flag = 0
for t in range(len_1):
if str_1[t] == "0":
msb = t
if flag == 1:
break
if str_1[t] == "1":
flag = 1
seg_len = len_1 - msb
lst_val = []
u = 0
while seg_len + u <= len_1:
lst_val.append(int(str_1[u : seg_len + u], 2))
u += 1
val = int(str_1, 2)
max = val
for t in lst_val:
if val | t > max:
max = t | val
bin_2 = bin(max)
print(bin_2[2:]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = [int(x) for x in list(input())]
if sum(s) == 0:
print(0)
else:
leadingOnes = 0
s1 = []
stop = False
for i in range(n):
if not stop:
if s[i] == 1:
leadingOnes += 1
if s[i] == 0 and leadingOnes > 0:
stop = True
if leadingOnes > 0:
s1.append(s[i])
best = s1
for i in range(leadingOnes + 1):
s2 = [(0) for _ in range(i + 1)] + s1[: len(s1) - i + 1]
isBetter = False
new = []
for i in range(len(s1)):
if (
not (s2[i] == 1 or s1[i] == 1)
and (best[i] == 1 or s1[i] == 1)
and not isBetter
):
break
if s2[i] == 1 or s1[i] == 1:
if best[i] == 0:
isBetter = True
new.append(1)
else:
new.append(0)
if isBetter:
best = new
print("".join(map(str, best))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
s = input()
y = int(s, 2)
s = bin(y)[2:]
l = ""
if y == 0:
print("0")
else:
for i in s:
if i == "0":
l += "1"
elif l != "":
l += "0"
mx = 0
m = len(l)
if m == 0:
mx = y or int(s[-1], 2)
else:
for j in range(n - m):
mx = max(mx, y | int(s[j : j + m], 2))
print(bin(mx)[2:]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR STRING VAR STRING IF VAR STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | def getStr(i, k):
ans = ""
while i < n:
if s[i] == "1" or s[k] == "1":
ans += "1"
else:
ans += "0"
i += 1
k += 1
return ans
n = int(input())
s = input()
i = 0
while i < n and s[i] == "0":
i += 1
if i == n:
print(0)
exit()
j = i
while i < n and s[i] == "1":
i += 1
ans = "0" * (n - i - j)
for k in range(i, j - 1, -1):
t = getStr(i, k)
ans = max(ans, t)
print(s[j:i] + ans) | FUNC_DEF ASSIGN VAR STRING WHILE VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING VAR STRING VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | def solve1(n, o, s):
p = ""
flag = False
for i in range(0, n):
if s[i] == "1" or flag:
flag = True
p += s[i]
if len(p) == 0:
print(0)
exit(0)
s = p
n = len(s)
p = ""
for i in range(2, n + 1):
x = n - o + 1
y = n - i + 1
for j in range(min(x, y), n + 1):
if s[j - 1] == "0":
if j >= x:
a = s[j - x] == "1"
else:
a = 0
if j >= y:
b = s[j - y] == "1"
else:
b = 0
if a < b:
o = i
if a != b:
break
for i in range(1, n + 1):
p += str(
((i >= n - o + 1 and s[i - n + o - 1] == "1") | int(s[i - 1]) - 48) + 48
)
print(p)
n, o = [int(input()), 1]
s = input()
solve1(n, o, s)
while None:
pass
while 1:
break | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR ASSIGN VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE NONE WHILE NUMBER |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | from sys import stdin, stdout
def ss(n, s):
if s.count("0") == n:
return "0"
y = int(s, 2)
s = bin(y)[2:]
l = ""
if y == 0:
return "0"
for t in range(len(s)):
i = s[t]
if i == "0":
l += "1"
elif l != "":
l += "0"
mx = 0
m = len(l)
if l:
for j in range(n - m):
mx = max(mx, y | int(s[j : j + m], 2))
else:
mx = y or int(s[-1], 2)
return bin(mx)[2:]
n = int(input())
s = input()
print(ss(n, s)) | FUNC_DEF IF FUNC_CALL VAR STRING VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING IF VAR STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | n = int(input())
a = int(input(), 2)
temp = a
mx = a | temp
for i in range(7):
temp = temp >> 1
m = a | temp
if mx < m:
mx = m
print(bin(mx).replace("0b", "")) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING |
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (possibly intersecting, possibly the same, possibly non-intersecting β just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:
let $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$);
the value is the bitwise OR of $f(s_1)$ and $f(s_2)$.
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
-----Input-----
The first line contains one integer $n$ β the number of characters in $s$.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$.
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$, $n = 5$; in tests from $11$ to $20$, $n = 1000$; in tests from $21$ to $40$, $n = 10^6$.
Hacks are forbidden in this problem.
-----Output-----
Print the maximum possible value you can get in binary representation without leading zeroes.
-----Examples-----
Input
5
11010
Output
11111
Input
7
1110010
Output
1111110
Input
4
0000
Output
0
-----Note-----
In the first example, you can choose the substrings 11010 and 101. $f(s_1) = 26$, $f(s_2) = 5$, their bitwise OR is $31$, and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100. | def sor(s1: str, s2: str):
a1 = list(max(s1, s2))
a2 = min(s1, s2)
for i in range(len(a2)):
if a2[i] == "1":
a1[len(a1) - len(a2) + i] = "1"
return "".join(a1).lstrip("0")
n = int(input())
s = input().lstrip("0")
n = len(s)
ans = "0"
a1 = s.find("1")
if a1 != -1:
a2 = s.find("0")
if a2 != -1:
for i in range(a1, a2):
l = n - a2
s2 = s[i : i + l]
ans = max(ans, sor(s, s2))
print(ans) | FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING RETURN FUNC_CALL FUNC_CALL STRING VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | numset = set()
def num(now, n):
if n == 1:
numset.add(now + 1)
numset.add(now + 5)
numset.add(now + 10)
numset.add(now + 50)
else:
num(now + 1, n - 1)
num(now + 5, n - 1)
num(now + 10, n - 1)
num(now + 50, n - 1)
n = int(input())
if n < 11:
num(0, n)
print(len(numset))
else:
print(292 + 49 * (n - 11)) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
l = [1, 3, 6, 10, 15, 21, 27, 33, 39, 43, 46, 48]
if n < 12:
print(sum(l[: n + 1]))
else:
print(sum(l) + 49 * (n - 11)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input().strip())
def C(n, r):
c = 1
for i in range(r):
c = c * (n - i)
for i in range(r):
c = c // (i + 1)
return c
def calc(n, r):
if n < 0:
return 0
return C(n + r - 1, r - 1)
ans = 0
for i in range(5):
ans += calc(n - i, 2)
for i in range(4):
ans += calc(n - i, 2)
for i in range(5):
for j in range(4):
ans -= calc(n - i - j, 1)
for i in range(5):
for j in range(8):
ans += calc(n - i - j - 1, 2)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | ans = 0
def solve(nn, su, ans):
if nn == n:
s.add(su)
ans += 1
return
solve(nn + 1, su + 1, ans)
solve(nn + 1, su + 5, ans)
solve(nn + 1, su + 10, ans)
solve(nn + 1, su + 50, ans)
s = set()
n = int(input())
if n <= 13:
solve(0, 0, ans)
print(len(s))
else:
print(292 + 49 * (n - 11)) | ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
if n > 20:
print(733 + (n - 20) * 49)
else:
s = set()
for i in range(n + 1):
for v in range(n - i + 1):
for x in range(n - i - v + 1):
l = n - i - v - x
s.add(i + 5 * v + 10 * x + 50 * l)
print(len(s)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | from itertools import combinations_with_replacement as cwr
def compute_lt12(n):
chars = "IVXL"
nums = [1, 5, 10, 50]
num_map = {c: n for c, n in zip(chars, nums)}
sum_set = set()
for comb in cwr(chars, n):
sum_set.add(sum(num_map[c] for c in comb))
return len(sum_set)
def main():
n = int(input())
if n < 12:
print(compute_lt12(n))
else:
print(292 + 49 * (n - 11))
main() | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | from itertools import combinations_with_replacement
l = []
for n in range(1, 20):
st = set()
for cmb in combinations_with_replacement((1, 5, 10, 50), n):
st.add(sum(cmb))
l.append(len(st))
n = int(input())
if n <= len(l):
print(l[n - 1])
else:
print(n * 49 - 247) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = [1, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341]
if n <= 12:
print(ans[n])
else:
print(49 * n - 247) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input().strip())
R1 = [4, 9, 49]
def get_after_slow(k, T=0):
dp = [(k + 1) for _ in range(49 * k + 1)]
dp[0] = 0
for i in range(1, 49 * k + 1):
for R in R1:
if i >= R:
dp[i] = min(dp[i], dp[i - R] + 1)
return len(dp) - T - dp[T:].count(k + 1)
def get_fast(k):
if k <= 20:
return get_after_slow(k)
else:
return (k - 19) * 49 - 12 + get_after_slow(20, 49)
print(get_fast(n)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FUNC_DEF NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def f(n):
if n < 0:
return 0
val = (n + 3) * (n + 2) * (n + 1) // 6
return val
def g(n):
return f(n) - f(n - 6) - 2 * f(n - 9) + f(n - 10) + f(n - 14)
n = int(input())
print(g(n)) | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def mi():
return map(int, input().split())
n = list(mi())[0]
a = [4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341]
if n >= 13:
print((n - 11) * 49 + a[10])
else:
print(a[n - 1]) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | lst, m = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244], 292
n = int(input())
if n <= 10:
print(lst[n])
else:
print(m + (n - 11) * 49) | ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
if n < 12:
print([1, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292][n])
else:
print(n * 50 - n - 247) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | from sys import setrecursionlimit
setrecursionlimit(10**9)
n = int(input())
s = set()
arr = [1, 5, 10, 50]
def comb(num, digit):
global n
if digit == n:
s.add(num)
else:
for i in range(4):
comb(num + arr[i], digit + 1)
if n <= 12:
comb(0, 0)
print(len(s))
else:
print(49 * n - 247) | EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | import sys
input = sys.stdin.readline
n = int(input())
dp = [0] * 150
s = set([0])
for i in range(150):
dp[i] = len(s)
s2 = set(s)
for j in s:
s2.add(j + 4)
s2.add(j + 9)
s2.add(j + 49)
s = s2
if 0:
for i in range(100):
if dp[i + 49] - dp[i] != 2401:
print(i)
if n < 150:
print(dp[n])
else:
stuff = n // 49
while n - stuff * 49 + 49 < 150:
stuff -= 1
print(dp[n - stuff * 49] + 2401 * stuff) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def foo(n):
return (n + 3) * (n + 2) * (n + 1) // 6
n = int(input())
ans = foo(n)
if n >= 6:
ans -= foo(n - 6)
if n >= 9:
ans -= foo(n - 9) * 2
if n >= 10:
ans += foo(n - 10)
if n >= 14:
ans += foo(n - 14)
print(ans) | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = 0
for v in range(0, 9):
for x in range(0, 49):
if n < v + x:
continue
wrong = 0
for vv in range(0, 9):
for xx in range(0, 49):
if n < vv + xx or vv == v and x == xx:
continue
if (v * 4 + x * 9) % 49 == (vv * 4 + xx * 9) % 49 and (
v * 4 + x * 9 > vv * 4 + xx * 9
or v * 4 + x * 9 == vv * 4 + xx * 9
and v > vv
):
wrong = 1
if wrong == 0:
ans += n - v - x + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
s = set()
x = [1, 5, 10, 50]
l = list()
def dfs(a, b, c):
if a == n:
s.add(b)
return
while c < len(x):
dfs(a + 1, b + x[c], c)
c += 1
if n <= 10:
dfs(0, 0, 0)
print(len(s))
return
else:
print(244 + 49 * (n - 10) - 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
rec = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341]
ans = 0
if n <= 12:
ans = rec[n]
else:
ans = (n - 12) * 49 + rec[12]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | import itertools
STC = [[0, 4, 0, 5], [1, 0, 8, 0], [1, 0, 0, 5]]
def ch(N, K):
ans = 1
for k in range(K):
ans *= N - k
for k in range(K):
ans //= k + 1
return ans
N = int(input())
ans = ch(N + 3, 3)
sgn = -1
for s in range(1, len(STC) + 1):
for cb in itertools.combinations(STC, s):
aq = [0, 0, 0, 0]
for c in cb:
for i in range(4):
aq[i] = max(aq[i], c[i])
tot = sum(aq)
if N >= tot:
ans += sgn * ch(N - tot + 3, 3)
sgn *= -1
print(ans) | IMPORT ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
l = [int(1e20) for i in range(49)]
r = [int(-1e20) for i in range(49)]
ans = 0
for i in range(49):
for j in range(49):
t = (i * 10 + j * 5 + (n - i - j)) % 49
l[t] = min(l[t], i * 10 + j * 5 + (n - i - j))
r[t] = max(r[t], i * 10 + j * 5 + (n - i - j) * 50)
for i in range(49):
ans += max(r[i] - l[i], -49) // 49 + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def answer(n):
sums = set()
for d1 in range(n + 1):
for d5 in range(n + 1 - d1):
for d10 in range(n + 1 - d1 - d5):
d50 = n - d1 - d5 - d10
sums.add(d1 * 1 + d5 * 5 + d10 * 10 + d50 * 50)
return len(sums)
answers = [answer(x) for x in range(31)]
n = int(input())
if n < len(answers):
answer = answers[n]
else:
growth = answers[30] - answers[29]
answer = answers[29] + (n - 29) * growth
print(answer) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
m = min([n, 100])
result = 50 * (n - m) + m - n + 1
my_set = set()
for i in range(m + 1):
for j in range(i, m + 1):
for k in range(j, m + 1):
tmp = 50 * i + 10 * (j - i) + 5 * (k - j) + (m - k)
my_set.add(tmp)
result += len(my_set) - 1
print(result) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | non_representable = {
(1): 46,
(2): 89,
(3): 128,
(4): 162,
(5): 190,
(6): 212,
(7): 228,
(8): 238,
(9): 244,
(10): 247,
}
n = int(input())
print(49 * n + 1 - non_representable.get(n, 248)) | ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def check(n, b, c):
for tb in range(0, 9):
for tc in range(0, min(n - tb + 1, 9)):
s1 = 9 * b + 4 * c
s2 = 9 * tb + 4 * tc
if s1 > s2 and (s1 - s2) % 49 == 0:
return False
return True
def main():
n = int(input())
ans = 0
for b in range(0, min(n + 1, 9)):
for c in range(0, min(n - b + 1, 9)):
if check(n, b, c):
ans += n - b - c + 1
print(ans)
exit(main()) | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
a = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]
print(max(49 * n - 247, a[n % 12])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def c(n):
ans = 0
if n > 15:
ans += 49 * (n - 15)
n = 15
l = set()
for i in range(max(n + 1, 441)):
for j in range(max(n - i + 1, 196)):
for k in range(n - i - j + 1):
l.add(i * 4 + j * 9 + k * 49)
return ans + len(l)
n = int(input())
print(c(n)) | FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = 0
minv = [int(1000000000.0)] * 200000
minv[0] = 0
for i in range(49):
for j in range(49):
minv[(4 * i + 9 * j) % 49] = min(minv[(4 * i + 9 * j) % 49], i + j)
for i in range(49):
if n >= minv[i]:
ans += n - minv[i] + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def main():
a, b, c, res, nxt = -1, -1, 0, [1], [True]
while b - a < c - b:
cur, nxt = nxt, [False] * (len(nxt) + 50)
for p in (1, 5, 10, 50):
for i, f in enumerate(cur):
if f:
nxt[i + p] = True
a, b, c = b, c, sum(nxt)
res.append(c)
n = int(input())
print(res[n] if len(res) > n else c + (c - b) * (n - len(res) + 1))
def __starting_point():
main()
__starting_point() | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER LIST NUMBER LIST NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def solve(n):
s = set()
for i in range(0, n + 1):
for v in range(0, n - i + 1):
for x in range(0, n - i - v + 1):
l = n - i - v - x
s.add(i + v * 5 + x * 10 + l * 50)
return len(s)
n = int(input())
if n < 11:
print(solve(n))
else:
print(49 * n - 247) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
if n < 20:
q = []
i = 0
while i <= n:
j = 0
while j <= n - i:
k = 0
while k <= n - i - j:
t = n - i - j - k
q.append(i * 1 + j * 5 + k * 10 + t * 50)
k = k + 1
j = j + 1
i = i + 1
print(len(set(q)))
else:
an = int((n + 1) * (n + 2) * (n + 3) // 6)
st = int(856)
diff = int(182)
t = int(21)
cnt = int(t + n - 20 - t + 1)
su = int(
(diff + diff + t * (cnt - 1)) * cnt // 2
+ (n - 20) * (n - 20 + 1) * (n - 20 + 2) // 6
)
st = st + su
print(an - st) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | import sys
n = int(input())
res = 0
for V in range(1, min(n, 8) + 1):
for X in range(min(n - V, 4) + 1):
res += n + 1 - V - X
for X in range(min(n, 8) + 1):
res += n + 1 - X
print(res) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | arr = []
for i in range(1, 15):
dict1 = {}
for j in range(0, i + 1):
for k in range(0, i + 1):
for l in range(0, i + 1):
if j + k + l <= i:
z = j * 50 + k * 10 + l * 5 + (i - j - k - l)
dict1[z] = 1
arr.append(len(dict1))
n = int(input())
if n < 15:
print(arr[n - 1])
else:
print(arr[-1] + (n - 14) * 49) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | a = [4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]
digits = input()
def result(digits):
if int(digits) <= 11:
return a[int(digits) - 1]
return a[10] + (int(digits) - 11) * 49
print(result(digits)) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = 0
for i in range(9):
for j in range(49):
def check(y, x):
for i in range(49):
for j in range(9):
if i == x and j == y:
continue
t = (x - i) * 9 + (y - j) * 4
if t >= 0 and t % 49 == 0:
return False
return True
if n - i - j >= 0 and check(i, j):
ans += n - i - j + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
N = 30
S = [set() for i in range(N)]
for i in range(N):
for v in range(N):
for x in range(N):
for l in range(N):
cnt = i + v + x + l
if cnt < N:
val = i + 5 * v + 10 * x + 50 * l
S[cnt].add(val)
if n < 30:
print(len(S[n]))
exit(0)
ans = 0
for x in range(5):
for v in range(1, 9):
ans += n - x - v + 1
for x in range(9):
ans += n - x + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | def ceildiv(a, b):
return -(-a // b)
def test_ceildiv():
assert ceildiv(6, 3) == 2
assert ceildiv(7, 3) == 3
assert ceildiv(5, 3) == 2
def brute_force(n, m):
numbers = set()
max_c = min(n, m // 49)
for c in range(max_c + 1):
_49c = 49 * c
max_b = min(n - c, (m - _49c) // 9, 48)
for b in range(max_b + 1):
_9b_49c = 9 * b + _49c
max_a = min(n - b - c, (m - _9b_49c) // 4, 8)
for a in range(max_a + 1):
numbers.add(4 * a + _9b_49c)
assert 0 in numbers
for x in (4, 9, 49):
if m // x <= n:
assert m - m % 49 in numbers
return len(numbers)
def brute_force_range(n, l, u):
numbers = set()
min_c = max(0, ceildiv(l - 9 * n, 40))
max_c = min(n, u // 49)
for c in range(min_c, max_c + 1):
_49c = 49 * c
min_b = max(0, ceildiv(l - 4 * n - 45 * c, 5))
max_b = min(n - c, (u - _49c) // 9, 48)
for b in range(min_b, max_b + 1):
_9b_49c = 9 * b + _49c
min_a = max(0, ceildiv(l - _9b_49c, 4))
max_a = min(n - b - c, (u - _9b_49c) // 4, 8)
for a in range(min_a, max_a + 1):
numbers.add(4 * a + _9b_49c)
if numbers:
assert min(numbers) >= l
assert max(numbers) <= u
return len(numbers)
def test_brute_force_range():
for u, l in ((60, 80), (104, 599), (200, 777)):
for n in (10, 13, 15, 17, 20):
assert brute_force_range(n, u, l) == brute_force(n, l) - brute_force(
n, u - 1
)
X = 12
Y = 24
def solid_interval(n):
assert n >= X
return Y, 49 * (n - X) + Y + 49
def test_solid_interval():
for n in (X, X + 1, 100, 200, 300, 1000, 5000):
begin, end = solid_interval(n)
assert brute_force_range(n, begin, end - 1) == end - begin
def main():
n = int(input())
if n < X:
result = brute_force(n, 49 * n)
else:
begin, end = solid_interval(n)
assert begin < end < 49 * n
result = sum(
(
brute_force_range(n, 0, begin - 1),
end - begin,
brute_force_range(n, end, 49 * n),
)
)
print(result)
main() | FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR FOR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR VAR RETURN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER FUNC_DEF FOR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = 0
i = 0
while i <= 8 and i <= n:
j = 0
while j <= (8 if i == 0 else 4) and j + i <= n:
ans += n - i - j + 1
j = j + 1
i = i + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = 0
kol = 0
ma = 0
if n > 20:
ma = (n - 10) * 50
mi = n - 10 + 10 * 50
ans = ma - mi + 1
kol = n - 20
n = 20
a = set()
for i in range(n + 1):
for j in range(n - i + 1):
for u in range(n - i - j + 1):
z = n - i - j - u
ch = i + j * 5 + u * 10 + z * 50 + kol * 50
if ch not in a and ch > ma:
ans += 1
a.add(ch)
if ma != 0:
for i in range(n + 1):
for j in range(n - i + 1):
for u in range(n - i - j + 1):
z = n - i - j - u
ch = i + j * 5 + u * 10 + z * 50 + kol
if ch not in a and ch < mi:
ans += 1
a.add(ch)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
ans = 0
precomp = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244]
if n <= 10:
print(precomp[n])
exit()
for i in range(9):
ans += n - i + 1
for i in range(1, 9):
for j in range(5):
ans += n - i - j + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | n = int(input())
add = [1, 5, 10, 50]
sumMap = {}
def dfs(k, s):
if k == 0:
t = 0
for x in s:
t += x
if not t in sumMap:
sumMap[t] = 1
return
for x in add:
if len(s) > 0 and x >= s[-1]:
dfs(k - 1, s + [x])
elif len(s) == 0:
dfs(k - 1, s + [x])
if n < 12:
dfs(n, [])
print(len(sumMap))
else:
dfs(12, [])
base = len(sumMap)
print(base + (n - 12) * 49) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER RETURN FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to $35$ and the number IXIΒ β to $12$.
Pay attention to the difference to the traditional roman systemΒ β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $11$, not $9$.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $n$ roman digits I, V, X, L.
-----Input-----
The only line of the input file contains a single integer $n$ ($1 \le n \le 10^9$)Β β the number of roman digits to use.
-----Output-----
Output a single integerΒ β the number of distinct integers which can be represented using $n$ roman digits exactly.
-----Examples-----
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
-----Note-----
In the first sample there are exactly $4$ integers which can be representedΒ β I, V, X and L.
In the second sample it is possible to represent integers $2$ (II), $6$ (VI), $10$ (VV), $11$ (XI), $15$ (XV), $20$ (XX), $51$ (IL), $55$ (VL), $60$ (XL) and $100$ (LL). | from sys import stdin, stdout
def count(n):
d = {}
cnt = 0
cur = 0
for i in range(n + 1):
for j in range(n - i + 1):
for z in range(n - j - i + 1):
v = i * 1 + j * 5 + z * 10 + (n - i - j - z) * 50
if not v in d:
d[v] = 1
cur += 1
else:
d[v] += 1
return cur
n = int(stdin.readline())
if n >= 20:
upp = count(20) + 49 * (n - 20)
else:
upp = count(n)
print(upp) | FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | ans = [1, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341, 390, 439]
n = int(input())
if n < 12:
print(ans[n])
else:
print(292 + (n - 11) * 49) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER |
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | a = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]
n = int(input())
if n < len(a):
print(a[n])
else:
print(a[11] + 49 * (n - 11)) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
s1 = s.find("AB")
while s1 != -1:
if s[:s1].find("BA") != -1 or s[s1 + 2 :].find("BA") != -1:
print("YES")
exit()
s1 = s.find("AB", s1 + 1)
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR NUMBER IF FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
abEarly = 0
baEarly = 0
aSeen = False
bSeen = False
done = False
for i in range(len(s)):
if baEarly > 0:
baEarly += 1
if abEarly > 0:
abEarly += 1
next = s[i]
if next == "A":
if bSeen:
baEarly += 1
if abEarly > 2:
done = True
aSeen = True
bSeen = False
elif next == "B":
if aSeen:
abEarly += 1
if baEarly > 2:
done = True
bSeen = True
aSeen = False
else:
aSeen = False
bSeen = False
if done:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a = s.find("AB")
b = s.rfind("AB")
c = s.find("BA")
d = s.rfind("BA")
print("YNEOS"[not ((abs(a - d) > 1 or abs(b - c) > 1) and min(a, b, c, d) >= 0) :: 2]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
fi = s.find("AB")
se = s.find("BA")
ab = s.count("AB")
ba = s.count("BA")
if fi == -1 or se == -1:
print("NO")
elif (
(s.count("ABAB") == 1 or s.count("BABA") == 1)
and s.count("A") == 2
and s.count("B") == 2
):
print("NO")
elif ab == 1 and ba == 1:
if max(fi, se) - min(fi, se) > 1:
print("YES")
else:
print("NO")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
l = len(s)
a = 0
b = 0
for i in range(l - 1):
if s[i] == "A" and s[i + 1] == "B":
a += 1
if s[i] == "B" and s[i + 1] == "A":
b += 1
r = "YES"
if a * b == 0:
r = "NO"
if a == b == 1:
if "ABA" in s or "BAB" in s:
r = "NO"
if a == 1 and b == 2 or a == 2 and b == 1:
if "ABAB" in s or "BABA" in s:
r = "NO"
print(r) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
n = len(s)
if n == 1 or n == 2 or n == 3:
print("NO")
else:
cnt1 = 0
cnt2 = 0
i = 0
ind1 = []
ind2 = []
while i < n - 1:
if s[i] == "A" and s[i + 1] == "B":
cnt1 += 1
ind1.append(i)
i += 1
i += 1
i = 0
while i < n - 1:
if s[i] == "B" and s[i + 1] == "A":
cnt2 += 1
ind2.append(i)
i += 1
i += 1
if cnt1 * cnt2 > 0:
f = 0
for i in range(len(ind1)):
for j in range(len(ind2)):
if abs(ind1[i] - ind2[j]) > 1:
f = 1
break
if f == 1:
break
if f == 1:
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s1 = input().strip()
AB = []
BA = []
for i in range(len(s1) - 1):
if s1[i] == "A" and s1[i + 1] == "B":
AB.append(i)
elif s1[i] == "B" and s1[i + 1] == "A":
BA.append(i)
x = True
for i in AB:
for j in BA:
if abs(i - j) > 1:
print("YES")
x = False
break
if not x:
break
if x:
print("NO") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | def two_substring(string):
AB = []
BA = []
for i in range(len(string)):
if string[i] == "A" and i < len(string) - 1:
if string[i + 1] == "B":
AB.append([i, i + 1])
elif string[i] == "B" and i < len(string) - 1:
if string[i + 1] == "A":
BA.append([i, i + 1])
if len(AB) == 0 or len(BA) == 0:
return "no"
for i in range(len(AB)):
for j in range(len(BA)):
if AB[i][0] == BA[j][1] or AB[i][1] == BA[j][0]:
continue
else:
return "yes"
return "no"
string = input().strip()
print(two_substring(string)) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a, a1, b, b1 = s.count("AB"), s.count("BA"), s.count("ABA"), s.count("BAB")
if a > 0 and a1 > 0 and a + a1 - (b + b1) >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
fi = s.find("AB")
sc = s.rfind("BA")
if fi == -1 or sc == -1:
print("NO")
exit(0)
if sc >= fi + 2:
print("YES")
else:
fi = s.rfind("AB")
sc = s.find("BA")
if fi >= sc + 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
x = s.count("AB")
y = s.count("BA")
if x > 1:
if y > 1:
print("YES")
elif y == 1:
s = s.replace("BA", " ")
if s.count("AB"):
print("YES")
else:
print("NO")
else:
print("NO")
elif x == 1:
s = s.replace("AB", " ")
if s.count("BA"):
print("YES")
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
n = len(s)
cnt1 = [0] * (n - 1)
cnt2 = [0] * (n - 1)
stat = 0
if s[0:2] == "AB":
cnt1[0] = 1
elif s[0:2] == "BA":
cnt2[0] = 1
for i in range(1, n - 1):
if s[i : i + 2] == "BA":
cnt2[i] = cnt2[i - 1] + 1
if i >= 2 and cnt1[i - 2] > 0:
stat = 1
print("YES")
break
else:
cnt2[i] = cnt2[i - 1]
if s[i : i + 2] == "AB":
cnt1[i] = cnt1[i - 1] + 1
if i >= 2 and cnt2[i - 2] > 0:
stat = 1
print("YES")
break
else:
cnt1[i] = cnt1[i - 1]
if stat == 0:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | string1 = input()
ab = string1.count("ABA")
string = string1.replace("ABA", "h")
ab += string.count("BAB")
string = string.replace("BAB", "h")
a = string.count("AB")
b = string.count("BA")
if ab > 0 and ab + a + b > 1 or a > 0 and b > 0 or "BABAB" in string1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | data = input()
abs = []
bas = []
for i in range(len(data) - 1):
if data[i : i + 2] == "AB":
abs.append(i)
elif data[i : i + 2] == "BA":
bas.append(i)
def is_valid(l1, l2):
for i in l1:
for j in l2:
if j > i + 1:
return True
return False
print("YES" if is_valid(abs, bas) or is_valid(bas, abs) else "NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR STRING STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | st = input().strip()
cab = st.count("AB")
cba = st.count("BA")
if cab == 0 or cba == 0:
print("NO")
else:
found = False
idx = None
for i in range(cab):
if idx == None:
idx = st.find("AB")
else:
idx = idx + 1 + st[idx + 1 :].find("AB")
try:
if max(st[0:idx].count("BA"), st[idx + 2 :].count("BA")) > 0:
found = True
break
except:
pass
if found:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | string = input()
found = 0
ab = string.find("AB")
if ab != -1:
if string[ab + 2 :].find("BA") != -1:
found = 1
ba = string.find("BA")
if ba != -1:
if string[ba + 2 :].find("AB") != -1:
found = 1
if found == 1:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a = s.find("AB")
b = s.rfind("AB")
c = s.find("BA")
d = s.rfind("BA")
e = min(a, b, c, d)
if (abs(a - d) > 1 or abs(b - c) > 1) and e >= 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | s = input()
a = s.count("AB")
b = s.count("BA")
t = s.count("ABA")
u = s.count("BAB")
s = a + b - t - u
if s >= 2 and a > 0 and b > 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | t = 1
for __ in range(t):
s = input()
s1 = "AB"
s2 = "BA"
f, se = 0, 0
n = len(s)
i = 0
while i < n - 1:
if f == 1:
if s2 == s[i : i + 2]:
se = 1
i += 1
if s1 == s[i : i + 2] and f == 0:
f = 1
i += 1
i += 1
if f == 1 and se == 1:
print("YES")
else:
f, se = 0, 0
i = 0
i = 0
while i < n - 1:
if se == 1:
if s1 == s[i : i + 2]:
f = 1
i += 1
if s2 == s[i : i + 2] and se == 0:
se = 1
i += 1
i += 1
if f == se == 1:
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.