description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
def f(n, l):
pl = [None] * (n + 1)
for a, b, c in l:
if pl[b] is None:
pl[b] = []
pl[b].append(c)
cr = sum([(p is None) for p in pl])
if cr > 2:
return -1
return sum([min(p) for p in pl if p is not None])
n = int(input())
input()
a = int(input())
l = [list(map(int, input().split())) for _ in range(a)]
print(f(n, l))
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR NONE ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NONE VAR VAR IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
num_de_func = int(input())
qualificacoes_dos_func = map(int, input().split())
num_de_inscricoes = int(input())
custos = num_de_func * [-1]
for i in range(num_de_inscricoes):
numero_a, numero_b, numero_c = map(int, input().split())
numero_b -= 1
if custos[numero_b] != -1:
aux = min(custos[numero_b], numero_c)
custos[numero_b] = aux
else:
custos[numero_b] = numero_c
custo_min = sum(custos) + 1
contagem_custo = custos.count(-1)
if contagem_custo <= 1:
print(custo_min)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
(n,) = map(int, input().split())
map(int, input().split())
p = [-1] * (n + 1)
(m,) = map(int, input().split())
for i in range(m):
a, b, c = map(int, input().split())
if p[b] < 0:
p[b] = c
else:
p[b] = min(p[b], c)
print(-1 if p.count(-1) > 2 else sum(p) + 2)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
__author__ = "Darren"
def solve():
n = int(input())
input()
m = int(input())
costs = [1000001] * (n + 1)
for _i in range(m):
a, b, c = map(int, input().split())
if c < costs[b]:
costs[b] = c
boss = 0
for i in range(1, n + 1):
if costs[i] == 1000001:
boss += 1
if boss >= 2:
break
if boss != 1:
print(-1)
return
min_cost = sum(costs) - 2 * 1000001
print(min_cost)
solve()
|
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
qualifications = list(map(int, input().split()))
apps = []
limit = 10**6 + 1
result = [limit for i in range(n)]
m = int(input())
for i in range(m):
a, b, c = map(int, input().split())
result[b - 1] = min(result[b - 1], c)
count = 0
for i in result:
if i == limit:
count += 1
if count > 1:
print(-1)
else:
out = 0
for i in result:
if i != limit:
out += i
print(out)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
ls = [int(i) for i in input().split()]
par = list(range(0, n + 1))
appls = []
for i in range(int(input())):
x, y, z = [int(i) for i in input().split()]
appls.append((x, y, z))
appls.sort(key=lambda item: item[2])
def find(p):
return par[p]
count = 0
for tup in appls:
if tup[1] == find(tup[1]):
par[tup[1]] = tup[0]
count += tup[2]
res = 0
for i in range(1, n + 1):
if i == par[i]:
res += 1
if res == 1:
print(count)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
lis = list(map(int, input().split()))
m = int(input())
edges = []
for d in range(m):
edges.append(list(map(int, input().split())))
edges.sort(key=lambda x: x[2])
visited = []
count = 0
for i in range(m):
if edges[i][1] not in visited:
visited.append(edges[i][1])
count += edges[i][2]
if len(visited) == n - 1:
print(count)
else:
print(-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 FUNC_CALL VAR 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
def find(arr, a):
if arr[a] == a:
return a
arr[a] = find(arr, arr[a])
return arr[a]
n = int(input())
x = list(map(int, input().split()))
arr = [i for i in range(n + 1)]
m = int(input())
l = []
for _ in range(m):
l.append(list(map(int, input().split())))
l.sort(key=lambda k: k[2])
val = n
ans = 0
for i in range(m):
x = find(arr, l[i][0])
y = find(arr, l[i][1])
if x != y and y == l[i][1]:
val -= 1
arr[y] = x
ans += l[i][2]
if val != 1:
print(-1)
else:
print(ans)
|
FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
read1 = [-1] * int(input())
read2 = input()
n = int(input())
for i in range(n):
x, y, z = list(map(int, input().split()))
if read1[y - 1] == -1:
read1[y - 1] = z
else:
read1[y - 1] = min(read1[y - 1], z)
if read1.count(-1) <= 1:
print(sum(read1, 1))
else:
print(-1)
|
ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
input()
arr = n * [-1]
for i in range(int(input())):
a, b, c = map(int, input().split())
b -= 1
if arr[b] == -1:
arr[b] = c
else:
arr[b] = min(arr[b], c)
if arr.count(-1) > 1:
print(-1)
else:
print(sum(arr) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST 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 VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
a = int(input())
input()
z = [pow(10, 9)] * a
for i in range(int(input())):
a, b = map(int, input().split()[1:])
z[a - 1] = min(z[a - 1], b)
z.remove(max(z))
if pow(10, 9) in z:
print(-1)
else:
print(sum(z))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
t = 1
for i in range(t):
n = int(input())
q = [int(x) for x in input().split()]
big = q.index(max(q))
costs = [(1000001) for x in range(n)]
m = int(input())
for i in range(m):
a, b, c = map(int, input().split())
costs[b - 1] = min(costs[b - 1], c)
ans = 0
for i in range(n):
if i == big:
continue
if costs[i] == 1000001:
ans = -1
break
ans += costs[i]
print(ans)
|
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def getResult(n, q, m, edges, graph):
maxq = max(q)
pRoots = [i for i, j in enumerate(q) if j == maxq]
canBeSubbordinateFor = []
count = 0
for i in range(n):
canBeSubbordinateForEach = []
for u, v, c in edges:
if v == i:
canBeSubbordinateForEach.append(c)
canBeSubbordinateFor.append(canBeSubbordinateForEach)
if len(canBeSubbordinateForEach) == 0:
count += 1
if count > 1:
return -1
cost = 0
for i in range(n):
if len(canBeSubbordinateFor[i]) > 0:
cost += min(canBeSubbordinateFor[i])
return cost
n = inp()
q = inlt()
m = inp()
edges = []
graph = []
for i in range(n):
line = []
for j in range(n):
line.append(-1)
graph.append(line)
for i in range(m):
ed = inlt()
ed[0] = ed[0] - 1
ed[1] = ed[1] - 1
edges.append(ed)
for u, v, c in edges:
if graph[u][v] > c:
graph[u][v] = c
elif graph[u][v] == -1:
graph[u][v] = c
result = getResult(n, q, m, edges, graph)
print(result)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n, q = int(input()), list(map(int, input().split()))
p = [(1000001) for i in range(n + 1)]
for i in range(int(input())):
a, b, c = map(int, input().split())
p[b] = min(p[b], c)
k = q.index(max(q)) + 1
p = p[1:k] + p[k + 1 :]
print(-1 if 1000001 in p else sum(p))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
MAX = 1000001
e = int(input())
q = input().split()
m = int(input())
arr1 = [MAX] * e
for i in range(m):
[a, b, c] = list(map(int, input().split()))
arr1[b - 1] = min(arr1[b - 1], c)
count = 0
for x in arr1:
if x == MAX:
count += 1
if count > 1:
print(-1)
else:
res = 0
for k in arr1:
if k != MAX:
res += k
print(res)
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
qualifications = list(map(int, input().split()))
m = int(input())
applications = [[(int(e) - 1) for e in input().split()] for i in range(m)]
maior_custo = 10**6 + 2
menor_custo = [maior_custo] * n
empregados = []
for e in range(n):
empregados.append([])
for e in range(m):
empregados[applications[e][1]].append(applications[e][0])
menor_custo[applications[e][1]] = min(
menor_custo[applications[e][1]], applications[e][2] + 1
)
contador = 0
for e in empregados:
if len(e) == 0:
contador += 1
if contador > 1:
print(-1)
else:
menor = 0
for c in menor_custo:
if c < maior_custo:
menor += c
print(menor)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
import sys
input = sys.stdin.readline
def main():
n = int(input())
q = list(map(int, input().split()))
m = int(input())
cost = {}
for _ in range(m):
a, b, c = map(int, input().split())
a, b = a - 1, b - 1
if q[a] > q[b]:
if b in cost:
if cost[b] > c:
cost[b] = c
else:
cost[b] = c
print(-1 if len(cost) < n - 1 else sum(cost.values()))
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
input()
m = int(input())
supervisor = [[] for _ in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
supervisor[b - 1].append(c)
boss = 0
ans = 0
for i in range(n):
if len(supervisor[i]) > 0:
ans += min(supervisor[i])
else:
boss += 1
if boss == 1:
print(ans)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
import sys
def solution():
n = int(input().strip())
input()
m = int(input().strip())
costs = [10**6 + 1] * n
for _ in range(m):
a, b, c = map(int, input().strip().split())
costs[b - 1] = min(c, costs[b - 1])
boss = 0
for i in range(n):
if costs[i] == 10**6 + 1:
boss += 1
if boss >= 2:
break
if boss != 1:
print(-1)
return
min_cost = sum(costs) - 10**6 - 1
print(min_cost)
solution()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
n = int(input())
input()
m = int(input())
zp_nach = [-1] * (n + 1)
for _ in range(m):
a, b, c = map(int, input().split())
if zp_nach[b] == -1:
zp_nach[b] = c
else:
zp_nach[b] = min(c, zp_nach[b])
if zp_nach.count(-1) == 2:
print(sum(zp_nach) + 2)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input
The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Examples
Input
4
7 2 3 1
4
1 2 5
2 4 1
3 4 1
1 3 5
Output
11
Input
3
1 2 3
2
3 1 2
3 1 3
Output
-1
Note
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def ind(m):
d = {}
for i in range(m):
Manager, subordinate, cost = [int(x) for x in input().split()]
if subordinate not in d:
d[subordinate] = [Manager, cost]
elif d[subordinate][1] > cost:
d[subordinate][1] = cost
return d
N = inp()
Q = inlt()
M = inp()
App = ind(M)
minimum_cost = -1
subordinate = []
if len(App) < N - 1:
print(minimum_cost)
else:
minimum_cost = 0
for i in App:
minimum_cost = minimum_cost + App[i][1]
print(minimum_cost)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
if n == 2:
print(1)
else:
ans = 3
oldans = 2
count = 2
b = 0
while ans <= n:
if ans == n:
b = 1
print(count)
break
else:
oldans, ans = ans, ans + oldans
count += 1
if b == 0:
print(count - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
ans = 0
a, b, x = 1, 1, 2
while x <= n:
x = a + b
a, b = b, x
ans += 1
print(ans - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
ans = 0
cl = [1, 2, 3]
if n <= 4:
print([1, 2][n > 2])
else:
i = 2
while cl[i] <= n:
cl += [cl[i] + cl[i - 1]]
i += 1
print(i - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def cost(nk):
ns = max(0, k - 1)
if ns > n - 2:
return 0
return f(n - ns - 1, k + 1) + 1
n = int(input())
F = [0] * 100
F[0] = 1
F[1] = 2
ans = 1
for i in range(2, 100):
F[i] = F[i - 1] + F[i - 2]
if F[i] <= n:
ans = i
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
f = []
ans = 1
f.append(1)
f.append(2)
while f[ans] < n:
f.append(f[ans] + f[ans - 1])
ans += 1
if f[ans] == n:
print(ans)
else:
print(ans - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
if n == 2:
print(1)
exit()
p = 2
pp = 1
i = 1
while True:
c = p + pp
if c > n:
print(i)
exit()
i += 1
pp = p
p = c
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
l = [1, 2]
for i in range(100):
l.append(l[-1] + l[-2])
for i in range(100):
if l[i] > n:
print(i - 1)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
fib = [0] * 2
fib[0] = 2
fib[1] = 3
def func(x):
global fib
if x == 2:
return 1
if x == 3:
return 2
while fib[-1] <= x:
fib.append(fib[-1] + fib[-2])
return len(fib) - 1
n = int(input())
print(func(n))
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
arr = [1, 2]
while True:
tmp = arr[-1] + arr[-2]
if tmp > n:
break
arr.append(tmp)
print(len(arr) - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
a = [(0) for i in range(1000)]
a[1] = 2
a[2] = 3
if n < 4:
print(n - 1)
exit()
i = 3
while True:
a[i] = a[i - 1] + a[i - 2]
if a[i] > n:
print(i - 1)
exit()
i += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def tennis(n):
u, v = 1, 2
j = 1
while v <= n:
u, v = v, u + v
j += 1
return j - 1
print(tennis(int(input())))
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
from sys import stdout
n = int(input())
dp = [(0) for i in range(100)]
dp[0] = 1
dp[1] = 2
for i in range(2, n + 10):
if dp[i - 1] > n:
stdout.write(str(i - 2))
break
dp[i] = dp[i - 1] + dp[i - 2]
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
ans = 1
a = 1
b = 2
n = int(input())
if n == 1:
print(0)
elif n == 2:
print(1)
else:
while a + b <= n:
ans += 1
temp = a + b
a = b
b = temp
print(ans)
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
fib = 1
last = 1
i = 0
while True:
i += 1
fib = fib + last
last = fib - last
if fib > n:
print(i - 1)
exit(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
dp = {(1): 2, (2): 3}
def cost(i):
if i not in dp:
dp[i] = cost(i - 1) + cost(i - 2)
return dp[i]
ans = 1
while cost(ans) <= n:
ans += 1
print(ans - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
x, y = 1, 1
z = -1
for i in range(0, n + 1):
if y > n:
print(i - 1)
break
z = x + y
x = y
y = z
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
x, y, cnt, s = 1, 1, 0, 0
while s + y < n:
s += y
x, y = x + y, x
cnt += 1
print(cnt)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
l = []
l.append(0)
l.append(1)
l.append(2)
k = 2
m = 1
while k < n:
k = k + l[m]
m = m + 1
l.append(k)
if k > n:
m = m - 1
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
if n <= 2:
print(1)
exit(0)
F = [1, 1]
while F[-1] < n:
F.append(F[-1] + F[-2])
s = 0
for i in range(len(F)):
s += F[i]
if s >= n:
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def fibo(n):
f0 = 0
f1 = 1
if n == 0:
fibo = 0
elif n == 1:
fibo = 1
else:
for i in range(1, n):
fibo = f0 + f1
f0 = f1
f1 = fibo
return fibo
n = int(input())
ans = 0
for k in range(n + 5):
if fibo(k) > n:
ans = k - 3
break
else:
pass
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
prefix = [1, 1, 2]
now = 0
for i in range(85):
prefix.append(prefix[-1] + prefix[-2])
while n >= prefix[now] + 1:
n -= prefix[now]
now += 1
print(now)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
lst1 = 1
lst2 = 1
cnt = 0
while True:
cnt += 1
lst1, lst2 = lst2, lst1
if lst1 + lst2 == n:
print(cnt)
return
if lst1 + lst2 > n:
print(cnt - 1)
return
lst2 = lst1 + lst2
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def main():
try:
while True:
s = int(input()) - 2
if s == 0:
print(1)
else:
a = b = 1
result = 1
while s >= b:
s -= b
result += 1
a, b = b, a + b
print(result)
except EOFError:
pass
main()
|
FUNC_DEF WHILE NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def getLnInput():
return input().split()
def main(n):
current = 1
prev = 1
term = -1
while current <= n:
current, prev = current + prev, current
term += 1
print(term)
return
main(int(getLnInput()[0]))
|
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
if n == 2:
print(1)
elif n == 3:
print(2)
else:
a = 2
b = 3
res = 2
while True:
res += 1
c = a + b
if c > n:
break
a = b
b = c
print(res - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
f = [1, 1]
while f[-1] < n:
f += [f[-1] + f[-2]]
if f[-1] == n:
print(len(f) - 2)
else:
print(len(f) - 3)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER VAR VAR LIST BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def ii():
return int(input())
def si():
return input()
def mi():
return map(int, input().split())
def msi():
return map(str, input().split())
def li():
return list(mi())
n = ii()
ans = 0
p, q = 2, 1
while p <= n:
p, q = p + q, p
ans += 1
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
fib = [1, 2]
for i in range(2, 10000):
fib.append(fib[i - 1] + fib[i - 2])
l = 0
r = 10000
while r - l > 1:
mid = (r + l) // 2
if fib[mid] > n:
r = mid
else:
l = mid
print(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
a = [0] * 20000
a[0] = 1
a[1] = 2
i = 1
while a[i] <= n:
i += 1
a[i] = a[i - 1] + a[i - 2]
print(i - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
arr = [1, 2]
while arr[-1] < 10**18:
l = arr[-1] + arr[-2]
arr.append(l)
ans = 0
for i in range(len(arr)):
if arr[i] <= n:
ans = i
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
a = []
a.append(1)
a.append(1)
n = int(input())
if n == 2:
print(1)
return
i = 2
while 1:
a.append(a[i - 1] + a[i - 2])
if a[i] >= n:
print(i - 2 + int(a[i] == n))
break
i += 1
|
ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
fib = [0, 1]
for i in range(2, 100):
fib.append(fib[i - 1] + fib[i - 2])
fib = fib[2:]
n = int(input())
maks = 0
for i in range(len(fib)):
if n >= fib[i]:
maks = max(maks, i)
else:
break
print(maks)
|
ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def f():
a, b = 1, 1
while True:
yield a
a, b = a + b, a
def main():
n = int(input())
for i, x in enumerate(f()):
if x > n:
print(i - 1)
return
main()
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER EXPR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
T = {}
T[1] = 2
T[2] = 3
T[3] = 5
T[4] = 8
t = 1
r = 0
while r < 4 and t <= n:
r += 1
t = T[r]
while t <= n:
r += 1
t += T[r - 2]
T[r] = t
print(r - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
games = n - 1
massiv = [2]
while massiv[-1] <= games:
if len(massiv) == 1:
massiv += [4]
else:
massiv += [massiv[-1] + massiv[-2] + 1]
print(len(massiv))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER WHILE VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER VAR LIST NUMBER VAR LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
from sys import stdin, stdout
n = int(stdin.readline().strip())
m = 1
a = 1
b = 2
while b < n:
m += 1
a, b = b, a + b
if b > n:
m -= 1
stdout.write(str(m))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def solve(n):
k = 0
f1, f2 = 1, 2
while not f1 <= n < f2:
k += 1
t = f1
f1 = f2
f2 = f1 + t
return k
n = int(input())
print(solve(n))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
x = 1
y = 1
z = 2
ans = 0
while n >= z:
x = y
y = z
z = x + y
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def solucion():
n = int(input())
minDJugadores = [2, 3]
if 2 <= n <= 3:
if n == 2:
print("1")
else:
print("2")
else:
while n >= minDJugadores[len(minDJugadores) - 1]:
minDJugadores.append(
minDJugadores[len(minDJugadores) - 1]
+ minDJugadores[len(minDJugadores) - 2]
)
print(len(minDJugadores) - 1)
solucion()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER IF NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING WHILE VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
n -= 2
sc = 1
first = True
f1 = 1
f2 = 1
f3 = 2
while n > 0:
if first:
first = False
n -= 1
sc += 1
else:
n -= f3
sc += 1
f1 = f2
f2 = f3
f3 = f1 + f2
if n < 0:
sc -= 1
print(sc)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
fibo = [
1,
2,
3,
5,
8,
13,
21,
34,
55,
89,
144,
233,
377,
610,
987,
1597,
2584,
4181,
6765,
10946,
17711,
28657,
46368,
75025,
121393,
196418,
317811,
514229,
832040,
1346269,
2178309,
3524578,
5702887,
9227465,
14930352,
24157817,
39088169,
63245986,
102334155,
165580141,
267914296,
433494437,
701408733,
1134903170,
1836311903,
2971215073,
4807526976,
7778742049,
12586269025,
20365011074,
32951280099,
53316291173,
86267571272,
139583862445,
225851433717,
365435296162,
591286729879,
956722026041,
1548008755920,
2504730781961,
4052739537881,
6557470319842,
10610209857723,
17167680177565,
27777890035288,
44945570212853,
72723460248141,
117669030460994,
190392490709135,
308061521170129,
498454011879264,
806515533049393,
1304969544928657,
2111485077978050,
3416454622906707,
5527939700884757,
8944394323791464,
14472334024676221,
23416728348467685,
37889062373143906,
61305790721611591,
99194853094755497,
160500643816367088,
259695496911122585,
420196140727489673,
679891637638612258,
1100087778366101931,
1779979416004714189,
2880067194370816120,
4660046610375530309,
7540113804746346429,
12200160415121876738,
19740274219868223167,
31940434634990099905,
51680708854858323072,
83621143489848422977,
135301852344706746049,
218922995834555169026,
354224848179261915075,
573147844013817084101,
927372692193078999176,
1500520536206896083277,
]
n = int(input())
for i in range(len(fibo)):
if fibo[i] > n:
print(i - 1)
break
|
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def rints():
return list(map(int, input().split()))
def ri():
return int(input())
n = ri()
i = 1
prev = 1
cur = 2
while cur + prev <= n:
cur, prev = cur + prev, cur
i += 1
print(i)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
dp = [(0) for i in range(100)]
dp[0] = 1
dp[1] = 2
i = 1
while 1:
if dp[i] == 0:
dp[i] = dp[i - 1] + dp[i - 2]
if dp[i] > n:
print(i - 1)
break
else:
i += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def h(z):
a = 0
b = 1
res = 1
while True:
a, b = b, a + b + 1
if b >= z:
break
res += 1
return res
n = int(input())
print(h(n))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
player = int(input())
def thefunc(players):
if players == 1 or players == 2:
return 1
if players == 3:
return 2
min_players_on_before_level = 2
min_players_on_this_level = 3
rounds = 1
while min_players_on_this_level <= player:
temp = min_players_on_before_level
min_players_on_before_level = min_players_on_this_level
min_players_on_this_level = temp + min_players_on_this_level
rounds += 1
return rounds
print(thefunc(player))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def main():
num = int(input())
num1 = 1
num2 = 2
tmp = 0
cont = 0
while tmp <= num:
tmp = num1 + num2
num1 = num2
num2 = tmp
cont += 1
print(cont)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
a = 1
b = 1
c = 0
while a + b <= n:
t = a
a = a + b
b = t
c += 1
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
a = int(input())
fib = [1, 2]
for i in range(100):
fib.append(fib[-1] + fib[-2])
for i in range(1, 1000):
if fib[i] <= a < fib[i + 1]:
print(i)
quit()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
def games(m):
lst = [2]
while lst[-1] <= m - 1:
if len(lst) == 1:
lst += [4]
else:
lst += [lst[-1] + lst[-2] + 1]
return len(lst)
print(games(int(input())))
|
FUNC_DEF ASSIGN VAR LIST NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR LIST NUMBER VAR LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
a = [2]
n = int(input())
while a[-1] < n:
if len(a) == 1:
a.append(4)
else:
a.append(a[-1] + a[-2] + 1)
print(len(a))
|
ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
prev, cur = 1, 2
iters = 0
while cur < n:
prev, cur = cur, cur + prev
iters += 1
ans = iters + bool(cur == n)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n, arr, i = int(input()), [2, 3], 1
if n == 2:
print(1)
elif n == 3:
print(2)
else:
a, ans = arr[i] + arr[i - 1], 2
while a <= n:
i += 1
arr.append(a)
a = arr[i] + arr[i - 1]
ans += 1
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
if n == 2:
print(1)
elif n == 3:
print(2)
else:
x = 2
y = 3
counter = 0
while x + y <= n:
x, y = y, x + y
counter += 1
print(2 + counter)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
n = int(input())
if n <= 2:
print(n - 1)
exit()
fib = [0, 1]
while fib[-1] <= n:
fib.append(fib[-1] + fib[-2])
print(len(fib) - 4)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
|
fib = [1, 2]
for i in range(90):
fib.append(fib[-1] + fib[-2])
n = int(input())
for i in range(len(fib)):
if fib[i] > n:
print(i - 1)
break
|
ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
if n == 1:
ans = (10 - int(s[0])) % 10
if ans <= k:
print(1)
else:
print(0)
elif n == 2:
a1 = (10 - int(s[1])) % 10
b = (int(s[0]) + a1) % 10
a2 = (10 - b) % 10
if a1 + a2 <= k:
print(2)
else:
a3 = (10 - int(s[0])) % 10
if a3 <= k:
print(1)
else:
print(0)
else:
li = []
val = (10 - int(s[0])) % 10
li.append(val)
a1 = (10 - int(s[1])) % 10
b = (int(s[0]) + a1) % 10
a2 = (10 - b) % 10
li.append(a1 + a2)
for i in range(2, n):
c1 = (10 - int(s[i])) % 10
d = (int(s[i - 1]) + c1) % 10
c2 = (10 - d) % 10
c3 = a2
li.append(c1 + c2 + c3)
a2 = c2 + c3
count = 0
for i in range(len(li)):
if li[i] <= k:
count = count + 1
else:
break
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def f(a, b):
c = a % 10
b += a
b %= 10
if b == 0:
return 0
return 10 - b
def check(ar, l, p):
i = 0
for r in range(l, -1, -1):
j = f(i, ar[r])
if i + j > p:
return False
i += j
return True
t = int(input())
for tt in range(t):
n, k = map(int, input().split())
a = input()
aa = [int(a[i]) for i in range(n)]
o = 0
u = n - 1
ans = 0
while o <= u:
if check(aa, (o + u) // 2, k):
o = (o + u) // 2 + 1
ans = o
else:
u = (o + u) // 2 - 1
print(ans)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
from sys import stdin, stdout
def main():
t = int(stdin.readline())
for tt in range(t):
n, k = map(int, stdin.readline().split())
s = list(map(int, list(stdin.readline().strip())))
if k < 10 - s[0] and s[0] != 0:
print(0)
else:
db = 1
if s[0] != 0:
k = k - (10 - s[0])
for i in range(1, n):
if s[i] == 0:
db += 1
elif s[i] >= s[i - 1] and s[i - 1] != 0:
db += 1
else:
if k >= 10:
db += 1
k -= 10
if k < 0:
break
print(db)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def compute(s):
net = 0
for i in s[::-1]:
x = (int(i) + net) % 10
if x == 0:
continue
net += 10 - x
return net
t = int(input())
while t != 0:
n, k = map(int, input().split())
s = input()
ans = 0
low, high = 1, n
while low <= high:
mid = (low + high) // 2
if compute(s[:mid]) > k:
high = mid - 1
else:
ans = mid
low = mid + 1
print(ans)
t -= 1
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
s = input()
l = 0
u = n - 1
ans = 0
while l <= u:
mid = (u + l) // 2
add = 0
for i in range(mid, -1, -1):
v = (ord(s[i]) - ord("0") + add) % 10
if v == 0:
continue
add = 10 - v + add
if add > k:
u = mid - 1
else:
l = mid + 1
ans = mid + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP 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 NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for i in range(t):
n, k = list(map(int, input().split()))
s = input()
ans = 0
for c in s:
req = (10 - int(c)) % 10
if req > k:
break
ans += 1
k = int((k - req) / 10) * 10 + req
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
from sys import stdin
def good_prefix(s, mid):
operations = 0
for i in range(mid - 1, -1, -1):
req = (operations + int(s[i])) % 10
if req != 0:
operations += 10 - req
return operations
def binary_search(s, low, high, k):
while low < high:
mid = low + (high - low) // 2
op = good_prefix(s, mid)
if op <= k:
low = mid + 1
else:
high = mid
return low - 1
t = int(stdin.readline().strip())
while t > 0:
n, k = list(map(int, stdin.readline().strip().split(" ")))
s = stdin.readline().strip()
low = 0
high = n + 1
result = binary_search(s, low, high, k)
print(result)
t -= 1
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()
l = 0
r = len(s) - 1
ans = 0
def calc(m):
add = 0
for i in range(m, -1, -1):
v = (ord(s[i]) - ord("0") + add) % 10
if v == 0:
continue
add += 10 - v
return add
while l <= r:
m = (l + r) // 2
if calc(m) > k:
r = m - 1
else:
ans = m + 1
l = m + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN 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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def f2(z, s, t=0):
for i in range(z, -1, -1):
v = (int(s[i]) + t) % 10
t += 10 - v if v != 0 else 0
return t
for tcs in range(int(input())):
n, k = map(int, input().split())
wrd = list(map(int, list(input())))
a, x, y = 0, 0, n - 1
while x <= y:
z = x + (y - x) // 2
if f2(z, wrd) <= k:
a = z + 1
x = a
else:
y = z - 1
print(a)
|
FUNC_DEF NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def solver(n, k, s):
l = 0
r = n + 1
while l < r - 1:
mid = (l + r) // 2
count = 0
for i in range(mid - 1, -1, -1):
req = (int(s[i]) + count) % 10
if req != 0:
count += 10 - req
if count <= k:
l = mid
else:
r = mid
print(l)
t = int(input())
while t > 0:
t -= 1
n, k = list(map(int, input().split(" ")))
s = input()
solver(n, k, s)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def check(index, s):
temp = 0
ans = 0
for i in range(index - 1, -1, -1):
val = int(s[i])
val = (val + temp) % 10
temp += (10 - val) % 10
return temp
for t in range(int(input())):
n, k = map(int, input().split())
s = input()
low = 0
high = n
while low <= high:
mid = (low + high) // 2
val = check(mid, s)
if val > k:
high = mid - 1
elif val <= k:
res = mid
low = mid + 1
print(res)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def zero(m, s):
z = 0
for i in range(m + 1):
b = (int(s[m - i]) - int("0") + z) % 10
if b == 0:
continue
z += 10 - b
return z
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
ans = 0
l = 0
r = n - 1
m = 0
while l <= r:
m = l + (r - l) // 2
if zero(m, s) > k:
r = m - 1
else:
ans = m + 1
l = m + 1
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
for z in range(t):
n, k = map(int, input().split())
a = list(input())
for i in range(len(a)):
a[i] = int(a[i])
h = 10 - a[0]
g = k
while g % 10 != h % 10 and g > 0:
g -= 1
c = 0
if g <= k:
for i in range(len(a)):
while g % 10 != (10 - a[i]) % 10 and g > 0:
g -= 1
if g > 0:
c += 1
else:
j = i
while j < len(a) and a[j] == 0:
c += 1
j += 1
break
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def countOps(S, L):
ret = 0
for i in range(L - 1, -1, -1):
ret += (10 - (int(S[i]) + ret) % 10) % 10
return ret
def main():
T = int(input())
for _ in range(T):
N, K = [int(w) for w in input().split()]
S = input().strip()
lo, hi = 0, N
while hi - lo > 1:
mid = (lo + hi) // 2
if countOps(S, mid) <= K:
lo = mid
else:
hi = mid - 1
if countOps(S, hi) > K:
hi = lo
print(hi)
main()
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR 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 VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
low = 0
high = n + 1
while high - low > 1:
mid = (low + high) // 2
ops = 0
for i in range(mid - 1, -1, -1):
ops += (10 - (int(s[i]) + ops) % 10) % 10
if ops <= k:
low = mid
else:
high = mid
print(low)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
a, b = map(int, input().split())
s = input()
s = list(map(lambda x: int(x), s))
x = 0
count = 0
l, h = 0, a - 1
while l <= h:
mid = (l + h) // 2
x = 0
for j in range(mid, -1, -1):
r = (s[j] + x) % 10
if r != 0:
x += 10 - r
if b < x:
break
if j == 0:
count = max(count, mid + 1)
if b < x:
h = mid - 1
else:
l = mid + 1
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
import sys
def input():
return sys.stdin.readline().rstrip("\r\n")
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
ans = 0
for i in range(n):
x = int(s[i])
k -= (k % 10 + x) % 10
if k < 0:
break
else:
ans += 1
print(ans)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
t = int(input())
while t != 0:
n, k = map(int, input().split())
l = list(map(int, list(input())))
low, high = 0, n + 1
f = 0
ma = 0
while low < high:
mid = low + (high - low) // 2
new = k
gy = 0
for j in range(mid - 1, -1, -1):
x = (l[j] + gy) % 10
if x % 10 != 0:
new = new - (10 - x % 10)
gy = gy + 10 - x % 10
if new >= 0:
low = mid + 1
ma = mid
else:
high = mid
print(ma)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
a = []
b = []
a.append((10 - int(s[0])) % 10)
b.append((10 - int(s[0])) % 10)
if a[0] > k:
print(0)
else:
f = 0
for i in range(1, n):
x = (10 - int(s[i])) % 10
b.append(x)
if b[i - 1] < x:
a.append(10 + a[i - 1])
else:
a.append(a[i - 1])
if a[i] > k:
f = i
break
if f != 0:
print(f)
else:
print(n)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
x = int(input())
for i in range(x):
n, k = list(map(int, input().split()))
z = input()
ans = 0
jj = 0
p = 0
while jj < n:
if z[jj] == "0":
p += 1
else:
break
jj += 1
if jj < n:
flag = 0
if jj == 0 and ans + 10 - int(z[jj]) <= k:
ans += 10 - int(z[jj])
p += 1
final = int(z[jj])
jj += 1
flag = 1
elif ans + 10 <= k:
ans += 10
p += 1
final = int(z[jj])
jj += 1
flag = 1
if flag == 1:
for kk in range(jj, n):
if z[kk] != "0" and (int(z[kk]) < int(z[kk - 1]) or z[kk - 1] == "0"):
final = int(z[kk])
if ans + 10 <= k:
ans += 10
p += 1
else:
break
else:
if z[kk] != "0":
final = int(z[kk])
p += 1
print(p)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
s = list(input().split())[0]
ls = [int(i) for i in s]
l = 0
h = n + 1
final = 0
while l < h:
m = l + h >> 1
tem = ls[:m]
add = 0
new = 0
for i in range(m - 1, -1, -1):
tem[i] = (tem[i] + add) % 10
if tem[i] == 0:
continue
else:
add = 10 - tem[i]
new += add
tem[i] = 0
add = new
if new <= k:
l = m + 1
final = len(tem)
elif new > k:
h = m
print(final)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def check(len_tried, k, arr):
total_felt = 0
for j in range(len_tried - 1, -1, -1):
num = arr[j]
needed = (10 - (num + total_felt) % 10) % 10
if total_felt + needed > k:
return False
total_felt = total_felt + needed
return True
def solve(n, k, arr) -> int:
l = 0
r = n
while r - l > 1:
mid = (l + r) // 2
is_possible = check(mid, k, arr)
if is_possible:
l = mid
else:
r = mid
if check(r, k, arr):
return r
return l
T = int(input())
for t in range(T):
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in list(input())]
print(solve(n, k, arr))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def costf(x):
add = 0
x1 = 0
while x >= 0:
if (int(s[x]) + add) % 10 == 0:
x -= 1
else:
x1 = x1 + (10 - (int(s[x]) + add) % 10)
add += 10 - (int(s[x]) + add) % 10
x -= 1
return x1
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
lp = 0
l = 0
h = n - 1
while l <= h:
m = (l + h) // 2
cost = costf(m)
if cost > k:
h = m - 1
elif cost <= k:
lp = m + 1
l = m + 1
print(lp)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1≤ L ≤ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 ≤ i ≤ L.
For example, if S=39590, then choosing L=3 and applying the operation yields the string S=\underline{406}90.
The prefix of string S of length l\;(1 ≤ l ≤ \mid S \mid ) is string S_{1} S_{2} \dots S_{l}. A prefix of length l is called good if S_{1}=0, S_{2}=0, \dots, S_{l}=0. Find the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains two space-separated integers N, K.
- The second line of each test case contains the string S.
------ Output Format ------
For each test case, output in a single line the length of the longest good prefix that can be obtained in string S by applying the given operation maximum K times.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$
$\mid S \mid = N$
$S$ contains digits from $0$ to $9$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
------ subtasks ------
Subtask 1 (100 points): Original constraints
----- Sample Input 1 ------
6
3 5
380
3 9
380
4 2
0123
5 13
78712
6 10
051827
8 25
37159725
----- Sample Output 1 ------
0
3
1
3
2
5
----- explanation 1 ------
Test case $1$: There is no way to obtain zeros on the prefix of the string $S = 380$ by applying the given operation maximum $5$ times.
Test case $2$: The optimal strategy is: choose $L = 2$ and apply the operation twice, resulting in $S=500$, then choose $L = 1$ and apply the operation $5$ times, resulting in $S=000$.
Test case $4$: One of the possible sequence of operations is the following:
- Choose $L = 5$ and apply the operation thrice, resulting in $S=01045$.
- Choose $L = 2$ and apply the operation $9$ times, resulting in $S=90045$.
- Choose $L = 1$ and apply the operation once, resulting in $S=00045$.
|
def prefx(s, r):
ops = 0
for i in range(r - 1, -1, -1):
req = (ops + ord(s[i]) - ord("0")) % 10
if req != 0:
ops += 10 - req
return ops
t = int(input())
for i in range(t):
n, k = map(int, input().split())
s = input()
l = 0
r = n + 1
while r - l > 1:
mid = (l + r) // 2
if prefx(s, mid) <= k:
l = mid
else:
r = mid
print(l)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN 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.