description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
def f(s) -> int:
while s != "" and s[0] == s[-1]:
s = s[1:-1]
while s != "" and s[0] == s[1]:
s = s[2:]
if s == "":
return 1
else:
return 0
n = int(input())
ans = ["Alice", "Draw"]
for _ in range(0, n):
s = input()
print(ans[f(s)])
|
FUNC_DEF WHILE VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING RETURN NUMBER RETURN NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
t = int(input())
for i in range(t):
s = input()
while s and s[-1] == s[0]:
s = s[1:-1]
d = 1
for j in range(len(s) // 2):
if s[j * 2] != s[j * 2 + 1]:
d = 0
if d:
print("Draw")
else:
print("Alice")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
def codeforces(s):
n = len(s)
dp = [(0) for i in range(n - 1)]
for i in range(n - 1):
if s[i] != s[i + 1]:
dp[i] = 1
x = n // 2
for i in range(2, x + 1):
tp = [(0) for i in range(n - 2 * i + 1)]
for ind in range(n - 2 * i + 1):
a = ind + 2 * (i - 1)
x = dp[ind + 1] or s[ind] < s[a + 1]
y = dp[ind] or s[a + 1] < s[a]
z = dp[ind + 2] or s[ind] < s[ind + 1]
p = dp[ind + 1] or s[a + 1] < s[ind]
tp[ind] = x and z or y and p
dp = tp
return dp[0]
t = int(input())
for test in range(t):
s = input()
if codeforces(s):
print("Alice")
else:
print("Draw")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
def solution(string):
n = len(string)
left, right = 0, n - 1
while left < right and string[left] == string[right]:
left += 1
right -= 1
flag = False
for i in range(left, right + 1, 2):
if string[i] != string[i + 1]:
flag = True
break
if flag:
print("Alice")
else:
print("Draw")
t = int(input())
for _ in range(t):
string = input()
solution(string)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
import sys
sys.setrecursionlimit(6100)
test = int(input())
def solve(i, j, last, turn):
ans = False
if i > j:
return True
if (i, j, last, turn) in dp:
return dp[i, j, last, turn]
if turn == 0:
a = solve(i + 1, j, s[i], turn ^ 1)
b = solve(i, j - 1, s[j], turn ^ 1)
if a and b:
ans = True
else:
if s[i] == last:
ans |= solve(i + 1, j, s[i], turn ^ 1)
if s[j] == last:
ans |= solve(i, j - 1, s[j], turn ^ 1)
dp[i, j, last, turn] = ans
return ans
while test:
test -= 1
s = input()
pal = True
i, j = 0, len(s) - 1
while i <= j:
if s[i] != s[j]:
pal = False
break
i += 1
j -= 1
if pal:
print("Draw")
continue
dp = {}
if solve(0, len(s) - 1, "", 0):
print("Draw")
else:
print("Alice")
|
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT IF FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
N = int(input())
for _ in range(N):
S = input()
ans = "Draw"
f = 0
while len(S) != 0 and S[0] == S[-1]:
S = S[1:-1]
for i in range(len(S) // 2):
if ord(S[2 * i]) != ord(S[2 * i + 1]):
ans = "Alice"
print(ans)
f = 1
break
if f == 0:
print("Draw")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
import sys
rd = sys.stdin.readline
for _ in range(int(rd())):
s = rd().strip()
while s and s[-1] == s[0]:
s = s[1:-1]
m = 1
for i in range(0, len(s) - 1, 2):
m *= s[i] == s[i + 1]
if not m:
print("Alice")
else:
print("Draw")
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
def get_lst_pos(beg, ed, lst_pos):
if lst_pos == 0:
return beg - 1
else:
return ed + 1
def solve():
s = list(input().strip())
n = len(s)
dp = [[(0) for j in range(n)] for i in range(n)]
for i in range(n - 1):
if s[i] != s[i + 1]:
dp[i][i + 1] = 1
for s_len in range(4, n + 1, 2):
for beg in range(0, n - 3):
ed = beg + s_len - 1
if ed >= n:
break
if dp[beg + 1][ed - 1] == 1 and (
dp[beg + 2][ed] == 1
or dp[beg + 2][ed] == 0
and ord(s[beg]) < ord(s[beg + 1])
):
dp[beg][ed] = 1
elif dp[beg + 1][ed - 1] == 1 and (
dp[beg][ed - 2] == 1
or dp[beg][ed - 2] == 0
and ord(s[ed]) < ord(s[ed - 1])
):
dp[beg][ed] = 1
elif dp[beg + 1][ed - 1] == 0 and s[beg] != s[ed]:
dp[beg][ed] = 1
else:
dp[beg][ed] = 0
print("Alice" if dp[0][n - 1] == 1 else "Draw")
t = int(input().strip())
for _ in range(t):
solve()
|
FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
for _ in range(int(input())):
s = input().strip()
ans = "Draw"
while len(s) != 0 and s[0] == s[-1]:
s = s[1:-1]
for i in range(len(s) // 2):
if s[2 * i] != s[2 * i + 1]:
ans = "Alice"
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
Alice and Bob are playing a game. Initially, they are given a non-empty string $s$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.
Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $s$, removes it from $s$ and prepends (adds to the beginning) it to their own string.
The game ends when the string $s$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.
A string $a$ is lexicographically smaller than a string $b$ if there exists such position $i$ that $a_j = b_j$ for all $j < i$ and $a_i < b_i$.
What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Each testcase consists of a single line — a non-empty string $s$, consisting of lowercase Latin letters. The length of the string $s$ is even.
The total length of the strings over all testcases doesn't exceed $2000$.
-----Output-----
For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".
-----Examples-----
Input
2
forces
abba
Output
Alice
Draw
-----Note-----
One of the possible games Alice and Bob can play in the first testcase:
Alice picks the first letter in $s$: $s=$"orces", $a=$"f", $b=$"";
Bob picks the last letter in $s$: $s=$"orce", $a=$"f", $b=$"s";
Alice picks the last letter in $s$: $s=$"orc", $a=$"ef", $b=$"s";
Bob picks the first letter in $s$: $s=$"rc", $a=$"ef", $b=$"os";
Alice picks the last letter in $s$: $s=$"r", $a=$"cef", $b=$"os";
Bob picks the remaining letter in $s$: $s=$"", $a=$"cef", $b=$"ros".
Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.
|
def solve(s):
while len(s) and s[0] == s[-1]:
s = s[1 : len(s) - 1]
for i in range(len(s) // 2):
if s[2 * i] != s[2 * i + 1]:
return "Alice"
return "Draw"
t = int(input())
for _ in range(t):
s = input()
print(solve(s))
|
FUNC_DEF WHILE FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
import sys
input = sys.stdin.readline
a, b = map(int, input().split())
z = list(map(int, input().split()))
ans = [0]
for i in range(1, len(z)):
if z[i] > z[i - 1]:
ans.append(1)
elif z[i] < z[i - 1]:
ans.append(2)
else:
ans.append(0)
start = [(0) for i in range(len(ans))]
for i in range(len(ans) - 1, -1, -1):
if ans[i] == 2:
start[i] = i
elif i == len(ans) - 1:
start[i] = -1
else:
start[i] = start[i + 1]
end = [(0) for i in range(len(ans))]
for i in range(len(ans)):
if ans[i] == 1:
end[i] = i
elif i == 0:
end[i] = -1
else:
end[i] = end[i - 1]
for i in range(b):
l, r = map(int, input().split())
if l == len(z):
print("Yes")
continue
if start[l] == -1 or end[r - 1] == -1:
print("Yes")
elif start[l] > end[r - 1]:
print("Yes")
else:
print("No")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
import sys
n, m = map(int, sys.stdin.readline().split())
L = list(map(int, sys.stdin.readline().split()))
R = [0] * n
K = [0] * n
p = 0
for i in range(1, n):
if L[i] < L[i - 1]:
for j in range(p, i):
R[j] = i
p = i
for j in range(p, n):
R[j] = n
p = 0
for i in range(1, n):
if L[i] > L[i - 1]:
for j in range(p, i):
K[j] = i
p = i
for j in range(p, n):
K[j] = n
for i in range(m):
x, y = map(int, sys.stdin.readline().split())
x -= 1
y -= 1
r = R[x]
if r >= y:
sys.stdout.write("Yes\n")
continue
e = K[r]
if e > y:
sys.stdout.write("Yes\n")
continue
sys.stdout.write("No\n")
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
n, m = list(map(int, input().split()))
l = list(map(int, input().split()))
l1 = [0] * n
l3 = [0] * n
f = False
v = 0
for i in range(1, n):
if l[i] < l[i - 1]:
f = True
v = i
if l[i] > l[i - 1] and f:
f = False
for j in range(i - 1, v - 1, -1):
l3[j] = j
l1[v] = 1
v = -1
l2 = [0] * n
for i in range(1, n):
l2[i] = l1[i] + l2[i - 1]
s = []
for i in range(m):
a, b = list(map(int, input().split()))
t = l2[b - 1] - l2[a - 1]
if l3[b - 1] >= b - 1:
t -= 1
if t > 0:
s.append("No")
else:
s.append("Yes")
print("\n".join(s))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
from sys import stdin
input = stdin.readline
[n, q] = [int(item) for item in input().split(" ")]
arr = [int(item) for item in input().split(" ")]
queries = [[int(item) for item in input().split(" ")] for i in range(q)]
b = [1]
for i in range(1, n):
b.append(b[-1] + 1 if arr[i] <= arr[i - 1] else 1)
c = [1]
for i in reversed(range(n - 1)):
c.append(c[-1] + 1 if arr[i] <= arr[i + 1] else 1)
c = [item for item in reversed(c)]
for query in queries:
x, y = query
x -= 1
y -= 1
print("Yes" if x + c[x] > y or y - b[y] < x or x + c[x] > y - b[y] else "No")
|
ASSIGN VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR STRING STRING
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
import sys
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def input():
return sys.stdin.readline().strip()
n, m = get_ints()
Arr = get_array()
up = [i for i in range(n)]
down = [i for i in range(n)]
for i in range(1, n):
if Arr[i - 1] <= Arr[i]:
up[i] = up[i - 1]
if Arr[i - 1] >= Arr[i]:
down[i] = down[i - 1]
while m:
l, r = get_ints()
if l - 1 >= up[down[r - 1]]:
print("Yes")
else:
print("No")
m -= 1
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
n, m = map(int, input().split())
(*a,) = map(int, input().split())
inc = [*range(n)]
dec = [*range(n)]
for i in range(n - 1, 0, -1):
if a[i] >= a[i - 1]:
inc[i - 1] = inc[i]
if a[i] <= a[i - 1]:
dec[i - 1] = dec[i]
k = ["No"] * m
l = 0
for i, j in (map(lambda i: int(i) - 1, input().split()) for _ in " " * m):
if dec[inc[i]] >= j:
k[l] = "Yes"
l += 1
print("\n".join(k))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR BIN_OP STRING VAR IF VAR VAR VAR VAR ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
from sys import stdin, stdout
def main():
from sys import stdin, stdout
n, m = map(int, stdin.readline().strip().split(" "))
a = [0] + list(map(int, stdin.readline().strip().split(" ")))
r = [0] * (n + 1)
l = [0] * (n + 1)
l[1] = 1
r[n] = n
for i in range(2, n + 1):
if a[i - 1] >= a[i]:
l[i] = l[i - 1]
else:
l[i] = i
for i in range(n - 1, 0, -1):
if a[i + 1] >= a[i]:
r[i] = r[i + 1]
else:
r[i] = i
for i in range(m):
a, b = map(int, stdin.readline().strip().split(" "))
if r[a] >= l[b]:
stdout.write("Yes\n")
else:
stdout.write("No\n")
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
n, m = list(map(int, input().split()))
arr = list(map(int, input().split()))
up = [i for i in range(n)]
down = [i for i in range(n)]
for i in range(1, n):
if arr[i - 1] <= arr[i]:
up[i] = up[i - 1]
if arr[i - 1] >= arr[i]:
down[i] = down[i - 1]
all_res = []
seg = list(tuple(list(map(int, input().split())) for _ in range(m)))
for l, r in seg:
if l - 1 >= up[down[r - 1]]:
all_res.append("Yes")
else:
all_res.append("No")
print("\n".join(all_res))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
M = lambda: map(int, input().split())
L = lambda: list(map(int, input().split()))
I = lambda: int(input())
n, k = M()
t = [0] + L()
a, b = list(range(n + 1)), list(range(n + 1))
for i in range(n, 1, -1):
if t[i] >= t[i - 1]:
a[i - 1] = a[i]
if t[i] <= t[i - 1]:
b[i - 1] = b[i]
p = ["No"] * k
for i in range(k):
x, y = M()
if b[a[x]] >= y:
p[i] = "Yes"
print("\n".join(p))
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
n, q = map(int, input().split())
arr = [int(x) for x in input().split()]
inc = [-1] * n
dec = [-1] * n
inc[n - 1] = n - 1
for i in range(n - 2, -1, -1):
if arr[i] <= arr[i + 1]:
inc[i] = inc[i + 1]
else:
inc[i] = i
dec[n - 1] = n - 1
for i in range(n - 2, -1, -1):
if arr[i] >= arr[i + 1]:
dec[i] = dec[i + 1]
else:
dec[i] = i
for i in range(q):
l, r = map(int, input().split())
if dec[inc[l - 1]] >= r - 1:
print("Yes")
else:
print("No")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
[n, q] = list(map(int, input().split()))
arr = list(map(int, input().split()))
interval = [idx for idx in range(n)]
l, r = 0, 1
while l <= r and r < n:
while r < n and arr[r] >= arr[r - 1]:
r += 1
last = r
while r < n and arr[r] <= arr[r - 1]:
if arr[r] != arr[last]:
last = r
r += 1
for idx in range(l, r):
interval[idx] = max(interval[idx], r - 1)
l = last
ans = []
for _ in range(q):
[l, r] = list(map(int, input().split()))
if interval[l - 1] >= r - 1:
ans.append("Yes")
else:
ans.append("No")
for x in ans:
print(x)
|
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
from sys import stdin, stdout
n, m = map(int, stdin.readline().strip().split())
dp = [(1) for i in range(n + 1)]
ap = [(1) for i in range(n + 1)]
def solve(ar):
for i in range(n - 1, 0, -1):
if ar[i] <= ar[i + 1]:
dp[i] = dp[i + 1] + 1
for i in range(1, n + 1):
if ar[i - 1] >= ar[i]:
ap[i] = ap[i - 1] + 1
ar = list(map(int, stdin.readline().strip().split()))
ar.insert(0, 0)
solve(ar)
for i in range(m):
l, r = map(int, stdin.readline().strip().split())
x = ap[r] + dp[l] - 1
if x >= r - l + 1:
stdout.write("Yes\n")
else:
stdout.write("No\n")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
import sys
n, m = list(map(int, sys.stdin.readline().split()))
M = [m]
A = list(map(int, sys.stdin.readline().split()))
L = [0] * n
inc = False
dec = False
def ALLYes():
Ans = ""
for i in range(M[0]):
Ans += "Yes\n"
sys.stdout.write(Ans)
return
for i in range(1, n):
if A[i] > A[i - 1]:
L[i] = 1
inc = True
elif A[i] == A[i - 1]:
L[i] = 0
else:
L[i] = -1
dec = True
if inc == False or dec == False:
ALLYes()
else:
neg = L.index(-1)
pos = L.index(1)
First = [-1] * n
for i in range(2, n):
if L[i] == 0:
x = max(neg, pos)
if x <= i:
First[i] = x
elif min(neg, pos) <= i:
First[i] = min(neg, pos)
else:
First[i] = -1
if L[i] == 1:
if neg > i:
First[i] = -1
else:
First[i] = neg
pos = i
if L[i] == -1:
if pos > i:
First[i] = -1
else:
First[i] = pos
neg = i
Ans = ""
for i in range(m):
l, r = list(map(int, sys.stdin.readline().split()))
r -= 1
if r - l < 1:
Ans += "Yes\n"
continue
if L[r] == 0:
r = First[r]
if r < 1:
Ans += "Yes\n"
continue
if L[r] == 1:
r = First[r]
if r < l:
Ans += "Yes\n"
continue
else:
Ans += "No\n"
continue
elif L[r] == -1:
r = First[r]
if r < l:
Ans += "Yes\n"
continue
r = First[r]
if r < l:
Ans += "Yes\n"
continue
else:
Ans += "No\n"
continue
sys.stdout.write(Ans)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR STRING VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
values, increase, decrease = (
[int(i) for i in input().split()],
[(0) for _ in range(n)],
[(0) for _ in range(n)],
)
for i in range(n - 2, -1, -1):
if values[i] <= values[i + 1]:
increase[i] = increase[i + 1] + 1
else:
increase[i] = 0
if values[i] >= values[i + 1]:
decrease[i] = decrease[i + 1] + 1
else:
decrease[i] = 0
for i in range(m):
a, b = map(int, input().split())
a, b = a - 1, b - 1
if (
a + increase[a] >= b
or a + decrease[a] >= b
or a + increase[a] + decrease[a + increase[a]] >= b
):
print("Yes")
else:
print("No")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{l}_{i}, a_{l}_{i} + 1, a_{l}_{i} + 2, ..., a_{r}_{i}. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers b_1, b_2, ..., b_{k}, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b_1 ≤ b_2 ≤ ... ≤ b_{x} ≥ b_{x} + 1 ≥ b_{x} + 2... ≥ b_{k}. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of array elements and the number of queries. The second line contains the sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where number a_{i} stands for the i-th array element.
The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
-----Output-----
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
-----Examples-----
Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Output
Yes
Yes
No
Yes
No
Yes
|
import sys
def get_ints():
return list(map(int, sys.stdin.readline().strip().split()))
n, m = get_ints()
a = get_ints()
d1 = [0] * n
d2 = [0] * n
for i in range(1, n - 1):
if a[i] < a[i - 1] and a[i] < a[i + 1]:
d1[i] = 1
elif a[i] < a[i - 1] and a[i] == a[i + 1]:
d2[i] = 1
elif a[i] == a[i - 1] and a[i + 1] > a[i]:
d2[i] = 1
for i in range(1, n):
d1[i] = d1[i - 1] + d1[i]
d2[i] = d2[i] + d2[i - 1]
d1 = [0] + d1
d2 = [0] + d2
for i in range(m):
l, r = get_ints()
if d1[r - 1] - d1[l] > 0 or d2[r - 1] - d2[l] > 1:
print("No")
else:
print("Yes")
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
b.append(abs(a[i] - a[i + 1]))
mx = -float("inf")
now = 0
for i in range(n - 1):
now += b[i] * (-1) ** (i % 2)
mx = max(mx, now)
if now < 0:
now = 0
now = 0
for i in range(1, n - 1):
now += b[i] * (-1) ** (i % 2 + 1)
mx = max(mx, now)
if now < 0:
now = 0
print(mx)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def max_subarray(numbers, k):
best_sum = 0
current_sum = 0
for x in range(len(numbers)):
if k % 2 == k:
current_sum = max(0, current_sum + numbers[x])
else:
current_sum = current_sum + numbers[x]
best_sum = max(best_sum, current_sum)
return best_sum
n = int(input())
l = list(map(int, input().split()))
l1 = []
l2 = []
s = 1
for i in range(n - 1):
l1.append(abs(l[i] - l[i + 1]) * s)
l2.append(abs(l[i] - l[i + 1]) * (-1 * s))
s = s * -1
print(max(max_subarray(l1, 0), max_subarray(l2, 1)))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR 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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
first = [
(-abs(a[i] - a[i - 1]) if (i + 1) % 2 else abs(a[i] - a[i - 1]))
for i in range(1, n)
]
second = [
(abs(a[i] - a[i - 1]) if (i + 1) % 2 else -abs(a[i] - a[i - 1]))
for i in range(2, n)
]
mx = -(10**18)
cur = 0
for i in range(len(first)):
cur = first[i] + max(cur, 0)
if i % 2 == 0:
mx = max(mx, cur)
cur = 0
for i in range(len(second)):
cur = second[i] + max(cur, 0)
if i % 2 == 0:
mx = max(mx, cur)
print(mx)
|
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 BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
arr = list(map(int, input().split()))
ls = [(abs(arr[i + 1] - arr[i]) * (-1) ** (i % 2)) for i in range(n - 1)]
ls1 = [(abs(arr[i + 1] - arr[i]) * (-1) ** (1 - i % 2)) for i in range(n - 1)]
su = 0
s = 0
for i in ls:
su += i
if su < 0:
su = 0
else:
s = max(s, su)
su = 0
for j in ls1:
su += j
if su < 0:
su = 0
else:
s = max(su, s)
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def solve():
n = int(input())
a = tuple(map(int, input().split()))
d = []
for i in range(0, n - 1):
d.append(abs(a[i] - a[i + 1]))
subtracted = [(0) for i in range(n - 1)]
added = [(0) for i in range(n - 1)]
if n == 2:
print(d[0])
else:
added[0] = d[0]
added[1] = d[1]
subtracted[1] = added[0] - d[1]
for i in range(2, n - 1):
added[i] = max(d[i], subtracted[i - 1] + d[i])
subtracted[i] = added[i - 1] - d[i]
res = 0
for i in range(n - 1):
res = max(res, max(added[i], subtracted[i]))
print(res)
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
from sys import stdin, stdout
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().strip().split(" ")))
tarr1 = [abs(arr[1] - arr[0])]
tarr2 = []
for i in range(2, n):
tarr1.append(pow(-1, i - 1) * abs(arr[i] - arr[i - 1]))
tarr2.append(-1 * tarr1[-1])
ans = tarr1[0]
tans = tarr1[0]
for i in tarr1[1:]:
if tans < 0:
tans = i
else:
tans += i
ans = max(tans, ans)
if len(tarr2) > 0:
tans = tarr2[0]
ans = max(ans, tans)
for i in tarr2[1:]:
if tans < 0:
tans = i
else:
tans += i
ans = max(tans, ans)
stdout.write(str(ans) + "\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def max_subarray(A):
max_ending_here = max_so_far = A[0]
for x in A[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
n = int(input())
a = [int(v) for v in input().split()]
b = [(abs(a[i] - a[i + 1]) * (-1) ** i) for i in range(n - 1)]
print(max(max_subarray(b), max_subarray([(-v) for v in b])))
|
FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
d1 = []
d2 = []
for i in range(n - 1):
if i % 2 == 0:
d1.append(abs(a[i] - a[i + 1]))
d2.append(-1 * abs(a[i] - a[i + 1]))
else:
d1.append(-1 * abs(a[i] - a[i + 1]))
d2.append(abs(a[i] - a[i + 1]))
s1 = [(0) for i in range(n)]
s2 = [(0) for i in range(n)]
s1[0] = d1[0]
s2[0] = d2[0]
ans = max(s1[0], s2[0])
for i in range(1, n - 1):
s1[i] = max(d1[i], d1[i] + s1[i - 1])
s2[i] = max(d2[i], d2[i] + s2[i - 1])
ans = max(s1[i], s2[i], ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input().strip("\n"))
si = lambda: input().strip("\n")
dgl = lambda: list(map(int, input().strip("\n")))
f = lambda: map(int, input().strip("\n").split())
il = lambda: list(map(int, input().strip("\n").split()))
ls = lambda: list(input().strip("\n"))
lsi = lambda: [int(i) for i in ls()]
let = "abcdefghijklmnopqrstuvwxyz"
def kadaneneg(arr, n):
mx = -(10**16)
mxend = 0
for i in range(n):
mxend += arr[i]
if mxend > mx:
mx = mxend
if mxend < 0:
mxend = 0
return mx
for _ in range(1):
n = ii()
l = il()
for i in range(n - 1):
if i & 1:
l[i] = -1 * abs(l[i] - l[i + 1])
else:
l[i] = abs(l[i] - l[i + 1])
l = l[: n - 1]
l2 = [(-1 * i) for i in l]
mx1 = kadaneneg(l[: n - 1], n - 1)
mx2 = kadaneneg(l2[: n - 1], n - 1)
print(max(mx1, mx2))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = [abs(a[i] - a[i + 1]) for i in range(n - 1)]
p, q, r = 0, 0, 0
for i in b:
_p = max(0, q + i)
_q = max(0, p - i)
p, q = _p, _q
r = max(p, q, r)
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = input().split()
arr = [(abs(int(a[i]) - int(a[i + 1])) * (-1) ** i) for i in range(n - 1)]
maximum = 0
summ = 0
for j in arr:
if j > 0 or abs(j) < abs(summ):
summ += j
else:
summ = 0
maximum = max(maximum, abs(summ))
summ = 0
for k in arr[1:]:
if k < 0 or abs(k) < abs(summ):
summ += k
else:
summ = 0
maximum = max(maximum, abs(summ))
print(maximum)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split(" ")))
def sign(n):
return [1, -1][n % 2]
b1 = [abs(a[i] - a[i - 1]) for i in range(1, len(a))]
b1 = [(sign(i) * b1[i]) for i in range(len(b1))]
b2 = [(-x) for x in b1]
max_ending_here = b1[0]
max_so_far = b1[0]
for i, x in enumerate(b1):
if i == 0:
continue
if i % 2 == 1:
max_ending_here += x
elif x > max_ending_here + x:
max_ending_here = x
else:
max_ending_here += x
max_so_far = max(max_so_far, max_ending_here)
b1 = b2
max_ending_here = b1[0]
max_so_far2 = b1[0]
for i, x in enumerate(b1):
if i == 0:
continue
if i % 2 == 0:
max_ending_here += x
elif x > max_ending_here + x:
max_ending_here = x
else:
max_ending_here += x
max_so_far2 = max(max_so_far2, max_ending_here)
print(max(max_so_far, max_so_far2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
arr = list(map(int, input().split()))
def function(n, arr):
dp = {}
for i in range(1, n):
temp, dp[i] = abs(arr[i] - arr[i - 1]), {}
if i == 1:
dp[i][0], dp[i][1] = temp, 0
else:
dp[i][0] = max(dp[i - 1][1], 0) + temp
dp[i][1] = dp[i - 1][0] - temp
Max = dp[1][0]
for i in range(2, n):
Max = max(Max, dp[i][0], dp[i][1])
return Max
print(function(n, arr))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER DICT IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = [int(i) for i in input().split()]
b = [abs(a[i] - a[i - 1]) for i in range(1, len(a))]
sm = [([0] * 2) for i in range(n)]
mn = [([0] * 2) for i in range(n + 1)]
ans = -1000000
for i in range(n - 2, -1, -1):
if i % 2 == 0:
sm[i][0] = b[i] + sm[i + 1][0]
sm[i][1] = -b[i] + sm[i + 1][1]
mn[i][1] = min(mn[i + 2][1], sm[i][1])
ans = max(ans, sm[i][0] - mn[i + 1][0])
else:
sm[i][1] = b[i] + sm[i + 1][1]
sm[i][0] = -b[i] + sm[i + 1][0]
mn[i][0] = min(mn[i + 2][0], sm[i][0])
ans = max(ans, sm[i][1] - mn[i + 1][1])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
c = [0] * n
for i in range(n - 1):
x = abs(a[i] - a[i + 1])
if i % 2 == 0:
b[i] = x
c[i] = -x
else:
b[i] = -x
c[i] = x
def maxSubArray(arr):
best = 0
current = 0
for x in arr:
current = max(0, current + x)
best = max(best, current)
return best
print(max(maxSubArray(c), maxSubArray(b)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
n = int(input())
a = list(map(int, input().split()))
d = []
for i in range(1, n):
d.append(abs(a[i] - a[i - 1]))
evencur = 0
sgn = 1
ans = 0
for i in range(len(d)):
evencur += d[i] * sgn
sgn *= -1
ans = max(evencur, ans)
if evencur < 0:
evencur = 0
sgn = 1
evencur = 0
sgn = 1
for i in range(1, len(d)):
evencur += d[i] * sgn
sgn *= -1
ans = max(evencur, ans)
if evencur < 0:
evencur = 0
sgn = 1
print(ans)
|
IMPORT 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 EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
dif = list()
for i in range(n - 1):
if i % 2 == 0:
dif.append(int(abs(a[i] - a[i + 1])))
else:
dif.append(-1 * int(abs(a[i] - a[i + 1])))
pref = list()
for i in range(len(dif)):
if i == 0:
pref.append(dif[0])
else:
pref.append(pref[i - 1] + dif[i])
mx = 0
mn = 0
mxidx = 0
mnidx = 0
for i in range(len(pref)):
if pref[i] > mx:
mx = pref[i]
mxidx = i
if pref[i] < mn:
mn = pref[i]
mnidx = i
print(mx - mn)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
(*a,) = map(int, input().split())
l = [abs(a[i] - a[i - 1]) for i in range(1, n)]
ans = 0
x = y = 0
for i in range(n - 1):
t = [l[i], -l[i]][i % 2]
x += t
y -= t
ans = max(ans, x, y)
x = max(x, 0)
y = max(y, 0)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
d = [[] for i in range(2)]
pre = a[0]
mi = 1
for i in range(1, n):
d[0].append(mi * abs(pre - a[i]))
d[1].append(-mi * abs(pre - a[i]))
pre = a[i]
mi *= -1
m = len(d[0])
L = [([0] * m) for i in range(2)]
R = [([0] * m) for i in range(2)]
L[0][0] = d[0][0]
L[1][0] = d[1][0]
R[0][0] = d[0][0]
R[1][0] = d[1][0]
for k in range(2):
for i in range(1, m):
if L[k][i - 1] >= R[k][i - 1]:
L[k][i] = L[k][i - 1]
else:
L[k][i] = R[k][i - 1]
if R[k][i - 1] + d[k][i] < d[k][i]:
R[k][i] = d[k][i]
else:
R[k][i] = R[k][i - 1] + d[k][i]
if L[0][-1] > R[0][-1]:
num1 = L[0][-1]
else:
num1 = R[0][-1]
if L[1][-1] > R[1][-1]:
num2 = L[1][-1]
else:
num2 = R[1][-1]
print(max(num1, num2))
|
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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = [int(i) for i in input().split()]
b = [abs(a[i] - a[i + 1]) for i in range(n - 1)]
n -= 1
def fn(i0):
f0 = 0
ans = 0
for i in range(i0, n):
if i - i0 & 1:
f0 -= b[i]
if f0 < 0:
f0 = 0
else:
f0 += b[i]
ans = max(ans, f0)
return ans
ans = max(fn(0), fn(1))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
l = list(map(int, input().split()))
arr = []
for i in range(n - 1):
if i % 2 == 0:
arr.append(abs(-l[i + 1] + l[i]))
else:
arr.append(-abs(-l[i + 1] + l[i]))
arr1 = []
for i in range(n - 1):
if i % 2 == 1:
arr1.append(abs(-l[i + 1] + l[i]))
else:
arr1.append(-abs(-l[i + 1] + l[i]))
pre1 = [arr[0]]
pre2 = [arr1[0]]
for i in range(1, len(arr)):
pre1.append(max(pre1[-1] + arr[i], arr[i]))
pre2.append(max(pre2[-1] + arr1[i], arr1[i]))
print(max(max(pre1), max(pre2)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
nums = input().split(" ")
sumas = [0] * (n + 1)
dp = [([0] * 2) for _ in range(n + 1)]
res = -100000000000.0
for x in range(0, n):
if x > 0:
sumas[x] = abs(int(nums[x]) - int(nums[x - 1]))
for x in range(1, n + 1):
dp[x][0] = max(sumas[x], dp[x - 1][1] + sumas[x])
dp[x][1] = max(-sumas[x], dp[x - 1][0] - sumas[x])
res = max(max(dp[x][0], dp[x][1]), res)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
b.append(abs(a[i] - a[i + 1]))
c = []
s = 1
summ = 0
for i in range(n - 1):
summ += s * b[i]
s = -s
c.append(summ)
c.sort()
if c[0] < 0:
print(c[n - 2] - c[0])
else:
print(c[n - 2])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
R = lambda: list(map(int, input().split()))
n = int(input())
a = R()
dif = [0] * (n - 1)
for i in range(n - 1):
dif[i] = abs(a[i] - a[i + 1]) * (1 - 2 * (i % 2))
sum = [0] * n
sum[0] = 0
for i in range(1, n):
sum[i] = sum[i - 1] + dif[i - 1]
ma = [0] * (n - 1)
mi = [0] * (n - 1)
for i in range(n - 2, -1, -1):
ma[i] = max(sum[i + 1], ma[i + 1] if i < n - 2 else sum[i + 1])
mi[i] = min(sum[i + 1], mi[i + 1] if i < n - 2 else sum[i + 1])
res = 0
for i in range(n - 1):
if i % 2 == 0:
res = max(res, ma[i] - sum[i])
else:
res = max(res, -(mi[i] - sum[i]))
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def maxSubArray(A):
if not A:
return 0
curSum = maxSum = A[0]
for num in A[1:]:
curSum = max(num, curSum + num)
maxSum = max(maxSum, curSum)
return maxSum
n = int(input())
L = list(map(int, input().split()))
D1 = []
D2 = []
for i in range(1, len(L)):
D1.append(abs(L[i] - L[i - 1]) * (-1) ** i)
D2.append(abs(L[i] - L[i - 1]) * (-1) ** (i + 1))
print(max(maxSubArray(D1), maxSubArray(D2)))
|
FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
from sys import stdin, stdout
def ri():
return map(int, input().split())
n = int(input())
a = list(ri())
b = [(abs(a[i] - a[i + 1]) * (-1) ** i) for i in range(n - 1)]
ans = 0
s = 0
i = 0
while i < n - 1:
s += b[i]
if s < 0:
s = 0
if i % 2 == 0:
i += 1
i += 1
ans = max(s, ans)
b = [(-b[i]) for i in range(n - 1)]
s = 0
i = 1
while i < n - 1:
s += b[i]
if s < 0:
s = 0
if i % 2 == 1:
i += 1
i += 1
ans = max(s, ans)
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
first = []
second = []
ans = float("-inf")
for i in range(n - 1):
first.append(abs(values[i] - values[i + 1]) * (-1) ** i)
second.append(abs(values[i] - values[i + 1]) * (-1) ** (i + 1))
cnt = 0
for i in range(n - 1):
cnt += first[i]
ans = max(ans, cnt)
if cnt < 0:
cnt = 0
cnt = 0
for i in range(n - 1):
cnt += second[i]
ans = max(ans, cnt)
if cnt < 0:
cnt = 0
stdout.write(str(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
arr = list(map(int, input().split()))
new = []
c = 1
for i in range(n - 1):
new.append(abs(arr[i] - arr[i + 1]) * c)
c *= -1
s = 0
s1 = 0
m = 0
for i in range(n - 1):
s += new[i]
if s < 0:
s = 0
if i > 0:
s1 += -new[i]
if s1 < 0:
s1 = 0
m = max(m, s1)
m = max(m, s)
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
input = sys.stdin.readline
n = int(input())
l = input().split()
li = [int(i) for i in l]
l = []
for i in range(1, n):
l.append(abs(li[i] - li[i - 1]) * pow(-1, i))
dp = [(0) for i in range(n - 1)]
dp[0] = l[0]
for i in range(1, n - 1):
dp[i] = max(l[i], l[i] + dp[i - 1])
maxa = 0
for i in dp:
maxa = max(maxa, i)
for i in range(n - 1):
l[i] = -l[i]
dp = [(0) for i in range(n - 1)]
dp[0] = l[0]
for i in range(1, n - 1):
dp[i] = max(l[i], l[i] + dp[i - 1])
for i in dp:
maxa = max(maxa, i)
print(maxa)
|
IMPORT ASSIGN VAR VAR 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 LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
arr = list(map(int, input().split()))
diff = [abs(arr[i] - arr[i + 1]) for i in range(n - 1)]
dp = [[0, 0, 0] for _ in range(n - 1)]
dp[0][1] = diff[0]
for i in range(1, n - 1):
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2])
dp[i][1] = max(dp[i - 1][2] + diff[i], diff[i])
dp[i][2] = dp[i - 1][1] - diff[i]
print(max(dp[n - 2][0], dp[n - 2][1], dp[n - 2][2]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def mp():
return map(int, input().split())
def lt():
return list(map(int, input().split()))
def pt(x):
print(x)
def ip():
return input()
def it():
return int(input())
def sl(x):
return [t for t in x]
def spl(x):
return x.split()
def aj(liste, item):
liste.append(item)
def bin(x):
return "{0:b}".format(x)
def listring(l):
return " ".join([str(x) for x in l])
def ptlist(l):
print(" ".join([str(x) for x in l]))
n = it()
a = lt()
L = [abs(a[i] - a[i + 1]) for i in range(n - 1)]
ans = [(0) for _ in range(n)]
ans[0] = L[0]
for i in range(1, n - 1):
ans[i] = max(L[i], L[i] - ans[i - 1])
if i - 2 >= 0:
ans[i] = max(ans[i], L[i] - L[i - 1] + ans[i - 2])
print(max(ans))
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
n = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
B = [abs(A[i] - A[i + 1]) for i in range(n - 1)]
C, m = [B[0]], -1
for i in range(1, n - 1):
C.append(C[i - 1] + m * B[i])
m *= -1
print(max(max(C), max(C) - min(C)))
|
IMPORT 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
aux = 0
minaux = 0
maxim = 0
results = []
for i in range(1, n):
results.append(abs(a[i - 1] - a[i]))
for i in range(0, n - 1):
if i % 2 == 1:
condition = -results[i]
else:
condition = results[i]
aux += condition
minaux -= condition
if aux > maxim:
maxim = aux
if condition > maxim:
maxim = condition
if minaux > maxim:
maxim = minaux
if minaux < 0:
minaux = 0
if aux < 0:
aux = 0
print(maxim)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def main():
n = int(input())
a = list(map(int, input().split()))
b = [abs(a[i] - a[i + 1]) for i in range(len(a) - 1)]
ansmx = [0] * len(b)
ansmn = [0] * len(b)
ansmx[-1] = b[-1]
ansmn[-1] = 0
for i in range(1, len(b)):
j = i - 1
ansmx[-1 - i] = b[-1 - i] - ansmn[-i]
ansmn[-1 - i] = min(b[-1 - i] - ansmx[-i], 0)
print(max(ansmx))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
inf = float("inf")
mod = 1000000007
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return list(map(int, sys.stdin.readline().split()))
def input():
return sys.stdin.readline()
def main():
n = int(input())
arr = get_array()
ans = 0
prefix_odd = [0] * n
for i in range(n - 1):
prefix_odd[i] = abs(arr[i + 1] - arr[i]) * pow(-1, i)
prefix_even = [0] * n
for i in range(n - 1):
prefix_even[i] = abs(arr[i + 1] - arr[i]) * pow(-1, i + 1)
curr_mx, mx = prefix_odd[0], prefix_odd[0]
for i in range(1, n):
curr_mx = max(prefix_odd[i], prefix_odd[i] + curr_mx)
mx = max(curr_mx, mx)
curr_mx = prefix_even[0]
for i in range(1, n):
curr_mx = max(prefix_even[i], prefix_even[i] + curr_mx)
mx = max(curr_mx, mx)
print(mx)
def __starting_point():
main()
__starting_point()
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = []
for i in range(n - 1):
if i % 2 == 0:
d.append(abs(a[i + 1] - a[i]))
else:
d.append(-abs(a[i + 1] - a[i]))
ans = -(10**18)
m = 0
acc = 0
for i in range(n - 1):
acc += d[i]
ans = max(ans, acc - m)
if i % 2 == 1:
m = min(m, acc)
d = list(map(lambda x: -x, d))
m = 0
acc = 0
for i in range(1, n - 1):
acc += d[i]
ans = max(ans, acc - m)
if i % 2 == 0:
m = min(m, acc)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def f(l, r, p):
if l > r:
return 0
return p[r] - p[l - 1] if l % 2 == 1 else -f(l - 1, r, p) + p[l - 1]
def main():
read = lambda: tuple(map(int, input().split()))
n = read()[0]
v = read()
p = [0]
pv = 0
for i in range(n - 1):
cp = abs(v[i] - v[i + 1]) * (-1) ** i
pv += cp
p += [pv]
mxc, mxn = 0, 0
mnc, mnn = 0, 0
for i in range(n):
cc, cn = f(1, i, p), f(2, i, p)
mxc, mxn = max(mxc, cc - mnc), max(mxn, cn - mnn)
mnc, mnn = min(mnc, cc), min(mnn, cn)
return max(mxc, mxn)
print(main())
|
FUNC_DEF IF VAR VAR RETURN NUMBER RETURN BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR LIST VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def f(a):
c, v, m = 0, 0, 1
for i in range(len(a) - 1):
x = m * abs(a[i] - a[i + 1])
c = max(c + x, x)
v = max(v, c)
m *= -1
return v
n, a = int(input()), list(map(int, input().split()))
print(max(f(a), f(a[1:])))
|
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def max_sum(a):
s, ans = 0, 0
for i in a:
s += i
ans = max(s, ans)
s = max(0, s)
return ans
n = int(input())
(*a,) = map(int, input().split())
a = [abs(a[i] - a[i + 1]) for i in range(n - 1)]
b = [(-1 * a[i] if i & 1 else a[i]) for i in range(n - 1)]
a = [(a[i] if i & 1 else -1 * a[i]) for i in range(n - 1)]
print(max(max_sum(a), max_sum(b)))
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
l = list(map(int, input().split()))
ma = 0
p1 = 0
p2 = 0
for i in range(n - 1):
if (i + 1) % 2 != 0:
p1 = p1 + abs(l[i] - l[i + 1])
p2 = p2 - abs(l[i] - l[i + 1])
if p2 < 0:
p2 = 0
ma = max(p1, ma)
else:
p2 = p2 + abs(l[i] - l[i + 1])
p1 = p1 - abs(l[i] - l[i + 1])
if p1 < 0:
p1 = 0
ma = max(p2, ma)
print(ma)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
num = list(map(int, input().split()))
diff = [abs(j - i) for i, j in zip(num, num[1:])]
s1 = 0
s2 = 0
m1 = 0
m2 = 0
for i, x in enumerate(diff):
if s1 < 0:
s1 = 0
if s2 < 0:
s2 = 0
if i % 2 == 0:
s1 += x
s2 -= x
else:
s1 -= x
s2 += x
if s1 > m1:
m1 = s1
if s2 > m2:
m2 = s2
print(max(m1, m2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def maxSubArraySum(a, size):
max_so_far = a[0]
curr_max = a[0]
for i in range(1, size):
curr_max = max(a[i], curr_max + a[i])
max_so_far = max(max_so_far, curr_max)
return max_so_far
n = int(input())
a = list(map(int, input().split()))
aa = [abs(a[i] - a[i + 1]) for i in range(n - 1)]
b = [(aa[i] * (-1) ** i) for i in range(n - 1)]
c = [(aa[i] * (-1) ** (i + 1)) for i in range(n - 1)]
print(max(maxSubArraySum(b, n - 1), maxSubArraySum(c, n - 1)))
|
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR 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 ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def getNum():
inp = input()
return int(inp)
def getArrNum():
inp = input()
A = [int(x) for x in inp.split(" ")]
return A
def getMaximal(arr):
best = 0
curBest = 0
for x in arr:
if curBest >= 0:
curBest += x
else:
curBest = x
best = max(best, curBest)
return best
N = getNum()
arr = getArrNum()
odd = []
even = []
for i in range(N - 1):
nm = abs(arr[i] - arr[i + 1])
neg = nm * -1
if i % 2 == 0:
odd.append(nm)
even.append(neg)
else:
odd.append(neg)
even.append(nm)
ans = max(getMaximal(odd), getMaximal(even))
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
ans = -(10**9) - 1
mini = 0
temp = 0
for i in range(n - 1):
if i % 2 == 0:
temp += abs(a[i] - a[i + 1])
else:
temp -= abs(a[i] - a[i + 1])
mini = min(mini, temp)
ans = max(ans, temp - mini)
mini = 0
temp = 0
for i in range(1, n - 1):
if i % 2 == 0:
temp -= abs(a[i] - a[i + 1])
else:
temp += abs(a[i] - a[i + 1])
mini = min(mini, temp)
ans = max(ans, temp - mini)
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 BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
if n == 2:
print(abs(a[0] - a[1]))
exit()
mx_cur1, mx_glob1 = abs(a[0] - a[1]), abs(a[0] - a[1])
for i in range(1, n - 1):
tmp = abs(a[i] - a[i + 1]) * (-1) ** i
mx_cur1 = max(mx_cur1 + tmp, tmp)
mx_glob1 = max(mx_cur1, mx_glob1)
mx_cur2, mx_glob2 = abs(a[1] - a[2]), abs(a[1] - a[2])
for i in range(2, n - 1):
tmp = abs(a[i] - a[i + 1]) * (-1) ** (i - 1)
mx_cur2 = max(mx_cur2 + tmp, tmp)
mx_glob2 = max(mx_glob2, mx_cur2)
print(max(mx_glob1, mx_glob2))
|
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 FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
from sys import stdin
inf = float("inf")
(N,) = map(int, stdin.readline().split())
A = list(map(int, stdin.readline().split()))
diffodd = [0] * N
diffeven = [0] * N
for i in range(1, N):
v = abs(A[i - 1] - A[i])
if i % 2 == 1:
diffodd[i] = v
diffeven[i] = -v
else:
diffeven[i] = v
diffodd[i] = -v
for i in range(1, N):
diffodd[i] += diffodd[i - 1]
diffeven[i] += diffeven[i - 1]
best_startodd = 0
best_starteven = 0
best_sum = -inf
for end in range(1, N):
best_sum = max(
best_sum,
diffodd[end] - diffodd[best_startodd],
diffeven[end] - diffeven[best_starteven],
)
if diffodd[end] < diffodd[best_startodd]:
best_startodd = end
if diffeven[end] < diffeven[best_starteven]:
best_starteven = end
print(best_sum)
|
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
l = tuple(map(int, input().split()))
a = []
for i in range(n - 1):
a.append(abs(l[i] - l[i + 1]))
ev = [(a[i] if i % 2 == 0 else -a[i]) for i in range(n - 1)]
od = [(-i) for i in ev]
od[0] = 0
dp = [ev[0]]
st = ["ev"]
vmax = dp[0]
evsum = evans = 0
odsum = odans = 0
for i in range(0, n - 1):
evsum += ev[i]
odsum += od[i]
evans = max(evsum, evans)
odans = max(odsum, odans)
if evsum < 0 and i % 2 == 1:
evsum = 0
if odsum < 0 and i % 2 == 0:
odsum = 0
print(max(evans, odans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def f(list):
listA = []
listB = [0]
res = 0
for i in range(len(list)):
res = max(res, list[i])
if i % 2 == 0:
if len(listA) > 0:
listA.append(list[i] + listA[len(listA) - 1])
else:
listA.append(list[i])
elif len(listB) > 0:
listB.append(list[i] + listB[len(listB) - 1])
else:
listB.append(list[i])
s = 0
for i in range(len(listA)):
if i > 0:
s = max(s, listB[i] - listA[i - 1])
res = max(res, listA[i] - listB[i] + s)
return res
N = int(input())
list = []
line = input().split()
last = int(line[0])
for i in range(1, N):
n = int(line[i])
list.append(abs(last - n))
last = n
v = f(list)
del list[0]
print(max(v, f(list)))
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
R = lambda: map(int, input().split())
n = int(input())
a = list(R())
for i in range(len(a) - 1):
a[i] = abs(a[i] - a[i + 1])
a = [(v * (1 if i % 2 == 0 else -1)) for i, v in enumerate(a[:-1])]
res = 0
running_sum = 0
for i in range(len(a)):
running_sum += a[i]
res = max(res, abs(running_sum))
if running_sum < 0:
running_sum = 0
running_sum = 0
for i in range(len(a)):
running_sum += a[i]
res = max(res, abs(running_sum))
if running_sum > 0:
running_sum = 0
print(res)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
b = list(map(int, input().split()))
s1 = 0
s2 = 0
j = 0
c = []
while j < n - 1:
c.append(abs(b[j + 1] - b[j]))
j += 1
j = 0
p = 0
r = 0
while j < n - 1:
if j + 1 < n - 1:
r = max(c[j] - c[j + 1], r + c[j] - c[j + 1])
p = max(p, r + c[j + 1])
else:
r = max(c[j], r + c[j])
p = max(p, r)
j += 2
j = 1
r = 0
while j < n - 1:
if j + 1 < n - 1:
r = max(c[j] - c[j + 1], r + c[j] - c[j + 1])
p = max(p, r + c[j + 1])
else:
r = max(c[j], r + c[j])
p = max(p, r)
j += 2
print(p)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
f = []
arr = list(map(int, input().split()))
for i in range(0, len(arr) - 1):
f.append(abs(arr[i] - arr[i + 1]))
dp = [[0] * len(f), [0] * len(f)]
dp[0][0] = 0
dp[1][0] = f[0]
for i in range(1, len(f)):
dp[0][i] = dp[1][i - 1] - f[i]
dp[1][i] = max(dp[0][i - 1] + f[i], f[i])
ans = max(max(dp[0]), max(dp[1]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
input = sys.stdin.buffer.readline
def solution():
n = int(input())
l = list(map(int, input().split()))
d = [0] * (n + 1)
for i in range(n - 1):
if i % 2 == 0:
d[i + 1] = d[i] + abs(l[i] - l[i + 1])
else:
d[i + 1] = d[i] - abs(l[i] - l[i + 1])
d.sort()
print(d[n] - d[0])
solution()
|
IMPORT ASSIGN VAR 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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split(" ")))
d = []
for k in range(n - 1):
d.append(abs(a[k] - a[k + 1]))
for k in range(n - 1):
if k % 2:
d[k] *= -1
maxsum = 0
minsum = 0
curmax = 0
curmin = 0
for k in range(n - 1):
if d[k] > 0:
minsum = min(curmin, minsum)
curmax += d[k]
curmin += d[k]
if curmin > 0:
curmin = 0
else:
maxsum = max(maxsum, curmax)
curmin += d[k]
curmax += d[k]
if curmax < 0:
curmax = 0
maxsum = max(maxsum, curmax)
minsum = min(minsum, curmin)
print(max(abs(maxsum), abs(minsum)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def main():
input()
aa = list(map(int, input().split()))
a, s = aa[0], 1
u = c = mi = ma = 0
for b in aa:
c += abs(a - b) * s
a = b
s *= -1
if ma < c:
ma = c
u = ma - mi
elif mi > c:
mi = c
a, s = aa[0], -1
v = c = mi = ma = 0
for b in aa:
c += abs(a - b) * s
a = b
s *= -1
if ma < c:
ma = c
v = ma - mi
elif mi > c:
mi = c
print(max(u, v))
def __starting_point():
main()
__starting_point()
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
from itertools import accumulate
inf = 10**9 + 1
def solve():
n = int(input())
a = [int(i) for i in input().split()]
ad = [abs(a[i + 1] - a[i]) for i in range(n - 1)]
ap = [0] + list(accumulate(ai * (-1) ** i for i, ai in enumerate(ad)))
max_dif, max_mdif = max_min_profit(ap)
ans = max(max_dif, max_mdif)
print(ans)
def max_min_profit(a):
max_dif = 0
max_mdif = 0
min_v = max_v = 0
for i in range(1, len(a)):
if a[i] < min_v:
min_v = a[i]
else:
max_dif = max(max_dif, a[i] - min_v)
if a[i] > max_v:
max_v = a[i]
else:
max_mdif = max(max_mdif, max_v - a[i])
return max_dif, max_mdif
solve()
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF 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 BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def maxSubArraySum(a, size):
max_so_far = a[0]
curr_max = a[0]
for i in range(1, size):
curr_max = max(a[i], curr_max + a[i])
max_so_far = max(max_so_far, curr_max)
return max_so_far
n = int(input())
l = list(map(int, input().split()))
o = []
p = []
m = 0
i = 0
while i < len(l) - 1:
if m % 2 == 0:
x = 1
else:
x = -1
o.append(x * abs(l[i] - l[i + 1]))
p.append(-1 * x * abs(l[i] - l[i + 1]))
i = i + 1
m = m + 1
p.pop(0)
s = maxSubArraySum(o, len(o))
if len(p) > 0:
k = maxSubArraySum(p, len(p))
print(max(s, k))
else:
print(s)
|
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR 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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
l = list(map(int, input().split()))
M = abs(l[0] - l[1])
k = 0
i = 0
t_p = 0
t_n = 0
while i < n - 1:
k = (abs(l[i] - l[i + 1]), -abs(l[i] - l[i + 1]))[i % 2]
t_n += k
t_p -= k
M = max(M, t_n, t_p)
t_p = max(0, t_p)
t_n = max(0, t_n)
i += 1
print(M)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
def solve():
n = int(input())
a = [int(i) for i in input().split()]
a_dif = [abs(a[i + 1] - a[i]) for i in range(n - 1)]
a1 = [(a_dif[i] * (-1) ** i) for i in range(n - 1)]
md1 = 0
m1 = 0
v = 0
for i in range(n - 1):
v += a1[i]
if v < m1:
m1 = v
else:
md1 = max(v - m1, md1)
a2 = [(a1[i] * -1) for i in range(n - 1)]
md2 = 0
m2 = 0
v = 0
for i in range(n - 1):
v += a2[i]
if v < m2:
m2 = v
else:
md2 = max(v - m2, md2)
ans = max(md1, md2)
print(ans)
def debug(x, table):
for name, val in table.items():
if x is val:
print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
return None
solve()
|
IMPORT FUNC_DEF 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 BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR RETURN NONE EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
arr = list(map(int, input().split()))
even = [(0) for i in range(n)]
odd = [(0) for i in range(n)]
diff = []
for i in range(n - 1):
diff.append(abs(arr[i] - arr[i + 1]))
for i in range(len(diff)):
even[i] = max(diff[i], diff[i] + odd[i - 1])
odd[i] = max(-diff[i], -diff[i] + even[i - 1])
print(max(max(even), max(odd)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
d = list(map(lambda i: abs(a[i] - a[i + 1]), range(n - 1)))
x = list(map(lambda i: d[i] * (-1) ** i, range(0, n - 1)))
y = list(map(lambda i: d[i] * (-1) ** (i + 1), range(0, n - 1)))
max1 = x[0]
s = 0
for l in range(0, n - 1, 1):
s += x[l]
max1 = max([max1, s])
s = max([s, 0])
max2 = max1
s = 0
for l in range(1, n - 1, 1):
s += y[l]
max2 = max([max2, s])
s = max([s, 0])
print(max2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = [abs(a[i] - a[i + 1]) for i in range(n - 1)]
for i in range(0, n - 1, 2):
b[i] *= -1
dp = [0] * (n - 1)
dp[0] = b[0]
for i in range(1, n - 1):
dp[i] = max(dp[i - 1] + b[i], b[i])
ans = max(dp)
for i in range(n - 1):
b[i] *= -1
dp = [0] * (n - 1)
dp[0] = b[0]
for i in range(1, n - 1):
dp[i] = max(dp[i - 1] + b[i], b[i])
ans = max(ans, max(dp))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
dp = [[0, 0] for i in range(n)]
dp[0][1] = abs(a[1] - a[0])
maxi = abs(a[1] - a[0])
for i in range(1, n - 1):
dp[i][0] = max(0, dp[i - 1][1] - abs(a[i] - a[i + 1]))
dp[i][1] = max(0, dp[i - 1][0] + abs(a[i] - a[i + 1]))
maxi = max(maxi, dp[i][0], dp[i][1])
print(maxi)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
input()
numbers = [int(x) for x in input().split()]
diffs = []
sum_odd, sum_even = 0, 0
for x in range(len(numbers) - 1):
diffs.append(abs(numbers[x] - numbers[x + 1]))
_max = 0
for x in range(len(diffs)):
aux = diffs[x]
if x % 2 == 1:
aux *= -1
sum_even += aux
sum_odd -= aux
if sum_even < 0:
sum_even = 0
if sum_odd < 0:
sum_odd = 0
_max = max([sum_even, sum_odd, _max])
print(_max)
|
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def maxSubArraySum(a, size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_ending_here < 0:
max_ending_here = 0
elif max_so_far < max_ending_here:
max_so_far = max_ending_here
return max_so_far
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(len(a) - 1):
c.append(abs(a[i] - a[i + 1]))
p = []
q = []
for i in range(len(c)):
p.append(c[i] * pow(-1, i))
for i in range(len(c)):
q.append(c[i] * pow(-1, i + 1))
print(max(maxSubArraySum(p, len(p)), maxSubArraySum(q, len(q))))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = []
sign = 1
for i in range(len(a) - 1):
b.append(abs(a[i] - a[i + 1]) * sign)
sign *= -1
max_ = 0
max1, max2 = 0, 0
a1, a2 = 0, 0
for i in range(n - 1):
if a1 + b[i] > 0:
a1 += b[i]
else:
a1 = 0
max1 = max(a1, max1)
if a2 - b[i] > 0:
a2 -= b[i]
else:
a2 = 0
max2 = max(a2, max2)
print(max(max1, max2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(1, n):
b.append(abs(a[i] - a[i - 1]))
n = len(b)
for i in range(n):
b[i] *= (-1) ** (i % 2)
ans = 0
mx = 0
mi = 0
s = 0
for i in range(n):
s += b[i]
ans = max(ans, max(abs(s - mx), abs(s - mi)))
mx = max(s, mx)
mi = min(s, mi)
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 NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
arr = list(map(int, input().split()))
diff = [abs(arr[i] - arr[i - 1]) for i in range(1, n)]
res0, res1, res, curr_sum = -2000000000.0, 0, -2000000000.0, 0
for i in range(n - 1):
curr_sum += diff[i] * (1 if i % 2 == 0 else -1)
res = max(res, curr_sum - res1, res0 - curr_sum)
if i % 2 == 0:
res0 = max(res0, curr_sum)
else:
res1 = min(res1, curr_sum)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def main():
n = int(input())
arr = list(map(int, input().split()))
dp = []
ans = -float("inf")
total = 0
for i in range(n - 1):
if i % 2 == 0:
total += abs(arr[i] - arr[i + 1])
else:
total -= abs(arr[i] - arr[i + 1])
ans = max(ans, abs(arr[i] - arr[i + 1]))
dp.append(total)
dp2 = []
dp.reverse()
for i in dp:
if not dp2:
dp2.append([i, i])
else:
dp2.append([min(dp2[-1][0], i), max(dp2[-1][1], i)])
dp.reverse()
dp2.reverse()
for i in range(len(dp) - 1):
if i % 2 == 0:
total = dp2[i + 1][1]
if i - 1 >= 0:
total -= dp[i - 1]
else:
total = abs(dp2[i + 1][0] - dp[i - 1])
ans = max(ans, total)
if n == 2:
print(dp[-1])
return
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR VAR IF VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
R = [int(i) for i in input().split()]
L = [abs(R[i] - R[i + 1]) for i in range(n - 1)]
ans = [(0) for _ in range(n)]
ans[0] = L[0]
for i in range(1, n - 1):
ans[i] = max(L[i], L[i] - ans[i - 1])
if i - 2 >= 0:
ans[i] = max(ans[i], L[i] - L[i - 1] + ans[i - 2])
print(max(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
read = lambda: map(int, input().split())
n = int(input())
a = list(read())
d = [0] * n
b = [0] * n
c = [0] * n
sgn = 1
for i in range(1, n):
d[i] = abs(a[i - 1] - a[i])
b[i] = d[i] * sgn
c[i] = -b[i]
sgn *= -1
s = [0] * n
for i in range(1, n):
s[i] = s[i - 1] + b[i]
mn = ans = 0
for i in range(1, n):
if i % 2:
ans = max(ans, s[i] - mn)
else:
mn = min(mn, s[i])
for i in range(1, n):
s[i] = s[i - 1] + c[i]
mn = 0
for i in range(1, n):
if i % 2:
mn = min(mn, s[i])
else:
ans = max(ans, s[i] - mn)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
a = list(map(int, input().strip().split()))
b = [0] * (n - 1)
c = [0] * (n - 1)
for i in range(n - 1):
if i % 2 == 0:
b[i] = abs(a[i] - a[i + 1])
else:
b[i] = abs(a[i] - a[i + 1]) * -1
for i in range(1, n - 1):
if (i - 1) % 2 == 0:
c[i] = abs(a[i] - a[i + 1])
else:
c[i] = abs(a[i] - a[i + 1]) * -1
d1 = [-1000000001] * (n - 1)
d2 = [-1000000001] * (n - 1)
for i in range(n - 1):
if i > 0:
d1[i] = max(b[i] + d1[i - 1], max(0, b[i]))
else:
d1[i] = max(b[i], 0)
for i in range(n - 1):
if i > 0:
d2[i] = max(c[i] + d2[i - 1], max(0, c[i]))
else:
d2[i] = max(c[i], 0)
print(max(max(d1), max(d2)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
def main():
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a) - 1):
b.append(abs(a[i] - a[i + 1]))
max_odd = b[0]
max_even = 0
all_values = [max_odd, max_even]
for bi in b[1:]:
new_odd = max(max_even + bi, bi)
new_even = max(max_odd - bi, 0)
max_odd = new_odd
max_even = new_even
all_values += [max_odd, max_even]
print(max(all_values))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
w = [int(k) for k in input().split()]
a = []
for j in range(1, len(w)):
a.append(abs(w[j] - w[j - 1]))
b, c = [], []
for j in range(len(a)):
if j % 2:
b.append(-a[j])
c.append(a[j])
else:
b.append(a[j])
c.append(-a[j])
res = 0
x, y = [], []
q = 0
for j in b:
x.append(q)
q += j
x.append(q)
q = 0
for j in c:
y.append(q)
q += j
y.append(q)
mx, mn = 0, 0
for j in x:
mx = max(mx, j)
mn = min(mn, j)
res = max(res, mx - mn)
mx, mn = 0, 0
for j in y:
mx = max(mx, j)
mn = min(mn, j)
res = max(res, mx - mn)
print(res)
|
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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(n - 1):
B.append(abs(A[i] - A[i + 1]))
dpmin = [0] * n
dpmax = [0] * n
for i in range(n - 2, -1, -1):
dpmax[i] = B[i]
dpmin[i] = B[i]
dpmin[i] = min(dpmin[i], B[i] - dpmax[i + 1])
dpmax[i] = max(dpmax[i], B[i] - dpmin[i + 1])
print(max(dpmax))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
|
import sys
def read_ints():
return [int(x) for x in sys.stdin.readline().strip().split()]
def main():
N = read_ints()[0]
a = read_ints()
nums = [abs(a[i] - a[i + 1]) for i in range(N - 1)]
N -= 1
odd = [0] * N
even = [0] * N
odd[0] = nums[0]
for ix in range(1, N):
odd[ix] = max(nums[ix], even[ix - 1] + nums[ix])
even[ix] = odd[ix - 1] - nums[ix]
print(max(max(odd), max(even)))
main()
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.