description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
poke = list(input())
st, cur = 0, 0
dct = {}
k = len(set(poke))
while len(dct) < k:
dct[poke[cur]] = dct.get(poke[cur], 0) + 1
cur += 1
ans = cur
while dct[poke[st]] > 1:
dct[poke[st]] -= 1
st += 1
ans = min(ans, cur - st)
for i in range(cur, n):
dct[poke[i]] += 1
while dct[poke[st]] > 1:
dct[poke[st]] -= 1
st += 1
ans = min(ans, i - st + 1)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
def createdict():
x = {}
for i in range(26):
x[chr(ord("a") + i)] = i
for i in range(26, 52):
x[chr(ord("A") + i - 26)] = i
return x
n = int(input().strip())
s = input().strip()
l = [[] for i in range(52)]
ts = set()
cs = set()
d = createdict()
for i in range(n):
if s[i] not in ts:
ts.add(s[i])
l[d[s[i]]].append(i)
for end in range(n):
if s[end] not in cs:
cs.add(s[end])
if ts & cs == ts:
break
ans = end + 1
flag = 0
for start in range(1, n):
c = s[start - 1]
while l[d[c]]:
if l[d[c]][0] < start:
del l[d[c]][0]
if len(l[d[c]]) == 0:
flag = 1
elif start <= l[d[c]][0] <= end:
break
else:
end = l[d[c]][0]
break
if flag:
break
ans = min(ans, end - start + 1)
print(ans)
|
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
t = set()
for i in range(n):
t.add(ord(s[i]))
l = len(t)
o = dict()
p = 0
i = 0
while p < l:
r = o.get(ord(s[i]), 0)
if r == 0:
o[ord(s[i])] = 1
p += 1
else:
o[ord(s[i])] += 1
i += 1
left = 0
minn = i - left
while True:
if o[ord(s[left])] > 1:
o[ord(s[left])] -= 1
left += 1
minn = min(minn, i - left)
else:
if i >= n:
break
o[ord(s[i])] += 1
i += 1
print(minn)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
apartments_nr = int(input())
idx___pockemon_type = list(input())
types_nr = len(set(idx___pockemon_type))
idx___mandatory = [(-1) for x in range(apartments_nr)]
type___last_met = {}
for type_ in set(idx___pockemon_type):
type___last_met[type_] = -1
type__idx___prev_idx = {}
for idx in range(apartments_nr):
type_ = idx___pockemon_type[idx]
type__idx___prev_idx[type_, idx] = type___last_met[type_]
type___last_met[type_] = idx
left_idx = 0
right_idx = 1
idx___mandatory[0] = 1
ans = apartments_nr
curr_catched = 1
while right_idx < apartments_nr:
idx___mandatory[right_idx] = 1
right_type = idx___pockemon_type[right_idx]
prev_idx = type__idx___prev_idx[right_type, right_idx]
if prev_idx != -1:
idx___mandatory[prev_idx] = 0
else:
curr_catched += 1
while idx___mandatory[left_idx] == 0:
left_idx += 1
right_idx += 1
if curr_catched == types_nr:
curr_ans = right_idx - left_idx
ans = min(ans, curr_ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
def calc(c):
if c >= "a" and c <= "z":
return ord(c) - ord("a")
return ord(c) - ord("A") + 26
n = int(input())
s = input()
was = [False] * 52
for i in range(n):
was[calc(s[i])] = True
go = [([10 * n] * 52) for i in range(n)]
for i in range(n - 1, -1, -1):
if i < n - 1:
for j in range(52):
go[i][j] = go[i + 1][j]
go[i][calc(s[i])] = i
res = 10 * n
for i in range(n):
curRight = i
for j in range(52):
if was[j]:
curRight = max(curRight, go[i][j])
res = min(res, curRight - i + 1)
print(res)
|
FUNC_DEF IF VAR STRING VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
c = set(s)
d = {i: (0) for i in c}
maks = 999999
l = 0
for i in range(n):
d[s[i]] += 1
if c != set():
if s[i] in c:
c.remove(s[i])
if c == set():
while True:
d[s[l]] -= 1
if d[s[l]] == 0:
c.add(s[l])
l += 1
break
l += 1
maks = min(maks, i - l + 2)
print(maks)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR WHILE NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = list(input())
types = len(set(s))
def check(l):
mp = dict()
for i in range(l):
if s[i] not in mp:
mp[s[i]] = 1
else:
mp[s[i]] += 1
if len(mp) == types:
return True
for i in range(l, n):
mp[s[i - l]] -= 1
if mp[s[i - l]] is 0:
mp.pop(s[i - l])
if s[i] not in mp:
mp[s[i]] = 1
else:
mp[s[i]] += 1
if len(mp) == types:
return True
return False
l, r = 1, n
while l < r:
mid = (l + r) // 2
if check(mid):
r = mid
else:
l = mid + 1
print(r)
|
ASSIGN 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_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
exi = [(0) for i in range(52)]
def fill(x):
if x.islower():
exi[ord(x) - 97] = 1
return ord(x) - 97
else:
exi[ord(x) - 65 + 26] = 1
return ord(x) - 65 + 26
arr = []
for c in s:
arr.append(fill(c))
now = [(0) for i in range(52)]
def check():
for i in range(52):
if exi[i]:
if exi[i] > now[i]:
return 0
return 1
first = 0
now[arr[first]] += 1
if check():
print(1)
return
min = n
for i in range(1, n):
now[arr[i]] += 1
for j in range(first, i):
if now[arr[j]] > 1:
first += 1
now[arr[j]] -= 1
else:
break
if check():
leng = i - first + 1
if min > leng:
min = leng
print(min)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
collected = {}
for pokemon in s:
collected[pokemon] = 0
first = 0
last = 0
collectedCount = 0
while collectedCount < len(collected):
if collected[s[last]] == 0:
collectedCount += 1
collected[s[last]] += 1
last += 1
min = last
while first < n:
if collectedCount == len(collected) and last - first < min:
min = last - first
collected[s[first]] -= 1
if collected[s[first]] == 0:
collectedCount -= 1
first += 1
while last < n and collectedCount < len(collected):
if collected[s[last]] == 0:
collectedCount += 1
collected[s[last]] += 1
last += 1
print(min)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
def main(n, s):
k = set()
for i in range(n):
k.add(s[i])
v = len(k)
h = dict()
for i in k:
h[i] = 0
l = 0
r = n
while l + 1 < r:
m = (l + r) // 2
f = False
for i in h:
h[i] = 0
x = 0
for i in range(m):
h[s[i]] += 1
if h[s[i]] == 1:
x += 1
if x == v:
f = True
else:
for i in range(m, n):
h[s[i - m]] -= 1
if h[s[i - m]] == 0:
x -= 1
h[s[i]] += 1
if h[s[i]] == 1:
x += 1
if x == v:
f = True
break
if f:
r = m
else:
l = m
print(r)
main(n, s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
abc = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
d = {x: (0) for x in abc}
i = 0
j = 0
ans = 100000000
ctd = len(set([i for i in s]))
for _ in s:
d[s[j]] += 1
if d[s[j]] == 1:
ctd -= 1
while d[s[i]] > 1:
d[s[i]] -= 1
i += 1
j += 1
if not ctd:
ans = min(ans, j - i)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
d = set()
p = {}
D = 0
for i in s:
if i not in d:
d.add(i)
p[i] = D
D += 1
def calc(k):
P = [0] * D
num = 0
for i in range(n):
if i >= k:
P[p[s[i - k]]] -= 1
if P[p[s[i - k]]] == 0:
num -= 1
if P[p[s[i]]] == 0:
P[p[s[i]]] += 1
num += 1
if num == D:
return True
else:
P[p[s[i]]] += 1
return False
l, r = 0, n
while r - l > 1:
mid = (l + r) // 2
if calc(mid):
r = mid
else:
l = mid
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
check = {}
size_check = set(x for x in s)
ans = 10**5
left = 0
for right in range(n):
if s[right] in check:
check[s[right]] += 1
else:
check[s[right]] = 1
while left < right and s[left] in check and check[s[left]] > 1:
check[s[left]] -= 1
left += 1
if len(check) == len(size_check):
if right - left + 1 < ans:
ans = right - left + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
def isAllOccurences(left, right):
global letters
global disLetters
for i in disLetters:
if (
letters[right][ord(i)] - (0 if left == 0 else letters[left - 1][ord(i)])
== 0
):
return False
return True
def binSolve(leftStart, rightStart):
left = leftStart
right = rightStart
mid = (left + right) // 2
lastAllOccurences = mid
while left <= right:
mid = (left + right) // 2
if isAllOccurences(leftStart, mid):
right = mid - 1
lastAllOccurences = mid
else:
left = mid + 1
return lastAllOccurences
n = int(input())
s = input()
letters = []
for _ in range(n):
letters.append([0] * 256)
letters[0][ord(s[0])] = 1
disLetters = [s[0]]
for i, x in enumerate(s[1:]):
for j in range(ord("a"), ord("z") + 1):
letters[i + 1][j] = letters[i][j]
for j in range(ord("A"), ord("Z") + 1):
letters[i + 1][j] = letters[i][j]
if letters[i + 1][ord(x)] == 0:
disLetters.append(x)
letters[i + 1][ord(x)] += 1
globalMin = 1000000
for left in range(n):
right = binSolve(left, len(s) - 1)
if isAllOccurences(left, right):
if abs(right - left + 1) < globalMin:
globalMin = abs(right - left + 1)
print(globalMin)
|
FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
a = list(input())
p = len(set(a))
l, i, j = 0, 0, 0
b = []
c = {}
while i < n or j < n:
if l == p:
b.append(j - i)
c[a[i]] -= 1
if c[a[i]] == 0:
l = l - 1
i = i + 1
elif j < n:
while l != p and j < n:
if a[j] in c:
if c[a[j]] == 0:
l = l + 1
c[a[j]] = c[a[j]] + 1
else:
c[a[j]] += 1
else:
l += 1
c[a[j]] = 1
j += 1
else:
i += 1
print(min(b))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR DICT WHILE VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
def pro():
n = int(input())
s = input()
l = 0
r = 0
p = len(set(s))
m = 100001
y = len(s)
k = set(s[0])
d = dict()
d[s[0]] = d.get(s[0], 0) + 1
while r < y:
if len(k) < p:
r += 1
if r < y:
k.add(s[r])
d[s[r]] = d.get(s[r], 0) + 1
else:
m = min(m, r - l + 1)
if d[s[l]] == 1:
d[s[l]] = 0
k.remove(s[l])
else:
d[s[l]] -= 1
l += 1
print(m)
pro()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
all_types = set()
count = {}
for c in s:
all_types.add(c)
count[c] = 0
n_all_types = len(all_types)
def solve():
ret = n
first = 0
last = 0
n_types = 0
while first <= last:
while n_types < n_all_types:
if last == n:
return ret
if count[s[last]] == 0:
n_types += 1
count[s[last]] += 1
last += 1
ret = min(ret, last - first)
if count[s[first]] == 1:
n_types -= 1
count[s[first]] -= 1
first += 1
return ret
print(solve())
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR IF VAR VAR RETURN VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
flats = input()
ans = n
count = {}
for c in flats:
count[c] = 0
all_char = len(count)
j = 0
exist = 0
for i in range(n):
while j < n and exist < all_char:
if count[flats[j]] == 0:
exist += 1
count[flats[j]] += 1
j += 1
if exist == all_char:
ans = min(ans, j - i)
else:
break
count[flats[i]] -= 1
if count[flats[i]] == 0:
exist -= 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
letters = set()
for i in range(len(s)):
letters.add(s[i])
magic = 1000000000
length = [0] * len(s)
for c in letters:
last = -1
for i in range(len(s)):
if s[i] == c:
last = i
if last == -1:
length[i] = magic
else:
length[i] = max(length[i], i - last + 1)
ans = magic
for i in range(len(s)):
if length[i] < ans:
ans = length[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
from sys import stdin
def main():
n = int(stdin.readline())
ville = stdin.readline()
minimum = n
maisons = {}
nbType = 0
for maison in ville:
if maison != "\n" and maison not in maisons:
maisons[maison] = 0
nbType += 1
nbZeros = nbType - 1
inf = 0
sup = 0
maisons[ville[0]] += 1
while n > sup:
if nbZeros == 0:
minimum = min(minimum, sup - inf + 1)
maisons[ville[inf]] -= 1
if maisons[ville[inf]] == 0:
nbZeros += 1
inf += 1
else:
sup += 1
if n > sup:
maisons[ville[sup]] += 1
if maisons[ville[sup]] == 1:
nbZeros -= 1
print(minimum)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n, s = int(input()), input()
p, q, r = len(set(s)), {}, 10**6
for i in range(n):
q[s[i]] = i
if len(q) == p:
r = min(r, max(q.values()) - min(q.values()))
print(r + 1)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR DICT BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
flat_num = int(input())
flats = input()
types = set(flats)
lo = 0
hi = flat_num
valid = -1
while lo <= hi:
mid = (lo + hi) // 2
all_catchable = False
curr_caught = {}
for to_add in range(flat_num):
if flats[to_add] not in curr_caught:
curr_caught[flats[to_add]] = 0
curr_caught[flats[to_add]] += 1
if to_add >= mid:
to_remove = flats[to_add - mid]
curr_caught[to_remove] -= 1
if curr_caught[to_remove] == 0:
del curr_caught[to_remove]
if len(curr_caught) == len(types):
all_catchable = True
break
if all_catchable:
valid = mid
hi = mid - 1
else:
lo = mid + 1
print(valid)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n, s = int(input()), input()
dis = len(set(s))
mp = {}
l, r, m, cnt = 0, 0, 99999999, 0
for c in s:
if c not in mp:
mp[c] = 0
cnt += 1
mp[c] += 1
if cnt == dis:
while mp[s[l]] > 1:
mp[s[l]] -= 1
l += 1
m = min(m, r - l + 1)
r += 1
print(m)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
h = input()
n = len(h)
if n == 1:
print(1)
exit()
symbols = {}
for c in h:
if c not in symbols:
symbols[c] = 0
symbols[c] += 1
K = len(symbols)
symbols = symbols.fromkeys(symbols, 0)
l, r = 0, 0
m = 100001
s = set()
while l < n:
while r < n and len(s) < K:
s.add(h[r])
symbols[h[r]] += 1
r += 1
if len(s) >= K:
m = min(m, r - l)
if symbols[h[l]] == 1:
s.remove(h[l])
symbols[h[l]] -= 1
l += 1
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
def calculate_ans(flats):
needed, shortest = len(set(flats)), len(flats)
counter = dict()
ind1, ind2 = 0, 0
while ind1 < len(flats):
if len(counter.keys()) == needed:
shortest = min(shortest, ind2 - ind1)
counter[flats[ind1]] -= 1
if counter[flats[ind1]] == 0:
del counter[flats[ind1]]
ind1 += 1
else:
if ind2 == len(flats):
break
if flats[ind2] in counter:
counter[flats[ind2]] += 1
else:
counter[flats[ind2]] = 1
ind2 += 1
return shortest
_ = input()
print(calculate_ans(input()))
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
types = set(list(s))
current_d = {}
i = j = 0
mn = len(s)
check = False
while j < n:
while j < n and set(current_d) != types:
current_d[s[j]] = current_d.get(s[j], 0) + 1
j += 1
while set(current_d) == types:
check = True
current_d[s[i]] -= 1
if not current_d[s[i]]:
del current_d[s[i]]
i += 1
if check:
mn = min(j - i + 1, mn)
print(mn)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
a = set(s)
N = len(a)
ans = 100000000
a = set()
b = dict()
l = 0
r = 0
while r != n:
if len(a) == N - 1 and s[l] not in a:
ans = min(ans, r - l + 1)
if s[l] in a:
l += 1
b[s[l]] -= 1
if b[s[l]] == 0:
a.remove(s[l])
else:
r += 1
if r != n:
if s[r] not in b.keys():
b[s[r]] = 1
else:
b[s[r]] += 1
a.add(s[r])
else:
if len(a) == N:
while len(a) == N:
a.remove(s[l])
l += 1
else:
ans = min(ans, r - l)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = str(input())
m = {}
for i in s:
m[i] = 0
d = len(m.keys()) - 1
l = 0
m[s[0]] = 1
answer = n
for i in range(1, len(s)):
if m[s[i]] == 0:
m[s[i]] = 1
d -= 1
else:
m[s[i]] += 1
if d == 0:
answer = min(answer, i - l + 1)
for j in range(l, i + 1):
if m[s[j]] == 1:
l = j
answer = min(answer, i - l + 1)
break
m[s[j]] -= 1
else:
l = i
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
p = set()
for c in s:
p.add(c)
pc = len(p)
d = dict()
l = 0
r = 0
d[s[r]] = 1
while len(d) < pc:
r += 1
if s[r] in d:
d[s[r]] += 1
else:
d[s[r]] = 1
m = r - l
while l + 1 < n:
d[s[l]] -= 1
if d[s[l]] == 0:
del d[s[l]]
l += 1
while r + 1 < n and len(d) < pc:
r += 1
if s[r] in d:
d[s[r]] += 1
else:
d[s[r]] = 1
if len(d) < pc:
break
m = min(m, r - l)
print(m + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
p = {}
c = set(s)
L = 0
k = n
for R in range(n):
p[s[R]] = p.get(s[R], 0) + 1
if p[s[R]] == 1:
c.discard(s[R])
while L <= R and p[s[L]] > 1:
p[s[L]] -= 1
L += 1
if len(c) == 0:
k = min(k, R - L + 1)
print(k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
def calc(l1, set1):
leftMost = 0
dict1 = {}
shortestInterval = float("inf")
for right in range(len(l1)):
if l1[right] not in dict1:
dict1[l1[right]] = 0
dict1[l1[right]] += 1
while leftMost + 1 <= right and dict1[l1[leftMost]] > 1:
dict1[l1[leftMost]] -= 1
leftMost += 1
if len(dict1) == len(set1):
shortestInterval = min(shortestInterval, right - leftMost + 1)
return shortestInterval
def main():
n = int(input())
l1 = input()
set1 = set(l1)
ans = calc(l1, set1)
print(ans)
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = input()
houses = input()
houses = houses[0 : int(n)]
tmp = []
tmpCount = 0
for a in houses:
if a not in tmp:
tmpCount = tmpCount + 1
tmp.append(a)
ddd = {}
totalTypes = 0
def addPok(c):
global totalTypes
if c not in ddd:
totalTypes = totalTypes + 1
ddd[c] = 1
else:
if ddd[c] == 0:
totalTypes = totalTypes + 1
ddd[c] = ddd[c] + 1
def peekRemove(c):
if c in ddd:
if ddd[c] > 1:
return True
else:
return False
def removePok(c):
if c in ddd:
ddd[c] = ddd[c] - 1
if ddd[c] == 0:
totalTypes = totalTypes - 1
h = -1
t = -1
minAns = None
t = t + 1
while t < len(houses):
addPok(houses[t])
if totalTypes == tmpCount:
while h < t and peekRemove(houses[h + 1]):
removePok(houses[h + 1])
h = h + 1
if minAns == None or minAns > t - h:
minAns = t - h
t = t + 1
print(minAns)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NONE VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 β€ n β€ 100 000) β the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
n = int(input())
s = input()
se = set()
d = dict()
k = 0
for i in s:
if i not in se:
se.add(i)
k += 1
d[i] = 0
queue = []
mi = 100000000000
cnt = 0
for i in range(n):
if d[s[i]] == 0:
cnt += 1
d[s[i]] += 1
queue.append(i)
while cnt == k:
temp = i - queue[0] + 1
mi = min(mi, temp)
x = queue.pop(0)
d[s[x]] -= 1
if d[s[x]] == 0:
cnt -= 1
print(mi)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19
|
n = int(input())
if n < 3:
print(1)
else:
fail = []
x = 0
y = (n // 3 + 1) * 2
while y >= x:
while 4 * n * n >= (3 * y + 2) * (3 * y + 2) + 3 * x * x:
x += 2
fail.append((x, y))
if x:
x -= 1
else:
x = 1
y -= 1
total = 0
for x, y in fail:
if x >= y + 2:
total += y
elif x > 1:
total += x - 1
while y > 1:
y -= 1
total += y
print(total * 6 + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR WHILE BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
input_ = list(map(int, input().split()))
pos = n
a = [(0) for i in range(n + 1)]
res = 1
ans = [1]
for x in input_:
a[x] = 1
res += 1
while a[pos] == 1:
pos -= 1
res -= 1
ans.append(res)
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 VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
p = list(map(int, input().split()))
lp = n + 1
ans = [1]
vis = [(0) for i in range(n)]
ans = [1]
top = n
hardness = 1
for i in range(len(p)):
vis[p[i] - 1] = 1
hardness += 1
while vis[top - 1] == 1 and top > 0:
top -= 1
hardness -= 1
ans.append(hardness)
print(" ".join([str(i) for i in ans]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
l = list(map(int, input().split()))
p = n
iss = set()
ans = [1]
out = 1
for i in range(n):
if l[i] == p:
p -= 1
while p in iss:
p -= 1
out -= 1
ans.append(out)
else:
iss.add(l[i])
out += 1
ans.append(out)
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
x = [0] * n
a = 0
p = list(map(int, input().split()))
z = n - 1
ans = ["1"]
for i in range(n):
x[p[i] - 1] = 1
a += 1
while z > -1 and x[z] == 1:
z -= 1
a -= 1
ans.append(str(a + 1))
print(" ".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
l = list(map(int, input().split()))
print(1, end=" ")
ptr = n - 1
v = [0] * n
for i in range(n):
v[l[i] - 1] = 1
while ptr >= 0 and v[ptr] == 1:
ptr -= 1
print(i + 1 - (n - 1 - ptr) + 1, end=" ")
|
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 NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
p = [int(x) for x in input().split()]
mx = n
a = [0] * (n + 1)
ans = [1]
for i in range(0, n):
t = p[i]
a[t] = 1
while a[mx] == 1 and mx >= 1:
mx -= 1
ans.append(i + 1 - (n - mx) + 1)
print(" ".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
P = list(map(int, input().split()))
P[:] = [(x - 1) for x in P]
lst = [0] * n
i = 0
S = n - 1
ans = [1] * (n + 1)
while i < n:
lst[P[i]] = 1
if P[i] == S:
k = 0
while k == 0:
S += -1
if lst[S] == 0 or S == -1:
k = 1
i += 1
ans[i] = i - n + S + 2
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 BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
positions = [int(x) for x in input().split(" ")]
output = "1 "
pointer_to_right_wall = n - 1
coins = [(False) for i in range(len(positions))]
filled = 1
for i in range(len(positions)):
coins[positions[i] - 1] = True
if positions[i] - 1 == pointer_to_right_wall:
count = 0
while coins[pointer_to_right_wall] == True:
if pointer_to_right_wall == 0 and coins[0] == True:
count += 1
break
pointer_to_right_wall -= 1
count += 1
filled = filled - count + 1
else:
filled += 1
output += str(filled) + " "
print(output[:-1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
arr = list(map(int, input().split()))
ar2 = [False] * (n + 2)
ar2[-1] = True
res = [1]
acc = 1
ptr = n
for e in arr:
ar2[e] = True
acc += 1
while ar2[ptr]:
ptr -= 1
res.append(acc - (n - ptr))
print(*res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
used = [(0) for i in range(n)]
right, cnt = n, 0
ans = 1
stdout.write(str(ans) + " ")
for v in values:
used[v - 1] = 1
ans += 1
while right and used[right - 1]:
ans -= 1
right -= 1
stdout.write(str(ans) + " ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))
flag = [1] * n
r = n - 1
cnt = 0
print(1, end=" ")
for i in range(n - 1):
flag[p[i] - 1] = 0
while flag[r] == 0:
r -= 1
cnt += 1
print(i + 2 - cnt, end=" ")
print(1)
|
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 VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR NUMBER
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
def f(n, a):
a = list(map(lambda s: s - 1, a))
ar = [0] * (n + 1)
l = 0
ans = [1]
hi = n - 1
cnt = 0
for i in a:
if i == hi:
ar[i] = 1
hi -= 1
while ar[hi] == 1:
hi -= 1
cnt -= 1
else:
ar[i] = 1
cnt += 1
ans.append(cnt + 1)
return ans
a = int(input())
ls = list(map(int, input().strip().split()))
print(*f(a, ls))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 β€ n β€ 300 000)Β β number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 β€ p_{i} β€ n)Β β positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X β coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO β OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO β OXOX β OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX β OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
|
n = int(input())
a = list(map(int, input().split()))
p = [0] * (n + 1)
ans = [1] * (n + 1)
ind = n
for i in range(n):
p[a[i] - 1] = 1
while ind > 0 and p[ind - 1] == 1:
ind -= 1
ans[i + 1] = 1 + (i + 1) - (n - ind)
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
from sys import stdin
def main():
a, b, k = map(int, stdin.readline().split())
check = [True] * (10**6 + 1)
check[1] = False
check[0] = False
index = 2
bound = 10**6
while index * index <= bound:
if check[index]:
for i in range(index * index, bound + 1, index):
check[i] = False
index += 1
dp = [0] * (bound + 1)
for i in range(2, bound + 1):
if check[i]:
dp[i] = dp[i - 1] + 1
else:
dp[i] = dp[i - 1]
low = 0
high = b - a + 2
while low < high:
mid = low + high >> 1
ok = True
for i in range(a, b - mid + 2):
if dp[i + mid - 1] - dp[i - 1] < k:
ok = False
break
if ok:
high = mid
else:
low = mid + 1
print(low if low <= b - a + 1 else -1)
main()
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
a, b, k = map(int, input().split())
prime = [True] * (b + 1)
p = []
for i in range(2, b + 1):
if prime[i]:
if i >= a:
p.append(i)
for j in range(i, b + 1, i):
prime[j] = False
if len(p) < k:
print(-1)
else:
arr1 = [(p[i] - p[i - k]) for i in range(k, len(p))]
arr2 = [b - p[-k] + 1, p[k - 1] - a + 1]
arr = arr1 + arr2
print(max(arr))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
def f(a, b):
t = [1] * (b + 1)
for i in range(3, int(b**0.5) + 1):
if t[i]:
t[i * i :: 2 * i] = [0] * ((b - i * i) // (2 * i) + 1)
return [i for i in range(3, b + 1, 2) if t[i] and i > a]
a, b, k = map(int, input().split())
p = f(a - 1, b)
if 3 > a and b > 1:
p = [2] + p
if k > len(p):
print(-1)
elif len(p) == k:
print(max(p[k - 1] - a + 1, b - p[0] + 1))
else:
print(
max(
p[k - 1] - a + 1,
b - p[len(p) - k] + 1,
max(p[i + k] - p[i] for i in range(len(p) - k)),
)
)
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER RETURN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
def isprime(a):
if a < 2:
return False
if a == 2:
return True
for h in range(2, int(a**0.5) + 1):
if a % h == 0:
return False
return True
a, b, k = map(int, input().split())
arr = []
for g in range(a, b + 1):
if isprime(g):
arr += [g]
check = a
ptr1 = -1
ptr2 = 0
count = 0
n = len(arr)
maxm = 0
if n < k:
print(-1)
else:
while ptr2 < n:
count += 1
if count >= k:
if count == k:
maxm = max(maxm, arr[ptr2] - check + 1)
maxm = max(maxm, arr[ptr2] - check)
ptr1 += 1
check = arr[ptr1]
ptr2 += 1
if arr[-1] < b:
maxm = max(maxm, b - check + 1)
print(maxm)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
p = [1] * 1000005
p[0] = 0
p[1] = 0
for i in range(2, 1001):
if p[i]:
for j in range(2 * i, 1000005, i):
p[j] = 0
for i in range(1, 1000001):
p[i] += p[i - 1]
a, b, k = map(int, input().split())
if p[b] - p[a - 1] < k:
print(-1)
return ()
i = j = a
l = 0
while j <= b:
if p[j] - p[i - 1] < k:
j += 1
else:
l = max(l, j - i + 1)
i += 1
l = max(j - i + 1, l)
print(l)
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
N = 10**6 + 6
primes = [1] * N
p = 2
while p * p <= N:
if primes[p]:
for j in range(p * p, N, p):
primes[j] = 0
p += 1
primes[1] = primes[0] = 0
def fn(x):
for i in range(n - x + 1):
ones = aa[i + x - 1] - (aa[i - 1] if i >= 1 else 0)
if ones < k:
return False
return True
for _ in range(1):
a, b, k = lst()
n = b - a + 1
l = 1
r = b - a + 1
aa = [0] * (b - a + 1)
c = 0
for i in range(a, b + 1):
aa[c] = primes[i] + aa[max(0, c - 1)]
c += 1
while l <= r:
mid = l + r >> 1
if fn(mid) == False:
l = mid + 1
else:
r = mid - 1
print(l if l <= n else -1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
a, b, k = list(map(int, input().split()))
c = [1] * b
c[0] = 0
for i in range(1, b):
if c[i]:
for j in range(2 * i + 1, b, i + 1):
c[j] = 0
l = -1
i, j = a - 1, a - 2
x = 0
m = b + 1
while j < b:
if x < k:
j += 1
if j < b:
x += c[j]
elif x == k:
m = i
l = max(l, j - i + 1)
x -= c[i]
i += 1
l = max(l, b - m)
print(l)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
def f(n):
m = int(n**0.5) + 1
t = [1] * (n + 1)
for i in range(3, m):
if t[i]:
t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)
return [2] + [i for i in range(3, n + 1, 2) if t[i]]
a, b, k = map(int, input().split())
n = 2000001
t, p, x = [-1] * n, f(n), -1
k -= 1
b += 1
for i in range(len(p) - k):
t[p[i]] = p[i + k] - p[i]
t.reverse()
for i in range(1, n):
if t[i] < 0:
t[i] = t[i - 1] + 1
t.reverse()
for i in range(a + 1, b):
t[i] = max(t[i], t[i - 1])
for l in range(1, b - a + 1):
if t[b - l] < l:
x = l
break
print(x)
|
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER RETURN BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
I = lambda: map(int, input().split())
visited = [(False) for i in range(10**6 + 1)]
a, b, k = I()
visited[1] = True
li = []
for i in range(2, int(b**0.5) + 1):
if visited[i] == False:
for j in range(i + i, b + 1, i):
visited[j] = True
for i in range(a, b + 1):
if visited[i] == False:
li.append(i)
ans = 0
maxx = 0
t1 = a
if len(li) < k:
print("-1")
return
n = len(li)
for i in range(n - k + 1):
ans = li[i + k - 1] - t1 + 1
maxx = max(maxx, ans)
t1 = li[i] + 1
ww = b - li[-k] + 1
maxx = max(ww, maxx)
print(maxx)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a β€ b). You want to find the minimum integer l (1 β€ l β€ b - a + 1) such that for any integer x (a β€ x β€ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 β€ a, b, k β€ 10^6;Β a β€ b).
-----Output-----
In a single line print a single integer β the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
|
p1000 = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
151,
157,
163,
167,
173,
179,
181,
191,
193,
197,
199,
211,
223,
227,
229,
233,
239,
241,
251,
257,
263,
269,
271,
277,
281,
283,
293,
307,
311,
313,
317,
331,
337,
347,
349,
353,
359,
367,
373,
379,
383,
389,
397,
401,
409,
419,
421,
431,
433,
439,
443,
449,
457,
461,
463,
467,
479,
487,
491,
499,
503,
509,
521,
523,
541,
547,
557,
563,
569,
571,
577,
587,
593,
599,
601,
607,
613,
617,
619,
631,
641,
643,
647,
653,
659,
661,
673,
677,
683,
691,
701,
709,
719,
727,
733,
739,
743,
751,
757,
761,
769,
773,
787,
797,
809,
811,
821,
823,
827,
829,
839,
853,
857,
859,
863,
877,
881,
883,
887,
907,
911,
919,
929,
937,
941,
947,
953,
967,
971,
977,
983,
991,
997,
]
sieve = [True] * 1000001
for i in p1000:
for j in range(2 * i, 1000001, i):
sieve[j] = False
k = [0] * 1000001
for i in range(2, 1000001):
if sieve[i]:
k[i] = k[i - 1] + 1
else:
k[i] = k[i - 1]
def primes(a, b):
return k[b] - k[a - 1]
a, b, kk = list(map(int, input().split(" ")))
lo = 0
hi = 1000000
while lo < hi:
mid = (lo + hi) // 2
ok = True
for x in range(a, b - mid + 2):
if primes(x, x + mid - 1) < kk:
ok = False
if ok:
hi = mid
else:
lo = mid + 1
if primes(a, b) < kk:
print(-1)
else:
print(lo)
|
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
s1 = input()
s2 = input()
l1 = len(s1)
l2 = len(s2)
dl = {}
dr = {}
i1 = 0
i2 = 0
while i1 < l1 and i2 < l2:
while i1 < l1 and s1[i1] != s2[i2]:
i1 += 1
if i1 < l1:
dl[i2] = i1
i2 += 1
i1 += 1
lmax = i2
if lmax == l2:
print(s2)
else:
i1 = l1 - 1
i2 = l2 - 1
while i1 >= 0 and i2 >= 0:
while i1 >= 0 and s1[i1] != s2[i2]:
i1 -= 1
if i1 >= 0:
dr[i2] = i1
i2 -= 1
i1 -= 1
rmax = i2
le = -1
re = -1
if l2 - lmax < rmax + 1:
rcnt = l2 - lmax
ls = 0
rs = lmax
else:
rcnt = rmax + 1
ls = rmax + 1
rs = l2
rr = rmax + 1
for ll in range(lmax):
while rr < l2 and (rr <= ll or dl[ll] >= dr[rr]):
rr += 1
if rr < l2:
dif = rr - ll - 1
if dif < rcnt:
rcnt = dif
ls = 0
rs = ll + 1
le = rr
re = l2
result = s2[ls:rs]
if le != -1:
result += s2[le:re]
print(result if len(result) > 0 else "-")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR STRING
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
from sys import stdin
def main():
t = stdin.readline()
s = stdin.readline()
n = len(s) - 1
m = len(t) - 1
post = [-1] * n
ss = n - 1
st = m - 1
while st >= 0 and ss >= 0:
if t[st] == s[ss]:
post[ss] = st
ss -= 1
st -= 1
pre = [-1] * n
ss = 0
st = 0
while st < m and ss < n:
if t[st] == s[ss]:
pre[ss] = st
ss += 1
st += 1
low = 0
high = n
min_ans = n
start = -1
end = -1
while low < high:
mid = low + high >> 1
ok = False
if post[mid] != -1:
if mid < min_ans:
min_ans = mid
start = 0
end = mid - 1
ok = True
for i in range(1, n - mid):
if pre[i - 1] != -1 and post[i + mid] != -1 and post[i + mid] > pre[i - 1]:
if mid < min_ans:
min_ans = mid
start = i
end = i + mid - 1
ok = True
if pre[n - mid - 1] != -1:
if mid < min_ans:
min_ans = mid
start = n - mid
end = n - 1
ok = True
if not ok:
low = mid + 1
else:
high = mid
ans = []
for i in range(n):
if start <= i <= end:
continue
ans.append(s[i])
if min_ans == n:
print("-")
else:
print("".join(ans))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a = list(input())
b = list(input())
s = [-1]
i = 0
j = 0
while i < len(a) and j < len(b):
if a[i] == b[j]:
s.append(i)
j += 1
i += 1
e = [10**6]
i = len(a) - 1
j = len(b) - 1
while i >= 0 and j >= 0:
if a[i] == b[j]:
e.append(i)
j -= 1
i -= 1
ans_len = 0
ans = ["-"]
i = len(s) - 1
j = 0
while i >= 0 and j < len(e):
if s[i] < e[j] and i + j - 1 < len(b):
new_len = j + i
if new_len > ans_len:
ans_len = new_len
if j > 0:
ans = b[:i] + b[-j:]
else:
ans = b[:i]
j += 1
else:
i -= 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a = input()
b = input()
x = []
j = 0
for i in range(len(a)):
if j >= len(b):
break
if a[i] == b[j]:
x.append(i)
j += 1
y = []
j = len(b) - 1
for i in range(len(a) - 1, -1, -1):
if j < 0:
break
if a[i] == b[j]:
y.append(len(a) - i - 1)
j -= 1
lb, rb = 0, 0
ans = len(b)
if ans > len(b) - len(x):
ans = len(b) - len(x)
lb = len(x)
if ans > len(b) - len(y):
ans = len(b) - len(y)
lb = 0
rb = len(y)
j = len(y) - 1
for i in range(len(x)):
if i + j + 2 > len(b):
j -= 1
while j >= 0 and x[i] + y[j] + 2 > len(a):
j -= 1
if j < 0:
break
if ans > len(b) - i - j - 2:
ans = len(b) - i - j - 2
lb = i + 1
rb = j + 1
if ans == len(b):
print("-")
else:
for i in range(lb):
print(b[i], end="")
for i in range(len(b) - rb, len(b)):
print(b[i], end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a = input()
b = input()
pre = [len(a) for i in range(len(b))]
suf = [(-1) for i in range(len(b))]
temp = 0
whole = 0
for i in range(len(a)):
if b[temp] == a[i]:
pre[temp] = i
temp += 1
if temp == len(b):
whole = 1
break
temp = len(b) - 1
for i in range(len(a) - 1, -1, -1):
if b[temp] == a[i]:
suf[temp] = i
temp -= 1
if temp == -1:
whole = 1
break
ans = []
index = 0
for i in range(len(b)):
temp = pre[i]
index = max(i + 1, index)
start = index
for j in range(start, len(b)):
if suf[j] > pre[i]:
index = j
break
else:
index = len(b)
if index != len(b) and pre[i] != len(a):
ans += [len(b) + 1 + i - index]
elif pre[i] == len(a):
ans += [0]
elif index == len(b) and pre[i] != len(a):
ans += [i + 1]
else:
ans += [0]
MAXsufANS = 0
MAXsufindex = len(b)
for i in range(len(b) - 1, -1, -1):
if suf[i] != -1:
MAXsufANS = len(b) - i
MAXsufindex = i
MAX = 0
MAXindex = -1
for i in range(len(b)):
if ans[i] > MAX:
MAXindex = i
MAX = ans[i]
usesuf = 0
if MAXsufANS > MAX:
usesuf = 1
if whole == 1:
print(b)
elif max(MAX, MAXsufANS) == 0:
print("-")
elif usesuf == 1:
anss = b[MAXsufindex:]
print(anss)
else:
m = MAXindex
L = MAX
anss = b[: m + 1] + b[len(b) - (MAX - (m + 1)) :]
print(anss)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR LIST NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a, b = input(), input()
n = len(b)
def f(a, b):
i, t = 0, [0]
for q in a:
if i < n and q == b[i]:
i += 1
t.append(i)
return t
u, v = f(a, b), f(a[::-1], b[::-1])[::-1]
t = [(x + y) for x, y in zip(u, v)]
i = t.index(max(t))
x, y = u[i], v[i]
s = b[:x] + b[max(x, n - y) :]
print(s if s else "-")
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER LIST NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a, b = str(input()), str(input())
p, s, pp, sp = [0] * len(b), [0] * len(b), 0, len(a) - 1
p[0] = a.find(b[0])
while sp >= 0 and a[sp] != b[-1]:
sp -= 1
s[len(b) - 1] = sp
pp, sp = p[0] + 1, sp - 1
for i in range(1, len(b)):
if p[i - 1] == -1:
p[i] = -1
else:
while pp < len(a) and a[pp] != b[i]:
pp += 1
p[i] = pp if pp < len(a) else -1
pp += 1
for i in range(len(b) - 2, -1, -1):
if s[i + 1] == -1:
s[i] = -1
else:
while sp >= 0 and a[sp] != b[i]:
sp -= 1
s[i] = sp if sp >= 0 else -1
sp -= 1
anss, ans = 0, (-1, -1, -1)
for i in range(0, len(b)):
if p[i] == -1:
break
while anss < len(b) and (s[anss] <= p[i] or s[anss] == -1) or anss <= i:
anss += 1
ln = (i + 1 if p[i] != -1 else 0) + (
len(b) - anss if anss < len(b) and s[anss] != -1 else 0
)
if ln > ans[0]:
ans = ln, i, anss
only_s = len(b) - 1
while only_s - 1 >= 0 and s[only_s - 1] >= 0:
only_s -= 1
if only_s >= 0 and s[-1] >= 0 and len(b) - only_s > ans[0]:
print(b[only_s:])
elif ans[0] == -1:
print("-")
else:
print(b[: ans[1] + 1] + (b[ans[2] :] if ans[2] < len(b) else ""))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER STRING
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a = input()
b = input()
p = [None] * (len(b) + 1)
s = [None] * (len(b) + 1)
j = 0
p[0] = -1
for i in range(len(b)):
while j < len(a) and a[j] != b[i]:
j += 1
if j >= len(a):
break
else:
p[i + 1] = j
j += 1
j = len(a) - 1
s[-1] = len(b)
for i in range(len(b) - 1, -1, -1):
while j >= 0 and a[j] != b[i]:
j -= 1
if j < 0:
break
else:
s[i] = j
j -= 1
ans = ""
for i in range(len(b) + 1):
if p[i] == None:
break
else:
l = i - 1
r = len(b)
while l + 1 < r:
mid = (l + r) // 2
if s[mid] != None and p[i] < s[mid]:
r = mid
else:
l = mid
if len(ans) < i + len(b) - r:
ans = b[:i] + b[r:]
if ans == "":
print("-")
else:
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NONE VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
import sys
s, t = input(), "*" + input()
n, m = len(s), len(t) - 1
inf = 10**9
pre, suf = [-1] + [inf] * (m + 1), [-1] * (m + 1) + [n]
i = 0
for j in range(1, m + 1):
while i < n and s[i] != t[j]:
i += 1
if i == n:
break
pre[j] = i
i += 1
i = n - 1
for j in range(m, 0, -1):
while 0 <= i and s[i] != t[j]:
i -= 1
if i == -1:
break
suf[j] = i
i -= 1
max_len, best_l, best_r = 0, 0, 0
j = 1
for i in range(m + 1):
j = max(j, i + 1)
while j <= m and pre[i] >= suf[j]:
j += 1
if pre[i] == inf:
break
if max_len < i + m + 1 - j:
max_len = i + m + 1 - j
best_l, best_r = i, j
pre_s = t[1 : best_l + 1]
suf_s = t[best_r:]
print(pre_s + suf_s if max_len else "-")
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP LIST VAR BIN_OP VAR NUMBER BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR STRING
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a = input()
b = input()
prefix = [-1] * len(b)
postfix = [-1] * len(b)
prefix[0] = a.find(b[0])
postfix[len(b) - 1] = a.rfind(b[len(b) - 1])
for i in range(1, len(b)):
prefix[i] = a.find(b[i], prefix[i - 1] + 1)
if prefix[i] == -1:
break
for i in range(len(b) - 2, -1, -1):
postfix[i] = a.rfind(b[i], 0, postfix[i + 1])
if postfix[i] == -1:
break
best_left = -1
best_right = len(b)
left = -1
while left + 1 < len(b) and prefix[left + 1] != -1:
left += 1
if left > -1:
best_left = left
best_right = len(b)
right = len(b)
while right - 1 >= 0 and postfix[right - 1] != -1:
right -= 1
if right < len(b) and right + 1 < best_right - best_left:
best_left = -1
best_right = right
left = 0
right = len(b)
while left < right and postfix[right - 1] != -1 and postfix[right - 1] > prefix[left]:
right -= 1
while prefix[left] != -1 and left < right < len(b):
while right < len(b) and postfix[right] <= prefix[left]:
right += 1
if right >= len(b):
break
if right - left < best_right - best_left:
best_left = left
best_right = right
left += 1
if left == right:
right += 1
res = b[: best_left + 1] + b[best_right:]
if res == "":
print("-")
else:
print(res)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
def get_substr_ends(haystack, needle):
ans = [-1]
index = 0
for char in needle:
while index < len(haystack) and char != haystack[index]:
index += 1
ans.append(index)
if index < len(haystack):
index += 1
return ans
haystack = input()
needle = input()
pref = get_substr_ends(haystack, needle)
suff = get_substr_ends(haystack[::-1], needle[::-1])
pref_index = 0
suff_len = 0
while suff_len < len(suff) and suff[suff_len] < len(haystack):
suff_len += 1
suff_len -= 1
best_str = needle[len(needle) - suff_len :]
if len(best_str) == len(needle):
print(needle)
exit(0)
for pref_len in range(1, len(pref)):
while suff_len >= 0 and suff[suff_len] + pref[pref_len] + 2 > len(haystack):
suff_len -= 1
ans = pref_len + suff_len
if ans > len(best_str) and suff_len >= 0:
best_str = needle[:pref_len] + needle[len(needle) - suff_len :]
print(best_str if best_str else "-")
|
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
a = list(input())
b = list(input())
m = len(a)
n = len(b)
s = [-1]
i = 0
j = 0
while i < m and j < n:
if a[i] == b[j]:
s.append(i)
j += 1
i += 1
e = [1000000]
i = m - 1
j = n - 1
while i >= 0 and j >= 0:
if a[i] == b[j]:
e.append(i)
j -= 1
i -= 1
i = len(s) - 1
j = 0
ans = "-"
ctr = 0
while j < len(e) and i >= 0:
if s[i] < e[j]:
if i + j > ctr and i + j <= len(b):
ctr = i + j
if j > 0:
ans = b[:i] + b[-j:]
else:
ans = b[:i]
j += 1
else:
i -= 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second lineΒ β string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output Β«-Β» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
import sys
input = sys.stdin.readline
def solve():
a = input().strip()
b = input().strip()
n = len(a)
m = len(b)
c = [0] * m
d = [0] * m
p = 0
for i in range(m):
for j in range(p, n):
if a[j] == b[i]:
c[i] = j
p = j + 1
break
else:
for j in range(i, m):
c[j] = n
break
p = n - 1
for i in range(m - 1, -1, -1):
for j in range(p, -1, -1):
if a[j] == b[i]:
d[i] = j
p = j - 1
break
else:
for j in range(i, -1, -1):
d[j] = -1
break
j = 0
while j < m and d[j] < 0:
j += 1
res = m - j, 0, j
for i in range(m):
p = c[i]
if p == n:
break
while j < m and (j <= i or d[j] <= p):
j += 1
res = max(res, (i + 1 + m - j, i + 1, j))
if res[0] == 0:
print("-")
else:
print(b[: res[1]] + b[res[2] :])
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
def readline():
return map(int, input().split())
MOD = 10**9 + 7
f = [1, 1]
def factorial(x):
l = len(f)
while l <= x:
f.append(f[l - 1] * l % MOD)
l += 1
return f[x]
def inv(x):
return pow(x, -1, MOD)
def comb(n, k):
return factorial(n) * inv(factorial(k)) % MOD * inv(factorial(n - k)) % MOD
def solve():
n, l, r = readline()
d = min(r - n, 1 - l)
h = n >> 1
partitions = ((h, h + 1), (h + 1, h)) if n & 1 else ((h, h),)
ans = sum(comb(n, p) for p, __ in partitions) * d % MOD
loop = True
while loop:
d += 1
plus = max(0, d - (1 - l))
minus = max(0, d - (r - n))
loop = False
for p_, m_ in partitions:
p = p_ - plus
m = m_ - minus
if p >= 0 and m >= 0:
ans += comb(p + m, p)
ans %= MOD
loop = True
print(ans)
def main():
t = int(input())
for __ in range(t):
solve()
main()
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
mod = 10**9 + 7
maxn = int(200000.0 + 10)
Factorial = [1]
for i in range(1, maxn + 1):
Factorial.append(Factorial[i - 1] * i % mod)
InvFactorial = [1] * len(Factorial)
InvFactorial[-1] = pow(Factorial[-1], mod - 2, mod)
for i in reversed(range(0, maxn)):
InvFactorial[i] = InvFactorial[i + 1] * (i + 1) % mod
def comb(n, k):
if n < 0 or k < 0 or k > n:
return 0
return Factorial[n] * InvFactorial[k] % mod * InvFactorial[n - k] % mod
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
ans = 0
if n % 2 == 0:
ans = (ans + comb(n, n // 2) * len(range(1, min(1 - l, r - n) + 1))) % mod
else:
ans = 2 * (ans + comb(n, n // 2) * len(range(1, min(1 - l, r - n) + 1))) % mod
for k in range(min(1 - l, r - n) + 1, (r - l + 2) // 2 + 1):
if min(n, r - k) < max(0, l + k - 1):
break
if n % 2 == 0:
ans = (
ans
+ comb(
n - max(0, l + k - 1) - max(0, n - (r - k)),
n // 2 - max(0, l + k - 1),
)
) % mod
else:
ans = (
ans
+ comb(
n - max(0, l + k - 1) - max(0, n - (r - k)),
n // 2 - max(0, l + k - 1),
)
+ comb(
n - max(0, l + k - 1) - max(0, n - (r - k)),
n // 2 + 1 - max(0, l + k - 1),
)
) % mod
print(ans)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
import sys
from sys import stdin
def modfac(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def modnCr(n, r):
return fac[n] * inv[n - r] * inv[r] % mod
mod = 10**9 + 7
fac, inv = modfac(300000, mod)
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
n, l, r = map(int, stdin.readline().split())
ans = 0
dmax = min(1 - l, r - n)
if dmax >= 0:
if n % 2 == 0:
ans += dmax * modnCr(n, n // 2) % mod
else:
ans += 2 * dmax * modnCr(n, n // 2) % mod
nd = dmax + 1
while True:
lrist = max(0, l + nd - 1)
rrist = max(0, n - (r - nd))
if lrist + rrist > n or min(lrist, rrist) > (n + 1) // 2:
break
if n % 2 == 1:
uprem = n // 2 - lrist
downrem = (n + 1) // 2 - rrist
if min(uprem, downrem) >= 0:
ans += modnCr(uprem + downrem, uprem)
uprem = (n + 1) // 2 - lrist
downrem = n // 2 - rrist
if min(uprem, downrem) >= 0:
ans += modnCr(uprem + downrem, uprem)
else:
uprem = n // 2 - lrist
downrem = n // 2 - rrist
if min(uprem, downrem) >= 0:
ans += modnCr(uprem + downrem, uprem)
nd += 1
ANS.append(str(ans % mod))
print("\n".join(ANS))
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
N = 200000 + 1
MOD = 10**9 + 7
F = [1] * N
G = [1] * N
def init():
for i in range(1, N):
F[i] = F[i - 1] * i % MOD
G[N - 1] = pow(F[N - 1], MOD - 2, MOD)
for i in range(N - 2, 0, -1):
G[i] = G[i + 1] * (i + 1) % MOD
def C(n, m):
if m > n or m < 0:
return 0
return F[n] * G[m] * G[n - m] % MOD
def solve():
n, l, r = list(map(int, input().split()))
answer = 0
common_offset = max(min(1 - l, r - n), 0)
if common_offset:
answer = common_offset * C(n, n // 2) % MOD
if n % 2:
answer += common_offset * C(n, n // 2 + 1) % MOD
for offset in range(common_offset + 1, min(r - 1, n - l) + 1):
u = min(r - offset, n) - max(l - offset, 1) + 1
v = min(r + offset, n) - max(l + offset, 1) + 1
if u + v < n:
break
answer += C(u + v - n, n // 2 - n + v) % MOD
if n % 2:
answer += C(u + v - n, n // 2 + 1 - n + v) % MOD
answer %= MOD
return answer
init()
for case in range(int(input())):
print(solve())
|
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def LI1():
return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number):
return [LI1() for _ in range(rows_number)]
def SI():
return sys.stdin.readline().rstrip()
inf = 10**16
md = 10**9 + 7
def nCr(com_n, com_r):
if com_r < 0:
return 0
if com_n < com_r:
return 0
return fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md
n_max = 200005
fac = [1]
for i in range(1, n_max + 1):
fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1):
ifac[i] = ifac[i + 1] * (i + 1) % md
def solve():
n, l, r = LI()
ans = 0
mn = max(1, 1 - r, l - n)
mx = min(1 - l, r - n)
if mn <= mx:
if n & 1:
ans += nCr(n, n // 2) * 2 * (mx - mn + 1 - (mn <= 0 <= mx)) % md
else:
ans += nCr(n, n // 2) * (mx - mn + 1 - (mn <= 0 <= mx)) % md
s = mn - 1
while s > 0:
L = max(1, l + s)
R = min(n, r - s)
ans += nCr(R - L + 1, n // 2 - L + 1)
if n & 1:
ans += nCr(R - L + 1, n // 2 - L + 2)
s -= 1
s = mx + 1
while 1:
L = max(1, l + s)
R = min(n, r - s)
if L > R + 1:
break
ans += nCr(R - L + 1, n // 2 - L + 1)
if n & 1:
ans += nCr(R - L + 1, n // 2 - L + 2)
s += 1
ans %= md
print(ans)
for testcase in range(II()):
solve()
|
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
import sys
input = sys.stdin.readline
mod = 10**9 + 7
for t in range(int(input())):
n, l, r = map(int, input().split())
F = [0] * (n + 1)
F[0] = 1
for i in range(1, n + 1):
F[i] = i * F[i - 1] % mod
iF = [0] * (n + 1)
iF[-1] = pow(F[-1], mod - 2, mod)
for i in range(n - 1, -1, -1):
iF[i] = (i + 1) * iF[i + 1] % mod
def comb(n, m):
if m < 0 or m > n:
return 0
return F[n] * iF[m] * iF[n - m] % mod
a, b = l - 1, r - n
c = min(-a, b)
ans = comb(n, n // 2) * (1 + n % 2) * c
d = c + 1
while True:
x = min(n, n - (l - 1 + d))
y = min(n, r - d)
if x < 0 or y < 0:
break
ans += comb(x + y - n, n // 2 - (n - y))
if n % 2:
ans += comb(x + y - n, n // 2 - (n - x))
ans %= mod
d += 1
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
M = 10**9 + 7
def choose(n, k):
p = 1
for i in range(k):
p = p * (n - i) * pow(i + 1, -1, M) % M
return p
for _ in range(int(input())):
n, l, r = map(int, input().split())
ud = (
[(n // 2, n // 2)]
if n % 2 == 0
else [(n // 2 + 1, n // 2), (n // 2, n // 2 + 1)]
)
ans = 0
for u, d in ud:
p, prev_n, prev_k = 0, 0, 0
a = min(r - n, 1 - l)
ans += choose(u + d, u) * a
ans %= M
for x in range(min(d + r - n, u + 1 - l), a, -1):
uu = max(0, min(d, d + r - n - x))
dd = max(0, min(u, u + 1 - l - x))
if p == 0:
p = choose(uu + dd, uu)
else:
for i in range(prev_n + 1, uu + dd + 1):
p = p * i % M
for i in range(prev_k + 1, uu + 1):
p = p * pow(i, -1, M) % M
for i in range(prev_n - prev_k + 1, dd + 1):
p = p * pow(i, -1, M) % M
ans = (ans + p) % M
prev_n, prev_k = uu + dd, uu
print(ans)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
from sys import setrecursionlimit, stdin
def main():
from sys import setrecursionlimit, stdin
input = stdin.buffer.readline
def c(n, k):
if n < k or k < 0:
return 0
return f[n] * rev[k] * rev[n - k] % mod
mod = 10**9 + 7
f = [1]
for i in range(1, 200001):
f.append(f[-1] * i % mod)
rev = [pow(f[-1], mod - 2, mod)]
for i in range(200000, 0, -1):
rev.append(rev[-1] * i % mod)
rev = rev[::-1]
for _ in range(int(input())):
n, l, r = map(int, input().split())
h = n >> 1
s = min(1 - l, r - n)
ans = s * (c(n, h) + [0, c(n, h + 1)][n & 1])
x = s + 1
while 1:
ll = max(1, l + x)
rr = min(n, r - x)
if rr - ll + 1 < 0:
break
ans += (
c(rr - ll + 1, h - (ll - 1))
+ [0, c(rr - ll + 1, h + 1 - (ll - 1))][n & 1]
)
x += 1
print(ans % mod)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR LIST NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER LIST NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if:
$a$ is good;
$l \le a_i \le r$ for each $i$;
$F(a)$ is the maximum possible among all good arrays of size $n$.
Given $n$, $l$ and $r$, calculate the number of excellent arrays modulo $10^9 + 7$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first and only line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $-10^9 \le l \le 1$; $n \le r \le 10^9$).
It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the number of excellent arrays modulo $10^9 + 7$.
-----Examples-----
Input
4
3 0 3
4 -3 5
42 -33 55
69 -42 146
Output
4
10
143922563
698570404
-----Note-----
In the first test case, it can be proven that the maximum $F(a)$ among all good arrays $a$ is equal to $2$. The excellent arrays are:
$[2, 1, 2]$;
$[0, 3, 2]$;
$[2, 3, 2]$;
$[3, 0, 1]$.
|
def comb(n, r):
return fact[n] * inv[r] % mod * inv[n - r] % mod if n >= r >= 0 else 0
mod = pow(10, 9) + 7
l = 200005
fact = [1] * (l + 1)
for i in range(1, l + 1):
fact[i] = i * fact[i - 1] % mod
inv = [1] * (l + 1)
inv[l] = pow(fact[l], mod - 2, mod)
for i in range(l - 1, -1, -1):
inv[i] = (i + 1) * inv[i + 1] % mod
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
m = min(1 - l, r - n)
n0 = n // 2 + n % 2
ans = m * comb(n, n0) % mod * (n % 2 + 1) % mod
c1, c2 = 0, 0
l0, r0 = 1, n
for _ in range(n):
m += 1
if l0 - m < l:
c1 += 1
if r0 + m > r:
c2 += 1
x = n - c1 - c2
ans += comb(x, n0 - c1)
ans %= mod
if n % 2:
ans += comb(x, n0 - c2)
ans %= mod
print(ans)
|
FUNC_DEF RETURN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER 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 BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = [[0, 0]]
for i in range(n):
m, f = map(int, input().split())
friends.append([m, f])
friends.sort()
friendship = [0]
monies = []
for i in range(1, n + 1):
friendship.append(friendship[i - 1] + friends[i][1])
ans = 0
j = 0
diff = 0
for i in range(n + 1):
diff = friends[i][0] - friends[j][0]
if diff < d:
ans = max(friendship[i] - friendship[j], ans)
else:
while diff >= d:
j += 1
diff = friends[i][0] - friends[j][0]
j -= 1
ans = max(ans, friendship[i] - friendship[j])
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = list(map(int, input().split()))
F = []
for i in range(n):
F.append(list(map(int, input().split())))
F = sorted(F, key=lambda x: x[0])
f_factor = 0
j = 0
ans = -1
for i in range(n):
if i != 0:
f_factor -= F[i - 1][1]
while j < n:
if F[j][0] - F[i][0] >= d:
break
f_factor += F[j][1]
j += 1
ans = max(ans, f_factor)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def main():
n, d = map(int, input().split())
ms = []
for i in range(n):
ms.append(list(map(int, input().split())))
ms.sort()
hr = 0
hl = 0
mini = ms[0][0]
sumi = 0
s = 0
while hr < n:
mini = ms[hr][0]
while hl < n and ms[hl][0] - mini < d:
s += ms[hl][1]
hl += 1
if s > sumi:
sumi = s
s -= ms[hr][1]
hr += 1
print(sumi)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, m = map(int, input().split())
arr = list()
for i in range(n):
a, b = map(int, input().split())
arr.append([a, b])
arr.sort()
res = arr[0][1]
g = 0
M = -float("inf")
i = 1
while i < n:
if arr[i][0] - arr[g][0] >= m:
M = max(M, res)
res -= arr[g][1]
g += 1
else:
res += arr[i][1]
i += 1
print(max(res, M))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for i in range(n)]
ls.sort(reverse=True)
su, maximum = 0, 0
su = ls[0][1]
maximum = su
top = 0
i = 1
while i < n:
while i < n and ls[i][0] + m > ls[top][0]:
su += ls[i][1]
i += 1
maximum = max(maximum, su)
if i == n:
break
while i > top and ls[i][0] + m <= ls[top][0]:
su -= ls[top][1]
top += 1
su += ls[i][1]
maximum = max(maximum, su)
i += 1
print(maximum)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
f = []
for i in range(n):
f.append(list(map(int, input().split())))
f.sort()
pf = [0]
for i in range(n):
pf.append(pf[-1] + f[i][1])
l = 0
r = 0
mx = 0
while r < n:
if f[r][0] - f[l][0] < d:
mx = max(mx, pf[r + 1] - pf[l])
r += 1
else:
l += 1
print(mx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def cmp(a):
return a[0]
n, d = [int(x) for x in input().split()]
arr = []
for i in range(n):
l = [int(x) for x in input().split()]
arr.append(l)
arr.sort(key=cmp)
i = 0
ans = arr[0][1]
now = arr[0][1]
for j in range(1, n):
if arr[j][0] - arr[i][0] < d:
now += arr[j][1]
else:
if now > ans:
ans = now
while arr[j][0] - arr[i][0] >= d:
now -= arr[i][1]
i += 1
now += arr[j][1]
if now > ans:
ans = now
print(ans)
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
s = 0
ans = 0
r = 0
for l in range(n):
while r < n and a[r][0] - a[l][0] < k:
s += a[r][1]
r += 1
ans = max(ans, s)
s -= a[l][1]
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, money = [int(x) for x in input().split()]
data = []
for i in range(n):
d = [int(x) for x in input().split()]
data.append(d)
data.sort(key=lambda x: x[0])
i, j, soma, soma_parcial = 0, 1, data[0][1], data[0][1]
while j < n and i < n:
if abs(data[i][0] - data[j][0]) < money:
soma_parcial += data[j][1]
j += 1
else:
soma_parcial -= data[i][1]
i += 1
if soma_parcial > soma:
soma = soma_parcial
print(soma)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def byF(p1):
x, y = p1
return x
n, d = map(int, input().split())
friends = []
iSt = 0
s = 0
m = 0
for i in range(n):
x, y = map(int, input().split())
friends.append((x, y))
friends.sort(key=byF)
for i in range(n):
s += friends[i][1]
while friends[i][0] - friends[iSt][0] >= d:
s -= friends[iSt][1]
iSt += 1
if s > m:
m = s
print(m)
|
FUNC_DEF ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
m = [(0) for i in range(n)]
s = [(0) for i in range(n)]
hash = [(0) for i in range(n)]
mod = 10**9 + 1
for i in range(n):
m[i], s[i] = map(int, input().split())
hash[i] = m[i] * mod + s[i]
hash = sorted(hash)
def get_value(x):
return x % mod
def get_key(x):
return int(x / mod)
i_max = n - 1
i_min = n - 1
S = 0
S_max = S
while (i_min >= 0) & (i_max >= 0):
while (get_key(hash[i_min]) > get_key(hash[i_max]) - d) & (i_min >= 0):
S += get_value(hash[i_min])
i_min -= 1
if S > S_max:
S_max = S
S -= get_value(hash[i_max])
i_max -= 1
print(S_max)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def binary_search(arr, n, key):
l, r = 0, n - 1
while l <= r:
mid = l + r >> 1
if arr[mid][0] <= key:
l = mid + 1
else:
r = mid - 1
return l
def main():
n, d = map(int, input().split())
arr = []
for _ in range(n):
m, s = map(int, input().split())
arr += [(m, s)]
arr.sort()
arr_acc = [0] * (n + 1)
for i in range(n):
arr_acc[i + 1] = arr_acc[i] + arr[i][1]
res = 0
for i in range(n):
key = arr[i][0] + d - 1
j = binary_search(arr, n, key)
res = max(res, arr_acc[j] - arr_acc[i])
print(res)
main()
|
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, m = map(int, input().split())
matrix = []
ans = -1000000
kol = 0
for i in range(n):
a, b = map(int, input().split())
matrix.append((a, b))
matrix.sort()
pr = [0]
for i in range(n):
pr.append(matrix[i][1] + pr[-1])
for i in range(n):
kol = 0
s = matrix[i][1]
cost = matrix[i][0]
l = i
r = n
while l + 1 < r:
mi = (l + r) // 2
if matrix[mi][0] - cost < m:
l = mi
else:
r = mi
ans = max(ans, pr[l + 1] - pr[i])
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def find_index(arr, num, low, high, best):
mid = (low + high) // 2
if low > high:
return best
if arr[mid][0] >= num:
return find_index(arr, num, low, mid - 1, best)
return find_index(arr, num, mid + 1, high, mid)
n, d = map(int, input().split())
arr = [tuple(map(int, input().split())) for _ in range(n)]
arr.sort(key=lambda x: x[0])
s = [arr[0][1]]
ans = 0
for i in range(1, n):
s.append(s[i - 1] + arr[i][1])
s += [0]
for i in range(n):
j = find_index(arr, arr[i][0] + d, i, n - 1, i)
ans = max(ans, s[j] - s[i - 1])
print(ans)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
l = []
for i in range(n):
m, s = map(int, input().split())
l.append((m, s))
l.sort()
r = []
j = 0
s = 0
d1 = l[0][0]
for i in range(n):
if l[i][0] - d1 < d:
s += l[i][1]
else:
r.append(s)
for k in range(j, i):
if l[i][0] - l[k][0] >= d:
s -= l[k][1]
d1 = l[k + 1][0]
j = k + 1
s += l[i][1]
r.append(s)
print(max(r))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
friends = [(0, 0)]
for i in range(n):
money, cute = map(int, input().split())
friends.append((money, cute))
friends.sort()
sumcute = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
sumcute[i] = sumcute[i - 1] + friends[i][1]
l = 1
r = 1
ans = 0
while r != len(sumcute):
while r != len(sumcute) - 1 and friends[r + 1][0] - friends[l][0] < d:
r += 1
ans = max(sumcute[r] - sumcute[l - 1], ans)
if r == len(sumcute) - 1:
r += 1
l += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = input().split()
n, d = int(n), int(d)
l = {}
for i in range(n):
m, s = input().split()
m, s = int(m), int(s)
if m not in l:
l[m] = s
else:
l[m] += s
a = sorted(l.keys())
e, f = 0, 1
m = l[a[0]]
ma = l[a[0]]
while f < len(a):
m += l[a[f]]
while a[f] - a[e] >= d:
m -= l[a[e]]
e += 1
if m > ma:
ma = m
f += 1
print(ma)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
def solve(m, d):
m.sort()
res = 0
curr = 0
i, j = 0, 0
while j < len(m):
if m[j][0] - m[i][0] >= d:
curr -= m[i][1]
i += 1
else:
curr += m[j][1]
res = max(res, curr)
j += 1
return res
n, d = map(int, input().split())
f = []
for i in range(n):
mi, fi = map(int, input().split())
f.append((mi, fi))
print(solve(f, d))
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split(" "))
sol = []
for i in range(n):
x, y = map(int, input().split())
sol.append([x, y])
sol.sort()
i = 0
j = 1
first = sol[0][1]
solution = sol[0][1]
while j < n:
if sol[j][0] - sol[i][0] < d:
first = first + sol[j][1]
if solution < first:
solution = first
j += 1
else:
first = first - sol[i][1]
i += 1
print(solution)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
friend = []
n, d = [int(i) for i in input().split(" ")]
for i in range(n):
friend.append([int(i) for i in input().split(" ")])
friend = sorted(friend, key=lambda fr: fr[0])
ans = 0
cur = 0
rich = iter(friend)
i = next(rich)
for poor in friend:
try:
while i[0] < poor[0] + d:
cur += i[1]
i = next(rich)
ans = max(ans, cur)
cur -= poor[1]
except StopIteration:
break
ans = max(ans, cur)
print(ans)
|
ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR WHILE VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
-----Input-----
The first line of the input contains two space-separated integers, n and d (1 β€ n β€ 10^5, $1 \leq d \leq 10^{9}$) β the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.
Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type m_{i}, s_{i} (0 β€ m_{i}, s_{i} β€ 10^9) β the amount of money and the friendship factor, respectively.
-----Output-----
Print the maximum total friendship factir that can be reached.
-----Examples-----
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
-----Note-----
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.
In the second sample test we can take all the friends.
|
n, d = map(int, input().split())
arr = []
for i in range(n):
arr.append(list(map(int, input().split())))
arr.sort(key=lambda arr: arr[0])
maxx = 0
left = 0
right = 0
curr = 0
while right < n and left < n:
if abs(arr[left][0] - arr[right][0]) < d:
curr += arr[right][1]
right += 1
else:
curr -= arr[left][1]
left += 1
maxx = max(curr, maxx)
print(maxx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.