text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Tags: brute force, geometry
Correct Solution:
```
dic = {"t": False, "s": False}
a, b, c, d = list(map(int, input().split(" ")))
l = [[a, b, c], [a, b, d], [a, c, d], [b, c, d]]
for x, y, z in l:
if(x + y > z and y + z > x and x + z > y):
dic["t"] = True
break
elif(x + y == z or y + z == x or x + z == y):
dic["s"] = True
if(dic["t"]):
print("TRIANGLE")
elif(dic["s"]):
print("SEGMENT")
else:
print("IMPOSSIBLE")
```
| 94,000 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Tags: brute force, geometry
Correct Solution:
```
import sys
from itertools import combinations
sticks = list(map(int,sys.stdin.readline().split()))
for edges in combinations(sticks, 3):
edges = sorted(edges)
# edges.sort()
# print(edges)
if edges[0] + edges[1] > edges[-1] and edges[-1] - edges[0] < edges[1]:
print('TRIANGLE')
exit(0)
for edges in combinations(sticks, 3):
edges = sorted(edges)
# print(edges)
if edges[0] + edges[1] == edges[-1]:
print('SEGMENT')
exit(0)
print('IMPOSSIBLE')
```
| 94,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
a,b,c,d=sorted(list(map(int,input().split())))
if a+b>c or b+c>d:
print("TRIANGLE")
elif(a+b==c or b+c==d):
print("SEGMENT")
else:
print("IMPOSSIBLE")
```
Yes
| 94,002 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
def triangle(x, y, z):
if x + y > z and y + z > x and x + z > y:
return 'T'
if x + y == z or y + z == x or x + z == y:
return 'S'
else:
return 'I'
temp = list(map(int, input().split(' ')))
a, b, c, d = temp[0], temp[1], temp[2], temp[3]
if triangle(a, b, c) == 'T' or \
triangle(b, c, d) == 'T' or \
triangle(c, d, a) == 'T' or \
triangle(d, a, b) == 'T':
print('TRIANGLE')
elif triangle(a, b, c) == 'S' or \
triangle(b, c, d) == 'S' or \
triangle(c, d, a) == 'S' or \
triangle(d, a, b) == 'S':
print('SEGMENT')
else:
print('IMPOSSIBLE')
```
Yes
| 94,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
t = list(map(int,input().split()))
t.sort()
# print(t) # s0, s1, s2, s3
if t[3] < t[2] + t[1] or t[3] < t[0] + t[1] or t[2] < t[1] + t[0]:
print('TRIANGLE')
elif t[3] == t[2] + t[1] or t[3] == t[0] + t[1] or t[2] == t[1] + t[0]:
print('SEGMENT')
else:
print('IMPOSSIBLE')
```
Yes
| 94,004 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
a = sorted(int(x) for x in input().split())
if a[0] + a[1] > a[2] or a[1] + a[2] > a[3]:
print("TRIANGLE")
elif a[0] + a[1] == a[2] or a[1] + a[2] == a[3]:
print("SEGMENT")
else:
print("IMPOSSIBLE")
```
Yes
| 94,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
s_original = [int(i) for i in input().split()]
for i in range(4):
s = s_original.copy()
s.pop(i)
if(s[0] < s[1] + s[2] and s[1] < s[0] + s[2] and s[2] < s[1] + s[0]):
print('TRIANGLE')
exit(0)
for i in range(4):
s = s_original.copy()
s.pop(i)
if(s[0] == s[1] + s[2] or s[1] == s[0] + s[2] or s[2] == s[1] + s[0]):
print('SEGMENT')
exit(0)
print('IMPLOSSIBLE')
# 1512831717474
```
No
| 94,006 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
n=list(map(int,input().split()))
o,e=0,0
for i in range(4):
if n[i]%2==0:
e+=1
else:
o+=1
if o==1:
print('SEGMENT')
elif o==2:
print('TRIANGLE')
else:
print('IMPOSSIBLE')
```
No
| 94,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
#!/usr/bin/env python3
def s3(a, b, c):
diff = 2 * max(a, b, c) - (a + b + c)
if (diff < 0):
return 'TRIANGLE'
elif (diff == 0):
return 'SEGMENT'
else:
return 'IMPOSSIBLE'
def s4(a, b, c, d):
s = []
s.append(s3(a, b, c))
s.append(s3(a, b, d))
s.append(s3(a, c, d))
s.append(s3(b, c, d))
print(s)
if 'TRIANGLE' in s:
return 'TRIANGLE'
elif 'SEGMENT' in s:
return 'SEGMENT'
else:
return 'IMPOSSIBLE'
def main():
a, b, c, d = [ int(i) for i in input().split(' ') ]
print(s4(a, b, c, d))
if __name__ == '__main__':
main()
```
No
| 94,008 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Examples
Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
Submitted Solution:
```
a, b, c, d = map(int, input().split())
x = [a, b, c, d]
s=0
for i in range(4):
for j in range(4):
for k in range(4):
if (i != j != k):
a = min((x[i], x[j], x[k]))
c = max((x[i], x[j], x[k]))
b = sum((x[i], x[j], x[k]))-a-c
if (a+b<c):
print('TRIANGLE')
exit()
if (a+b==c):
s=1
if s:
print('SEGMENT')
else:
print('IMPOSSIBLE')
```
No
| 94,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
graph_b[v].append(t)
if u == 1:
double_graph_a[v][2] = t
double_graph_b[v][2] = 1
next_n = n + 1
for c in range(3, next_n):
for v in range(2, next_n):
for i, j in enumerate(graph_a[v]):
if double_graph_a[j][c-1]:
dist = double_graph_a[j][c-1] + graph_b[v][i]
if dist <= T and (not double_graph_a[v][c] or dist < double_graph_a[v][c]):
double_graph_a[v][c] = dist
double_graph_b[v][c] = j
start = n
stop = 0
step = -1
for i in range(start, stop, step):
if double_graph_b[start][i]:
break
res = [n]
while double_graph_b[res[-1]][i] != 1:
res.append(double_graph_b[res[-1]][i])
i -= 1
res += [1]
print(len(res))
print(' '.join(map(str, res[::-1])))
```
| 94,010 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
graph_b[v].append(t)
if u == 1:
double_graph_a[v][2] = t
double_graph_b[v][2] = 1
next_n = n + 1
for i in range(3, next_n):
for j in range(2, next_n):
for a, b in enumerate(graph_a[j]):
prev_i = i - 1
if double_graph_a[b][prev_i]:
to_compare = double_graph_a[b][prev_i] + graph_b[j][a]
if to_compare <= T and (not double_graph_a[j][i] or to_compare < double_graph_a[j][i]):
double_graph_a[j][i] = to_compare
double_graph_b[j][i] = b
start = n
stop = 0
step = -1
for i in range(start, stop, step):
if double_graph_b[start][i]:
break
lst = [n]
while double_graph_b[lst[-1]][i] != 1:
lst.append(double_graph_b[lst[-1]][i])
i -= 1
lst += [1]
len_res = len(lst)
print(len_res)
res = ' '.join(map(str, lst[::-1]))
print(res)
```
| 94,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
n, m, T = map(int, input().split())
adj = [[] for _ in range(n+1)]
ad_w = [[] for _ in range(n+1)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
pv = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
a, b, t = map(int, input().split())
# matrix[b][a] = t
adj[b].append(a)
ad_w[b].append(t)
if a == 1:
dp[b][2] = t
pv[b][2] = 1
# matrix[a][b] = t
for c in range(3, n + 1):
for v in range(2, n + 1):
for i, nx in enumerate(adj[v]):
if dp[nx][c-1]:
newdistance = dp[nx][c-1] + ad_w[v][i]
if newdistance <= T and (not dp[v][c] or newdistance < dp[v][c]):
dp[v][c] = newdistance
pv[v][c] = nx
for last in range(n,0,-1):
if pv[n][last]:
break
path = [n]
while pv[path[-1]][last] != 1:
path.append(pv[path[-1]][last])
last -= 1
path.append(1)
path.reverse()
print(len(path))
print(' '.join(map(str, path)))
```
| 94,012 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
from sys import stdin, stdout
# LinkedList.py
class LLNode:
def __init__(self, value = None, nextNode = None):
self.value, self.nextNode = value, nextNode
class LinkedList:
def __init__(self, rootNode = None):
self.rootNode = rootNode
def FindBestPath(self, wayTime):
cNode = self.rootNode
while cNode != None:
if cNode.value.wayTime <= wayTime:
break
cNode = cNode.nextNode
return cNode
def FindMaxPreNode(self, path, startNode): # by wayLen
if path.wayLen > startNode.value.wayLen:
return None
preNode = startNode
while preNode.nextNode != None:
if path.wayLen > preNode.nextNode.value.wayLen:
break
preNode = preNode.nextNode
return preNode
def FindMaxNextNode(self, path, startNode): # by wayTime
cNode = startNode
while cNode != None:
if cNode.value.wayTime < path.wayTime:
break
cNode = cNode.nextNode
return cNode
def RawInsert(self, path):
if path == None:
return
if self.rootNode == None:
self.rootNode = LLNode(path, None)
return
preNode = self.FindMaxPreNode(path, self.rootNode)
preNode.nextNode = LLNode(path, None)
def Insert(self, path):
if path == None:
return False
if self.rootNode == None:
self.rootNode = LLNode(path, None)
return True
preNode = self.FindMaxPreNode(path, self.rootNode)
node = None
if preNode == None:
node = LLNode(path, self.rootNode)
self.rootNode = node
else:
if path.wayTime < preNode.value.wayTime:
if path.wayLen == preNode.value.wayLen:
preNode.value = path
node = preNode
else:
node = LLNode(path, preNode.nextNode)
preNode.nextNode = node
else:
return False
if node.nextNode != None: # delete useless paths
nextNode = self.FindMaxNextNode(path, node.nextNode)
node.nextNode = nextNode
return True
# Main.py
cities = []
memo = []
T = 0
class Node:
def __init__(self, number, wayLen, wayTime, preNode):
self.number, self.wayLen, self.wayTime, self.preNode = number, wayLen, wayTime, preNode
class Path:
def __init__(self, wayLen, wayTime, nextNode):
self.wayLen, self.wayTime, self.nextNode = wayLen, wayTime, nextNode
def MemoizeWay2(endNode):
global memo, T
cNode = endNode
while cNode.preNode != None:
cLLNode = memo[cNode.number].rootNode
while cLLNode != None:
tailLen = cLLNode.value.wayLen + 1
tailTime = cLLNode.value.wayTime + cities[cNode.preNode.number][cNode.number]
memo[cNode.preNode.number].Insert(Path(tailLen, tailTime, cNode.number))
cLLNode = cLLNode.nextNode
cNode = cNode.preNode
def MemoizeWay(endNode, tailLen, tailTime):
global memo
cNode = endNode
while cNode.preNode != None:
tailLen += 1
tailTime += cities[cNode.preNode.number][cNode.number]
b = memo[cNode.preNode.number].Insert(Path(tailLen, tailTime, cNode.number))
if not b:
break
cNode = cNode.preNode
def main():
global T, cities
n, m, T = [int(s) for s in stdin.readline().split()]
cities = [None] * (n+1)
for i in range(m):
u, v, t = [int(s) for s in stdin.readline().split()]
if cities[u] == None:
cities[u] = {}
if u != n:
cities[u].update({v : t})
global memo
memo = [LinkedList() for i in range(n+1)]
memo[n].Insert(Path(1, 0, None))
stack = []
stack.append(Node(1, 1, 0, None))
while(len(stack) > 0):
city = stack.pop()
if city.number == n:
MemoizeWay(city, 1, 0)
continue
if memo[city.number].rootNode != None:
cNode = memo[city.number].rootNode
while cNode != None:
MemoizeWay(city, cNode.value.wayLen, cNode.value.wayTime)
cNode = cNode.nextNode
continue
if cities[city.number] != None:
for subCity in cities[city.number]:
stack.append(Node( subCity, city.wayLen + 1, city.wayTime + cities[city.number][subCity], city ))
cPath = memo[1].FindBestPath(T).value
stdout.write( "{}\n".format(cPath.wayLen) )
stdout.write( "{} ".format(1) )
while(cPath.nextNode != None):
stdout.write( "{} ".format(cPath.nextNode) )
cPath = memo[cPath.nextNode].FindBestPath(cPath.wayTime).value
main()
```
| 94,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
graph_b[v].append(t)
if u == 1:
double_graph_a[v][2] = t
double_graph_b[v][2] = 1
next_n = n + 1
for c in range(3, next_n):
for v in range(2, next_n):
for i, nx in enumerate(graph_a[v]):
if double_graph_a[nx][c-1]:
dist = double_graph_a[nx][c-1] + graph_b[v][i]
if dist <= T and (not double_graph_a[v][c] or dist < double_graph_a[v][c]):
double_graph_a[v][c] = dist
double_graph_b[v][c] = nx
for i in range(n, 0, -1):
if double_graph_b[n][i]:
break
res = [n]
while double_graph_b[res[-1]][i] != 1:
res.append(double_graph_b[res[-1]][i])
i -= 1
res += [1]
print(len(res))
print(' '.join(map(str, res[::-1])))
```
| 94,014 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
graph_b[v].append(t)
if u == 1:
double_graph_a[v][2] = t
double_graph_b[v][2] = 1
next_n = n + 1
for c in range(3, next_n):
for v in range(2, next_n):
for a, b in enumerate(graph_a[v]):
if double_graph_a[b][c-1]:
dist = double_graph_a[b][c-1] + graph_b[v][a]
if dist <= T and (not double_graph_a[v][c] or dist < double_graph_a[v][c]):
double_graph_a[v][c] = dist
double_graph_b[v][c] = b
start = n
stop = 0
step = -1
for i in range(start, stop, step):
if double_graph_b[start][i]:
break
res = [n]
while double_graph_b[res[-1]][i] != 1:
res.append(double_graph_b[res[-1]][i])
i -= 1
res += [1]
print(len(res))
print(' '.join(map(str, res[::-1])))
```
| 94,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
graph_b[v].append(t)
if u == 1:
double_graph_a[v][2] = t
double_graph_b[v][2] = 1
next_n = n + 1
for c in range(3, next_n):
for v in range(2, next_n):
for i, nx in enumerate(graph_a[v]):
if double_graph_a[nx][c-1]:
dist = double_graph_a[nx][c-1] + graph_b[v][i]
if dist <= T and (not double_graph_a[v][c] or dist < double_graph_a[v][c]):
double_graph_a[v][c] = dist
double_graph_b[v][c] = nx
start = n
stop = 0
step = -1
for i in range(start, stop, step):
if double_graph_b[start][i]:
break
res = [n]
while double_graph_b[res[-1]][i] != 1:
res.append(double_graph_b[res[-1]][i])
i -= 1
res += [1]
print(len(res))
print(' '.join(map(str, res[::-1])))
```
| 94,016 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Tags: dp, graphs
Correct Solution:
```
if __name__=='__main__':
n, m, t = map(int, input().split())
edge = {i:{} for i in range(n)}
income = [0 for i in range(n)]
for i in range(m):
u, v, ti = map(int, input().split())
edge[v-1][u-1] = ti
income[u-1] += 1
stat = [{} for _ in range(n)]
stat[n-1] = {1 : (0, -1)}
queue = [n-1]
first = 0
last = 1
for i in range(n-2, 0, -1):
if income[i] == 0:
queue.append(i)
last += 1
while (first < last):
v = queue[first]
first += 1
for u in edge[v].keys():
income[u] -= 1
for vis in stat[v].keys():
cost = stat[v][vis][0] + edge[v][u]
ucost = stat[u].get(vis+1, (t+1,-1))[0]
if ucost > cost:
stat[u][vis+1] = (cost, v)
if income[u] <= 0:
queue.append(u)
last += 1
#print(queue, last)
res = max(stat[0].keys())
print(res)
path = []
curr = 0
path.append(curr+1)
while(stat[curr][res][1] >= 0):
curr = stat[curr][res][1]
path.append(curr+1)
res -= 1
print(' '.join(map(str, path)))
```
| 94,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/20/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(N, M, T, edges):
g = collections.defaultdict(list)
for u, v, t in edges:
g[u].append((v, t))
dp = [[T+1 for _ in range(N+1)] for _ in range(N + 1)]
pre = [[0 for _ in range(N+1)] for _ in range(N + 1)]
dp[1][1] = 0
pre[1][1] = 0
# q = [(0, 0, -1, 1)]
# heapq.heapify(q)
# while q:
# _, pcost, pdist, pcity = heapq.heappop(q)
# pdist = -pdist
# if pcost > dp[pcity][pdist]:
# continue
# for dest, ncost in g[pcity]:
# cost = pcost + ncost
# dist = pdist + 1
# if cost <= T and dp[dest][dist] > cost:
# dp[dest][dist] = cost
# pre[dest][dist] = pcity
# heapq.heappush(q, (cost/dist, cost, -dist, dest))
q = [(1, 1, 0)]
while q:
nq = []
for city, dist, pcost in q:
dist += 1
for dest, ncost in g[city]:
cost = pcost + ncost
if cost <= T and dp[dest][dist] > cost:
dp[dest][dist] = cost
pre[dest][dist] = city
nq.append((dest, dist, cost))
q = nq
# print(dp[N])
ans = max([i for i in range(N, -1, -1) if dp[N][i] <= T])
print(ans)
path = []
k = N
l = ans
while k:
path.append(k)
k = pre[k][l]
l -= 1
print(' '.join(map(str, path[::-1])))
N, M, T = map(int, input().split())
edges = []
for i in range(M):
u, v, t = map(int, input().split())
edges.append((u, v, t))
solve(N, M, T, edges)
```
Yes
| 94,018 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
a, b, t = map(int, input().split())
graph_a[b].append(a)
graph_b[b].append(t)
if a == 1:
double_graph_a[b][2] = t
double_graph_b[b][2] = 1
for c in range(3, n+1):
for v in range(2, n+1):
for i, nx in enumerate(graph_a[v]):
if double_graph_a[nx][c-1]:
dist = double_graph_a[nx][c-1] + graph_b[v][i]
if dist <= T and (not double_graph_a[v][c] or dist < double_graph_a[v][c]):
double_graph_a[v][c] = dist
double_graph_b[v][c] = nx
for i in range(n,0,-1):
if double_graph_b[n][i]:
break
res = [n]
while double_graph_b[res[-1]][i] != 1:
res.append(double_graph_b[res[-1]][i])
i -= 1
res += [1]
print(len(res))
print(' '.join(map(str, res[::-1])))
```
Yes
| 94,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
from sys import stdin, stdout
# LinkedList.py
class LLNode:
def __init__(self, value = None, nextNode = None):
self.value, self.nextNode = value, nextNode
class LinkedList:
def __init__(self, rootNode = None):
self.rootNode = rootNode
def FindBestPath(self, wayTime):
cNode = self.rootNode
while cNode != None:
if cNode.value.wayTime <= wayTime:
break
cNode = cNode.nextNode
return cNode
def FindMaxPreNode(self, path, startNode): # by wayLen
if path.wayLen > startNode.value.wayLen:
return None
preNode = startNode
while preNode.nextNode != None:
if path.wayLen > preNode.nextNode.value.wayLen:
break
preNode = preNode.nextNode
return preNode
def FindMaxNextNode(self, path, startNode): # by wayTime
cNode = startNode
while cNode != None:
if cNode.value.wayTime < path.wayTime:
break
cNode = cNode.nextNode
return cNode
def RawInsert(self, path):
if path == None:
return
if self.rootNode == None:
self.rootNode = LLNode(path, None)
return
preNode = self.FindMaxPreNode(path, self.rootNode)
preNode.nextNode = LLNode(path, None)
def Insert(self, path):
if path == None:
return False
if self.rootNode == None:
self.rootNode = LLNode(path, None)
return True
preNode = self.FindMaxPreNode(path, self.rootNode)
node = None
if preNode == None:
node = LLNode(path, self.rootNode)
self.rootNode = node
else:
if path.wayTime < preNode.value.wayTime:
if path.wayLen == preNode.value.wayLen:
preNode.value = path
node = preNode
else:
node = LLNode(path, preNode.nextNode)
preNode.nextNode = node
else:
return False
if node.nextNode != None: # delete useless paths
nextNode = self.FindMaxNextNode(path, node.nextNode)
node.nextNode = nextNode
return True
# Main.py
cities = []
memo = []
T = 0
class Node:
def __init__(self, number, wayLen, wayTime, preNode):
self.number, self.wayLen, self.wayTime, self.preNode = number, wayLen, wayTime, preNode
class Path:
def __init__(self, wayLen, wayTime, nextNode):
self.wayLen, self.wayTime, self.nextNode = wayLen, wayTime, nextNode
# def MemoizeWay2(endNode):
# global memo, T
# cNode = endNode
# while cNode.preNode != None:
# cLLNode = memo[cNode.number].rootNode
# while cLLNode != None:
# tailLen = cLLNode.value.wayLen + 1
# tailTime = cLLNode.value.wayTime + cities[cNode.preNode.number][cNode.number]
# memo[cNode.preNode.number].Insert(Path(tailLen, tailTime, cNode.number))
# cLLNode = cLLNode.nextNode
# cNode = cNode.preNode
def MemoizeWay(endNode, tailLen, tailTime):
global memo
cNode = endNode
while cNode.preNode != None:
tailLen += 1
tailTime += cities[cNode.preNode.number][cNode.number]
b = memo[cNode.preNode.number].Insert(Path(tailLen, tailTime, cNode.number))
# if not b:
# break
cNode = cNode.preNode
def main():
global T, cities
n, m, T = [int(s) for s in stdin.readline().split()]
cities = [None] * (n+1)
for i in range(m):
u, v, t = [int(s) for s in stdin.readline().split()]
if cities[u] == None:
cities[u] = {}
if u != n:
cities[u].update({v : t})
global memo
memo = [LinkedList() for i in range(n+1)]
memo[n].Insert(Path(1, 0, None))
stack = []
stack.append(Node(1, 1, 0, None))
while(len(stack) > 0):
city = stack.pop()
if city.number == n:
MemoizeWay(city, 1, 0)
continue
if memo[city.number].rootNode != None:
cNode = memo[city.number].rootNode
while cNode != None:
MemoizeWay(city, cNode.value.wayLen, cNode.value.wayTime)
cNode = cNode.nextNode
continue
if cities[city.number] != None:
for subCity in cities[city.number]:
stack.append(Node( subCity, city.wayLen + 1, city.wayTime + cities[city.number][subCity], city ))
cPath = memo[1].FindBestPath(T).value
stdout.write( "{}\n".format(cPath.wayLen) )
stdout.write( "{} ".format(1) )
while(cPath.nextNode != None):
stdout.write( "{} ".format(cPath.nextNode) )
cPath = memo[cPath.nextNode].FindBestPath(cPath.wayTime).value
main()
```
Yes
| 94,020 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
graph_b[v].append(t)
if u == 1:
double_graph_a[v][2] = t
double_graph_b[v][2] = 1
next_n = n + 1
for i in range(3, next_n):
for j in range(2, next_n):
for a, b in enumerate(graph_a[j]):
if double_graph_a[b][i-1]:
dist = double_graph_a[b][i-1] + graph_b[j][a]
if dist <= T and (not double_graph_a[j][i] or dist < double_graph_a[j][i]):
double_graph_a[j][i] = dist
double_graph_b[j][i] = b
start = n
stop = 0
step = -1
for i in range(start, stop, step):
if double_graph_b[start][i]:
break
res = [n]
while double_graph_b[res[-1]][i] != 1:
res.append(double_graph_b[res[-1]][i])
i -= 1
res += [1]
print(len(res))
print(' '.join(map(str, res[::-1])))
```
Yes
| 94,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
t = input
p = print
r = range
n, m, T = map(int, t().split())
w = []
graph = {i: set() for i in r(n + 1)}
ti = {}
for i in r(m):
u, v, time = map(int, t().split())
graph[u].add(v)
graph[v].add(u)
ti[(u, v)] = time
def dfs_paths(graph, start, goal):
stack = [(start, [start])]
while stack:
(vertex, path) = stack.pop()
for next in graph[vertex] - set(path):
if next == goal:
yield path + [next]
else:
stack.append((next, path + [next]))
pos_paths = list(dfs_paths(graph, 1, n))
ans = 2
ans_p = [1, n]
for path in pos_paths:
t = 0
for i in r(1, len(path)):
t += ti[(path[i - 1], path[i])]
if t <= T and ans < len(path):
ans_p = path
p(ans)
p(' '.join(map(str, ans_p)))
```
No
| 94,022 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
import copy
def bfs(array, end, limit):
maximum = 0
queue = [[[1], 0]]
while queue:
path = queue.pop(0)
node = path[0][-1]
for i in range(node + 1, end + 1):
if array[node][i] != -1:
new_path = copy.deepcopy(path)
new_path[0].append(i)
new_path[1] += array[node][i]
if not new_path[1] > limit:
if i == end:
if len(new_path[0]) > maximum:
max_path = new_path
maximum = len(new_path[0])
else:
queue.append(new_path)
return max_path
n, m, T = [int(x) for x in input().split()]
adjacency = [[-1] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
u, v, t = [int(x) for x in input().split()]
adjacency[u][v] = t
answer = bfs(adjacency, n, T)[0]
print(len(answer))
for element in answer:
print(element, end=' ')
```
No
| 94,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
from collections import defaultdict
N, M, T = map(int, input().split())
G = defaultdict(list)
for _ in range(M):
u, v, t = map(int, input().split())
G[u] += [(v, t)]
global ans, j
ans = 0
j = []
def dfs(quota, u, count, stk):
global ans, j
stk.append(u)
for v, t in G[u]:
if quota - t > 0:
dfs(quota - t, v, count + 1, stk)
if count > ans:
j = list(stk)
ans = count
stk.pop()
dfs(T, 1, 0, [])
print(ans + 1)
print(" ".join(map(str, j)))
```
No
| 94,024 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
Input
The first line of the input contains three integers n, m and T (2 β€ n β€ 5000, 1 β€ m β€ 5000, 1 β€ T β€ 109) β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 β€ ui, vi β€ n, ui β vi, 1 β€ ti β€ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output
Print the single integer k (2 β€ k β€ n) β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line β indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Examples
Input
4 3 13
1 2 5
2 3 7
2 4 8
Output
3
1 2 4
Input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
Output
4
1 2 4 6
Input
5 5 6
1 3 3
3 5 3
1 2 2
2 4 3
4 5 2
Output
3
1 3 5
Submitted Solution:
```
n, m, T = map(int, input().split())
adj = [[] for _ in range(n+1)]
adj_w = [[] for _ in range(n+1)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
pv1 = [[1] for _ in range(n+1)]
pv2 = [[1] for _ in range(n+1)]
for i in range(m):
a, b, t = map(int, input().split())
adj[b].append(a)
adj_w[b].append(t)
if a == 1:
dp[b][2] = t
pv1[b].append(b)
pv2[b].append(b)
for c in range(3, n + 1):
for v in range(2, n + 1):
for i, nx in enumerate(adj[v]):
if nx == n or not dp[nx][c-1]:continue
newdistance = dp[nx][c-1] + adj_w[v][i]
if newdistance <= T and (not dp[v][c] or newdistance < dp[v][c]):
if m == 98 and v == 50:
print(pv1[11])
dp[v][c] = newdistance
pv1[v] = pv1[nx]
pv1[v].append(v)
# print(c,pv1[11])
if m == 98 and c == 50:
print(pv1[50])
pv1[nx] = pv2[nx].copy()
print(len(pv1[n]))
print(' '.join(map(str, pv1[n])))
```
No
| 94,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
#!/usr/bin/python
from sys import argv,exit
def get_str():
return input()
def get_int():
return int(input())
def get_ints(sep=' '):
if not sep:
return [int(c) for c in input()]
return [int(i) for i in input().split(sep)]
def prnt(*args):
if '-v' in argv:
print(*args)
def ir(aps, i):
return i >= 0 and i < len(aps)
l1 = get_ints()
n = l1[0]
start = l1[1]
end = l1[2]
aps = get_ints('')
start -= 1
end -= 1
total = 0
if aps[start] == aps[end]:
print(0)
exit(0)
else:
print(1)
#i = 1
#while ir(aps, end-i) or ir(aps, end+1):
# if ir(aps, end - i):
# if aps[end-i] == aps[start]:
# print(i)
# exit(0)
# if ir(aps, end + i):
# if aps[end+i] == aps[start]:
# print(i)
# exit(0)
# i+=1
#print('Hello World')
```
| 94,026 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
(a, b, _), owners = sorted(map(int, input().split())), '_' + input()
print(int(owners[a] != owners[b]))
```
| 94,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
val= input()
store=val.split()
n=int(store[0])
a=int(store[1])
b= int(store[2])
airport_code = input()
if airport_code[a-1]==airport_code[b-1]:
print(0)
else:
print(1)
```
| 94,028 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,a,b=map(int,input().split())
d=[int(x) for x in input()]
if d[a-1]==d[b-1]:
print(0)
else:
print(1)
```
| 94,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
def vla_air(n,a,b,s):
x=s[a-1]
y=s[b-1]
if x==y:
return 0
if a==b:
return 0
if a>b or a<b:
return 1
n,a,b=list(map(int,input().strip().split()))
s=str(input())
print(vla_air(n,a,b,s))
```
| 94,030 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
n, a, b = list(map(int, input().rstrip().split()))
s = input()
if s[a - 1] == s[b - 1]:
print(0)
else:
print(1)
```
| 94,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
tmp = input().split(' ')
n = int(tmp[0])
a = int(tmp[1])
b = int(tmp[2])
str = input()
if str[a-1] == str[b-1]:
print('0')
else:
print('1')
```
| 94,032 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
n, a, b = map(int, input().split())
s = input()
a -= 1
b -= 1
if a>b:
s = s[::-1]
a = n-a-1
b = n-b-1
if s[a] == s[b]:
print("0")
else:
count = 0
for i in range(b, a-1, -1):
if s[i]!=s[a]:
count += 1
break
print(count)
```
| 94,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
######### ## ## ## #### ##### ## # ## # ##
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # # # # # # # # #
# ##### # # # # ### # # # # # # # # #####
# # # # # # # # # # # # # # # # # #
######### # # # # ##### # ##### # ## # ## # #
"""
PPPPPPP RRRRRRR OOOO VV VV EEEEEEEEEE
PPPPPPPP RRRRRRRR OOOOOO VV VV EE
PPPPPPPPP RRRRRRRRR OOOOOOOO VV VV EE
PPPPPPPP RRRRRRRR OOOOOOOO VV VV EEEEEE
PPPPPPP RRRRRRR OOOOOOOO VV VV EEEEEEE
PP RRRR OOOOOOOO VV VV EEEEEE
PP RR RR OOOOOOOO VV VV EE
PP RR RR OOOOOO VV VV EE
PP RR RR OOOO VVVV EEEEEEEEEE
"""
"""
Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def factorial(x, m):
val = 1
while x>0:
val = (val * x) % m
x -= 1
return val
def fact(x):
val = 1
while x > 0:
val *= x
x -= 1
return val
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
## gcd function
def gcd(a,b):
if b == 0:
return a;
return gcd(b, a % b);
## lcm function
def lcm(a, b):
return (a * b) // math.gcd(a, b)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if k > n:
return 0
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0 and n > 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0 and n > 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b;
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
prime[0], prime[1] = False, False
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
# Euler's Toitent Function phi
def phi(n) :
result = n
p = 2
while(p * p<= n) :
if (n % p == 0) :
while (n % p == 0) :
n = n // p
result = result * (1.0 - (1.0 / (float) (p)))
p = p + 1
if (n > 1) :
result = result * (1.0 - (1.0 / (float)(n)))
return (int)(result)
def is_prime(n):
if n == 0:
return False
if n == 1:
return True
for i in range(2, int(n ** (1 / 2)) + 1):
if not n % i:
return False
return True
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
res = []
for i in range(2, int(x ** 0.5) + 1):
while x % i == 0:
res.append(i)
x //= i
if x != 1:
res.append(x)
return res
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
def factors(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
res.append(n // i)
return list(set(res))
## taking integer array input
def int_array():
return list(map(int, input().strip().split()));
def float_array():
return list(map(float, input().strip().split()));
## taking string array input
def str_array():
return input().strip().split();
def binary_search(low, high, w, h, n):
while low < high:
mid = low + (high - low) // 2
# print(low, mid, high)
if check(mid, w, h, n):
low = mid + 1
else:
high = mid
return low
## for checking any conditions
def check(l, a, n):
print(l, a, n)
for i in range(n - l):
if a[i:l] == list(sorted(a[i:l])):
return True
print("YEAAH")
return False
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
from itertools import permutations
import math
import bisect as bis
import random
import sys
def solve():
n, a, b = read()
airport = input().rstrip()
if airport[a - 1] == airport[b - 1]:
print(0)
else:
print(1)
if __name__ == '__main__':
for _ in range(1):
solve()
# fin_time = datetime.now()
# print("Execution time (for loop): ", (fin_time-init_time))
```
Yes
| 94,034 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
def findLR(s,a):
start = s[a-1]
l = -1
tmp = a-2
while(tmp>=0):
if start!=s[tmp]:
l = tmp
break
tmp = tmp-1
r = -1
tmp = a
while(tmp<len(s)):
if start!=s[tmp]:
r = tmp
break
tmp = tmp+1
return[a-l-1,r-a+1]
inp = input().split(' ')
n = int(inp[0])
a = int(inp[1])
b = int(inp[2])
s = str(input())
if s[a-1]==s[b-1]:
print(0)
else:
start = s[a-1]
m = abs(a-b)
for i in range(len(s)):
if(s[i]==start):
tmp = findLR(s,i+1)
if(tmp[0]>0):
if tmp[0]<m:
m = tmp[0]
if m == 1:
break
if tmp[1]>0:
if tmp[1]<m:
m = tmp[1]
if m ==1:
break
print(m)
```
Yes
| 94,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
a,b,c=map(int,input().split())
z=input()
print((z[b-1]!=z[c-1])+0)
```
Yes
| 94,036 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
n, a, b = [int(s) for s in input().split()]
c = [1 if c == '1' else 0 for c in input()]
print(0 if c[a-1] == c[b-1] else 1)
```
Yes
| 94,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
import sys
from os import path
if (path.exists('input.txt') and path.exists('output.txt')):
sys.stdout = open('output.txt', 'w')
sys.stdin = open('input.txt', 'r')
def main():
n, a, b = (int(i) for i in input().split())
a -= 1
b -= 1
s = input()
if s[a] == s[b]:
print(0)
else:
ans = 1e6
for i in range(n):
if s[i] == s[a] and i != a:
ans = min(ans, abs(i - b))
print(ans)
main()
```
No
| 94,038 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
n, a, b = map(int, input().split())
s = input().strip()
print(abs(s[a - 1] == s[b - 1]))
```
No
| 94,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
import sys
from os import path
if (path.exists('input.txt') and path.exists('output.txt')):
sys.stdout = open('output.txt', 'w')
sys.stdin = open('input.txt', 'r')
def main():
n, a, b = (int(i) for i in input().split())
a -= 1
b -= 1
s = input()
if s[a] == s[b]:
print(0)
else:
ans = 1e6
i = 0
while i < n:
if s[i] == s[a]:
for j in range(i + 1, n):
if s[j] == s[b]:
ans = min(ans, abs(i - j))
i = j
break
if s[i] == s[b]:
for j in range(i + 1, n):
if s[j] == s[a]:
ans = min(ans, abs(i - j))
i = j
break
i += 1
print(ans)
main()
```
No
| 94,040 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input
The first line contains three integers n, a, and b (1 β€ n β€ 105, 1 β€ a, b β€ n) β the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
Output
Print single integer β the minimum cost Vladik has to pay to get to the olympiad.
Examples
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
Note
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
Submitted Solution:
```
try:
n = int(input())
a = int(input()) - 1
b = int(input()) - 1
atemp = a
airports = input()
if n >= 1 and n <= 10**5 and n >= 1 and b >= 1 and a <= n and b <= n:
while True:
closest = 0
for i in range(b, n):
if airports[i] == airports[a]:
closest = i
break
for i in range(b, -1, -1):
if airports[i] == airports[a]:
if abs(closest - b) > abs(i - b):
closest = i
break
a = closest
if a == b:
break
if b - a < 0:
a -= 1
else:
a += 1
if airports[atemp] == airports[b]:
print(0)
else:
print(1)
except:
pass
```
No
| 94,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
n = int(input())
s = input()
S = [ord(znak) - 97 for znak in s]
a = list(map(int, input().strip().split(' ')))
#print(n, S, a)
MOD = 10**9 + 7
st = [0]*(n+1)
st[0] = 1
maks = [0]*(n+1)
minway = [10**4]*(n+1)
minway[0] = 0
for i in range(1, n + 1):
cnt = 0
maks_dolzina = n
for j in range(i, 0, -1):
maks_dolzina = min(maks_dolzina, a[S[j - 1]])
if i - j + 1 > maks_dolzina:
break
cnt += st[j-1]
maks[i] = max(i-j+1, maks[j-1], maks[i])
minway[i] = min(minway[i], 1 + minway[j-1])
st[i] = cnt
print(st[-1] % MOD)
print(maks[-1])
print(minway[-1])
```
| 94,042 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
N, s, l = int(input()), [ord(x) - ord('a') for x in input()], [int(x) for x in input().split()]
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
tmp = 0
for i in range(len(arr)):
arr[i][1] = min(arr[i][1],l[c])
if i + 1 >= arr[i][1]:
arr = arr[:i]
if(t > i):
t = 0
mi += 1
break
else:
tmp += arr[i][0]
t += 1
arr.insert(0, [total, l[c]])
ma = max(ma, len(arr))
total += tmp
total %= 10 ** 9 + 7;
print(total)
print(ma)
print(mi)
# Made By Mostafa_Khaled
```
| 94,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
from sys import stdin, stdout
n = int(stdin.readline())
s = stdin.readline().strip()
length = list(map(int, stdin.readline().strip().split()))
bn = [2 ** i for i in range(10 ** 3 + 2)]
dp = [0 for i in range(n + 10)]
dp[0] = 1
dp[-1] = 1
ans = [0, 1, 0]
dp1 = [0 for i in range(n + 5)]
dp1[0] = 1
for i in range(1, n):
label = 1
cnt = min(i + 1, length[ord(s[i]) - ord('a')])
while label:
label = 0
for ind in range(i - cnt + 1, i + 1):
if length[ord(s[ind]) - ord('a')] < cnt:
cnt -= 1
label = 1
break
dp1[i] = dp1[i - cnt] + 1
ans[1] = max(ans[1], cnt)
if cnt == i + 1:
dp[i] = bn[cnt - 1]
else:
for j in range(1, cnt + 1):
dp[i] += dp[i - j]
ans[0] = (dp[n - 1] % (10 ** 9 + 7))
ans[2] = dp1[n - 1]
stdout.write('\n'.join(list(map(str, ans))))
```
| 94,044 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations, combinations
from sys import stdout
R = lambda: map(int, input().split())
n = int(input())
arr = list(map(lambda x: ord(x) - ord('a'), input()))
dis = list(R())
comb = [0] * (1 + n)
cnt = [math.inf] * n
mlen = 0
for i in range(n):
lm = dis[arr[i]]
j = i
while j >= 0 and i - j + 1 <= min(lm, dis[arr[j]]):
lm = min(lm, dis[arr[j]])
comb[i] = (comb[i] + max(1, comb[j - 1])) % (10**9 + 7)
cnt[i] = min(cnt[i], (cnt[j - 1] if j >= 1 else 0) + 1)
j -= 1
mlen = max(mlen, i - j)
print(comb[n - 1])
print(mlen)
print(max(cnt))
```
| 94,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
import sys
from collections import deque
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
def get_minsp(message, As):
min_sp = 1
cur_len = 0
capa = 0
for ch in message:
index = ord(ch) - ord('a')
if cur_len == 0:
cur_len += 1
capa = As[index]
else:
capa = min(capa, As[index])
if cur_len + 1 <= capa:
cur_len += 1
else:
min_sp += 1
cur_len = 1
capa = As[index]
return min_sp
def solve():
MOD = 10**9 + 7
n = int(input())
msg = input()
As = [int(i) for i in input().split()]
caps = []
for ch in msg:
idx = ord(ch) - ord('a')
caps.append(As[idx])
dp = [0] * (n + 1)
dp[0] = 1
max_len = 0
lim = 0
for i in range(1, n + 1):
lim = caps[i - 1]
cur_len = 1
for j in range(i - 1, -1, -1):
if cur_len > lim:
break
max_len = max(max_len, cur_len)
dp[i] += dp[j]
dp[i] %= MOD
lim = min(lim, caps[j - 1])
cur_len += 1
min_sp = get_minsp(msg, As)
# debug(dp, locals())
print(dp[n])
print(max_len)
print(min_sp)
if __name__ == '__main__':
solve()
```
| 94,046 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
import sys
mod = pow(10, 9) + 7
n = int(sys.stdin.readline())
s = sys.stdin.readline()[:-1]
a = [int(x) for x in sys.stdin.readline().split()]
dp = [0 for _ in range(n+1)]
dp[0] = 1
def ci(c):
return ord(c)-ord('a')
l = 0
for i in range(1, n+1):
# f: represents the farther
# we can get from x (going from
# right to left) without breaking
# the splitting rules
f = 0
for x in range(i-1, -1, -1):
f = max(f, i-a[ci(s[x])])
if f > x:
# we broke the rule
continue
dp[i] = (dp[i]+dp[x]) % mod
l = max(l, i-x)
print(dp[n])
print(l)
res = 1
m = 9999
j = 0
for i in range(n):
m = min([a[ci(s[x])] for x in range(j, i+1)])
if m < i-j+1:
res += 1
j = i
print(res)
```
| 94,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
#!/bin/python3
import sys
mod = 10 **9 + 7
n = int(input())
s = input()
cnt = list(map(int, input().split()))
dp = [0]
for i in range(0,n):
dp.append(0)
dp[0] = 1
ans2 = 1
for i in range(1,n + 1):
o = i -1
ml = cnt[ord(s[o]) - ord('a')]
l = 1
while ml >= l and o >= 0:
dp[i] += dp[o]
dp[i] = dp[i] % mod
if l > ans2:
ans2 = l
l += 1
o -= 1
ml = min(ml, cnt[ord(s[o]) - ord('a')])
ans1 = dp[n] % mod
ans3 = 0
ml = n
l = 0
for i in range(n):
ml = min(ml,cnt[ord(s[i]) - ord('a')])
l+=1
if l > ml:
ans3+=1
l = 1
ml = cnt[ord(s[i]) - ord('a')]
ans3 += 1
print(ans1)
print(ans2)
print(ans3)
```
| 94,048 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Tags: brute force, dp, greedy, strings
Correct Solution:
```
N, s, l = int(input()), [ord(x) - ord('a') for x in input()], [int(x) for x in input().split()]
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
tmp = 0
for i in range(len(arr)):
arr[i][1] = min(arr[i][1],l[c])
if i + 1 >= arr[i][1]:
arr = arr[:i]
if(t > i):
t = 0
mi += 1
break
else:
tmp += arr[i][0]
t += 1
arr.insert(0, [total, l[c]])
ma = max(ma, len(arr))
total += tmp
total %= 10 ** 9 + 7;
print(total)
print(ma)
print(mi)
```
| 94,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
from math import inf
n=int(input())
s=input().strip()
a=[int(X) for X in input().split()]
dp=[0]*(n+1)
dp[1]=1
dp[0]=1
dp12=[inf]*(n+1)
dp12[1]=1
dp12[0]=0
c=1
mod=10**9 + 7
for i in range(2,n+1):
m=10000
for j in range(i,0,-1):
m=min(a[ord(s[j-1])-97],m)
if (i-j+1>m):
break
#print(m,i)
dp[i]=(dp[i]+dp[j-1])%mod
dp12[i]=min(dp12[i],dp12[j-1]+1)
c=max(c,i-j+1)
print(dp[n])
print(c)
print(dp12[n])
```
Yes
| 94,050 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
import sys
import copy
import os
# sys.stdin = open(os.path.join(os.path.dirname(__file__), '2.in'))
def solve():
MOD = int(1e9+7)
f = 0
n = int(input())
s = input()
alphabet ={ chr(ord('a')+i):num for i,num in enumerate( map(lambda x :int(x),input().split()) ) }
dp =[0 for _ in range(n)]; minlen = 2<<20; maxlen=0
minsplitnum =[2<<20 for _ in range(n)]
def check(newstr,start,end):
nl = end-start
while start < end:
if alphabet[newstr[start]] < nl:
return False
start+=1
# print(newstr)
return True
i = 0
while i < n:
# for i in range(n):
if i == 0:
dp[i] = 1
maxlen = 1
minsplitnum[i] = 1
else:
f = 0
# divide the element to one
dp[i] = (dp[i-1] + dp[i])%MOD
minsplitnum[i] = minsplitnum[i-1]+1 if minsplitnum[i] > minsplitnum[i-1]+1 else minsplitnum[i]
# divide the element to before
j = i-1
f = i + 1 - alphabet[s[i]] if i + 1 - alphabet[s[i]] > f else f
while j >= 0:
# print('j',j)
f = i + 1 - alphabet[s[j]] if i + 1 - alphabet[s[j]] > f else f
if j >= f:
if j == 0:
dp[i] = (1 + dp[i])%MOD
else:
dp[i] = (dp[j-1] + dp[i])%MOD
maxlen = i-j+1 if i -j + 1 > maxlen else maxlen
if j == 0:
minsplitnum[i] = 1 if 1 < minsplitnum[i] else minsplitnum[i]
else:
minsplitnum[i] = minsplitnum[j-1]+1 if minsplitnum[j-1]+1 < minsplitnum[i] else minsplitnum[i]
j -= 1
else:
j -= 1
continue
i += 1
# print(dp[i])
print(int(dp[n-1]))
print(maxlen)
print(int(minsplitnum[n-1]))
solve()
```
Yes
| 94,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
read = lambda: map(int, input().split())
n = int(input())
s = input()
a = list(read())
dp = [0] * (n + 2)
mn = [10 ** 4] * (n + 2)
dp[0] = dp[n + 1] = 1
mn[n + 1] = 0
mn[0] = 1
Max = 1
mod = 10 ** 9 + 7
for i in range(1, n):
res = 0
cur = 10 ** 4
for j in range(i, -1, -1):
c = ord(s[j]) - ord('a')
cur = min(cur, a[c])
if cur < (i - j + 1):
break
dp[i] = (dp[i] + dp[j - 1]) % mod
mn[i] = min(mn[i], mn[j - 1] + 1)
Max = max(Max, i - j + 1)
print(dp[n - 1])
print(Max)
print(mn[n - 1])
```
Yes
| 94,052 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
n=int(input())
d=[0]*(n+1)
way=[n]*(n+1)
s='0'+input()
m=list(map(int,input().split()))
d[1]=1
d[0]=1
way[0]=0
way[1]=1
dic=dict()
dic['0']=1000
i=0
for l in 'abcdefghijklmnopqrstuvwxyz':
dic[l]=m[i]
i+=1
high=1
big=10**9+7
for i in range(2,n+1):
z=i-1
x=i-dic[s[i]]
while z>=0 and x<=z:
x = max(x, i-dic[s[z]])
high = max(high, i - z)
d[i] += d[z]
way[i] = way[z] + 1
z -= 1
d[i]=d[i]%big
z+=1
if not z:
high=i
print(d[-1])
print(high)
print(way[-1])
```
Yes
| 94,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
n=int(input())
st=input()
a=list(map(int,input().split()))
list=[[] for i in range(n)]
arr=[]
for i in range(n):
arr.append(a[ord(st[i])-97])
ans3=0
add=0
flag=0
for i in range(n):
mini=arr[i]
count=1
j=i
while count <= mini and j<n:
list[i].append(j)
j+=1
count+=1
if j<n:
mini=min(mini,arr[j])
if i==ans3 and flag==0:
add+=1
ans3=j-1
if j==n:
flag=1
counted=[0 for i in range(n)]
for i in list[0]:
counted[i]=1
ans2=len(list[0])
i=0
while i<n-1:
total=counted[i]
ans2=max(ans2,len(list[i]))
for j in list[i+1]:
counted[j]+=total
i+=1
ans2=max(ans2,len(list[i]))
print(counted[n-1])
print(ans2)
print(add)
```
No
| 94,054 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
import sys
mod = pow(10, 9) + 7
n = int(sys.stdin.readline())
s = sys.stdin.readline()[:-1]
a = [int(x) for x in sys.stdin.readline().split()]
dp = [0 for _ in range(n+1)]
dp[0] = 1
def ci(c):
return ord(c)-ord('a')
l = 0
for i in range(1, n+1):
# f: represents the farther
# we can get from x (going from
# right to left) without breaking
# the splitting rules
f = 0
for x in range(i-1, -1, -1):
f = max(f, i-a[ci(s[x])])
if f > x:
# we broke the rule
continue
dp[i] = (dp[i]+dp[x]) % mod
l = max(l, i-x)
print(dp[n])
print(l)
res = 1
m = 9999
j = 0
for i in range(n):
m = min(m, a[ci(s[i])])
if m < i-j+1:
res += 1
j = i
print(res)
```
No
| 94,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
n = int(input())
s = input()
S = [ord(znak) - 97 for znak in s]
a = list(map(int, input().strip().split(' ')))
#print(n, S, a)
st = [0]*(n+1)
st[0] = 1
maks = [0]*(n+1)
minway = [10**4]*(n+1)
minway[0] = 0
for i in range(1, n + 1):
cnt = 0
maks_dolzina = n
for j in range(i, 0, -1):
maks_dolzina = min(maks_dolzina, a[S[j - 1]])
if i - j + 1 > maks_dolzina:
break
cnt += st[j-1]
maks[i] = max(i-j+1, maks[j-1], maks[i])
minway[i] = min(minway[i], 1 + minway[j-1])
st[i] = cnt
print(st[-1])
print(maks[-1])
print(minway[-1])
```
No
| 94,056 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.
Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.
A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.
While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:
* How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
* What is the maximum length of a substring that can appear in some valid splitting?
* What is the minimum number of substrings the message can be spit in?
Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".
Input
The first line contains an integer n (1 β€ n β€ 103) denoting the length of the message.
The second line contains the message s of length n that consists of lowercase English letters.
The third line contains 26 integers a1, a2, ..., a26 (1 β€ ax β€ 103) β the maximum lengths of substring each letter can appear in.
Output
Print three lines.
In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7.
In the second line print the length of the longest substring over all the ways.
In the third line print the minimum number of substrings over all the ways.
Examples
Input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
3
2
2
Input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
401
4
3
Note
In the first example the three ways to split the message are:
* a|a|b
* aa|b
* a|ab
The longest substrings are "aa" and "ab" of length 2.
The minimum number of substrings is 2 in "a|ab" or "aa|b".
Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Submitted Solution:
```
from sys import stdin, stdout
MOD = 10 ** 9 + 7
n = int(stdin.readline())
s = '#' + stdin.readline().strip()
length = [0] + list(map(int, stdin.readline().strip().split()))
dp = [0 for i in range(n + 10)]
dp[0] = 1
dp[-1] = 1
ans = [0, 1, 0]
dp1 = [0 for i in range(n + 5)]
dp1[0] = 0
for i in range(1, n + 1):
cnt = min(i, length[ord(s[i]) - ord('a')])
ind = i - cnt + 1
while ind <= i:
if length[ord(s[ind]) - ord('a')] < cnt:
cnt -= 1
else:
ind += 1
dp1[i] = dp1[i - cnt] + 1
ans[1] = max(ans[1], cnt)
if cnt == i + 1:
dp[i] = bn[cnt - 1] % MOD
else:
for j in range(1, cnt + 1):
dp[i] += dp[i - j]
dp[i] %= MOD
ans[0] = dp[n - 1] % MOD
ans[2] = dp1[n - 1]
stdout.write('\n'.join(list(map(str, ans))))
```
No
| 94,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
n=Int()
color="ROYGBIV"
ans=list(color[:3])
color=color[3:]
for i in range(n-3):
ans.append(color[i%4])
print(*ans,sep="")
```
| 94,058 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
s = "ROYGBIV"
a, b = divmod(n, len(s))
res = s * a
start = 3 if b <= 4 else 0
res += s[start:start+b]
print(res)
```
| 94,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
from sys import stdin, stdout
n = int(stdin.readline()) - 7
ans = 'ROYGBIV'
while n:
ans += ans[-4]
n -= 1
stdout.write(ans)
```
| 94,060 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
if __name__ == '__main__':
num = int(input().strip())
f_count = num // 7
rem = num % 7
chain = ['ROYGBIV','G','GB','YGB','ROYG','ROYGB','ROYGBI']
if(rem == 0):
print(chain[0] * f_count)
else:
print(chain[0] * f_count + chain[rem])
```
| 94,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
hat = int(input())
lst = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
new = ""
if hat == 7:
print("".join(lst))
elif hat == 8:
print("ROYGRBIV")
elif hat == 9:
print("ROYGROBIV")
elif hat == 10:
print("ROYGROYBIV")
else:
new += "".join(lst) * int(hat / 7)
x = 3
for i in range(hat % 7):
if x > 6:
x = 3
new += lst[x]
x += 1
print(new)
```
| 94,062 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
output = []
colors = ["R","O","Y","G","B","I","V"]
temp = 4
for x in range(n):
if x < 7:
output.append(colors[x])
else:
for i in colors:
if i not in output[temp:temp+4]:
if i not in output[0:3]:
output.append(i)
temp +=1
break
print("".join(output))
```
| 94,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
colors = "VIBGYOR"
ans = colors + (n-7)//4 * colors[3:] + colors[3:(3+(n-7)%4)]
print(ans)
```
| 94,064 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Tags: constructive algorithms, implementation
Correct Solution:
```
x=int(input())
n=x-7
s="ROYG"
l=['R','O','Y','G']
i=0
while(n!=0):
s+=l[i]
i+=1
if i>3:
i=0
n-=1
s+='BIV'
print(s)
```
| 94,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
res = {}
res[0] = 'R';
res[1] = 'O';
res[2] = 'Y';
res[3] = 'G';
res[4] = 'B';
res[5] = 'I';
res[6] = 'V';
n = int(input())
for i in range(7,n):
res[i] = res[i - 4]
k = res.values()
k = list(k)
s = ''.join(k)
print(s)
```
Yes
| 94,066 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
n = int(input())
colors = ["R", "O", "Y", "G", "B", "I", "V"]
answer = list()
for i in range(n):
answer.append(colors[i%7])
if (n % 7) < 4:
elements = n % 7
for i in range(elements):
j = len(answer) - 1
k = 3
temp = answer[j]
while k > 0:
answer[j] = answer[j-1]
j -= 1
k -= 1
answer[j] = temp
printstring = ""
for i in range(len(answer)):
printstring += answer[i]
print(printstring)
```
Yes
| 94,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
rgb = "ROYGBIV"
n = int(input())
out = ""
out += rgb * (n // 7)
n %= 7
out += rgb[3:] * (n // 4)
n %= 4
out += rgb[3:n+3]
print(out)
```
Yes
| 94,068 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
n = int(input())
while n >= 7:
n -= 7
print("ROYGBIV",end='')
if n <= 3:
print("GBI"[:n])
else:
print("ROYGBIV"[:n])
```
Yes
| 94,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
n=int(input())
k=n//7
k1=n%7
s='VIBGYOR'
s2='GYORVIB'
s=s*k + s2[:k1]
print(s)
```
No
| 94,070 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
n=int(input())
s='ROYGBIV'
se='GBIV'
c=n%len(s)
d=n//len(s)
f=int((c)%4)
if(c==0):
print(s*d)
else:
if(f<4):
print((s*d)+(se[0:c]))
else:
if(f%4==0):
print((s*d)+(se*(c//4)))
else:
print((s*d)+(se*(c//4))+se[0:(c%4)])
```
No
| 94,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
a = int(input())
s = "ROYGBIV"
if a > 7:
print(s * (a // 7) + s[3:] * 2)
else:
print(s[:a])
```
No
| 94,072 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input
The only line contains an integer n β the amount of eggs (7 β€ n β€ 100).
Output
Print one line consisting of n characters. The i-th character should describe the color of the i-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Examples
Input
8
Output
ROYGRBIV
Input
13
Output
ROYGBIVGBIVYG
Note
The way the eggs will be painted in the first sample is shown on the picture:
<image>
Submitted Solution:
```
str="ROYGBIV"
str2="GBIVROY"
n=int(input())
final=str*(n//7)
final+=str2[:(n%7)]
print(final)
```
No
| 94,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
from sys import stdout
def bsearch(l, r):
while l < r:
mid = (l+r)//2
print("%d %d %d"%(1, mid, mid+1))
stdout.flush()
resp = input()
if resp == "TAK":
r = mid
else:
l = mid+1
return l
n, k = map(int, input().split())
x = bsearch(1, n)
y = bsearch(x+1, n)
print('%d %d %d'%(1, y, x))
stdout.flush()
resp = input()
if resp == "NIE":
y = bsearch(1, x-1)
print('%d %d %d'%(2, x, y))
```
No
| 94,074 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
def do_something( some_value ):
if some_value < 1:
return False
print(1, some_value, some_value+1)
stdout.flush()
response = input()
if response == "TAK":
return True
else:
return False
def bin_search( first, last ):
middle = 0
while first < last:
middle = (first + last) / 2
if do_something(middle):
last = middle
else:
first = middle
return middle
def main():
n = k = 0
n,k = map(int, input().split())
firstdish = bin_search(1,n)
seconddish = bin_search(1,firstdish-1)
if not do_something(seconddish):
seconddish = bin_search(firstdish+1, n)
print(2, firstdish, seconddish)
```
No
| 94,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
def bsearch(l, r):
while l < r:
mid = (l + r) // 2
print(1, mid, mid + 1)
x = 1 if input() == 'TAK' else 0
if x:
r = mid
else:
l = mid + 1
return l
n, k = map(int, input().split())
x = bsearch(1, n)
print(1, x)
a = bsearch(1, x - 1)
print(2, x, a)
if input() == 'TAK':
print(1, a)
else:
print(1, bsearch(x + 1, n))
```
No
| 94,076 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
from sys import stdout
def do_something( some_value ):
if some_value < 1:
return False
print(1, some_value, some_value+1)
response = input()
if response == "TAK":
return True
else:
return False
def bin_search( first, last ):
middle = last
while first < last:
middle = (first + last) // 2
if do_something(middle):
last = middle
else:
first = middle + 1
return middle
def main():
n = k = 0
n,k = map(int, input().split())
firstdish = bin_search(1,n)
seconddish = bin_search(1,firstdish-1)
if not do_something(seconddish):
seconddish = bin_search(firstdish+1, n)
print(2, firstdish, seconddish)
main()
```
No
| 94,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
x=input()
z=input().split()
mx=0
for i in z:
pres=0
for a in i:
if a>='A' and a<='Z':
pres+=1
if mx < pres:
mx=pres
print(mx)
```
| 94,078 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
n = int(input())
s = input().split(' ')
ans = 0
for words in s:
c = 0
for ch in words:
if (ch >= 'A' and ch <= 'Z'):
c += 1
ans = max(ans, c)
print(ans)
```
| 94,079 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
big_letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
max_n = 0
n = int(input())
a = input().split(" ")
for el in a:
n = 0
for i in el:
if i in big_letters:
n += 1
if n > max_n:
max_n = n
print(max_n)
```
| 94,080 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
n = int(input())
text = input().split()
ans = 0
for word in text:
cur_ans = 0
for let in word:
if let >= "A" and let <= "Z":
cur_ans+=1
ans = max(ans,cur_ans)
print(ans)
```
| 94,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
"""
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1ββ€βnββ€β200) β length of the text.
The second line contains text of single-space separated words s1,βs2,β...,βsi, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
"""
def volumetext(length, sentence):
maxvol=0
vol=0
for word in sentence:
vol=0
for letter in word:
if letter.upper()==letter:
vol+=1
if vol>maxvol:
maxvol=vol
return maxvol
length=(map(int, input().strip().split()))
sentence=input().strip().split()
print(volumetext(length,sentence))
```
| 94,082 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
n =int(input())
capital= ['A','B','C','D','E','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
linha= input().split()
sum_max=0
for palavra in linha:
s=0
for ch in palavra:
if ch in capital:
s+=1
if s>sum_max:
sum_max=s
print(sum_max)
```
| 94,083 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
n = input()
s = input()
res = 0
mx = 0
for i in s.split():
for j in i:
if j.isupper():
res += 1
mx = max(res, mx)
res = 0
print (mx)
```
| 94,084 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Tags: implementation
Correct Solution:
```
n=int(input())
x=list(input().split())
ma=0
for i in x:
ca=0
for a in i:
if 'A'<=a<='Z':
ca+=1
if ca>ma:
ma=ca
print(ma)
```
| 94,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
def main():
input()
words = input().strip().split()
max_volume = 0
for word in words:
volume = sum(1 for ch in word if 'A' <= ch <= 'Z')
max_volume = max(volume, max_volume)
print(max_volume)
if __name__ == '__main__':
main()
```
Yes
| 94,086 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
a = input()
b = input().split()
ans = 0
for x in b:
c = sum([1 for q in x if q.isupper()])
if c > ans:
ans = c
print(ans)
```
Yes
| 94,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
n = int(input())
s = input().split()
k = 0
for i in s:
v = 0
for j in i:
if 65 <= ord(j) and ord(j) <= 90:
v += 1
if v > k:
k = v
print(k)
```
Yes
| 94,088 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
#Numero inservible
NumC= list(map(int, input().split()))
#Palabra que sirve
Word = input().split()
upper = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
MMayus = 0
for a in range(len(Word)):
thing = 0
for b in range(len(Word[a])):
if(Word[a][b] in upper):
thing+=1
if(thing>MMayus):
MMayus = thing
print(MMayus)
```
Yes
| 94,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
a = int(input())
word = list(map(str,input().split(" ")))
print(word)
lst = []
for c in range(len(word)) :
count = 0
for i in range(len(word[c])):
if word[c][i].isupper():
count += 1
lst.append(count)
print(max(lst))
```
No
| 94,090 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
#make it zero when you meet space.
def textVolume(n,s):
C=["A","B","C","D","E","F","G","H","I","J","K","L","M","Γ","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
con=0
contadores=[]
for x in s:
if x in C:
con=con+1
elif x==" ":
con=0
contadores.append(con)
contadores.sort(reverse=True)
return contadores[0]
def main():
n=int(input())
s = input()
print(textVolume(n,s))
if __name__ == "__main__":
main()
```
No
| 94,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
a=int(input())
n=input()
t=0
for i in range(0,a):
if ((ord(n[i])>=65) and (ord(n[i])<=90)):t+=1
if (ord(n[i])==32):t=0
print(t)
```
No
| 94,092 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
N = int(input())
A = str(input())
chars = []
chars2 = []
chars3 = []
for i in A:
chars.append(i)
curr = 0
mx = 0
x = len(chars)
for i in range(0,x):
if chars[i] == ' ':
if curr > mx:
mx = curr
curr = 0
elif chars[i] == chars[i].upper():
curr = curr + 1
print(mx)
```
No
| 94,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve() :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11], fac[i] % mod * fac[c0 - i] % mod, C[j + part - 1][part - 1] % mod * C[part + c0 - i - 1][c0 - i - 1] % mod )
ans = ( ans \
+ f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* fac[i] % mod * fac[c0 - i] % mod \
* C[j + part - 1][(c1 - part) - 1] % mod * C[part + c0 - i - 1][c0 - i - 1] ) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve()
```
No
| 94,094 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve(ttt) :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
if ttt == 38 :
print(a)
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0] * fac[c0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11] \
# , fac[i] % mod * fac[c0 - i] % mod, C[j + (c1 - part) - 1][(c1 - part) - 1] % mod * C[part + c0 - i][part] % mod )
ans = ( ans \
+ fac[i] % mod * fac[c0 - i] % mod \
* f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* C[i + (c1 - part) - 1][(c1 - part) - 1] % mod \
* C[part + c0 - i][part]
) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve(ttt + 1)
```
No
| 94,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve(ttt) :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
if ttt == 38 :
print(a)
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11] \
# , fac[i] % mod * fac[c0 - i] % mod, C[j + (c1 - part) - 1][(c1 - part) - 1] % mod * C[part + c0 - i][part] % mod )
ans = ( ans \
+ fac[i] % mod * fac[c0 - i] % mod \
* f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* C[i + (c1 - part) - 1][(c1 - part) - 1] % mod \
* C[part + c0 - i][part]
) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve(ttt + 1)
```
No
| 94,096 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve() :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11] \
# , fac[i] % mod * fac[c0 - i] % mod, C[j + (c1 - part) - 1][(c1 - part) - 1] % mod * C[part + c0 - i][part] % mod )
ans = ( ans \
+ fac[i] % mod * fac[c0 - i] % mod \
* f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* C[i + (c1 - part) - 1][(c1 - part) - 1] % mod \
* C[part + c0 - i][part]
) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve()
```
No
| 94,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017.
Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes.
Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages:
* download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package;
* download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package.
Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds.
Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages.
Input
The first line contains three integer numbers f, T and t0 (1 β€ f, T, t0 β€ 107) β size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff.
The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 β€ a1, t1, p1 β€ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles).
The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 β€ a2, t2, p2 β€ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles).
Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Output
Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1.
Examples
Input
120 964 20
26 8 8
13 10 4
Output
40
Input
10 200 20
1 1 1
2 2 3
Output
0
Input
8 81 11
4 10 16
3 10 12
Output
28
Input
8 79 11
4 10 16
3 10 12
Output
-1
Note
In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5 = 130 bytes) in 120Β·8 = 960 milliseconds (960 β€ 964). He spends 8Β·5 = 40 burles on it.
In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20 = 200 milliseconds which equals to upper constraint on download time.
In the third example Polycarp has to buy one first additional package and one second additional package.
In the fourth example Polycarp has no way to download the file on time.
Submitted Solution:
```
f = 0
T = 0
t0 = 0
a1 = 0
t1 = 0
p1 = 0
a2 = 0
t2 = 0
p2 = 0
R = 0
def func(leftt, leftb, mid):
global f, T, t0, a1, t1, p1, a2, t2, p2, R
ft = 0
if (mid == R):
ft += (mid - 1) * a2;
keks = (leftt - (mid - 1) * a2 * t2) // t2
ft += keks;
else:
ft += (leftt - mid * a2 * t2) // t0
ft += mid * a2
return ft >= leftb
def keks(cnt):
global f, T, t0, a1, t1, p1, a2, t2, p2, R
ks = cnt * a1
if (ks * t1 >= T):
g = (cnt - 1) * a1 + (T - (cnt - 1) * t1 * a1) // t1
if (g >= f):
return cnt * p1
return 1e18
if (ks >= f):
return cnt * p1
leftt = T - ks * t1
leftb = f - ks
if (t2 < t0):
r = (leftt) // (a2 * t2) + 1
R = r
diff = leftb * t0 - leftt
sf = t0 - t2
keks = (diff * t2 + sf - 1) // sf
if (keks % a2 != 0):
keks+= a2 - keks % a2
keks //= a2
keks //= t2
ans = 1e18
for i in range(keks - 1, keks + 1):
l = i
if (l >= 0 and l <= r):
if (func(leftt, leftb, l)):
ans = min(ans, cnt * p1 + l * p2)
return ans;
else:
if (func(leftt, leftb, 0)):
return cnt * p
return 1e18;
def main():
global f, T, t0, a1, t1, p1, a2, t2, p2, R
f, T, t0 = map(int, input().split())
a1, t1, p1 = map(int, input().split())
a2, t2, p2 = map(int, input().split())
ans = 1e18;
if (t0 * f <= T):
ans = 0;
print(ans)
return
ll = 0;
rr = T // (t1 * a1) + 1
for g in range(ll, rr + 1):
ans = min(ans, keks(g))
if (ans > 9e17):
print(-1)
return
print(ans)
main()
```
No
| 94,098 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017.
Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes.
Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages:
* download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package;
* download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package.
Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds.
Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages.
Input
The first line contains three integer numbers f, T and t0 (1 β€ f, T, t0 β€ 107) β size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff.
The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 β€ a1, t1, p1 β€ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles).
The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 β€ a2, t2, p2 β€ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles).
Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Output
Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1.
Examples
Input
120 964 20
26 8 8
13 10 4
Output
40
Input
10 200 20
1 1 1
2 2 3
Output
0
Input
8 81 11
4 10 16
3 10 12
Output
28
Input
8 79 11
4 10 16
3 10 12
Output
-1
Note
In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5 = 130 bytes) in 120Β·8 = 960 milliseconds (960 β€ 964). He spends 8Β·5 = 40 burles on it.
In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20 = 200 milliseconds which equals to upper constraint on download time.
In the third example Polycarp has to buy one first additional package and one second additional package.
In the fourth example Polycarp has no way to download the file on time.
Submitted Solution:
```
print("0")
```
No
| 94,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.