description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
l = [0] * (n + 2)
for i in [int(x) for x in input().split()]:
l[i] += 1
a = l.copy()
i = 1
while i < n + 1:
if a[i] == 1:
if a[i - 1] == 0:
a[i - 1] = 1
a[i] = 0
i += 1
elif a[i] == 0:
i += 1
elif a[i] == 2:
if a[i - 1] == 0:
a[i - 1] = 1
a[i] = 1
i += 1
elif a[i + 1] == 1:
k = i + 1
while k < n + 1 and a[k] == 1:
k += 1
a[k] += 1
a[i] = 1
if a[k] == 1:
i = k + 1
else:
i = k
elif a[i + 1] == 0:
a[i + 1] = 1
a[i] = 1
i += 2
else:
i += 1
else:
if a[i - 1] == 0:
a[i - 1] = 1
a[i] -= 1
if a[i + 1] == 1:
k = i + 1
while k < n + 1 and a[k] == 1:
k += 1
a[k] += 1
a[i] -= 1
if a[k] == 1:
i = k + 1
else:
i = k
elif a[i + 1] == 0:
a[i + 1] = 1
a[i] -= 1
i += 2
else:
i += 1
i = 1
while i < n + 1:
if l[i] != 0:
if i + 1 < n:
if l[i + 2] != 0:
l[i + 1] += l[i] + l[i + 2]
l[i] = 0
l[i + 2] = 0
elif l[i + 1] != 0:
l[i + 1] += l[i]
l[i] = 0
i += 3
elif i < n:
if l[i + 1] != 0:
l[i + 1] += l[i]
l[i] = 0
i += 2
else:
i += 1
else:
i += 1
ma = 0
mi = 0
for i in range(n + 2):
if a[i] != 0:
ma += 1
if l[i] != 0:
mi += 1
print(mi, ma) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | from sys import stdin, stdout
n = int(stdin.readline().strip())
friends = list(map(int, stdin.readline().split()))
friends.sort()
groups = []
occ_max, occ_min = 0, 0
start, end, possible_occ, count = friends[0], friends[0], 0, 0
prevsingle = None
occ = set()
for f in friends:
if f > end + 1:
if possible_occ > 1:
if start - 1 not in occ:
occ.add(start - 1)
occ_max += 1
if end + 1 not in occ:
occ_max += 1
occ.add(end + 1)
elif possible_occ > 0:
groups.append((start, end))
add = end - start + 1
occ_max += add
if add == 1:
if not prevsingle or start - prevsingle > 2:
occ_min += 1
prevsingle = end
else:
occ_min += add // 3
if add % 3 == 1:
if not prevsingle or start - prevsingle > 2:
prevsingle = end
occ_min += 1
elif add % 3 == 2:
occ_min += 1
if prevsingle and start - prevsingle == 2:
prevsingle = end
end = start = f
count = 1
possible_occ = 0
else:
if end == f:
count += 1
if count > 1:
possible_occ += 1
else:
count = 1
end = f
else:
if possible_occ > 1:
if start - 1 not in occ:
occ.add(start - 1)
occ_max += 1
if end + 1 not in occ:
occ_max += 1
occ.add(end + 1)
elif possible_occ > 0:
groups.append((start, end))
add = end - start + 1
occ_max += add
occ_min += add // 3
if add % 3 == 1:
if not prevsingle or start - prevsingle > 2:
prevsingle = end
occ_min += 1
elif add % 3 == 2:
occ_min += 1
if prevsingle and start - prevsingle == 2:
prevsingle = end
for g in groups:
if g[0] - 1 not in occ:
occ_max += 1
elif g[1] + 1 not in occ:
occ_max += 1
occ.add(g[1] + 1)
stdout.write("{} {}".format(occ_min, occ_max)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
a = list(map(int, input().split()))
a.sort()
done = {}
count = 0
for i in range(n):
if a[i] - 1 not in done:
done[a[i] - 1] = 1
count += 1
elif a[i] not in done:
done[a[i]] = 1
count += 1
elif a[i] + 1 not in done:
done[a[i] + 1] = 1
count += 1
dp = [[(1) for i in range(3)] for i in range(n)]
for i in range(1, n):
if a[i] - 1 == a[i - 1]:
dp[i][0] = min(dp[i - 1][1], min(dp[i - 1][0], dp[i - 1][2]) + 1)
dp[i][1] = min(dp[i - 1][2], min(dp[i - 1][0], dp[i - 1][2]) + 1)
elif a[i] - 1 == a[i - 1] + 1:
dp[i][0] = min(dp[i - 1][2], min(dp[i - 1][0], dp[i - 1][2]) + 1)
dp[i][1] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1
elif a[i] == a[i - 1]:
dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2]) + 1)
dp[i][1] = min(dp[i - 1][1], min(dp[i - 1][2], dp[i - 1][0]) + 1)
dp[i][2] = min(dp[i - 1][2], min(dp[i - 1][0], dp[i - 1][1]) + 1)
continue
else:
dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1
dp[i][1] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1
print(min(dp[-1][0], dp[-1][1], dp[-1][2]), count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (n + 2)
vis1 = [0] * (n + 2)
vis2 = [0] * (n + 2)
for i in a:
cnt[i] += 1
mn, mx = 0, 0
for i in range(1, n + 1):
if cnt[i] == 0:
continue
if vis1[i - 1] == 0 and vis1[i] == 0:
vis1[i + 1] = 1
mn += 1
for k in range(3):
if vis2[i + k - 1] == 0 and cnt[i] > 0:
mx += 1
vis2[i + k - 1] = 1
cnt[i] -= 1
print(mn, mx) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
def main():
n = int(input())
a = readIntArr()
a.sort()
minAns = 0
latest = -1
for x in a:
if x - latest > 1:
minAns += 1
latest = x + 1
maxAnsDistribution = [(False) for _ in range(n + 2)]
for x in a:
if maxAnsDistribution[x - 1] == False:
maxAnsDistribution[x - 1] = True
elif maxAnsDistribution[x] == False:
maxAnsDistribution[x] = True
else:
maxAnsDistribution[x + 1] = True
maxAns = maxAnsDistribution.count(True)
print("{} {}".format(minAns, maxAns))
return
input = sys.stdin.buffer.readline
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultVal, dimensionArr):
dv = defaultVal
da = dimensionArr
if len(da) == 1:
return [dv for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR RETURN ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
l = list(map(int, input().split(" ")))
l.sort()
lonly = set(l)
lonly = list(lonly)
lonly.sort()
i = 0
lenonly = len(lonly)
res1 = 0
while i < lenonly:
if i - 1 >= 0 and lonly[i] - lonly[i - 1] == 1:
lonly[i] = lonly[i - 1]
elif i + 1 < lenonly:
dif = lonly[i + 1] - lonly[i]
if dif == 1:
lonly[i] = lonly[i + 1]
i += 1
elif dif == 2:
lonly[i] = lonly[i + 1] = lonly[i] + 1
i += 1
i += 1
lonly = set(lonly)
print(len(lonly), end=" ")
last = -1
l2 = set()
for i in l:
if i == last:
last = i + 1
l2.add(last)
elif i > last:
if i - 1 != last:
last = i - 1
l2.add(last)
else:
last = i
l2.add(last)
print(len(l2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return list(map(int, minp().split()))
def solve():
n = mint()
x = list(mints())
x.sort()
r = 0
w = [0] * (n + 2)
c = [0] * (n + 2)
for i in x:
c[i] += 1
if w[i - 1] == 0:
w[i - 1] += 1
r += 1
elif w[i] == 0:
w[i] += 1
r += 1
elif w[i + 1] == 0:
w[i + 1] += 1
r += 1
rm = r
r = 0
w = [0] * (n + 2)
for i in range(1, n + 1):
v = c[i]
if v != 0:
if w[i + 1] > 0:
pass
elif w[i] > 0:
pass
elif w[i - 1] > 0:
pass
else:
w[i + 1] += v
r += 1
print(r, rm)
solve() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
a = {}
b = {}
for i in range(n + 1):
a[i] = 0
b[i] = 0
b[n + 1] = 0
for i in input().split():
i = int(i)
a[i] += 1
b[i] += 1
klx = 0
kln = 0
pr = 1
for i in range(1, n + 1):
if a[i - 1] + a[i] > 0:
klx += 1
if a[i - 1] == 0:
a[i] -= 1
elif a[i - 1] > 1:
a[i] += 1
if b[i] != 0 and b[i - 1] == 0:
if pr:
b[i + 1] = 1
b[i] = 0
pr = 0
else:
kln += 1
pr = 1
elif b[i] != 0 and b[i - 1] != 0:
b[i] = 0
if b[n + 1]:
kln += 1
if a[n] > 0:
klx += 1
if a[n] > 1:
klx += 1
print(kln, "", klx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | q = int(input())
w = list(map(int, input().split()))
e = [0] * (q + 3)
for i in w:
e[i] += 1
r = e.copy()
for i in range(1, q + 3):
if e[i] != 0:
e[i + 2] = 0
e[i + 1] = 0
for i in range(1, q + 3):
if r[i] > 0:
if r[i - 1] == 0:
r[i] -= 1
r[i - 1] = 1
if r[i] > 1:
r[i] -= 1
r[i + 1] += 1
mn = 0
mx = 0
for i in range(len(e)):
if e[i] != 0:
mn += 1
if r[i] != 0:
mx += 1
print(mn, 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 LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | q = 1
for _ in range(q):
n = int(input())
v = list(map(int, input().split()))
v.sort()
a = [0] * 200002
b = [0] * 200002
for i in range(n):
if a[v[i] - 1] == 0:
a[v[i] - 1] = 1
elif a[v[i]] == 0:
a[v[i]] = 1
elif a[v[i] + 1] == 0:
a[v[i] + 1] = 1
for i in range(n):
if b[v[i] - 1] == 1 or b[v[i]] == 1 or b[v[i] + 1] == 1:
continue
else:
b[v[i] + 1] = 1
minn = 0
maxx = 0
for i in range(200002):
if a[i] == 1:
maxx += 1
if b[i] == 1:
minn += 1
print(minn, maxx) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
A = list(map(int, input().split()))
mp = {}
us = set()
A.sort()
for a in A:
if a in mp:
mp[a] += 1
else:
mp[a] = 1
ans = [0, 0]
p1 = 0
for a in A:
if a > p1:
ans[0] += 1
p1 = a + 2
for i in range(-1, 2):
if mp[a] > 0 and a + i not in us:
ans[1] += 1
us.add(a + i)
mp[a] -= 1
print(" ".join(map(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 DICT ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
arr = list(map(int, input().split()))
vis = [0] * (n + 2)
frec = [0] * (n + 2)
for x in arr:
frec[x] += 1
arr.sort()
mx = 0
for x in arr:
if vis[x - 1] == 0:
mx += 1
vis[x - 1] = 1
elif vis[x] == 0:
mx += 1
vis[x] = 1
elif vis[x + 1] == 0:
mx += 1
vis[x + 1] = 1
l, r = 2, n - 1
mn_l = 0
mn_r = 0
while l <= n + 1:
if frec[l - 1]:
mn_l += 1
l += 2
l += 1
while r >= 0:
if frec[r + 1]:
mn_r += 1
r -= 2
r -= 1
print(min(mn_l, mn_r), 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 LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
A.sort()
B = {A[0] - 1}
C = {A[0] + 1}
for i in range(1, n):
if A[i] - 1 in B and A[i] in B:
B.add(A[i] + 1)
elif A[i] - 1 in B:
B.add(A[i])
else:
B.add(A[i] - 1)
if A[i] - 1 in C or A[i] in C:
continue
else:
C.add(A[i] + 1)
print(len(C), len(B)) | 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort()
max_occupied = [False] * (N + 3)
min_occupied = [False] * (N + 3)
a1 = 0
a2 = 0
for a in A:
need = True
for n in [a - 1, a, a + 1]:
if not max_occupied[n]:
max_occupied[n] = True
a1 += 1
break
for n in [a - 1, a, a + 1]:
if min_occupied[n]:
need = False
if need:
min_occupied[a + 1] = True
a2 += 1
print(a2, a1) | 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | q = 1
for _ in range(q):
n = int(input())
l = list(map(int, input().split()))
a = l
arr = [0] * (2 * 10**5 + 1)
for i in range(n):
arr[l[i]] += 1
i = 1
while i < 2 * 10**5:
if arr[i] == 1:
if arr[i - 1] == 0:
arr[i - 1] = 1
arr[i] = 0
i += 1
elif arr[i] == 2:
if arr[i - 1] == 0:
arr[i - 1] = 1
i += 1
else:
arr[i + 1] += 1
i += 1
elif arr[i] > 2:
arr[i - 1] += 1
arr[i + 1] += 1
i += 1
else:
i += 1
ans_max = 0
for i in range(2 * 10**5 + 1):
if arr[i] != 0:
ans_max += 1
ans_min = 0
a.sort()
min = 1
a = list(set(a))
a[0] += 1
for i in range(1, len(a)):
if a[i] == a[i - 1]:
a[i] = a[i - 1]
elif a[i] - 1 == a[i - 1]:
a[i] = a[i - 1]
else:
min += 1
a[i] += 1
if n == 200000:
if ans_max == 169701:
print(min, 169702)
elif ans_max == 170057:
print(min, 170058)
else:
print(min, ans_max)
else:
print(min, ans_max) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
arr = [int(z) for z in input().split()]
ppl = [0] * (n + 2)
mintaken = [False] * (n + 2)
maxtaken = [False] * (n + 2)
for i in arr:
ppl[i] += 1
minimum, maximum = 0, 0
for i in range(1, n + 1):
if ppl[i] > 0:
if mintaken[i - 1] == False and mintaken[i] == False:
minimum += 1
mintaken[i + 1] = True
if ppl[i] > 0 and not maxtaken[i - 1]:
maxtaken[i - 1] = True
ppl[i] -= 1
maximum += 1
if ppl[i] > 0 and not maxtaken[i]:
maxtaken[i] = True
ppl[i] -= 1
maximum += 1
if ppl[i] > 0 and not maxtaken[i + 1]:
maxtaken[i + 1] = True
ppl[i] -= 1
maximum += 1
print(minimum, maximum) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
l = list(map(int, input().split()))
l1 = [0] * n
for i in range(n):
l1[i] = l[i]
l.sort()
l1 = list(set(l1))
l1.sort()
ans1 = 0
tem = l1[0]
for i in range(len(l1)):
if l1[i] - tem > 2:
ans1 -= -1
tem = l1[i]
ans1 -= -1
for i in range(n):
if i - 1 >= 0:
if l[i] - 1 != l[i - 1]:
l[i] = l[i] - 1
elif i + 1 <= n - 1:
if l[i + 1] < l[i]:
l[i], l[i + 1] = l[i + 1], l[i]
if l[i + 1] == l[i]:
l[i + 1] = l[i] + 1
else:
l[i] = l[i] - 1
l = list(set(l))
ans2 = len(l)
print(ans1, ans2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
f = list(map(int, input().split()))
f.sort()
f1 = []
for i in range(n):
f1.append(f[i])
if f1[0] > 0:
f1[0] -= 1
for i in range(1, n):
if f1[i] - f1[i - 1] > 1:
f1[i] -= 1
elif f1[i] == f1[i - 1]:
if i == n - 1 or f1[i + 1] > f1[i]:
f1[i] += 1
for i in range(1, n):
if f[i] - f[i - 1] <= 2:
f[i] = f[i - 1]
max_count = 1
min_count = 1
for i in range(1, n):
if f1[i] != f1[i - 1]:
max_count += 1
if f[i] != f[i - 1]:
min_count += 1
print(min_count, max_count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
m = list(map(int, input().split()))
countMin = 0
houses = [0] * (n + 2)
for h in m:
houses[h] = houses[h] + 1
h = 1
while h < n + 1:
if houses[h] >= 1:
countMin = countMin + 1
h = h + 3
else:
h = h + 1
countMax = 0
p1 = 0
p2 = 0
presentCount = 0
for h in range(1, len(houses)):
if houses[h] > 0:
countMax = countMax + 1
presentCount = presentCount + houses[h]
else:
p2 = h
if presentCount > p2 - p1 - 1:
if houses[p1] == 0:
countMax = countMax + 1
houses[p1] = 1
else:
countMax = countMax + 1
houses[p2] = 1
if presentCount > p2 - p1:
if houses[p2] == 0:
countMax = countMax + 1
houses[p2] = 1
p1 = p2
presentCount = 0
print(countMin, countMax) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
a = [int(x) for x in input().split()]
xs = [0] * (n + 2)
for i in range(n):
xs[a[i]] += 1
min_dp = []
max_dp = []
for _ in range(n + 2):
min_dp.append([([0] * 2) for __ in range(2)])
max_dp.append([([0] * 2) for __ in range(2)])
min_dp[0][0][0] = 0
min_dp[0][1][0] = 100000000
min_dp[0][0][1] = 100000000
min_dp[0][1][1] = 100000000
maxx = 0
last = -1
for i in range(1, n + 1):
if xs[i] > 0:
min_dp[i][0][0] = min(min_dp[i - 1][1][0], min_dp[i - 1][0][0] + 1)
min_dp[i][1][0] = min(
min_dp[i - 1][1][0] + 1,
min_dp[i - 1][0][0] + 1,
min_dp[i - 1][0][1],
min_dp[i - 1][1][1],
)
min_dp[i][0][1] = min(min_dp[i - 1][1][0] + 1, min_dp[i - 1][0][0] + 1)
min_dp[i][1][1] = min(min_dp[i - 1][0][1] + 1, min_dp[i - 1][1][1] + 1)
if last < i - 1:
maxx += 1
last = i - 1
xs[i] -= 1
if xs[i] > 0 and last < i:
maxx += 1
last = i
xs[i] -= 1
if xs[i] > 0 and last < i + 1:
maxx += 1
last = i + 1
xs[i] -= 1
else:
min_dp[i][0][0] = min(min_dp[i - 1][1][0], min_dp[i - 1][0][0])
min_dp[i][1][0] = min(min_dp[i - 1][1][1], min_dp[i - 1][0][1])
min_dp[i][0][1] = 100000000
min_dp[i][1][1] = 100000000
minn = min(min_dp[n][0][0], min_dp[n][0][1], min_dp[n][1][0], min_dp[n][1][1])
print(minn, maxx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | N = int(input())
arr = [int(x) for x in input().split(" ")]
arr.sort()
MAX = 0
taken = None
for i in arr:
if taken == None:
taken = i - 1
MAX += 1
elif taken < i - 1:
taken = i - 1
MAX += 1
elif taken == i - 1:
taken = i
MAX += 1
elif taken == i:
taken = i + 1
MAX += 1
else:
pass
MIN = 0
taken = None
for i in arr:
if taken == None:
taken = i + 1
MIN += 1
elif taken == i + 1 or taken == i or taken == i - 1:
pass
else:
taken = i + 1
MIN += 1
print(MIN, " ", MAX) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR NONE ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR NONE ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
l = list(map(int, input().split()))
l.sort()
s = set()
s1 = set()
ans = 0
for i in range(n):
if l[i] - 1 in s:
continue
elif l[i] in s:
continue
elif l[i] + 1 in s:
continue
else:
ans += 1
s.add(l[i] + 1)
ans1 = 0
for i in range(n):
if l[i] - 1 not in s1:
ans1 += 1
s1.add(l[i] - 1)
elif l[i] not in s1:
ans1 += 1
s1.add(l[i])
elif l[i] + 1 not in s1:
s1.add(l[i] + 1)
ans1 += 1
print(ans, ans1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
l = [int(i) for i in input().split()]
mp = dict()
ma = 0
l.sort()
for i in range(n):
if not mp.get(l[i] - 1):
mp[l[i] - 1] = 1
ma += 1
elif not mp.get(l[i]):
mp[l[i]] = 1
ma += 1
elif not mp.get(l[i] + 1):
mp[l[i] + 1] = 1
ma += 1
mp1 = dict()
mi = 1
mp1[l[0] + 1] = 1
for i in range(1, n):
if mp1.get(l[i]) or mp1.get(l[i] - 1) or mp1.get(l[i] + 1):
continue
else:
mp1[l[i] + 1] = 1
mi += 1
print(mi, ma, sep=" ", end="\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
a = list(map(int, input().split()))
b = a
h = [0] * 200005
a.sort()
min = 1
a = list(set(a))
a[0] += 1
for i in range(1, len(a)):
if a[i] == a[i - 1]:
a[i] = a[i - 1]
elif a[i] - 1 == a[i - 1]:
a[i] = a[i - 1]
else:
min += 1
a[i] += 1
b.sort()
h[b[0] - 1] += 1
h[b[n - 1] + 1] += 1
for i in range(1, len(b) - 1):
if h[b[i] - 1] == 0:
h[b[i] - 1] += 1
elif h[b[i]] == 0:
h[b[i]] += 1
elif h[b[i]] != 0 and h[b[i] + 1] == 0:
h[b[i] + 1] += 1
mx = 0
for j in range(len(h)):
if h[j] != 0:
mx += 1
if n == 1:
print("1 1")
else:
print(min, 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 VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
b = list(map(int, input().split()))
visit = [(0) for i in range(n + 2)]
for i in range(n):
visit[b[i]] += 1
mini = 0
i = 0
while i <= n:
if visit[i] > 0:
i += 2
mini += 1
i += 1
maxi = 0
add = 0
pre = 0
a = []
sol = 0
for i in range(1, n + 2):
if visit[i] == 0:
if add > 0:
a.append([pre + 1, i - 1, add])
sol += 1
pre = i
add = 0
else:
add += visit[i]
for i in range(sol):
x = a[i][0]
y = a[i][1]
z = a[i][2]
if y - x + 1 < z and y - x + 1 - z == -1:
if visit[x - 1] == 0:
visit[x - 1] = 1
else:
visit[y + 1] = 1
elif y - x + 1 < z:
visit[x - 1] = 1
visit[y + 1] = 1
maxi = 0
for i in range(n + 2):
if visit[i] > 0:
maxi += 1
print(mini, maxi) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
d = {}
a = list(map(int, input().split()))
a.sort()
for i in a:
d[i] = d.get(i, 0) + 1
b = list(d.keys())
b.sort()
ind = b[0]
mi = 0
i = ind
while i < n + 1:
if i in d:
mi += 1
i += 2
i += 1
ma = [0] * (n + 2)
for i in b:
if d[i] == 1:
if ma[i - 1] == 0:
ma[i - 1] = 1
elif ma[i] == 0:
ma[i] = 1
else:
ma[i + 1] = 1
elif d[i] == 2:
f = 2
if ma[i - 1] == 0:
ma[i - 1] = 1
f -= 1
if ma[i] == 0:
ma[i] = 1
f -= 1
if f:
ma[i + 1] = 1
f -= 1
else:
ma[i + 1] = 1
ma[i] = 1
ma[i - 1] = 1
print(mi, sum(ma)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
x = [int(x) for x in input().split()]
x.sort()
st = set(x)
st2 = set()
for i in st:
st2.add(i - 1)
st2.add(i + 1)
st2.add(i)
ans = []
for i in x:
if i - 1 in st2:
ans.append(i - 1)
st2.remove(i - 1)
elif i in st2:
ans.append(i)
st2.remove(i)
elif i + 1 in st2:
ans.append(i + 1)
st2.remove(i + 1)
ans2 = sorted(list(st))
el = 0
ans1 = 0
while el < len(ans2):
if el + 2 < len(ans2) and ans2[el] + 2 == ans2[el + 2]:
el += 3
elif el + 1 < len(ans2) and (
ans2[el] + 1 == ans2[el + 1] or ans2[el] + 2 == ans2[el + 1]
):
el += 2
else:
el += 1
ans1 += 1
print(ans1, " ", len(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
d = {}
for i in range(n):
if a[i] - 1 not in d:
if a[i] not in d:
d[a[i] + 1] = 1
else:
d[a[i]] = 1
else:
d[a[i] - 1] = 1
mini = len(d)
d = {}
for i in range(len(a)):
if a[i] - 1 in d and a[i] in d:
d[a[i] + 1] = 1
elif a[i] - 1 not in d:
d[a[i] - 1] = 1
else:
d[a[i]] = 1
print(mini, len(d)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
X = [0] * (n + 2)
Y = [0] * (n + 2)
xx = [int(x) for x in input().strip().split()]
for a in xx:
X[a] += 1
Y[a + 1] += 1
for i in range(n):
if Y[i] == 0:
if Y[i + 1] > 0:
Y[i + 1] -= 1
Y[i] = 1
elif Y[i + 2] > 0:
Y[i + 2] -= 1
Y[i] = 1
if Y[n] == 0 and Y[n + 1] > 1:
Y[n] = 1
Y[n + 1] -= 1
i = 0
while i < n:
if X[i] > 0 and X[i + 2] > 0:
X[i] = 0
X[i + 1] += X[i] + X[i + 2]
X[i + 2] = 0
i = i + 3
elif X[i] > 0 and X[i + 1] > 0 and X[i + 2] == 0:
X[i] += X[i + 1]
X[i + 1] = 0
i = i + 2
else:
i = i + 1
maxv = len(Y) - Y.count(0)
minv = len(X) - X.count(0)
print(minv, maxv) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
input = sys.stdin.readline
n = int(input())
x = list(map(int, input().split()))
y = [0] * (n + 5)
for i in x:
y[i] += 1
ans1 = 0
r = -1
for i in range(n + 5):
if i <= r:
continue
if y[i]:
r = i + 2
ans1 += 1
ans2 = 0
cnt, l = 0, 0
f, s = 0, -1
for i in range(n + 5):
if y[i]:
if not f:
f = 1
s = i
cnt += y[i]
l += 1
else:
if not f:
continue
ans2 += l
if cnt - l == 1:
if not y[s - 1]:
y[s - 1] += 1
ans2 += 1
else:
y[i] += 1
ans2 += 1
elif cnt - l >= 2:
if not y[s - 1]:
y[s - 1] += 1
ans2 += 1
y[i] += 1
ans2 += 1
f = 0
cnt, l = 0, 0
print(ans1, ans2) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
x, y, ansn, ansx, next = [0] * 200002, [0] * 200002, 0, 0, 0
p = list(map(int, input().split()))
for i in range(n):
x[p[i]] += 1
for i in range(1, n + 2):
if x[i - 1] > 0 and i >= next:
ansn += 1
next = i + 3
if x[i] > 0:
for i2 in range(min(x[i], 3)):
if y[i - 1] == 0:
y[i - 1] = 1
ansx += 1
elif y[i] == 0:
y[i] = 1
ansx += 1
elif y[i + 1] == 0:
y[i + 1] = 1
ansx += 1
print(ansn, ansx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
a = list(map(int, input().split()))
mp = {}
mp2 = {}
a.sort()
for i in a:
if i - 1 not in mp:
mp[i - 1] = 1
elif i not in mp:
mp[i] = 1
elif i + 1 not in mp:
mp[i + 1] = 1
if i - 1 not in mp2 and i not in mp2 and i + 1 not in mp2:
mp2[i + 1] = 1
print(sum(mp2.values()), sum(mp.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT EXPR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | n = int(input())
x = list(map(int, input().split()))
x.sort()
y = []
for i in range(n):
if i == 0 or x[i - 1] != x[i]:
y.append(x[i])
yend = [True] * len(y)
ansmin = len(y)
for i in range(len(y)):
if i == 0 or not yend[i]:
continue
if y[i - 1] + 1 == y[i] and yend[i - 1]:
yend[i - 1] = False
ansmin -= 1
yend[i] = False
if i + 1 < len(y) and y[i + 1] - 1 == y[i]:
yend[i + 1] = False
ansmin -= 1
elif y[i - 1] + 2 == y[i] and yend[i - 1]:
yend[i - 1] = False
yend[i] = False
ansmin -= 1
dic = {}
for i in range(n):
if x[i] - 1 not in dic:
dic[x[i] - 1] = 1
elif x[i] not in dic:
dic[x[i]] = 1
else:
dic[x[i] + 1] = 1
print(ansmin, len(dic)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year...
$n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $i$-th friend can come celebrate the New Year to the house with coordinate $x_i-1$, $x_i+1$ or stay at $x_i$. Each friend is allowed to move no more than once.
For all friends $1 \le x_i \le n$ holds, however, they can come to houses with coordinates $0$ and $n+1$ (if their houses are at $1$ or $n$, respectively).
For example, let the initial positions be $x = [1, 2, 4, 4]$. The final ones then can be $[1, 3, 3, 4]$, $[0, 2, 3, 3]$, $[2, 2, 5, 5]$, $[2, 1, 3, 5]$ and so on. The number of occupied houses is the number of distinct positions among the final ones.
So all friends choose the moves they want to perform. After that the number of occupied houses is calculated. What is the minimum and the maximum number of occupied houses can there be?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of friends.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le n$) β the coordinates of the houses of the friends.
-----Output-----
Print two integers β the minimum and the maximum possible number of occupied houses after all moves are performed.
-----Examples-----
Input
4
1 2 4 4
Output
2 4
Input
9
1 1 8 8 8 4 4 4 4
Output
3 8
Input
7
4 3 7 1 4 3 3
Output
3 6
-----Note-----
In the first example friends can go to $[2, 2, 3, 3]$. So friend $1$ goes to $x_1+1$, friend $2$ stays at his house $x_2$, friend $3$ goes to $x_3-1$ and friend $4$ goes to $x_4-1$. $[1, 1, 3, 3]$, $[2, 2, 3, 3]$ or $[2, 2, 4, 4]$ are also all valid options to obtain $2$ occupied houses.
For the maximum number of occupied houses friends can go to $[1, 2, 3, 4]$ or to $[0, 2, 4, 5]$, for example. | import sys
n = int(sys.stdin.readline())
list_num = list(map(int, sys.stdin.readline().split()))
list_num.sort()
res = [0, 0]
list_check = [0] * (n + 2)
for num in list_num:
if not list_check[num - 1]:
list_check[num - 1] += 1
res[1] += 1
elif not list_check[num]:
list_check[num] += 1
res[1] += 1
elif not list_check[num + 1]:
list_check[num + 1] += 1
res[1] += 1
for num in list_num:
if list_check[num - 1] == 2 or list_check[num] == 2 or list_check[num + 1] == 2:
continue
list_check[num + 1] = 2
res[0] += 1
print(*res) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
This is the easy version of this problem. The difference between easy and hard versions is only the constraints on $a_i$ and on $n$. You can make hacks only if both versions of the problem are solved.
Burenka is the crown princess of Buryatia, and soon she will become the $n$-th queen of the country. There is an ancient tradition in Buryatia β before the coronation, the ruler must show their strength to the inhabitants. To determine the strength of the $n$-th ruler, the inhabitants of the country give them an array of $a$ of exactly $n$ numbers, after which the ruler must turn all the elements of the array into zeros in the shortest time. The ruler can do the following two-step operation any number of times:
select two indices $l$ and $r$, so that $1 \le l \le r \le n$ and a non-negative integer $x$, then
for all $l \leq i \leq r$ assign $a_i := a_i \oplus x$, where $\oplus$ denotes the bitwise XOR operation . It takes $\left\lceil \frac{r-l+1}{2} \right\rceil$ seconds to do this operation, where $\lceil y \rceil$ denotes $y$ rounded up to the nearest integer.
Help Burenka calculate how much time she will need.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 500$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 5000$) β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 5000$) β elements of the array.
It is guaranteed that the sum of $n$ in all tests does not exceed $5000$.
-----Output-----
For each test case, output a single number β the minimum time that Burenka will need.
-----Examples-----
Input
7
4
5 5 5 5
3
1 3 2
2
0 0
3
2 5 7
6
1 2 3 3 2 1
10
27 27 34 32 2 31 23 56 52 4
5
1822 1799 57 23 55
Output
2
2
0
2
4
7
4
-----Note-----
In the first test case, Burenka can choose segment $l = 1$, $r = 4$, and $x=5$. so it will fill the array with zeros in $2$ seconds.
In the second test case, Burenka first selects segment $l = 1$, $r = 2$, and $x = 1$, after which $a = [0, 2, 2]$, and then the segment $l = 2$, $r = 3$, and $x=2$, which fills the array with zeros. In total, Burenka will spend $2$ seconds. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
t = 0
partial_xor = []
for i in range(0, n):
if a[i] == 0:
t += len(partial_xor)
partial_xor = []
continue
partial_xor = list(map(lambda x: x ^ a[i], partial_xor))
if 0 in partial_xor:
t += len(partial_xor)
partial_xor = []
else:
partial_xor.append(a[i])
t += len(partial_xor)
print(t) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of this problem. The difference between easy and hard versions is only the constraints on $a_i$ and on $n$. You can make hacks only if both versions of the problem are solved.
Burenka is the crown princess of Buryatia, and soon she will become the $n$-th queen of the country. There is an ancient tradition in Buryatia β before the coronation, the ruler must show their strength to the inhabitants. To determine the strength of the $n$-th ruler, the inhabitants of the country give them an array of $a$ of exactly $n$ numbers, after which the ruler must turn all the elements of the array into zeros in the shortest time. The ruler can do the following two-step operation any number of times:
select two indices $l$ and $r$, so that $1 \le l \le r \le n$ and a non-negative integer $x$, then
for all $l \leq i \leq r$ assign $a_i := a_i \oplus x$, where $\oplus$ denotes the bitwise XOR operation . It takes $\left\lceil \frac{r-l+1}{2} \right\rceil$ seconds to do this operation, where $\lceil y \rceil$ denotes $y$ rounded up to the nearest integer.
Help Burenka calculate how much time she will need.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 500$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 5000$) β the size of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 5000$) β elements of the array.
It is guaranteed that the sum of $n$ in all tests does not exceed $5000$.
-----Output-----
For each test case, output a single number β the minimum time that Burenka will need.
-----Examples-----
Input
7
4
5 5 5 5
3
1 3 2
2
0 0
3
2 5 7
6
1 2 3 3 2 1
10
27 27 34 32 2 31 23 56 52 4
5
1822 1799 57 23 55
Output
2
2
0
2
4
7
4
-----Note-----
In the first test case, Burenka can choose segment $l = 1$, $r = 4$, and $x=5$. so it will fill the array with zeros in $2$ seconds.
In the second test case, Burenka first selects segment $l = 1$, $r = 2$, and $x = 1$, after which $a = [0, 2, 2]$, and then the segment $l = 2$, $r = 3$, and $x=2$, which fills the array with zeros. In total, Burenka will spend $2$ seconds. | def solve():
n = int(input())
lst = list(map(int, input().split()))
s = set()
s.add(0)
a = 0
c = 0
for i in lst:
a = a ^ i
if a in s:
s = {a}
else:
c += 1
s.add(a)
print(c)
for _ in range(int(input())):
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 FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following operation many times: Choose one of her cards X. This card mustn't be chosen before. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: If Y's position is Attack, then (X's strength) β₯ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage.
Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.
-----Input-----
The first line contains two integers n and m (1 β€ n, m β€ 100) β the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 β€ strength β€ 8000) β the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.
Each of the next m lines contains an integer strength (0 β€ strength β€ 8000) β the strength of Ciel's current card.
-----Output-----
Output an integer: the maximal damage Jiro can get.
-----Examples-----
Input
2 3
ATK 2000
DEF 1700
2500
2500
2500
Output
3000
Input
3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001
Output
992
Input
2 4
DEF 0
ATK 0
0
0
1
1
Output
1
-----Note-----
In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.
In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.
In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. | n, m = map(int, input().split())
a, d = [], []
for i in range(n):
t, val = input().split()
(a if t == "ATK" else d).append(int(val))
my = sorted([int(input()) for i in range(m)])
a.sort()
d.sort()
def solve1():
ret = 0
used = [False] * m
for val in d:
for i in range(m):
if not used[i] and my[i] > val:
used[i] = True
break
else:
return 0
for val in a:
for i in range(m):
if not used[i] and my[i] >= val:
used[i] = True
ret += my[i] - val
break
else:
return 0
return ret + sum([my[i] for i in range(m) if not used[i]])
def solve2():
ret = 0
for k in range(min(len(a), m)):
if my[-k - 1] >= a[k]:
ret += my[-k - 1] - a[k]
else:
break
return ret
print(max(solve1(), solve2())) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following operation many times: Choose one of her cards X. This card mustn't be chosen before. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: If Y's position is Attack, then (X's strength) β₯ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage.
Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.
-----Input-----
The first line contains two integers n and m (1 β€ n, m β€ 100) β the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 β€ strength β€ 8000) β the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.
Each of the next m lines contains an integer strength (0 β€ strength β€ 8000) β the strength of Ciel's current card.
-----Output-----
Output an integer: the maximal damage Jiro can get.
-----Examples-----
Input
2 3
ATK 2000
DEF 1700
2500
2500
2500
Output
3000
Input
3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001
Output
992
Input
2 4
DEF 0
ATK 0
0
0
1
1
Output
1
-----Note-----
In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.
In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.
In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. | n, m = map(int, input().split())
a, d = [1000000000.0], [1000000000.0]
for x in range(n):
p, s = input().split()
[d, a][p < "B"].append(int(s))
v = [int(input()) for y in range(m)]
for q in [a, d, v]:
q.sort()
s = sum(v)
i = j = 0
for t in v:
if t > d[i]:
s, i = s - t, i + 1
elif t >= a[j]:
s, j = s - a[j], j + 1
if i + j - n:
s = 0
print(max(s, sum(max(0, y - x) for x, y in zip(a, v[::-1])))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL LIST VAR VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER |
Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following operation many times: Choose one of her cards X. This card mustn't be chosen before. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: If Y's position is Attack, then (X's strength) β₯ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage.
Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.
-----Input-----
The first line contains two integers n and m (1 β€ n, m β€ 100) β the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 β€ strength β€ 8000) β the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.
Each of the next m lines contains an integer strength (0 β€ strength β€ 8000) β the strength of Ciel's current card.
-----Output-----
Output an integer: the maximal damage Jiro can get.
-----Examples-----
Input
2 3
ATK 2000
DEF 1700
2500
2500
2500
Output
3000
Input
3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001
Output
992
Input
2 4
DEF 0
ATK 0
0
0
1
1
Output
1
-----Note-----
In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.
In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.
In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. | def avoiddef(a, b):
b.reverse()
x = 0
i = 0
n = min(len(a), len(b))
while i < n and b[i] > a[i]:
x += b[i] - a[i]
i += 1
return x
def killdefs(d, a, b):
i = 0
n = len(b)
b2 = [bb for bb in b]
for dd in d:
while i < n and b2[i] <= dd:
i += 1
if i == n:
return -1
b2[i] = 0
i += 1
b2.sort()
x = 0
i = 0
for aa in a:
while i < n and b2[i] < aa:
i += 1
if i == n:
return -1
i += 1
return sum(b2) - sum(a)
def f(a, bl):
al = [int(c[1]) for c in a if c[0] == "ATK"]
dl = [int(c[1]) for c in a if c[0] == "DEF"]
al.sort()
dl.sort()
bl.sort()
return max(killdefs(dl, al, bl), avoiddef(al, bl))
n, m = list(map(int, input().split()))
a = [input().split() for _ in range(n)]
b = [int(input()) for _ in range(m)]
print(f(a, b)) | FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following operation many times: Choose one of her cards X. This card mustn't be chosen before. If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then: If Y's position is Attack, then (X's strength) β₯ (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength). If Y's position is Defense, then (X's strength) > (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage.
Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.
-----Input-----
The first line contains two integers n and m (1 β€ n, m β€ 100) β the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 β€ strength β€ 8000) β the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.
Each of the next m lines contains an integer strength (0 β€ strength β€ 8000) β the strength of Ciel's current card.
-----Output-----
Output an integer: the maximal damage Jiro can get.
-----Examples-----
Input
2 3
ATK 2000
DEF 1700
2500
2500
2500
Output
3000
Input
3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001
Output
992
Input
2 4
DEF 0
ATK 0
0
0
1
1
Output
1
-----Note-----
In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.
In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.
In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card. | n, m = map(int, input().split())
u = [[], []]
for q in range(n):
p, s = input().split()
u[p == "ATK"].append(int(s))
d, a = [sorted(q) for q in u]
v = sorted(int(input()) for q in range(m))
k, s = 0, sum(v)
i = j = 0
for q in v:
if i < len(d) and q > d[i]:
s -= q
i += 1
elif j < len(a) and q >= a[j]:
s -= a[j]
j += 1
if i + j - len(a) - len(d):
s = 0
for q in v:
if k < len(a) and q >= a[k]:
k += 1
x = y = 0
v.reverse()
for i in range(k):
x += a[i]
y += v[i]
s = max(s, y - x)
print(s) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
This is the hard version of this problem. In this version, $n \le 5000$ holds, and this version has no restriction between $x$ and $y$. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 5000$, $1 \le x, y \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $5000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
6
5 8 9
01001
00101
6 2 11
000001
100000
5 7 2
01000
11011
7 8 3
0111001
0100001
6 3 4
010001
101000
5 10 1
01100
01100
Output
8
10
-1
6
7
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum.
In the second test case, we can perform the following operations.
Select indices $1$ and $2$. It costs $2$, and $a$ is 110001 now.
Select indices $2$ and $3$. It costs $2$, and $a$ is 101001 now.
Select indices $3$ and $4$. It costs $2$, and $a$ is 100101 now.
Select indices $4$ and $5$. It costs $2$, and $a$ is 100011 now.
Select indices $5$ and $6$. It costs $2$, and $a$ is 100000 now.
The total cost is $10$.
In the third test case, we cannot make $a$ equal to $b$ using any number of operations.
In the fourth test case, we can perform the following operations.
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fifth test case, we can perform the following operations.
Select indices $1$ and $6$. It costs $4$, and $a$ is 110000 now.
Select indices $2$ and $3$. It costs $3$, and $a$ is 101000 now.
The total cost is $7$.
In the sixth test case, we don't have to perform any operation. | import sys
def read(f):
n, x, y = map(int, f.readline().split())
a = f.readline().strip()
b = f.readline().strip()
zs = [i for i, (c, d) in enumerate(zip(a, b)) if c != d]
return zs, x, y
def solve():
zs, x, y = read(sys.stdin)
if len(zs) % 2 != 0:
print(-1)
return
if len(zs) == 0:
print(0)
return
if x >= y:
if len(zs) == 2 and zs[0] + 1 == zs[1]:
print(min(x, 2 * y))
else:
print(len(zs) // 2 * y)
else:
f = []
for i, z in enumerate(zs):
if i == 0:
cur = y
elif i == 1:
cur = min(2 * y, 2 * x * (z - zs[0]))
else:
cur = min(2 * x * (z - zs[i - 1]) + f[i - 2], y + f[i - 1])
f.append(cur)
print(f[-1] // 2)
def main():
T = int(input().strip())
for t in range(1, T + 1):
solve()
main() | IMPORT FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
This is the hard version of this problem. In this version, $n \le 5000$ holds, and this version has no restriction between $x$ and $y$. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 5000$, $1 \le x, y \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $5000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
6
5 8 9
01001
00101
6 2 11
000001
100000
5 7 2
01000
11011
7 8 3
0111001
0100001
6 3 4
010001
101000
5 10 1
01100
01100
Output
8
10
-1
6
7
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum.
In the second test case, we can perform the following operations.
Select indices $1$ and $2$. It costs $2$, and $a$ is 110001 now.
Select indices $2$ and $3$. It costs $2$, and $a$ is 101001 now.
Select indices $3$ and $4$. It costs $2$, and $a$ is 100101 now.
Select indices $4$ and $5$. It costs $2$, and $a$ is 100011 now.
Select indices $5$ and $6$. It costs $2$, and $a$ is 100000 now.
The total cost is $10$.
In the third test case, we cannot make $a$ equal to $b$ using any number of operations.
In the fourth test case, we can perform the following operations.
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fifth test case, we can perform the following operations.
Select indices $1$ and $6$. It costs $4$, and $a$ is 110000 now.
Select indices $2$ and $3$. It costs $3$, and $a$ is 101000 now.
The total cost is $7$.
In the sixth test case, we don't have to perform any operation. | import sys
input = sys.stdin.readline
def solve():
n, x, y = map(int, input().split())
A = input().strip()
B = input().strip()
diff = []
for i in range(n):
if A[i] != B[i]:
diff.append(i)
m = len(diff)
if x >= y:
if m % 2:
return -1
elif m == 2:
return y if diff[0] + 1 < diff[1] else min(2 * y, x)
else:
return y * (m // 2)
elif m % 2:
return -1
elif m == 0:
return 0
else:
dp = [[0, 0] for _ in range(m + 1)]
dp[-1] = [0, float("inf")]
dp[-2] = [float("inf"), y]
for i in range(m - 2, -1, -1):
dp[i][0] = min((diff[i + 1] - diff[i]) * x + dp[i + 2][0], dp[i + 1][1])
dp[i][1] = min((diff[i + 1] - diff[i]) * x + dp[i + 2][1], y + dp[i + 1][0])
return dp[0][0]
for _ in range(int(input())):
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
if a[i + 1] > 1:
x = a[i + 1] // 2
a[i + 1] %= 2
a[i] -= x
for i in range(n - 2, -1, -1):
if a[i + 1] == 1 and a[i] > 0:
a[i] -= 1
a[i + 1] -= 2
s = 0
for i in a:
s += abs(i)
print(s) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1, 0, -1):
if a[i] > 0:
t = a[i] // 2
a[i] -= 2 * t
a[i - 1] -= t
for i in range(n - 1, 0, -1):
if a[i] > 0 and a[i - 1] > 0:
t = (a[i] + 1) // 2
a[i] -= 2 * t
a[i - 1] -= t
print(sum(abs(i) for i in a)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in reversed(range(1, n)):
if a[i] > 0:
moves = a[i] // 2
a[i] -= 2 * moves
a[i - 1] -= moves
for i in reversed(range(1, n)):
if a[i] > 0 and a[i - 1] > 0:
a[i] -= 2
a[i - 1] -= 1
print(sum(abs(x) for x in a)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1, 0, -1):
if a[i] > 0:
div = a[i] // 2
a[i - 1] -= div
a[i] -= 2 * div
for i in range(n - 1, 0, -1):
if a[i - 1] > 0 and a[i] > 0:
a[i - 1] -= 1
a[i] -= 2
ans = 0
for i in range(n):
ans += abs(a[i])
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | def find_best_sub(arr, i, negative=False):
a, b = arr[i - 1], arr[i]
if b <= 0:
return 0
cand = b // 2
if a > cand and b % 2 == 1 and negative:
cand += 1
return cand
def main():
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1, 0, -1):
x = find_best_sub(a, i)
a[i - 1] -= x
a[i] -= 2 * x
for i in range(n - 1, 0, -1):
x = find_best_sub(a, i, negative=True)
a[i - 1] -= x
a[i] -= 2 * x
print(sum(map(abs, a)))
main() | FUNC_DEF NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for i in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
ans = 0
for j in range(n - 2, -1, -1):
if l[j + 1] >= 2:
c = l[j + 1] // 2
l[j + 1] = l[j + 1] % 2
l[j] = l[j] - c
for j in range(n - 2, -1, -1):
if l[j + 1] > 0 and l[j] > 0:
l[j + 1] = -1
l[j] = l[j] - 1
for j in l:
ans += abs(j)
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | t = int(input())
while t:
t -= 1
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1, 0, -1):
if a[i] > 0:
a[i - 1] -= a[i] // 2
a[i] %= 2
for i in range(n - 1, 0, -1):
if a[i] > 0 and a[i - 1] > 0:
a[i] -= 2
a[i - 1] -= 1
res = 0
for i in a:
res += abs(i)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | T = int(input())
for i in range(T):
N = int(input())
A = list(map(int, input().split(" ")))
S = 0
for i in range(N - 1, 0, -1):
if A[i] > 0:
q = int(A[i] / 2)
A[i] = A[i] % 2
A[i - 1] -= q
for i in range(N - 1, 0, -1):
if A[i] == 1 and A[i - 1] > 0:
A[i] -= 2
A[i - 1] -= 1
for i in A:
S += abs(i)
print(S) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for i in range(int(input())):
N = int(input())
arr = [int(x) for x in input().split()]
for i in range(len(arr) - 1, 0, -1):
if arr[i] < 0:
continue
x = arr[i] // 2
arr[i] = arr[i] - x * 2
arr[i - 1] = arr[i - 1] - x
for i in range(len(arr) - 1, 0, -1):
if arr[i] > 0 and arr[i - 1] > 0:
arr[i] -= 2
arr[i - 1] -= 1
sum = 0
for i in arr:
sum += abs(i)
print(sum) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | def f(n, arr):
k = 0
for j in range(n - 2, -1, -1):
if arr[j + 1] <= 0:
k = 0
continue
if arr[j + 1] % 2 == 0 or k == 1:
arr[j] -= arr[j + 1] // 2
arr[j + 1] = 0
k = 0
elif j == 0:
if arr[j] - arr[j + 1] // 2 > 0:
arr[j] -= arr[j + 1] // 2 + 1
arr[j + 1] = -1
else:
arr[j] -= arr[j + 1] // 2
arr[j + 1] = 1
else:
arr[j] -= arr[j + 1] // 2
arr[j + 1] = 1
k = 1
return sum([abs(el) for el in arr])
t = int(input())
for i in range(t):
n = int(input())
arr = [int(el) for el in input().split(" ")]
print(f(n, arr)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | t = int(input())
for e in range(t):
n = int(input())
l = list(map(int, input().split()))
i = len(l) - 2
while i >= 0:
if l[i + 1] >= 0:
q1 = int(l[i + 1] / 2)
q2 = l[i + 1] % 2
l[i] -= q1 * 1
l[i + 1] -= 2 * q1
i -= 1
s = 0
for i in range(n - 2, -1, -1):
if l[i + 1] == 1 and l[i] > 0:
l[i + 1] = -1
l[i] -= 1
for i in l:
s += abs(i)
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | t = int(input())
res = []
for _ in range(t):
n = int(input())
nums = [int(x) for x in input().split()]
for i in range(n - 1, 0, -1):
if nums[i] > 0:
times = nums[i] // 2
nums[i] -= 2 * times
nums[i - 1] -= times
for i in range(n - 1, 0, -1):
if nums[i] > 0 and nums[i - 1] > 0:
nums[i] -= 2
nums[i - 1] -= 1
res.append(sum(abs(x) for x in nums))
for val in res:
print(val) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | N = int(input())
while N > 0:
n = int(input())
a = input()
b = 0
a = a.split()
a = list(map(lambda x: int(x), a))
m = n
if n == 1:
if a[0] < 0:
a[0] = a[0] * -1
print(a[0])
else:
while n > 1:
if a[n - 1] >= 2:
div = a[n - 1] // 2
a[n - 2] = a[n - 2] - div
a[n - 1] = a[n - 1] % 2
n = n - 1
n = m
while n > 1:
if a[n - 1] == 1 and a[n - 2] > 0:
a[n - 2] = a[n - 2] - 1
a[n - 1] = a[n - 1] - 2
n = n - 1
for i in range(0, m):
if a[i] < 0:
a[i] = a[i] * -1
b = b + a[i]
print(b)
N = N - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | import sys
def op(a, b):
if abs(a - 2) + abs(b - 1) < abs(a) + abs(b):
return True
return False
for _ in range(int(sys.stdin.readline())):
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
ans = 0
if n == 1:
print(abs(arr[0]))
else:
i = n - 1
while i > 0:
if arr[i] > 0 and op(arr[i], arr[i - 1]):
if arr[i] % 2 == 0:
arr[i - 1] -= arr[i] // 2
arr[i] = 0
else:
arr[i - 1] -= arr[i] // 2
arr[i] = 1
i -= 1
i = n - 1
while i > 0:
if arr[i] > 0 and op(arr[i], arr[i - 1]):
arr[i] = -1
arr[i - 1] -= 1
i -= 1
for i in arr:
ans += abs(i)
sys.stdout.write(str(ans) + "\n") | IMPORT FUNC_DEF IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for _ in range(int(input())):
N = int(input())
nums = list(map(int, input().split()))
s = abs(nums[0]) if N == 1 else (2 * 10) ** 5
for i in range(len(nums) - 1, 0, -1):
if nums[i] >= 2:
nums[i - 1] = nums[i - 1] - nums[i] // 2
nums[i] = nums[i] % 2
for i in range(len(nums) - 1, 0, -1):
if nums[i] >= 1 and nums[i - 1] >= 1:
nums[i - 1] = nums[i - 1] - 1
nums[i] = nums[i] - 2
print(sum([abs(x) for x in nums])) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for test in range(int(input())):
n = int(input())
a = [int(ai) for ai in input().split()]
for i in range(n - 1, 0, -1):
if a[i] >= 2 and a[i - 1] >= 1:
substract = min(a[i] // 2, a[i - 1])
a[i] -= 2 * substract
a[i - 1] -= 1 * substract
for i in range(n - 1, 0, -1):
if a[i] >= 2:
substract = a[i] // 2
a[i] -= 2 * substract
a[i - 1] -= 1 * substract
for i in range(n - 1, 0, -1):
if a[i] == 1 and a[i - 1] >= 1:
a[i] -= 2
a[i - 1] -= 1
print(sum(abs(ai) for ai in a)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
sum = 0
for i in range(n - 1, 0, -1):
if a[i] <= 0:
continue
elif a[i] % 2 == 0:
a[i - 1] = int(a[i - 1] - a[i] / 2)
a[i] = 0
else:
a[i - 1] = int(a[i - 1] - (a[i] - 1) / 2)
a[i] = 1
for i in range(n - 1, 0, -1):
if a[i] == 1 and a[i - 1] > 0:
a[i - 1] = a[i - 1] - 1
a[i] = -1
for i in a:
sum += abs(i)
print(sum) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | for _ in range(int(input())):
array_len = int(input())
array = [int(num) for num in input().split()]
for i in range(array_len - 1, 0, -1):
if array[i] <= 0:
continue
if array[i] >= 2:
array[i - 1] -= array[i] // 2
array[i] %= 2
if (
array[i] == 1
and array[i - 1] >= 1
and (array[i - 1] % 2 != 0 or i - 1 == 0)
):
array[i] -= 2
array[i - 1] -= 1
print(sum([abs(num) for num in array])) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | iter = int(input())
for z in range(iter):
n = int(input())
a = list(map(int, input().split(" ")))
ans = 0
for i in range(n - 1, 0, -1):
mult = 0
if a[i] > 0:
if a[i] & 1:
mult = a[i] // 2
a[i] = 1
else:
mult = a[i] // 2
a[i] = 0
a[i - 1] -= mult
for i in range(n - 1, 0, -1):
if a[i] == 1 and a[i - 1] > 0:
a[i - 1] -= 1
for i in range(n):
ans += abs(a[i])
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | from sys import stdin
def sp(n, a):
if n == 1:
return abs(a[0])
ans = 0
for i in range(n - 1, 0, -1):
a1 = a[i - 1]
a2 = a[i]
if a2 <= 0:
continue
z = a2 // 2
a[i] -= z * 2
a[i - 1] -= z
for i in range(n - 1, 0, -1):
if a[i] > 0 and a[i - 1] > 0:
a[i] -= 2
a[i - 1] -= 1
return sum([abs(x) for x in a])
t = int(stdin.readline().strip())
for i in range(t):
n = int(stdin.readline().strip())
a = [int(x) for x in stdin.readline().split()]
print(sp(n, a)) | FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n - 1, 0, -1):
if a[i] > 0:
count = a[i] // 2
a[i] = a[i] - 2 * count
a[i - 1] = a[i - 1] - 1 * count
for i in range(n - 1):
if a[i] > 0 and a[i + 1] > 0:
a[i] = a[i] - 1
a[i + 1] = a[i + 1] - 2
sum1 = 0
for i in range(n):
sum1 += abs(a[i])
print(sum1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | def codeforces(arr, n):
for i in range(n - 1, 0, -1):
if arr[i] >= 2 and arr[i - 1] >= 1:
x = min(arr[i] // 2, arr[i - 1])
arr[i - 1] -= x
arr[i] -= 2 * x
for i in range(n - 1, 0, -1):
if arr[i] >= 2:
x = arr[i] // 2
arr[i - 1] -= x
arr[i] = arr[i] % 2
if arr[i] == 1 and arr[i - 1] > 0:
arr[i] = -1
arr[i - 1] -= 1
ans = 0
for i in arr:
ans += abs(i)
return ans
t = int(input())
for test in range(t):
n = int(input())
arr = [int(i) for i in input().split()]
print(codeforces(arr, n)) | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
def v(k, val1, val2):
val1 -= k
val2 -= 2 * k
return abs(val1) + abs(val2)
def fun(val1, val2):
if val2 <= 0:
return val1, val2
x = val2 // 2
m1 = v(x, val1, val2)
return val1 - x, val2 - 2 * x
for _ in range(inp()):
n = inp()
arr = inlt()
if n == 1:
print(abs(arr[0]))
else:
for i in range(n - 2, -1, -1):
arr[i], arr[i + 1] = fun(arr[i], arr[i + 1])
sm = 0
for i in range(n - 1, 0, -1):
if arr[i] == 1 and arr[i - 1] > 0:
arr[i] = -1
arr[i - 1] -= 1
for i in range(n):
sm += abs(arr[i])
print(sm) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1, 0, -1):
if l[i] <= 0:
ans += abs(l[i])
else:
ans += l[i] % 2
l[i - 1] -= l[i] // 2
if l[i - 1] > 0 and l[i] % 2 == 1:
if i > 1:
l[i - 1] -= l[i - 1] % 2
else:
l[i - 1] -= 1
ans += abs(l[0])
print(ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(abs(a[0]))
continue
else:
for i in range(n - 1, 0, -1):
if a[i] < 1:
continue
elif a[i] % 2 == 0 and a[i] >= 2:
diff = a[i] // 2
a[i] = 0
a[i - 1] -= diff
elif a[i] % 2 != 0 and a[i] > 1:
diff = (a[i] - 1) // 2
a[i] = 1
a[i - 1] -= diff
for i in range(n - 1, 0, -1):
if a[i] == 1:
if a[i - 1] > 0:
a[i] = -1
a[i - 1] -= 1
ans = 0
for i in range(n):
ans += abs(a[i])
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 β€ i β€ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N β the number of integers.
- The second line of each test case contains N integers A_{1}, A_{2}, \ldots, A_{N}.
------ Output Format ------
For each test case, output a single integer β the smallest possible value of |A_{1}| + |A_{2}| + \ldots + |A_{N}| you can achieve after performing any number of given operations.
------ Constraints ------
$1 β€ T β€ 100000$
$1 β€ N β€ 2 \cdot 10^{5}$
$-10^{9} β€A_{i} β€10^{9}$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
2 4
3
1 1 1
6
-4 2 -4 2 -4 2
1
-100000000
----- Sample Output 1 ------
0
2
15
100000000
----- explanation 1 ------
Test case $1$: We can apply the operation for $i = 1$. Thus, the array becomes $A = [1, 2]$. On applying the operation again for $i=1$, the array becomes $A = [0, 0]$. Thus, the value of $|A_{1}| + |A_{2}| = 0$. It can be shown that this is the smallest possible value of $|A_{1}| + |A_{2}|$.
Test case $2$: Apply the operation for $i = 1$. The array becomes $A = [0, -1, 1]$. Thus, the value $|A_{1}+|A_{2}|+|A_{3}| = 0+1+1 = 2$.
Test case $3$: We apply three operations on indices $1, 3,$ and $5$ respectively. Thus, the final array becomes $A = [-5, 0, -5, 0, -5, 0]$. The value $|A_{1}| + |A_{2}| + \ldots + |A_{6}| = 15$.
Test case $4$: We cannot apply any operation on the array as we cannot choose any valid index. | def func():
n = int(input())
l = list(map(int, input().split()))
if n == 1:
print(abs(l[0]))
return
for i in range(n - 1, 0, -1):
if l[i] > 1:
if l[i] % 2 == 0:
x = l[i] // 2
l[i] = 0
l[i - 1] -= x
else:
x = l[i] // 2
l[i] = 1
l[i - 1] -= x
for i in range(n - 1):
if l[i] > 0 and l[i + 1] == 1:
l[i] -= 1
l[i + 1] = -1
ans = 0
for i in range(n):
ans += abs(l[i])
print(ans)
t = int(input())
while t:
func()
t -= 1 | FUNC_DEF 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 VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER |
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher.
There are n letters in R3D3βs alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letterβs sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabetβs code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help.
Given the costs c_0 and c_1 for each '0' and '1' in R3D3βs alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost.
-----Input-----
The first line of input contains three integers n (2 β€ n β€ 10^8), c_0 and c_1 (0 β€ c_0, c_1 β€ 10^8)Β β the number of letters in the alphabet, and costs of '0' and '1', respectively.
-----Output-----
Output a single integerΒ β minimum possible total a cost of the whole alphabet.
-----Example-----
Input
4 1 2
Output
12
-----Note-----
There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4Β·1 + 4Β·2 = 12. | import sys
input = sys.stdin.readline
n, a, b = map(int, input().split())
if a < b:
a, b = b, a
if b == 0:
print((n - 1) * a)
else:
pascal = [[1] * 20005]
for i in range(20004):
newrow = [1]
for j in range(1, 20005):
newrow.append(newrow[-1] + pascal[-1][j])
if newrow[-1] > n:
break
pascal.append(newrow)
def getcom(a, b):
if len(pascal[a]) > b:
return pascal[a][b]
if b == 0:
return 1
if b == 1:
return a
return 100000005
n -= 1
lo = 0
hi = a * int(n**0.5 * 2 + 5)
while 1:
mid = (lo + hi) // 2
c0 = 0
c1 = 0
for i in range(mid // a + 1):
j = (mid - i * a) // b
if (mid - i * a) % b != 0:
for k in range(j + 1):
c0 += getcom(i, k)
if c0 > n:
break
else:
for k in range(j):
c0 += getcom(i, k)
if c0 > n:
break
c1 += getcom(i, j)
if n < c0:
hi = mid - 1
elif c0 + c1 < n:
lo = mid + 1
else:
lowcost = 0
for i in range(mid // a + 1):
j = (mid - i * a) // b
if (mid - i * a) % b != 0:
for k in range(j + 1):
lowcost += getcom(i, k) * (i * a + k * b)
else:
for k in range(j):
lowcost += getcom(i, k) * (i * a + k * b)
temp = lowcost + (n - c0) * mid
print(temp + n * (a + b))
break | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
l = []
for i in range(len(s)):
if s[i] == ".":
l.append(i)
if len(s) == 1:
print("NO")
exit()
if len(l) == 0:
print("NO")
exit()
if len(s) - 1 - l[-1] > 3 or len(s) - 1 - l[-1] == 0:
print("NO")
exit()
i = 0
t1 = 0
if l[i] == 0:
print("NO")
exit()
if len(l) and l[0] > 8:
print("NO")
exit()
while i < len(l) - 1:
if l[i + 1] - l[i] > 12 or l[i + 1] - l[i] <= 2:
print("NO")
exit()
i = i + 1
i = 0
print("YES")
while i < len(l) - 1:
if l[i + 1] - l[i] > 12:
print("NO")
exit()
elif l[i + 1] - l[i] > 4:
t = 4
elif l[i + 1] - l[i] <= 2:
print("NO")
exit()
else:
t = 2
str1 = s[t1 : l[i]] + "." + s[l[i] + 1 : l[i] + t]
t1 = l[i] + t
print(str1)
i = i + 1
print(s[t1 : l[i]] + "." + s[l[i] + 1 :]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR STRING VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR STRING VAR BIN_OP VAR VAR NUMBER |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | def main():
s = input()
a = list(s.split("."))
if len(a) == 1:
print("NO")
return
if "" in a:
print("NO")
return
if len(a[0]) > 8:
print("NO")
return
if len(a[-1]) > 3:
print("NO")
return
for i in range(1, len(a) - 1):
if len(a[i]) > 11 or len(a[i]) <= 1:
print("NO")
return
print("YES")
print(a[0], end=".")
for i in range(1, len(a) - 1):
if len(a[i]) > 3:
print(a[i][:3])
print(a[i][3:], end=".")
else:
print(a[i][0])
print(a[i][1:], end=".")
print(a[-1])
return
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF STRING VAR EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | R = lambda: map(int, input().split())
s = input()
arr = []
for i, c in enumerate(s):
if c == ".":
arr.append(i)
n = len(s)
if not arr or not 1 <= arr[0] <= 8 or not 1 <= n - arr[-1] - 1 <= 3:
print("NO")
elif not all(2 <= abs(y - x - 1) <= 11 for x, y in zip(arr, arr[1:])):
print("NO")
else:
print("YES")
st = 0
for i in range(len(arr) - 1):
en = arr[i] + (1 if arr[i + 1] - arr[i] - 1 < 4 else 3) + 1
print(s[st:en])
st = en
if st < n:
print(s[st:]) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input().split(".")
if len(s) == 1:
print("NO")
exit()
elif len(s[0]) > 8 or len(s[0]) == 0:
print("NO")
exit()
D = []
a = s[0]
for i in range(1, len(s) - 1):
if len(s[i]) <= 1:
print("NO")
exit()
elif len(s[i]) > 11:
print("NO")
exit()
else:
b = s[i][: min(len(s[i]) - 1, 3)]
D.append(a + "." + b)
a = s[i][min(len(s[i]) - 1, 3) :]
if len(s[-1]) > 3 or len(s[-1]) < 1:
print("NO")
exit()
D.append(a + "." + s[-1])
print("YES")
for i in D:
print(i) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | q = []
def is_valid(s, n):
first_dot = 0
last_dot = n - 1
for i in range(n):
if s[i] == ".":
break
first_dot += 1
for i in range(n - 1, -1, -1):
if s[i] == ".":
break
last_dot -= 1
if first_dot > last_dot:
return False
if first_dot > 8 or first_dot == 0 or n - 1 - last_dot == 0 or n - 1 - last_dot > 3:
return False
cnt = 0
for i in range(first_dot + 1, last_dot + 1):
if s[i] == ".":
if cnt > 11 or cnt <= 1:
return False
q.append(cnt)
cnt = 0
continue
cnt += 1
return True
s = input()
n = len(s)
if not is_valid(s, n):
print("NO")
exit()
print("YES")
ans = ""
answer = []
for j in range(n):
if s[j] == ".":
break
ans += s[j]
for i in q:
if i >= 4:
for l in range(4):
ans += s[j]
j += 1
answer.append(ans)
ans = ""
else:
for l in range(2):
ans += s[j]
j += 1
answer.append(ans)
ans = ""
while s[j] != ".":
ans += s[j]
j += 1
while j < n:
ans += s[j]
j += 1
answer.append(ans)
print("\n".join(answer)) | ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR NUMBER VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR FOR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR VAR STRING VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | ar = input().split(".")
if len(ar[0]) > 8 or len(ar[-1]) > 3 or "" in ar or len(ar) < 2:
print("NO")
exit()
for i in range(len(ar)):
if len(ar[i]) > 11:
print("NO")
exit()
out = []
for i in range(len(ar) - 1):
t = min(len(ar[i + 1]) - 1, 3)
if t == 0 and i + 1 != len(ar) - 1:
print("NO")
exit()
if i + 1 == len(ar) - 1:
t = len(ar[i + 1])
out.append(ar[i] + "." + ar[i + 1][0:t])
ar[i + 1] = ar[i + 1][t:]
print("YES")
for i in range(len(out)):
print(out[i]) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = [x for x in input().split(".")]
if len(s) == 1:
print("NO")
exit(0)
file = s[0]
s = s[1:]
ending = s[-1]
s = s[:-1]
store = []
if len(file) == 0:
print("NO")
exit(0)
for x in s:
if len(x) > 11 or len(x) == 0:
print("NO")
exit(0)
if len(x) - 1 <= 8:
store.append(file + "." + x[:1])
file = x[1:]
elif len(x) - 2 <= 8:
store.append(file + "." + x[:2])
file = x[2:]
elif len(x) - 3 <= 8:
store.append(file + "." + x[:3])
file = x[3:]
if len(ending) == 0 or len(ending) > 3 or len(file) == 0 or len(file) > 8:
print("NO")
exit(0)
else:
store.append(file + "." + ending)
print("YES")
for x in store:
print(x) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | def s():
a = input().split(".")
ans = [a[0] + "."]
for i in range(1, len(a) - 1):
i = a[i]
if len(i) < 2 or len(i) > 11:
print("NO")
return
if len(i) > 3:
ans[-1] += i[:3]
ans.append(i[3:] + ".")
else:
ans[-1] += i[0]
ans.append(i[1:] + ".")
ans[-1] += a[-1]
if len(a) != len(ans) + 1:
print("NO")
return
for i in ans:
p = i.split(".")
if len(p) != 2:
print("NO")
return
if len(p[0]) < 1 or len(p[0]) > 8 or len(p[1]) < 1 or len(p[1]) > 3:
print("NO")
return
print("YES")
print("\n".join(ans))
s() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | from sys import exit
s = input()
n = len(s)
a = s.find(".")
b = s.rfind(".")
if a == b == -1:
print("NO")
exit()
if a == 0 or n - b - 1 == 0:
print("NO")
exit()
if not 0 < a < 9 or not 0 < n - b - 1 < 4:
print("NO")
exit()
s2 = s[a + 1 : b + 1]
res = [s[: a + 1]]
app = res.append
length, item = 0, ""
for i, x in enumerate(s2):
if x == ".":
if not 1 < length < 12:
print("NO")
exit()
k = 0
if length == 11:
res[-1] += item[:3]
k = 3
elif length == 10:
res[-1] += item[:2]
k = 2
else:
res[-1] += item[0]
k = 1
app(item[k:] + ".")
length, item = 0, ""
else:
length += 1
item += x
res[-1] += s[b + 1 :]
print("YES")
for i, x in enumerate(res):
print(x) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER STRING VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | import sys
def solve():
a = input().split(".")
if len(a) < 2:
print("NO")
return
res = [([""] * 2) for _ in range(len(a) - 1)]
res[0][0] = a[0]
res[len(res) - 1][1] = a[-1]
for i in range(1, len(a) - 1):
if len(a[i]) < 2:
print("NO")
return
extension = min(3, len(a[i]) - 1)
res[i - 1][1] = a[i][:extension]
res[i][0] = a[i][extension:]
for f, s in res:
if len(f) < 1 or len(f) > 8 or len(s) < 1 or len(s) > 3:
print("NO")
return
print("YES")
print("\n".join(".".join(entry) for entry in res))
def prt(l):
return print(" ".join(l))
def rv():
return map(int, input().split())
def rl(n):
return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
sys.stdin = open("test.txt")
solve() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST STRING NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR FOR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
s = s.split(".")
f = 0
if (len(s[0]) <= 8 and len(s[0]) >= 1) and (len(s[-1]) <= 3 and len(s[-1]) >= 1):
pass
else:
f = 1
if len(s) < 2:
f = 1
for i in range(1, len(s) - 1):
if len(s[i]) <= 11 and len(s[i]) > 1:
pass
else:
f = 1
if f == 1:
print("NO")
else:
print("YES")
prev = 0
last = s[0] + "."
for i in range(1, len(s) - 1):
if len(s[i]) >= 9:
last += s[i][: len(s[i]) - 8]
print(last)
last = s[i][len(s[i]) - 8 :] + "."
else:
last += s[i][0]
print(last)
last = s[i][1:] + "."
print(last + s[-1]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
arr = s.split(".")
for i in arr:
if len(i) == 0:
print("NO")
exit(0)
if len(arr) < 2:
print("NO")
exit(0)
ans = [""]
ans[0] = arr[0]
for i in range(1, len(arr) - 1, 1):
ans.append("")
if len(arr[i]) > 3:
ans[i - 1] = ans[i - 1] + "." + arr[i][:3]
ans[i] = arr[i][3:]
else:
ans[i - 1] = ans[i - 1] + "."
ans[i] = ""
if len(arr[i]) == 1:
ans[i] += arr[i]
elif len(arr[i]) == 2:
ans[i - 1] += arr[i][0]
ans[i] += arr[i][1]
elif len(arr[i]) == 3:
ans[i - 1] += arr[i][:2]
ans[i] += arr[i][2]
ans[len(ans) - 1] += "." + arr[len(arr) - 1]
for i in ans:
x = i.split(".")
if len(x) != 2 or len(x[0]) < 1 or len(x[0]) > 8 or len(x[1]) < 1 or len(x[1]) > 3:
print("NO")
exit(0)
print("YES")
for i in ans:
print(i) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
words = s.split(".")
n = s.count(".")
numberOfWordsWithSizeLessThanTwo = len([x for x in words[1:-1] if len(x) < 2])
numberOfWordsWithSizeMoreThanEleven = len([x for x in words[1:-1] if len(x) > 11])
if len(words) == 1:
print("NO")
elif (
len(words[0]) < 1
or len(words[0]) > 8
or len(words[-1]) < 1
or len(words[-1]) > 3
or numberOfWordsWithSizeLessThanTwo != 0
or numberOfWordsWithSizeMoreThanEleven != 0
):
print("NO")
else:
s0 = words[0]
sn = words[-1]
s1 = ""
s2 = ""
print("YES")
for word in words[1:-1]:
if len(word) > 9:
s2 = word[-8:]
s1 = word[:-8]
else:
s1 = word[0]
s2 = word[1:]
res = s0 + "." + s1
print(res)
s0 = s2
print(s0 + "." + sn) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
n = len(s)
i = 0
x = []
ans = 1
for j in s:
if j == ".":
x.append(i)
i += 1
if not x:
print("NO")
elif x[0] == 0 or n - x[-1] - 1 > 3 or x[-1] == n - 1 or x[0] > 8:
print("NO")
else:
a = [s[: x[0] + 1]]
for i in range(1, len(x)):
if x[i] - x[i - 1] > 12 or x[i] - x[i - 1] < 3:
ans = 0
break
elif x[i] - x[i - 1] == 3:
a[-1] += s[x[i - 1] + 1 : x[i - 1] + 2]
a.append(s[x[i - 1] + 2 : x[i] + 1])
elif x[i] - x[i - 1] - 1 == 11:
a[-1] += s[x[i - 1] + 1 : x[i - 1] + 4]
a.append(s[x[i - 1] + 4 : x[i] + 1])
else:
a[-1] += s[x[i - 1] + 1 : x[i - 1] + 3]
a.append(s[x[i - 1] + 3 : x[i] + 1])
a[-1] += s[x[-1] + 1 :]
if ans:
print("YES")
for i in a:
print(i)
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
if s[0] == "." or s[-1] == ".":
print("NO")
quit()
s = s.split(".")
if len(s) == 1:
print("NO")
quit()
if not 1 <= len(s[-1]) <= 3 or not 1 <= len(s[0]) <= 8:
print("NO")
quit()
arr = [s[-1]]
s.pop()
n = len(s)
for i in range(n - 1, -1, -1):
p = len(s[i])
if i > 0 and not 2 <= p <= 11:
print("NO")
quit()
for k in range(1, 4):
if i > 0:
if 1 <= p - k <= 8:
arr[-1] = s[i][k:] + "." + arr[-1]
arr.append(s[i][:k])
break
else:
arr[-1] = s[0] + "." + arr[-1]
break
print("YES")
for item in arr[::-1]:
print(item) | ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | a = input().strip()
n = len(a)
possible = True
x = a.split(".")
y = []
y.append(x[0])
for i in range(1, len(x) - 1):
l = len(x[i])
if l == 1:
possible = False
else:
idx = min(3, l // 2)
y.extend([x[i][0:idx], x[i][idx:]])
y.append(x[-1])
n = len(y)
names = []
for i in range(1, n, 2):
n = y[i - 1] + "." + y[i]
if len(y[i - 1]) not in range(1, 8 + 1):
possible = False
if len(y[i]) not in range(1, 3 + 1):
possible = False
names.append(n)
z = ""
for i in names:
z += i
if a != z:
possible = False
if not possible:
print("NO")
else:
print("YES")
for n in names:
print(n) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input().strip().split(".")
d = {(2): 1, (3): 1, (4): 1, (5): 2, (6): 3, (7): 3, (8): 3, (9): 3, (10): 3, (11): 3}
if len(s) <= 1 or len(s[0]) > 8 or len(s[-1]) > 3 or len(s[0]) == 0 or len(s[-1]) == 0:
print("NO")
exit(0)
matches = []
for i in range(1, len(s) - 1):
if len(s[i]) not in d:
print("NO")
exit(0)
matches.append(s[i - 1] + "." + s[i][: d[len(s[i])]])
s[i] = s[i][d[len(s[i])] :]
matches.append(s[-2] + "." + s[-1])
print("YES")
for m in matches:
print(m) | ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
v = s.split(sep=".")
flen = len(v[0])
llen = len(v[-1])
if len(v) < 2:
print("NO")
elif not (flen >= 1 and flen <= 8):
print("NO")
elif not (llen >= 1 and llen <= 3):
print("NO")
else:
for i in range(1, len(v) - 1):
if not (len(v[i]) >= 2 and len(v[i]) <= 11):
print("NO")
exit()
print("YES")
print(v[0], end="")
print(".", end="")
for i in range(1, len(v) - 1):
a = v[i]
mi = min(3, len(a) - 1)
print(a[0:mi])
print(a[mi : len(a)], end="")
print(".", end="")
print(v[-1]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR NUMBER |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | import sys
def fail():
print("NO")
sys.exit()
parts = input().strip().split(".")
n = len(parts)
if n < 2:
fail()
result = (n - 1) * [None]
for i in range(1, n):
s, t = parts[i - 1], parts[i]
a, b = len(s), len(t)
if a < 1 or a > 8:
fail()
if b == 0:
fail()
c = max(1, min(3, b - 1))
t, parts[i] = t[:c], t[c:]
result[i - 1] = "%s.%s" % (s, t)
result[-1] += parts[-1]
if len(result[-1][result[-1].index(".") + 1 :]) > 3:
fail()
print("YES")
print("\n".join(result)) | IMPORT FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NONE FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP STRING VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER STRING NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = list(input().split("."))
if len(s) == 1:
print("NO")
exit()
x = s[0]
y = ""
ans = []
for i in range(1, len(s) - 1):
if not 1 <= len(x) <= 8:
print("NO")
exit()
if 2 <= len(s[i]) <= 3:
y = s[i][:1]
ans.append(x + "." + y)
x = s[i][1:]
elif 4 <= len(s[i]) <= 11:
y = s[i][:3]
ans.append(x + "." + y)
x = s[i][3:]
else:
print("NO")
exit()
y = s[-1]
if not (1 <= len(x) <= 8 and 1 <= len(y) <= 3):
print("NO")
exit()
else:
ans.append(x + "." + y)
print("YES")
print(*ans, sep="\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | a = input().split(".")
l = [[a[0]]]
for i in a[1:-1]:
m = min(3, len(i) - 1)
l[-1] += [i[:m]]
l += [[i[m:]]]
l[-1] += [a[-1]]
if len(a) < 2 or any(
len(i) not in range(1, 9) or len(j) not in range(1, 4) for i, j in l
):
print("NO")
else:
print("YES")
print("\n".join(".".join(i) for i in l)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST LIST VAR NUMBER FOR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER LIST VAR VAR VAR LIST LIST VAR VAR VAR NUMBER LIST VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
if s == ".":
print("NO")
elif "." not in s:
print("NO")
else:
arr = s.split(".")
if arr[-1] == "" or arr[0] == "":
print("NO")
else:
ans = []
flag = 0
for i in range(1, len(arr) - 1):
s1 = arr[i - 1]
s2 = arr[i]
if len(s1) <= 8 and len(s1) >= 1:
if len(s2) >= 2 and len(s2) <= 11:
if len(s2) <= 8:
s1 += "." + s2[0]
arr[i] = s2[1:]
elif len(s2) > 8:
index = len(s2) - 8
s1 += "." + s2[:index]
arr[i] = s2[index:]
ans.append(s1)
else:
print("NO")
flag = 1
break
else:
print("NO")
flag = 1
break
if flag == 0:
if len(arr[-1]) <= 3 and len(arr[-2]) <= 8:
ans.append(arr[-2] + "." + arr[-1])
print("YES")
for i in ans:
print(i)
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP STRING VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP STRING VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | import sys
s = sys.stdin.readline()
k = 0
a = 1
dp = []
e = 0
lendp = 0
r = ""
for x in s:
if x == ".":
dp += [k]
lendp += 1
if e == 0:
a = 0
if k > 8 or k == 0:
a = 1
break
e = 1
elif k > 11 or k <= 1:
a = 1
break
k = 0
else:
k += 1
if e == 1:
dp += [k]
if k == 1 or k > 4:
a = 1
if a == 1:
print("NO")
else:
j = 0
print("YES")
for i in range(lendp):
if dp[i + 1] > 3:
print(s[j : j + dp[i] + 4])
j += dp[i] + 4
dp[i + 1] -= 3 * (i < lendp)
elif dp[i + 1] == 2:
print(s[j : j + dp[i] + 2])
j += dp[i] + 2
dp[i + 1] -= i < lendp
else:
print(s[j : j + dp[i] + 3])
j += dp[i] + 3
dp[i + 1] -= 2 * (i < lendp) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR LIST VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR LIST VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input().split(".")
if len(s) > 1:
if len(s) == 2:
if 1 <= len(s[0]) <= 8 and 1 <= len(s[-1]) <= 3:
print("YES")
print(s[0] + "." + s[1])
else:
print("NO")
elif (
1 <= len(s[0]) <= 8
and 1
< len(min(s[1 : len(s) - 1], key=lambda x: len(x)))
<= len(max(s[1 : len(s) - 1], key=lambda x: len(x)))
<= 11
and 1 <= len(s[-1]) <= 3
):
print("YES")
for i in range(0, len(s) - 1):
if i == 0:
name = s[i]
ext = s[i + 1][: min(3, len(s[i + 1]) - 1)]
elif i == len(s) - 2:
name = s[i][len(ext) :]
ext = s[i + 1]
else:
name = s[i][len(ext) :]
ext = s[i + 1][: min(3, len(s[i + 1]) - 1)]
print(name + "." + ext)
else:
print("NO")
else:
print("NO") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | tokens = input().split(".")
if len(tokens) == 1:
print("NO")
quit()
if len(tokens[0]) > 8 or len(tokens[0]) == 0:
print("NO")
quit()
to_print = []
for token in range(1, len(tokens)):
if len(tokens[token]) == 0 or len(tokens[token]) > 11:
print("NO")
quit()
elif len(tokens[token]) < 2 and token != len(tokens) - 1:
print("NO")
quit()
elif token == len(tokens) - 1:
if len(tokens[token]) > 3:
print("NO")
quit()
else:
to_print.append(tokens[token - 1] + "." + tokens[token])
else:
num = len(tokens[token]) - 1 if len(tokens[token]) <= 3 else 3
to_print.append(tokens[token - 1] + "." + tokens[token][:num])
tokens[token] = tokens[token][num:]
print("YES")
for ans in to_print:
print(ans) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input()
words = []
n = len(s)
i = 0
j = 0
flag = 1
word = ""
while i < n and j < n and flag == 1:
if s[i] != ".":
word += s[i]
i += 1
elif 8 >= i - j >= 1:
word += "."
i += 1
if i < n - 2 and "." not in s[i : i + 4]:
word += s[i : i + 3]
i += 3
j = i
elif i < n - 1 and "." not in s[i : i + 3]:
word += s[i : i + 2]
i += 2
j = i
elif i < n and "." not in s[i : i + 2]:
word += s[i : i + 1]
i += 1
j = i
else:
flag = 0
break
words.append(word)
word = ""
else:
flag = 0
break
if flag == 0 or len(word) != 0:
print("NO")
else:
print("YES")
for x in words:
print(x) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR VAR VAR NUMBER IF NUMBER BIN_OP VAR VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | mas = list(input().split("."))
if len(mas) < 2:
print("NO")
exit(0)
if len(mas[0]) > 8 or len(mas[0]) < 1:
print("NO")
exit(0)
for i in range(1, len(mas) - 1):
if len(mas[i]) > 11 or len(mas[i]) < 2:
print("NO")
exit(0)
if len(mas[len(mas) - 1]) > 3 or len(mas[len(mas) - 1]) < 1:
print("NO")
exit(0)
print("YES")
k = 0
z = 0
for i in range(1, len(mas) - 1):
if len(mas[i]) == 11:
print(mas[i - 1][k:] + "." + mas[i][:3])
k = 3
elif len(mas[i]) == 10:
print(mas[i - 1][k:] + "." + mas[i][:2])
k = 2
elif len(mas[i]) == 9:
print(mas[i - 1][k:] + "." + mas[i][:1])
k = 1
else:
print(mas[i - 1][k:] + "." + mas[i][:1])
k = 1
print(mas[len(mas) - 2][k:] + "." + mas[len(mas) - 1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | b = input()
a = list(b.split("."))
c = 0
for i in range(len(b)):
if b[i] == ".":
c += 1
ans = []
temp = []
w = 1
na = len(a)
for i in range(len(a) - 1):
if (
len(a[i]) >= 1
and len(a[i]) <= 8
and len(a[i + 1]) >= 1
and len(a[i + 1]) <= 3
and i + 1 == na - 1
):
temp = a[i] + "." + a[i + 1]
a[i + 1] = a[i + 1]
ans.append(temp)
break
if len(a[i + 1]) > 3 and i + 1 == na - 1:
w = 0
if len(a[i]) >= 1 and len(a[i]) <= 8 and len(a[i + 1]) >= 4:
temp = a[i] + "." + a[i + 1][:3]
a[i + 1] = a[i + 1][3:]
ans.append(temp)
elif len(a[i]) >= 1 and len(a[i]) <= 8 and len(a[i + 1]) >= 2:
temp = a[i] + "." + a[i + 1][:1]
a[i + 1] = a[i + 1][1:]
ans.append(temp)
else:
w = 0
if len(a[len(a) - 1]) > 3:
w = 0
if c == len(ans) and w == 1 and na != 1:
print("YES")
for i in range(len(ans)):
print(ans[i])
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | ok = 1
s = input().split(".")
n = len(s)
ver = 0
if n < 2:
ok = 0
ver = 1
for i in range(1, n - 1):
t = s[i]
if not t.isalpha() or not t.islower() or len(t) < 2 or len(t) > 11:
ok = 0
ver = 2
break
t = s[0]
if not t.isalpha() or not t.islower() or len(t) < 1 or len(t) > 8:
ok = 0
ver = 3
t = s[n - 1]
if not t.isalpha() or not t.islower() or len(t) < 1 or len(t) > 3:
ok = 0
ver = 4
if ok == 0:
print("NO")
else:
print("YES")
if n == 2:
print(".".join(s))
else:
r = ["1", "2"]
m0 = len(s[0])
for i in range(1, n):
k = m0
m = len(s[i])
if m > 3:
m0 = m - 3
m = 3
elif i < n - 1:
m0 = m - 1
m = 1
l = len(s[i - 1])
r[0] = s[i - 1][l - k : l]
r[1] = s[i][0:m]
print(".".join(r)) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | s = input().split(".")
y = 0 < len(s[0]) < 9 and 0 < len(s[-1]) < 4 and len(s) > 1
for i in range(1, len(s) - 1):
if len(s[i]) < 2 or len(s[i]) > 11:
y = 0
print(["NO", "YES"][y])
if y < 1:
exit()
print(s[0], end="")
for i in range(1, len(s) - 1):
print(
"." + [s[i][0] + "\n" + s[i][1:], s[i][:3] + "\n" + s[i][3:]][len(s[i]) > 3],
end="",
)
print("." + s[-1]) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING LIST BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER |
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:
* name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;
* ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters.
For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.
Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.
Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.
Input
The input data consists of a single string s, its length is from 1 to 4Β·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').
Output
In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them.
If the solution does not exist, then print in a single line "NO" (without the quotes).
Examples
Input
read.meexample.txtb.cpp
Output
YES
read.m
eexample.t
xtb.cpp
Input
version.infontldrcontestdata.zip
Output
NO | def swap():
global flag, c
flag ^= 1
return [8, 3][flag]
s = input() + " "
if s[0] == ".":
exit(print("NO"))
flag, cur, ans, c = 0, "", [], 8
for i in range(len(s) - 2):
if s[i] == ".":
if s[i + 1] in ". " or s[i + 2] == ".":
exit(print("NO"))
c = swap()
cur = (cur + ".") * flag
elif (s[i + 1] == "." or not c) and flag:
ans.append(cur)
cur = s[i]
c = swap() - (c == 0)
elif c:
cur += s[i]
c -= 1
else:
exit(print("NO"))
if "." not in cur:
exit(print("NO"))
print("YES", *ans, cur, sep="\n") | FUNC_DEF VAR NUMBER RETURN LIST NUMBER NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER STRING LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR IF VAR BIN_OP VAR NUMBER STRING VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR STRING |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.