message stringlengths 2 22.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 16 109k | cluster float64 1 1 | __index_level_0__ int64 32 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.
You have a map of that network, so for each railway section you know which stations it connects.
Each of the n-1 sections has some integer value of the scenery beauty. However, these values are not marked on the map and you don't know them. All these values are from 1 to 10^6 inclusive.
You asked m passengers some questions: the j-th one told you three values:
* his departure station a_j;
* his arrival station b_j;
* minimum scenery beauty along the path from a_j to b_j (the train is moving along the shortest path from a_j to b_j).
You are planning to update the map and set some value f_i on each railway section β the scenery beauty. The passengers' answers should be consistent with these values.
Print any valid set of values f_1, f_2, ..., f_{n-1}, which the passengers' answer is consistent with or report that it doesn't exist.
Input
The first line contains a single integer n (2 β€ n β€ 5000) β the number of railway stations in Berland.
The next n-1 lines contain descriptions of the railway sections: the i-th section description is two integers x_i and y_i (1 β€ x_i, y_i β€ n, x_i β y_i), where x_i and y_i are the indices of the stations which are connected by the i-th railway section. All the railway sections are bidirected. Each station can be reached from any other station by the railway.
The next line contains a single integer m (1 β€ m β€ 5000) β the number of passengers which were asked questions. Then m lines follow, the j-th line contains three integers a_j, b_j and g_j (1 β€ a_j, b_j β€ n; a_j β b_j; 1 β€ g_j β€ 10^6) β the departure station, the arrival station and the minimum scenery beauty along his path.
Output
If there is no answer then print a single integer -1.
Otherwise, print n-1 integers f_1, f_2, ..., f_{n-1} (1 β€ f_i β€ 10^6), where f_i is some valid scenery beauty along the i-th railway section.
If there are multiple answers, you can print any of them.
Examples
Input
4
1 2
3 2
3 4
2
1 2 5
1 3 3
Output
5 3 5
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 3
3 4 1
6 5 2
1 2 5
Output
5 3 1 2 1
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 1
3 4 3
6 5 3
1 2 4
Output
-1
Submitted Solution:
```
from collections import defaultdict
n = int(input())
adj = [[] for _ in range(n)]
p = [-1]*n
h = [0]*n
edges = []
def dfs(root,par = -1):
p[root] = par
if(par+1):
h[root] = h[par]+1
for c in adj[root]:
if c!=par:
dfs(c,root)
def lca(v,u):
if v==u:
return v
if h[u]>h[v]:
v,u = u,v
return lca(p[v],u)
for i in range(n-1):
u,v = map(int,input().split())
if v<u:
u,v = v,u
u-=1
v-=1
edges.append((u,v))
adj[u].append(v)
adj[v].append(u)
m = int(input())
ms = []
for i in range(m):
a,b,g = map(int,input().split())
a-=1;b-=1;
ms.append([a,b,g])
ms.sort(key=lambda x:x[2])
dfs(0)
pairs = defaultdict(int)
for i in ms:
a,b,g = i
lc = lca(a,b)
while a!=lc:
pairs[tuple(sorted((a,p[a])))] = max(pairs[tuple(sorted((a,p[a])))],g)
a = p[a]
while b!=lc:
pairs[tuple(sorted((b,p[b])))] = max(pairs[tuple(sorted((a,p[b])))],g)
b = p[b]
done = True
for i in ms:
a,b,g = i
lc = lca(a,b)
mini = 10**9
while a!=lc:
mini = min(mini,pairs[tuple(sorted((a,p[a])))])
a = p[a]
while b!=lc:
mini = min(mini,pairs[tuple(sorted((b,p[b])))])
b = p[b]
if mini!=g:
done = False
print(-1)
break
if done:
for i in edges:
if pairs[i]==0:
print(10**6+1,end=" ")
else:
print(pairs[i],end=" ")
print()
``` | instruction | 0 | 105,383 | 1 | 210,766 |
No | output | 1 | 105,383 | 1 | 210,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.
You have a map of that network, so for each railway section you know which stations it connects.
Each of the n-1 sections has some integer value of the scenery beauty. However, these values are not marked on the map and you don't know them. All these values are from 1 to 10^6 inclusive.
You asked m passengers some questions: the j-th one told you three values:
* his departure station a_j;
* his arrival station b_j;
* minimum scenery beauty along the path from a_j to b_j (the train is moving along the shortest path from a_j to b_j).
You are planning to update the map and set some value f_i on each railway section β the scenery beauty. The passengers' answers should be consistent with these values.
Print any valid set of values f_1, f_2, ..., f_{n-1}, which the passengers' answer is consistent with or report that it doesn't exist.
Input
The first line contains a single integer n (2 β€ n β€ 5000) β the number of railway stations in Berland.
The next n-1 lines contain descriptions of the railway sections: the i-th section description is two integers x_i and y_i (1 β€ x_i, y_i β€ n, x_i β y_i), where x_i and y_i are the indices of the stations which are connected by the i-th railway section. All the railway sections are bidirected. Each station can be reached from any other station by the railway.
The next line contains a single integer m (1 β€ m β€ 5000) β the number of passengers which were asked questions. Then m lines follow, the j-th line contains three integers a_j, b_j and g_j (1 β€ a_j, b_j β€ n; a_j β b_j; 1 β€ g_j β€ 10^6) β the departure station, the arrival station and the minimum scenery beauty along his path.
Output
If there is no answer then print a single integer -1.
Otherwise, print n-1 integers f_1, f_2, ..., f_{n-1} (1 β€ f_i β€ 10^6), where f_i is some valid scenery beauty along the i-th railway section.
If there are multiple answers, you can print any of them.
Examples
Input
4
1 2
3 2
3 4
2
1 2 5
1 3 3
Output
5 3 5
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 3
3 4 1
6 5 2
1 2 5
Output
5 3 1 2 1
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 1
3 4 3
6 5 3
1 2 4
Output
-1
Submitted Solution:
```
def graphRoot(n, roots, s, vertex):
used = [False] * n
used[s] = True
queue = [s]
parents = [0] * n
parents[s] = -1
path = []
while len(queue) > 0:
for to in roots[queue[0]]:
if not used[to]:
used[to] = True
queue.append(to)
parents[to] = queue[0]
queue = queue[1:]
while vertex != -1:
path = [vertex] + path
vertex = parents[vertex]
return path
def dataSort(a):
return int(a[2])
n = int(input())
links = []
beauties = {}
for i in range(n - 1):
links.append(input().split(' '))
root = (int(links[i][0]) - 1, int(links[i][1]) - 1)
beauties[root] = 1
roots = []
for i in range(n):
roots.append([])
for i in range(n - 1):
roots[int(links[i][0]) - 1].append(int(links[i][1]) - 1)
roots[int(links[i][1]) - 1].append(int(links[i][0]) - 1)
m = int(input())
breaker = False
data = []
for i in range(m):
data.append(input().split(' '))
d = data[i]
path = graphRoot(n, roots, int(d[0]) - 1, int(d[1]) - 1)
beauty = int(d[2])
bFound = False
for j in range(len(path) - 1):
if beauties.get((path[j], path[j + 1])) != None:
if beauty >= beauties[(path[j], path[j + 1])]:
beauties[(path[j], path[j + 1])] = beauty
bFound = True
else:
if beauty >= beauties[(path[j + 1], path[j])]:
beauties[(path[j + 1], path[j])] = beauty
bFound = True
if not bFound:
breaker = True
break
if not breaker:
ans = []
for i in beauties:
ans.append(str(beauties[i]))
print(' '.join(ans))
else:
print(-1)
``` | instruction | 0 | 105,384 | 1 | 210,768 |
No | output | 1 | 105,384 | 1 | 210,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.
You have a map of that network, so for each railway section you know which stations it connects.
Each of the n-1 sections has some integer value of the scenery beauty. However, these values are not marked on the map and you don't know them. All these values are from 1 to 10^6 inclusive.
You asked m passengers some questions: the j-th one told you three values:
* his departure station a_j;
* his arrival station b_j;
* minimum scenery beauty along the path from a_j to b_j (the train is moving along the shortest path from a_j to b_j).
You are planning to update the map and set some value f_i on each railway section β the scenery beauty. The passengers' answers should be consistent with these values.
Print any valid set of values f_1, f_2, ..., f_{n-1}, which the passengers' answer is consistent with or report that it doesn't exist.
Input
The first line contains a single integer n (2 β€ n β€ 5000) β the number of railway stations in Berland.
The next n-1 lines contain descriptions of the railway sections: the i-th section description is two integers x_i and y_i (1 β€ x_i, y_i β€ n, x_i β y_i), where x_i and y_i are the indices of the stations which are connected by the i-th railway section. All the railway sections are bidirected. Each station can be reached from any other station by the railway.
The next line contains a single integer m (1 β€ m β€ 5000) β the number of passengers which were asked questions. Then m lines follow, the j-th line contains three integers a_j, b_j and g_j (1 β€ a_j, b_j β€ n; a_j β b_j; 1 β€ g_j β€ 10^6) β the departure station, the arrival station and the minimum scenery beauty along his path.
Output
If there is no answer then print a single integer -1.
Otherwise, print n-1 integers f_1, f_2, ..., f_{n-1} (1 β€ f_i β€ 10^6), where f_i is some valid scenery beauty along the i-th railway section.
If there are multiple answers, you can print any of them.
Examples
Input
4
1 2
3 2
3 4
2
1 2 5
1 3 3
Output
5 3 5
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 3
3 4 1
6 5 2
1 2 5
Output
5 3 1 2 1
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 1
3 4 3
6 5 3
1 2 4
Output
-1
Submitted Solution:
```
def graphRoot(n, roots, s, vertex):
used = [False] * n
used[s] = True
queue = [s]
parents = [0] * n
parents[s] = -1
path = []
while len(queue) > 0:
for to in roots[queue[0]]:
if not used[to]:
used[to] = True
queue.append(to)
parents[to] = queue[0]
queue = queue[1:]
while vertex != -1:
path = [vertex] + path
vertex = parents[vertex]
return path
n = int(input())
links = []
beauties = {}
for i in range(n - 1):
links.append(input().split(' '))
root = (int(links[i][0]) - 1, int(links[i][1]) - 1)
beauties[root] = 1
roots = []
for i in range(n):
roots.append([])
for i in range(n - 1):
roots[int(links[i][0]) - 1].append(int(links[i][1]) - 1)
roots[int(links[i][1]) - 1].append(int(links[i][0]) - 1)
m = int(input())
breaker = False
for i in range(m):
data = input().split(' ')
path = graphRoot(n, roots, int(data[0]) - 1, int(data[1]) - 1)
beauty = int(data[2])
for j in range(len(path) - 1):
if beauties.get((path[j], path[j + 1])) != None:
if beauty > beauties[(path[j], path[j + 1])]:
beauties[(path[j], path[j + 1])] = beauty
else:
breaker = True
break
else:
if beauty > beauties[(path[j + 1], path[j])]:
beauties[(path[j + 1], path[j])] = beauty
else:
breaker = True
break
if breaker:
break
if not breaker:
ans = []
for i in beauties:
ans.append(str(beauties[i]))
print(' '.join(ans))
else:
print(-1)
``` | instruction | 0 | 105,385 | 1 | 210,770 |
No | output | 1 | 105,385 | 1 | 210,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.
You have a map of that network, so for each railway section you know which stations it connects.
Each of the n-1 sections has some integer value of the scenery beauty. However, these values are not marked on the map and you don't know them. All these values are from 1 to 10^6 inclusive.
You asked m passengers some questions: the j-th one told you three values:
* his departure station a_j;
* his arrival station b_j;
* minimum scenery beauty along the path from a_j to b_j (the train is moving along the shortest path from a_j to b_j).
You are planning to update the map and set some value f_i on each railway section β the scenery beauty. The passengers' answers should be consistent with these values.
Print any valid set of values f_1, f_2, ..., f_{n-1}, which the passengers' answer is consistent with or report that it doesn't exist.
Input
The first line contains a single integer n (2 β€ n β€ 5000) β the number of railway stations in Berland.
The next n-1 lines contain descriptions of the railway sections: the i-th section description is two integers x_i and y_i (1 β€ x_i, y_i β€ n, x_i β y_i), where x_i and y_i are the indices of the stations which are connected by the i-th railway section. All the railway sections are bidirected. Each station can be reached from any other station by the railway.
The next line contains a single integer m (1 β€ m β€ 5000) β the number of passengers which were asked questions. Then m lines follow, the j-th line contains three integers a_j, b_j and g_j (1 β€ a_j, b_j β€ n; a_j β b_j; 1 β€ g_j β€ 10^6) β the departure station, the arrival station and the minimum scenery beauty along his path.
Output
If there is no answer then print a single integer -1.
Otherwise, print n-1 integers f_1, f_2, ..., f_{n-1} (1 β€ f_i β€ 10^6), where f_i is some valid scenery beauty along the i-th railway section.
If there are multiple answers, you can print any of them.
Examples
Input
4
1 2
3 2
3 4
2
1 2 5
1 3 3
Output
5 3 5
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 3
3 4 1
6 5 2
1 2 5
Output
5 3 1 2 1
Input
6
1 2
1 6
3 1
1 5
4 1
4
6 1 1
3 4 3
6 5 3
1 2 4
Output
-1
Submitted Solution:
```
import sys
input = sys.stdin.readline
from operator import itemgetter
n=int(input())
EDGE=[sorted(map(int,input().split())) for i in range(n-1)]
E=[[] for i in range(n+1)]
D=dict()
for i in range(n-1):
x,y=EDGE[i]
D[x,y]=i
E[x].append(y)
E[y].append(x)
m=int(input())
Q=sorted([tuple(map(int,input().split())) for i in range(m)],key=itemgetter(2),reverse=True)
def dfs(x,y,n):
if DD.get((x,y))!=None:
return DD[x,y]
USE=[-1]*(n+1)
NOW=[x]
while NOW:
n=NOW.pop()
if n==y:
break
for to in E[n]:
if USE[to]==-1:
USE[to]=n
NOW.append(to)
yield y
while y!=x:
y=USE[y]
yield y
ANS=[10**6]*(n-1)
DD=dict()
for a,b,q in Q:
PATH=tuple(dfs(a,b,n))
DD[a,b]=PATH
flag=1
for i in range(1,len(PATH)):
k=D[tuple(sorted((PATH[i-1],PATH[i])))]
if ANS[k]==10**6 or ANS[k]==q:
ANS[k]=q
flag=0
if flag:
print(-1)
sys.exit()
print(*ANS)
``` | instruction | 0 | 105,386 | 1 | 210,772 |
No | output | 1 | 105,386 | 1 | 210,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,387 | 1 | 210,774 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
n = int(input())
lis = list(map(int,input().split()))
d = {}
for i in range(n):
v = lis[i]-i
if d.get(v):
d[v] += lis[i]
else:
d[v] = lis[i]
m = 0
for k in d.values():
m = max(m,k)
print(m)
``` | output | 1 | 105,387 | 1 | 210,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,388 | 1 | 210,776 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
input()
l=list(map(int,input().split()))
d={}
i=1
for x in l:
d[x-i]=d.get(x-i,0)+x
i+=1
print(max(d.values()))
``` | output | 1 | 105,388 | 1 | 210,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,389 | 1 | 210,778 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
n = int(input())
b = list(map(int, input().split()))
a = [b[i] - i for i in range(n)]
c = dict()
for i in range(n):
if a[i] in c:
c[a[i]] += b[i]
else:
c[a[i]] = b[i]
print(max(c.values()))
``` | output | 1 | 105,389 | 1 | 210,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,390 | 1 | 210,780 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
n = int(input())
arr = list(map(int,input().split()))
dict = {}
maxi = 0
for i in range(len(arr)):
try:
temp = dict[i-arr[i]]
dict[i-arr[i]] = temp + arr[i]
if(maxi<temp + arr[i]):
maxi = temp + arr[i]
except:
dict[i-arr[i]] = arr[i]
if(maxi<arr[i]):
maxi = arr[i]
print(maxi)
``` | output | 1 | 105,390 | 1 | 210,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,391 | 1 | 210,782 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
import sys
n = int(sys.stdin.readline().strip())
b = list(map(int, sys.stdin.readline().strip().split()))
a = [0] * n
for i in range (0, n):
a[i] = b[i] - i
x = [0] * 10 ** 6
for i in range (0, n):
x[3 * 10 ** 5 + a[i]] = x[3 * 10 ** 5 + a[i]] + b[i]
print(max(x))
``` | output | 1 | 105,391 | 1 | 210,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,392 | 1 | 210,784 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
n=int(input())
b=list(map(int, input().split()))
List=[]
for i in range(n):
List.append([b[i]-(i+1), b[i]])
List.sort()
maxim=0
for i in range(1, len(List)):
if List[i][0]==List[i-1][0]:
List[i][1]+=List[i-1][1]
maxim=max(List[i][1], maxim)
print(max(b[0], maxim))
``` | output | 1 | 105,392 | 1 | 210,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,393 | 1 | 210,786 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
import sys
n=int(input())
if 1<=n <=2*(10**5):
lst=list(map(int,input().split()))
if len(lst)<n:
print("Enter all the input correctly.")
sys.exit(1)
g = {}
for j in range(n):
g[lst[j] - j] = g.get(lst[j] - j,0) +lst[j]
print(max(g.values()))
else:
print("Invalid Input")
``` | output | 1 | 105,393 | 1 | 210,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6]. | instruction | 0 | 105,394 | 1 | 210,788 |
Tags: data structures, dp, greedy, math, sortings
Correct Solution:
```
from collections import defaultdict
input()
vals = list(map(int, input().split()))
uwu = defaultdict(list)
[uwu[val - i].append(val) for i, val in enumerate(vals)]
print(max([sum(god) for god in uwu.values()]))
``` | output | 1 | 105,394 | 1 | 210,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
n = int(input())
arr = list(map(int,input().split()))
result = [0]*n
maxx = 0
for i in range(n):
result[i] = arr[i]-i
dic = {}
for i in range(n):
if result[i] in dic:
val = dic[result[i]]
val+=arr[i]
dic[result[i]] = val
else:
val = arr[i]
dic[result[i]] = val
maxx = max(maxx,val)
print(maxx)
``` | instruction | 0 | 105,395 | 1 | 210,790 |
Yes | output | 1 | 105,395 | 1 | 210,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
n = int(input())
b = list(map(int, input().split()))
mem = {}
for i in range(n):
if i-b[i] not in mem:
mem[i-b[i]] = 0
mem[i - b[i]] += b[i]
ans = 0
for i in mem:
ans = max(ans, mem[i])
print(ans)
``` | instruction | 0 | 105,396 | 1 | 210,792 |
Yes | output | 1 | 105,396 | 1 | 210,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
b = [int(x) for x in input().split()]
c = [0] * (10 ** 6)
for i in range(n):
c[b[i] - i] += b[i]
print(max(c))
``` | instruction | 0 | 105,397 | 1 | 210,794 |
Yes | output | 1 | 105,397 | 1 | 210,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
n = int(input())
list1 = list(map(int,input().split()))
list2 = list()
for i in range(len(list1)):
list2.append([list1[i]-(i+1),list1[i]])
list2.sort()
maxi = 0
i=0
while i<len(list2):
sum=0
p = list2[i][0]
while i<len(list2) and list2[i][0]==p:
sum+=list2[i][1]
i+=1
if sum>maxi:
maxi=sum
print(maxi)
``` | instruction | 0 | 105,398 | 1 | 210,796 |
Yes | output | 1 | 105,398 | 1 | 210,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
from collections import defaultdict
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = map(int, input().split())
return n,m
def da():
n, m = map(int, input().split())
a = list(map(int, input().split()))
return n,m, a
def dva():
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
return n,m,b
def prost(x):
d = math.sqrt(x)
d = int(d) + 1
for i in range(2, d):
if x % i == 0:
return False
return True
def eratosthenes(n):
sieve = list(range(n + 1))
for i in sieve:
if i > 1:
for j in range(i + i, len(sieve), i):
sieve[j] = 0
return sorted(set(sieve))
def lol(lst,k):
k=k%len(lst)
ret=[0]*len(lst)
for i in range(len(lst)):
if i+k<len(lst) and i+k>=0:
ret[i]=lst[i+k]
if i+k>=len(lst):
ret[i]=lst[i+k-len(lst)]
if i+k<0:
ret[i]=lst[i+k+len(lst)]
return(ret)
def nm():
n = int(input())
b = [int(x) for x in input().split()]
m = int(input())
c = [int(x) for x in input().split()]
return n,b,m,c
def dvs():
n = int(input())
m = int(input())
return n, m
n = int(input())
a = list(map(int, input().split()))
dp = [0] * (4 * 100000 +5)
for i in range(n):
dp[a[i] - i - 1] += a[i]
print(max(dp))
``` | instruction | 0 | 105,399 | 1 | 210,798 |
No | output | 1 | 105,399 | 1 | 210,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
# from debug import debug
inf = int(1e10)
n = int(input())
lis = list(map(int, input().split()))
c = sorted([(lis[i]-i, lis[i]) for i in range(n)])
v = c[0][1]
ans = 0
for i in range(1, n):
if c[i-1][0] == c[i][0] and c[i][0] >= 0:
v+=c[i][1]
else:
ans = max(ans, v)
v = c[i][1]
print(max(ans, v))
``` | instruction | 0 | 105,400 | 1 | 210,800 |
No | output | 1 | 105,400 | 1 | 210,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
res=0
n=int(input())
x=[0]*(4*10**5)
bi=[*map(int,input().split())]
for i in range(1,n):
a=bi[i]
x[a-i]+=a
res=max(res,x[a-i])
print(max(res,bi[0]))
``` | instruction | 0 | 105,401 | 1 | 210,802 |
No | output | 1 | 105,401 | 1 | 210,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some other city c_2 > c_1, then to some other city c_3 > c_2, and so on, until she chooses to end her journey in some city c_k > c_{k - 1}. So, the sequence of visited cities [c_1, c_2, ..., c_k] should be strictly increasing.
There are some additional constraints on the sequence of cities Tanya visits. Each city i has a beauty value b_i associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities c_i and c_{i + 1}, the condition c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i} must hold.
For example, if n = 8 and b = [3, 4, 4, 6, 6, 7, 8, 9], there are several three possible ways to plan a journey:
* c = [1, 2, 4];
* c = [3, 5, 6, 8];
* c = [7] (a journey consisting of one city is also valid).
There are some additional ways to plan a journey that are not listed above.
Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of cities in Berland.
The second line contains n integers b_1, b_2, ..., b_n (1 β€ b_i β€ 4 β
10^5), where b_i is the beauty value of the i-th city.
Output
Print one integer β the maximum beauty of a journey Tanya can choose.
Examples
Input
6
10 7 1 9 10 15
Output
26
Input
1
400000
Output
400000
Input
7
8 9 26 11 12 29 14
Output
55
Note
The optimal journey plan in the first example is c = [2, 4, 5].
The optimal journey plan in the second example is c = [1].
The optimal journey plan in the third example is c = [3, 6].
Submitted Solution:
```
import sys
a = int(input())
b = list(map(int,input().split()))
if a==1:
print(b[0])
sys.exit()
c = [0]*a
for i in range(a):
c[i]=(b[i]-i-1,b[i])
ans=0
c.sort()
maxx=0
cc = c[0]
i = 1
while i<a:
while i<a and c[i][0]==cc:
maxx+=c[i][1]
i+=1
ans=max(ans,maxx)
maxx=0
if i<a:cc=c[i][0]
print(ans)
``` | instruction | 0 | 105,402 | 1 | 210,804 |
No | output | 1 | 105,402 | 1 | 210,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
LiLand is a country, consisting of n cities. The cities are numbered from 1 to n. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the flights are arranged in a way that once you leave a city you will never be able to return to that city again.
Previously each flight took exactly one hour, but recently Lily has become the new manager of transportation system and she wants to change the duration of some flights. Specifically, she wants to change the duration of some flights to exactly 2 hours in such a way that all trips from city 1 to city n take the same time regardless of their path.
Your task is to help Lily to change the duration of flights.
Input
First line of the input contains two integer numbers n and m (2 β€ n β€ 1000; 1 β€ m β€ 5000) specifying the number of cities and the number of flights.
Each of the next m lines contains two integers ai and bi (1 β€ ai < bi β€ n) specifying a one-directional flight from city ai to city bi. It is guaranteed that there exists a way to travel from city number 1 to city number n using the given flights. It is guaranteed that there is no sequence of flights that forms a cyclical path and no two flights are between the same pair of cities.
Output
If it is impossible for Lily to do her task, print "No" (without quotes) on the only line of the output.
Otherwise print "Yes" (without quotes) on the first line of output, then print an integer ansi (1 β€ ansi β€ 2) to each of the next m lines being the duration of flights in new transportation system. You should print these numbers in the order that flights are given in the input.
If there are multiple solutions for the input, output any of them.
Examples
Input
3 3
1 2
2 3
1 3
Output
Yes
1
1
2
Input
4 4
1 2
2 3
3 4
1 4
Output
No
Input
5 6
1 2
2 3
3 5
1 4
4 5
1 3
Output
Yes
1
1
1
2
1
2 | instruction | 0 | 105,558 | 1 | 211,116 |
Tags: graphs, shortest paths
Correct Solution:
```
#Flights
from queue import Queue
def BFS(node ,mk,G):
q = Queue()
q.put(node)
mk[node] = True
while not q.empty():
top = q.get()
for ady in G[top]:
if not mk[ady]:
mk[ady] = True
q.put(ady)
def InitValue(n,m):
G1 = [[]for _ in range(n+1)]
G2 = [[]for _ in range(n+1)]
E = []
for _ in range(m):
u,v = map(int,input().split())
G1[u].append(v)
G2[v].append(u)
E.append((u,v))
return G1,G2,E
def Cleen_Graf(mk1,mk2,n,m,G1,G2):
E2 = []
for e in E:
if mk1[e[0]] and mk2[e[0]] and mk1[e[1]] and mk2[e[1]]:
E2.append((e[0],e[1],2))
E2.append((e[1],e[0],-1))
return E2
def Bellman_Ford(n,E2):
dist = [10e12 for _ in range(n+1)]
dist[1] = 0
is_posibol = True
for _ in range(n):
for e in E2:
dist[e[1]] = min(dist[e[1]],dist[e[0]]+e[2])
for e in E2:
if dist[e[0]]+e[2] < dist[e[1]]:
is_posibol = False
return dist,is_posibol
if __name__ == '__main__':
n,m = map(int,input().split())
G1,G2,E = InitValue(n,m)
mk1 = [False for _ in range(n+1)]
mk2 = [False for _ in range(n+1)]
BFS(1,mk1,G1)
BFS(n,mk2,G2)
E2 = Cleen_Graf(mk1,mk2,n,m,G1,G2)
dist,is_posibol = Bellman_Ford(n,E2)
if not is_posibol:
print("No")
else:
print("Yes")
for e in E:
if mk1[e[0]] and mk2[e[0]] and mk1[e[1]] and mk2[e[1]]:
print(dist[e[1]]- dist[e[0]])
else:
print(1)
``` | output | 1 | 105,558 | 1 | 211,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A motorcade of n trucks, driving from city Β«ZΒ» to city Β«ΠΒ», has approached a tunnel, known as Tunnel of Horror. Among truck drivers there were rumours about monster DravDe, who hunts for drivers in that tunnel. Some drivers fear to go first, others - to be the last, but let's consider the general case. Each truck is described with four numbers:
* v β value of the truck, of its passangers and cargo
* c β amount of passanger on the truck, the driver included
* l β total amount of people that should go into the tunnel before this truck, so that the driver can overcome his fear (Β«if the monster appears in front of the motorcade, he'll eat them firstΒ»)
* r β total amount of people that should follow this truck, so that the driver can overcome his fear (Β«if the monster appears behind the motorcade, he'll eat them firstΒ»).
Since the road is narrow, it's impossible to escape DravDe, if he appears from one side. Moreover, the motorcade can't be rearranged. The order of the trucks can't be changed, but it's possible to take any truck out of the motorcade, and leave it near the tunnel for an indefinite period. You, as the head of the motorcade, should remove some of the trucks so, that the rest of the motorcade can move into the tunnel and the total amount of the left trucks' values is maximal.
Input
The first input line contains integer number n (1 β€ n β€ 105) β amount of trucks in the motorcade. The following n lines contain four integers each. Numbers in the i-th line: vi, ci, li, ri (1 β€ vi β€ 104, 1 β€ ci β€ 105, 0 β€ li, ri β€ 105) β describe the i-th truck. The trucks are numbered from 1, counting from the front of the motorcade.
Output
In the first line output number k β amount of trucks that will drive into the tunnel. In the second line output k numbers β indexes of these trucks in ascending order. Don't forget please that you are not allowed to change the order of trucks. If the answer is not unique, output any.
Examples
Input
5
1 1 0 3
1 1 1 2
1 1 2 1
1 1 3 0
2 1 3 0
Output
4
1 2 3 5
Input
5
1 1 0 3
10 1 2 1
2 2 1 1
10 1 1 2
3 1 3 0
Output
3
1 3 5 | instruction | 0 | 105,559 | 1 | 211,118 |
Tags: binary search, data structures, dp, hashing
Correct Solution:
```
n = int(input())
v = n*[-1]
c = n*[-1]
L = n*[-1]
R = n*[-1]
for i in range(n):
v[i], c[i], L[i], R[i] = map(int, input().split())
index = [i for i in range(n)]
index.sort(key = lambda i: (c[i]+L[i]+R[i], i))
prev = n*[-1]
best_res = 0
best_last = -1
ii = 0
while ii < n:
i = index[ii]
jj = ii
d = {0: (0, -1)}
while jj < n:
j = index[jj]
if c[i]+L[i]+R[i] != c[j]+L[j]+R[j]: break
x = d.get(L[j])
if x is not None:
cur = v[j]+x[0]
prev[j] = x[1]
if R[j] == 0 and cur > best_res:
best_res = cur
best_last = j
y = d.get(L[j]+c[j])
if y is None or cur > y[0]:
d[L[j]+c[j]] = (cur, j)
jj += 1
ii = jj
ans = []
while best_last != -1:
ans.append(best_last)
best_last = prev[best_last]
ans.reverse()
for i in range(len(ans)):
ans[i] += 1
print (len(ans))
if len(ans):
print (" ".join(map(str, ans)))
``` | output | 1 | 105,559 | 1 | 211,119 |
Provide a correct Python 3 solution for this coding contest problem.
The city of Kyoto is well-known for its Chinese plan: streets are either North-South or East-West. Some streets are numbered, but most of them have real names.
Crossings are named after the two streets crossing there, e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo street. But there is a problem: which name should come first? At first the order seems quite arbitrary: one says Kawaramachi-Sanjo (North-South first) but Shijo-Kawaramachi (East-West first). With some experience, one realizes that actually there seems to be an "order" on the streets, for instance in the above Shijo is "stronger" than Kawaramachi, which in turn is "stronger" than Sanjo. One can use this order to deduce the names of other crossings.
You are given as input a list of known crossing names X-Y. Streets are either North-South or East-West, and only orthogonal streets may cross.
As your list is very incomplete, you start by completing it using the following rule:
* two streets A and B have equal strength if (1) to (3) are all true:
1. they both cross the same third street C in the input
2. there is no street D such that D-A and B-D appear in the input
3. there is no street E such that A-E and E-B appear in the input
We use this definition to extend our strength relation:
* A is stronger than B, when there is a sequence A = A1, A2, ..., An = B, with n at least 2,
where, for any i in 1 .. n-1, either Ai-Ai+1 is an input crossing or Ai and Ai+1 have equal strength.
Then you are asked whether some other possible crossing names X-Y are valid. You should answer affirmatively if you can infer the validity of a name, negatively if you cannot. Concretely:
* YES if you can infer that the two streets are orthogonal, and X is stronger than Y
* NO otherwise
Input
The input is a sequence of data sets, each of the form
>
> N
> Crossing1
> ...
> CrossingN
> M
> Question1
> ...
> QuestionM
>
Both Crossings and Questions are of the form
> X-Y
where X and Y are strings of alphanumerical characters, of lengths no more than 16. There is no white space, and case matters for alphabetical characters.
N and M are between 1 and 1000 inclusive, and there are no more than 200 streets in a data set.
The last data set is followed by a line containing a zero.
Output
The output for each data set should be composed of M+1 lines, the first one containing the number of streets in the Crossing part of the input, followed by the answers to each question, either YES or NO without any spaces.
Example
Input
7
Shijo-Kawaramachi
Karasuma-Imadegawa
Kawaramachi-Imadegawa
Nishioji-Shijo
Karasuma-Gojo
Torimaru-Rokujo
Rokujo-Karasuma
6
Shijo-Karasuma
Imadegawa-Nishioji
Nishioji-Gojo
Shijo-Torimaru
Torimaru-Gojo
Shijo-Kawabata
4
1jo-Midosuji
Midosuji-2jo
2jo-Omotesando
Omotesando-1jo
4
Midosuji-1jo
1jo-Midosuji
Midosuji-Omotesando
1jo-1jo
0
Output
8
YES
NO
YES
NO
YES
NO
4
YES
YES
NO
NO | instruction | 0 | 106,052 | 1 | 212,104 |
"Correct Solution:
```
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
L = 0
n_map = {}
def get(s):
nonlocal L
if s in n_map:
return n_map[s]
n_map[s] = L
L += 1
return L-1
G = [[] for i in range(2*N)]
RG = [[] for i in range(2*N)]
for i in range(N):
a, b = readline().strip().split("-")
ka = get(a); kb = get(b)
G[ka].append(kb)
RG[kb].append(ka)
F = [[-1]*L for i in range(L)]
for v in range(L):
for w1 in G[v]:
for w2 in G[v]:
F[w1][w2] = 1
for w1 in RG[v]:
for w2 in RG[v]:
F[w1][w2] = 1
for v in range(L):
for w1 in G[v]:
for w2 in RG[v]:
F[w1][w2] = F[w2][w1] = 0
G0 = [[] for i in range(L)]
for v in range(L):
for w in range(L):
if F[v][w] == 1:
G0[v].append(w)
G0[w].append(v)
PS = []
que = deque()
for i in range(L):
P = [-1]*L
que.append(i)
P[i] = 0
while que:
v = que.popleft()
p = P[v]
for w in G[v]:
if P[w] != -1:
continue
P[w] = p^1
que.append(w)
for w in G0[v]:
if P[w] != -1:
continue
P[w] = p
que.append(w)
PS.append(P)
write("%d\n" % L)
M = int(readline())
for i in range(M):
a, b = readline().strip().split("-")
ka = n_map.get(a, -1); kb = n_map.get(b, -1)
if ka == -1 or kb == -1:
write("NO\n")
continue
write("YES\n" if PS[ka][kb] == 1 else "NO\n")
return True
while solve():
...
``` | output | 1 | 106,052 | 1 | 212,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,131 | 1 | 212,262 |
Tags: implementation
Correct Solution:
```
def read():
return set(list(map(int, input().split()))[1:])
n = int(input())
t = read()
for _ in range(n - 1):
t = t & read()
for x in t:
print(x, end=' ')
print()
``` | output | 1 | 106,131 | 1 | 212,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,132 | 1 | 212,264 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=[]
min_r=100
min_i=0
for i in range(n):
ta=list(map(int,input().split()))
r=ta[0]
a.append(ta[1:])
if(r<min_r):
min_r=r
min_i=i
#print(min_i)
for i in a[min_i]:
f=1
for j in range(n):
s=i in set(a[j])
if(s==False):
#print(j)
f=0
break
if(f):
print(i,end=' ')
``` | output | 1 | 106,132 | 1 | 212,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,133 | 1 | 212,266 |
Tags: implementation
Correct Solution:
```
n = int(input())
d = {}
for i in range(n):
s = input().split()
for j in range(int(s[0])):
d[s[j+1]] = d.get(s[j+1],0)+1
ans = ""
for x in d:
if d[x] == n:
ans += str(x) + ' '
print(ans.strip())
``` | output | 1 | 106,133 | 1 | 212,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,134 | 1 | 212,268 |
Tags: implementation
Correct Solution:
```
n = int(input())
arr = []
for i in range(n):
arr.append(set([int(i) for i in input().split()][1:]))
x = arr[0]&arr[1]
for i in range(2,len(arr)):
x &= arr[i]
print(*x)
``` | output | 1 | 106,134 | 1 | 212,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,135 | 1 | 212,270 |
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
N = int(input())
for i in range(N):
lines = list(map(str, input().split()))
lines = lines[1:]
if i == 0:
res = set(lines)
else:
res &= set(lines)
print(' '.join(res))
``` | output | 1 | 106,135 | 1 | 212,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,136 | 1 | 212,272 |
Tags: implementation
Correct Solution:
```
def main():
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n = int(input())
a = [0 for i in range(100)]
for i in range(n):
for e in map(int, input().split()[1:]):
a[e-1] += 1
for i, e in enumerate(a):
if e == n:
print(str(i+1) + " ")
if __name__ == '__main__':
main()
``` | output | 1 | 106,136 | 1 | 212,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,137 | 1 | 212,274 |
Tags: implementation
Correct Solution:
```
n = int(input())
line = list(map(int, input().split()))
r = line[0]
variants = set(line[1:])
for i in range(1, n):
line = list(map(int, input().split()))
r = line[0]
var = set(line[1:])
variants.intersection_update(var)
for v in variants:
print(v, end=' ')
``` | output | 1 | 106,137 | 1 | 212,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4. | instruction | 0 | 106,138 | 1 | 212,276 |
Tags: implementation
Correct Solution:
```
n = int(input())
res = {i for i in range(1, 101)}
for _ in range(n):
res &= set(map(int, input().split()[1:]))
print(*res)
``` | output | 1 | 106,138 | 1 | 212,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n = int(input())
cnt = [0] * 101
for x in range(n):
lst = [int(y) for y in input().split()]
for i in range(1, len(lst)):
cnt[lst[i]] += 1
for x in range(1, 101):
if cnt[x] == n:
print(x, end = ' ')
``` | instruction | 0 | 106,139 | 1 | 212,278 |
Yes | output | 1 | 106,139 | 1 | 212,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n = int(input())
s = set()
for i in range(n):
x = list(map(int, input().split()))
tmp = set()
for r in x[1:]:
tmp.add(r)
if len(s) == 0:
s = tmp
else:
s = s.intersection(tmp)
if len(s) == 0:
exit()
print(*s)
``` | instruction | 0 | 106,140 | 1 | 212,280 |
Yes | output | 1 | 106,140 | 1 | 212,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n=int(input())
ans=[ ]
for i in range(n):
ar=tuple(map(int,input().split()))
ans.append(set(ar[1:]))
ans=set.intersection(*ans)
print(*ans)
``` | instruction | 0 | 106,141 | 1 | 212,282 |
Yes | output | 1 | 106,141 | 1 | 212,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n = int(input())
s = set()
for _ in range(n):
if s:
m = set(list(map(int,input().split()))[1:])
s = s.intersection(m)
else:
s = set(list(map(int,input().split()))[1:])
print(*s)
``` | instruction | 0 | 106,142 | 1 | 212,284 |
Yes | output | 1 | 106,142 | 1 | 212,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
def arkadyi(n, lst):
b = list()
a = [item for sublist in lst for item in sublist]
for elem in a:
if a.count(elem) == 3:
b.append(elem)
return set(b)
N = int(input())
b = list()
for j in range(N):
s = [int(x) for x in input().split()]
b.append(s[1:])
print(*arkadyi(N, b))
``` | instruction | 0 | 106,143 | 1 | 212,286 |
No | output | 1 | 106,143 | 1 | 212,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
def prog():
from sys import stdin
n = int(stdin.readline())
s = set(map(int,stdin.readline().split()))
for i in range(n-1):
d = set(map(int,stdin.readline().split()))
s = s&d
print(*s)
prog()
``` | instruction | 0 | 106,144 | 1 | 212,288 |
No | output | 1 | 106,144 | 1 | 212,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
r = int(input())
trains = []
res = []
stringRes = ""
for i in range(r):
lines = input().split(" ")
trains.append(lines)
exist = trains[0]
for i in range(1,len(trains)):
for j in range(len(trains[i])):
if trains[i][j] in exist:
res.append(trains[i][j])
if len(res) == 0:
res = trains[0]
for i in res:
stringRes = stringRes + i + " "
print(stringRes)
``` | instruction | 0 | 106,145 | 1 | 212,290 |
No | output | 1 | 106,145 | 1 | 212,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n=int(input())
s=set(input().split())
for i in range(n-1):
s1=set(input().split())
s=s & s1
print(*list(s))
``` | instruction | 0 | 106,146 | 1 | 212,292 |
No | output | 1 | 106,146 | 1 | 212,293 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,929 | 1 | 213,858 |
"Correct Solution:
```
# -*- coding:utf-8 -*-
def main():
LIST=[]
while True:
try:
IN=int(input())
if IN==0:
print(LIST[len(LIST)-1])
del LIST[len(LIST)-1]
else:
LIST.append(IN)
except:
break
if __name__ == '__main__':
main()
``` | output | 1 | 106,929 | 1 | 213,859 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,930 | 1 | 213,860 |
"Correct Solution:
```
# coding=utf-8
if __name__ == '__main__':
train_list = []
while True:
try:
n = int(input())
except EOFError:
break
if n == 0:
leaving = train_list.pop()
print(leaving)
else:
train_list.append(n)
``` | output | 1 | 106,930 | 1 | 213,861 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,931 | 1 | 213,862 |
"Correct Solution:
```
import sys
a=[]
stack=[]
for line in sys.stdin:
a.append(int(line))
for i in range(len(a)):
if a[i]==0:
print(stack[-1])
del stack[-1]
else:stack.append(a[i])
``` | output | 1 | 106,931 | 1 | 213,863 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,932 | 1 | 213,864 |
"Correct Solution:
```
import sys
x=[]
u=[]
for line in sys.stdin.readlines():
y=int(line)
if(y!=0):
x.append(y)
else:
u.append(x.pop(-1))
for i in range(len(u)):
print(u[i])
``` | output | 1 | 106,932 | 1 | 213,865 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,933 | 1 | 213,866 |
"Correct Solution:
```
import sys
stack = []
for nstr in sys.stdin:
n = int(nstr)
if n == 0:
print(stack.pop())
else:
stack.append(n)
``` | output | 1 | 106,933 | 1 | 213,867 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,934 | 1 | 213,868 |
"Correct Solution:
```
car = []
while 1:
try:
i = int(input())
if i == 0:
print(car.pop())
else:
car.append(i)
except ValueError:
print(car)
for j in range(len(car)):
print(car.pop())
break
except EOFError:
break
``` | output | 1 | 106,934 | 1 | 213,869 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,935 | 1 | 213,870 |
"Correct Solution:
```
import sys
s = []
[print(s.pop()) if int(e) == 0 else s.append(int(e)) for e in sys.stdin]
``` | output | 1 | 106,935 | 1 | 213,871 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1 | instruction | 0 | 106,936 | 1 | 213,872 |
"Correct Solution:
```
D=[]
while True:
try:
n=int(input())
if n==0:
print(D.pop(-1))
else:
D.append(n)
except EOFError:
break
``` | output | 1 | 106,936 | 1 | 213,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1
Submitted Solution:
```
DE = []
while True:
try:
N = int(input())
except:
break
if N > 0:
DE.insert(0,N)
if N==0:
print(DE[0])
DE.pop(0)
``` | instruction | 0 | 106,937 | 1 | 213,874 |
Yes | output | 1 | 106,937 | 1 | 213,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1
Submitted Solution:
```
from collections import deque
cars=deque()
while(True):
try:
n=int(input())
print(cars.popleft()) if n==0 else cars.appendleft(n)
except:
break
``` | instruction | 0 | 106,938 | 1 | 213,876 |
Yes | output | 1 | 106,938 | 1 | 213,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
* An entry of a car is represented by its number.
* An exit of a car is represented by 0
For example, a sequence
1
6
0
8
10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
Input
car number
car number or 0
car number or 0
.
.
.
car number or 0
The number of input lines is less than or equal to 100.
Output
For each 0, print the car number.
Example
Input
1
6
0
8
10
0
0
0
Output
6
10
8
1
Submitted Solution:
```
import sys
lst = [int(line) for line in sys.stdin.readlines()]
queue = []
for num in lst:
if num != 0:
queue.append(num)
else:
print(queue[-1])
del queue[-1]
``` | instruction | 0 | 106,939 | 1 | 213,878 |
Yes | output | 1 | 106,939 | 1 | 213,879 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.