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. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` n , m = map(int,input().split()) mat=[[0]*500 for i in range(500)] d=[0]*(500) for i in range(m): a , b = map(int,input().split()) mat[a][b]=1 mat[b][a]=1 d[1]=1 q=[1] t=0 if mat[1][n]==1: t=0 else: t=1 while len(q)>0: a=q[0] # print(q) q.pop(0) for i in range(1,n+1): if mat[a][i]==t and d[i]==0: q.append(i) d[i]=d[a]+1 print(d[n]-1) ```
instruction
0
45,777
1
91,554
Yes
output
1
45,777
1
91,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` n, k = map(int, input().split()) vt = [[] for i in range(n + 1)] vb = [[] for i in range(n + 1)] queue = [] visit = [0 for i in range(n + 1)] s = set([i for i in range(1, n + 1)]) for i in range(k): a, b = map(int, input().split()) vt[a].append(b) vt[b].append(a) visit[1] = 1 queue = [1] if vt[n].count(1): for i in range(n): vb[i] = list(s - set(vt[i])) h = 0 t = 1 while h != t: v = queue[h] h += 1 for u in vb[v]: if not visit[u]: visit[u] = visit[v] + 1 queue.append(u) t += 1 print(visit[n] - 1) else: h = 0 t = 1 while h != t: v = queue[h] h += 1 for u in vt[v]: if not visit[u]: visit[u] = visit[v] + 1 queue.append(u) t += 1 print(visit[n] - 1) ```
instruction
0
45,778
1
91,556
Yes
output
1
45,778
1
91,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return int(input()) class Stack(object): def __init__(self): self.items = [] def push(self,new): self.items.append(new) def pop(self): return self.items.pop(0) def empty(self): return self.items == [] n,m = mp() Rail = [[] for i in range(n)] Road = [[i for i in range(n)] for j in range(n)] for i in range(m): u,v = mp() Rail[u-1].append(v-1) Rail[v-1].append(u-1) Road[u-1].remove(v-1) Road[v-1].remove(u-1) visited = [False]*n time = [float("inf")]*n if n-1 in Road[0]: Q = Stack() Q.push(0) visited[0] = True time[0] = 0 while not Q.empty() and not visited[n-1] : r = Q.pop() for i in Rail[r]: if not visited[i]: visited[i] = True time[i] = time[r] + 1 Q.push(i) if not visited[n-1]: print(-1) else: print(time[n-1]) else: Q = Stack() Q.push(0) visited[0] = True time[0] = 0 while not Q.empty() and not visited[n-1]: r = Q.pop() for i in Road[r]: if not visited[i]: visited[i] = True time[i] = time[r] + 1 Q.push(i) if not visited[n-1]: print(-1) else: print(time[n-1]) ```
instruction
0
45,779
1
91,558
Yes
output
1
45,779
1
91,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` n,m=map(int,input().split()) rail = [ [False for v in range(n) ] for u in range(n) ] road= [ [True for v in range(n) ] for u in range(n) ] for i in range(m): u,v = map(lambda x:x-1,map(int,input().split())) rail[u][v]=rail[v][u]=True road[u][v]=road[v][u]=False source,target=0,n-1 if rail[source][target]: g = road else: g = rail seen = [ False for v in range(n) ] queue=[ (source,0) ] tail = 0 while tail < len(queue): (u,steps) = queue[tail] tail+=1 for v in range(n): if g[u][v] and not seen[v]: if v == target: print(steps+1) import sys; sys.exit() seen[v]=True queue.append((v,steps+1)) print(-1) ```
instruction
0
45,780
1
91,560
Yes
output
1
45,780
1
91,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` from collections import deque def bfs(start, g, n): q = deque() q.appendleft(start) d = [-1] * n d[start] = 0 while q: v = q[0] q.popleft() for i in range(len(g[v])): to = g[v][i] if d[to] == -1: q.appendleft(to) d[to] = d[v] + 1 return d[n-1] n, m = map(int, input().split()) g = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 g[x].append(y) g[y].append(x) start = 0 if n - 1 not in g[0]: ok = bfs(start, g, n) print(ok) else: g1 = [[] for i in range(n)] k = set([_ for _ in range(n)]) for i in range(n): g1[i] = list(k - set(g[i]) - {i}) ok = bfs(start,g1,n) print(ok) ```
instruction
0
45,781
1
91,562
No
output
1
45,781
1
91,563
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` from collections import deque def bfs(start, g, n): q = deque() q.appendleft(start) d = [-1] * n d[start] = 0 while q: v = q[0] q.popleft() for i in range(len(g[v])): to = g[v][i] if d[to] == -1: q.appendleft(to) d[to] = d[v] + 1 return d[n-1] n, m = map(int, input().split()) if n == 20 and m == 100: print(2) elif n == 86 and m == 715: print(3) elif n == 315 and m == 29773: print(2) elif n == 268 and m == 28600: print(2) elif n == 400 and m == 39907: print(2) else: g = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 g[x].append(y) g[y].append(x) start = 0 if n - 1 not in g[0]: ok = bfs(start, g, n) print(ok) else: g1 = [[] for i in range(n)] k = set([_ for _ in range(n)]) for i in range(n): g1[i] = list(k - set(g[i]) - {i}) ok = bfs(start,g1,n) print(ok) ```
instruction
0
45,782
1
91,564
No
output
1
45,782
1
91,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` from collections import deque def bfs(start, g, n): q = deque() q.appendleft(start) d = [-1] * n d[start] = 0 while q: v = q[0] q.popleft() for i in range(len(g[v])): to = g[v][i] if d[to] == -1: q.appendleft(to) d[to] = d[v] + 1 return d[n-1] n, m = map(int, input().split()) if n == 20 and m == 100: print(2) elif n == 86 and m == 715: print(3) else: g = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 g[x].append(y) g[y].append(x) start = 0 if n - 1 not in g[0]: ok = bfs(start, g, n) print(ok) else: g1 = [[] for i in range(n)] k = set([_ for _ in range(n)]) for i in range(n): g1[i] = list(k - set(g[i]) - {i}) ok = bfs(start,g1,n) print(ok) ```
instruction
0
45,783
1
91,566
No
output
1
45,783
1
91,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β€” for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety β€” in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 400, 0 ≀ m ≀ n(n - 1) / 2) β€” the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≀ u, v ≀ n, u β‰  v). You may assume that there is at most one railway connecting any two towns. Output Output one integer β€” the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. Examples Input 4 2 1 3 3 4 Output 2 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output -1 Input 5 5 4 2 3 5 4 5 5 1 1 2 Output 3 Note In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. Submitted Solution: ``` def bfs(mat): n = len(mat) q = [0] visited = [-1] * n visited[0] = 0 while (len(q) > 0): cur = q.pop() for i in range(n): if visited[i] == -1 and mat[cur][i] == 1: q.append(i) visited[i] = visited[cur]+1 if visited[n-1] != -1: return visited[n-1] return -1 def flip(mat): a = [1, 0] for i in range(len(mat)): for j in range(len(mat)): if i != j: mat[i][j] = a[mat[i][j]] def main(): n, m = [int(i) for i in input().split(" ")] mat = [[0]*n for i in range(n)] for i in range(m): a, b = [int(i) for i in input().split(" ")] a -= 1 b -= 1 mat[a][b], mat[b][a] = 1, 1 if mat[0][n-1] == 1: flip(mat) print (bfs(mat)) if __name__ == "__main__": main() ```
instruction
0
45,784
1
91,568
No
output
1
45,784
1
91,569
Provide a correct Python 3 solution for this coding contest problem. You are a teacher at Iazu High School is the Zuia Kingdom. There are $N$ cities and $N-1$ roads connecting them that allow you to move from one city to another by way of more than one road. Each of the roads allows bidirectional traffic and has a known length. As a part of class activities, you are planning the following action assignment for your students. First, you come up with several themes commonly applicable to three different cities. Second, you assign each of the themes to a group of three students. Then, each student of a group is assigned to one of the three cities and conducts a survey on it. Finally, all students of the group get together in one of the $N$ cities and compile their results. After a theme group has completed its survey, the three members move from the city on which they studied to the city for getting together. The longest distance they have to travel for getting together is defined as the cost of the theme. You want to select the meeting city so that the cost for each theme becomes minimum. Given the number of cities, road information and $Q$ sets of three cities for each theme, make a program to work out the minimum cost for each theme. Input The input is given in the following format. $N$ $Q$ $u_1$ $v_1$ $w_1$ $u_2$ $v_2$ $w_2$ $...$ $u_{N-1}$ $v_{N-1}$ $w_{N-1}$ $a_1$ $b_1$ $c_1$ $a_2$ $b_2$ $c_2$ $...$ $a_Q$ $b_Q$ $c_Q$ The first line provides the number of cities in the Zuia Kingdom $N$ ($3 \leq N \leq 100,000$) and the number of themes $Q$ ($1 \leq Q \leq 100,000$). Each of the subsequent $N-1$ lines provides the information regarding the $i$-th road $u_i,v_i,w_i$ ($ 1 \leq u_i < v_i \leq N, 1 \leq w_i \leq 10,000$), indicating that the road connects cities $u_i$ and $v_i$, and the road distance between the two is $w_i$. Each of the $Q$ lines that follows the above provides the three cities assigned to the $i$-th theme: $a_i,b_i,c_i$ ($1 \leq a_i < b_i < c_i \leq N$). Output For each theme, output the cost in one line. Examples Input 5 4 1 2 3 2 3 4 2 4 2 4 5 3 1 3 4 1 4 5 1 2 3 2 4 5 Output 4 5 4 3 Input 5 3 1 2 1 2 3 1 3 4 1 4 5 1 1 2 3 1 3 5 1 2 4 Output 1 2 2 Input 15 15 1 2 45 2 3 81 1 4 29 1 5 2 5 6 25 4 7 84 7 8 56 4 9 2 4 10 37 7 11 39 1 12 11 11 13 6 3 14 68 2 15 16 10 13 14 13 14 15 2 14 15 7 12 15 10 14 15 9 10 15 9 14 15 8 13 15 5 6 13 11 13 15 12 13 14 2 3 10 5 13 15 10 11 14 6 8 11 Output 194 194 97 90 149 66 149 140 129 129 194 111 129 194 140
instruction
0
46,114
1
92,228
"Correct Solution: ``` import sys sys.setrecursionlimit(1000000) def main(): n, q = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(n - 1): u, v, w = map(int, input().split()) u -= 1 v -= 1 edges[u].append((v, w)) edges[v].append((u, w)) height = [None] * n dist = [None] * n parent = [[None] * 20 for _ in range(n)] stack = [(0, 0, 0)] while stack: x, h, d = stack.pop() height[x] = h dist[x] = d for to, w in edges[x]: if height[to] == None: parent[to][0] = x stack.append((to, h + 1, d + w)) for j in range(1, 20): for i in range(1, n): if height[i] >= 2 ** j: parent[i][j] = parent[parent[i][j - 1]][j - 1] def adj_height(x, n): if n == 0: return x acc = 1 for i in range(20): if acc > n: return adj_height(parent[x][i - 1], n - acc // 2) acc *= 2 def _lca(x, y): if x == y: return x for i in range(1 ,20): if parent[x][i] == parent[y][i]: return _lca(parent[x][i - 1], parent[y][i - 1]) def lca(x, y): diff = height[x] - height[y] if diff < 0: y = adj_height(y, -diff) elif diff > 0: x = adj_height(x, diff) return _lca(x, y) def bs(index, target): if index == 0: return 0 if dist[index] >= target >= dist[parent[index][0]]: return index for i in range(1, 20): if parent[index][i] == None or dist[parent[index][i]] <= target: return bs(parent[index][i - 1], target) def max_dist(x, y, z, r): xr = lca(x, r) yr = lca(y, r) zr = lca(z, r) return max(dist[x] + dist[r] - dist[xr] * 2, dist[y] + dist[r] - dist[yr] * 2, dist[z] + dist[r] - dist[zr] * 2) def _score(x, y, z, xy, yz): dist_x = dist[x] dist_y = dist[y] dist_z = dist[z] dist_xy = dist[xy] dist_yz = dist[yz] dx = dist_x + dist_yz - dist_xy * 2 dy = dist_y - dist_yz dz = dist_z - dist_yz if dx >= dy >= dz: if dist_x >= dist_y: r = bs(x, dist_xy + (dist_x - dist_y) / 2) if r == 0: return dist_x return min(max(dist_x - dist[r], dist_y + dist[r] - dist_xy * 2), max(dist_x - dist[parent[r][0]], dist_y + dist[parent[r][0]] - dist_xy * 2)) else: r = bs(yz, dist_xy + (dist_y - dist_x) / 2) if r == 0: return dist_y return min(max(dist_y - dist[r], dist_x + dist[r] - dist_xy * 2), max(dist_y - dist[parent[r][0]], dist_x + dist[parent[r][0]] - dist_xy * 2)) elif dx >= dz >= dy: if dist_x >= dist_z: r = bs(x, dist_xy + (dist_x - dist_z) / 2) if r == 0: return dist_x return min(max(dist_x - dist[r], dist_z + dist[r] - dist_xy * 2), max(dist_x - dist[parent[r][0]], dist_z + dist[parent[r][0]] - dist_xy * 2)) else: r = bs(yz, dist_xy + (dist_z - dist_x) / 2) if r == 0: return dist_z return min(max(dist_z - dist[r], dist_x + dist[r] - dist_xy * 2), max(dist_z - dist[parent[r][0]], dist_x + dist[parent[r][0]] - dist_xy * 2)) elif dy >= dx >= dz: r = bs(y, dist_yz + (dy - dx) / 2) if r == 0: return dist_y return min(max(dist_y - dist[r], dist_x + dist[r] - dist_xy * 2), max(dist_y - dist[parent[r][0]], dist_x + dist[parent[r][0]] - dist_xy * 2)) elif dy >= dz >= dx: r = bs(y, dist_yz + (dy - dz) / 2) if r == 0: return dist_y return min(max(dist_y - dist[r], dist_z + dist[r] - dist_yz * 2), max(dist_y - dist[parent[r][0]], dist_z + dist[parent[r][0]] - dist_yz * 2)) elif dz >= dx >= dy: r = bs(z, dist_yz + (dz - dx) / 2) if r == 0: return dist_z return min(max(dist_z - dist[r], dist_x + dist[r] - dist_xy * 2), max(dist_z - dist[parent[r][0]], dist_x + dist[parent[r][0]] - dist_xy * 2)) elif dz >= dy >= dx: r = bs(z, dist_yz + (dz - dy) / 2) if r == 0: return dist_z return min(max(dist_z - dist[r], dist_y + dist[r] - dist_yz * 2), max(dist_z - dist[parent[r][0]], dist_y + dist[parent[r][0]] - dist_yz * 2)) def score(a, b, c): a -= 1 b -= 1 c -= 1 ab = lca(a, b) ac = lca(a, c) bc = lca(b, c) if ab == ac: return _score(a, b, c, ab, bc) elif ab == bc: return _score(b, a, c, ab, ac) else: return _score(c, a, b, ac, ab) for _ in range(q): a, b, c = map(int, input().split()) print(score(a, b, c)) main() ```
output
1
46,114
1
92,229
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,199
1
92,398
Tags: graphs Correct Solution: ``` def dfs(graph, i, s, n, mark): mark[i] = 1 if mark[s-1] == 1: return for j in range(n): if graph[i][j] == 1 and mark[j] == 0: dfs(graph, j, s, n, mark) n, s = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mark = [0]*n graph = [] for _ in range(n): temp = [0]*n graph.append(temp) prev = -1 for i in range(len(a)): if a[i] == 1: if prev == -1: prev = i else: graph[prev][i] = 1 prev = i prev = -1 for i in range(len(b)-1, -1, -1): if b[i] == 1: if prev == -1: prev = i else: graph[prev][i] = 1 prev = i dfs(graph, 0, s, n, mark) #print(graph) #print(mark) if mark[s-1]: print("YES") else: print("NO") ```
output
1
46,199
1
92,399
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,200
1
92,400
Tags: graphs Correct Solution: ``` n, s = input().split() n = int(n) s = int(s) a = input().split() b = input().split() for j in range(n): a[j] = int(a[j]) b[j] = int(b[j]) if a[0]==1: if a[s-1]==1: print("YES") elif b[s-1]==1: for i in range(s,n): if a[i]==1 and b[i]==1: print("YES") break else: print("NO") else: print("NO") else: print("NO") ```
output
1
46,200
1
92,401
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,201
1
92,402
Tags: graphs Correct Solution: ``` inp = input().split() s = int(inp[0]) n = int(inp[1]) seq1 = input().split(" ") seq2 = input().split(" ") if seq1[0] == '0': print("NO") elif seq1[n - 1] == '1': print("YES") else: end = False for i in range(n, s): if seq1[i] == '1' and seq2[i] == '1': if seq2[n-1] == '1': print("YES") end = True break if end == False: print("NO") ```
output
1
46,201
1
92,403
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,202
1
92,404
Tags: graphs Correct Solution: ``` n,s = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] ans = 0 c = 0 if a[0] == 0: print("NO") elif a[s - 1] == 0: for station in a[s:]: if station == 1 and b[a.index(station, s + c)] == 1: if b[s - 1] == 1: ans = 1 c += 1 if ans == 1: print("YES") else: print("NO") else: print("YES") ```
output
1
46,202
1
92,405
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,203
1
92,406
Tags: graphs Correct Solution: ``` n,s=map(int,input().split()) x=input().split() x1=input().split() men=8 if x1[s-1]=='1'and x[0]=='1': for i in range(s-1,n): if x[i]=='1'==x1[i]: print('YES') men-=1 break if men==8: if x[0] == '0' or x[s-1]==x1[s-1]=='0' or (x[s-1]=='0' and (x[n-1]=='0'or x1[n-1]=='0')): print('NO') else: print('YES') ```
output
1
46,203
1
92,407
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,204
1
92,408
Tags: graphs Correct Solution: ``` n, s = list(map(int, input("").split(" "))) B = list(map(int, input("").split(" "))) A = list(map(int, input("").split(" "))) can_reach = False if(B[0] == 0): can_reach = False elif B[s-1] == 1: can_reach = True elif A[s-1] == 0: can_reach = False else: for i in range(s-1, len(B)): if A[i] == 1 and B[i] == 1: can_reach = True break if can_reach == True: print("YES") else: print("NO") ```
output
1
46,204
1
92,409
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,205
1
92,410
Tags: graphs Correct Solution: ``` i = input n, s = map(int, i().split()) a = i().split() b = i().split() if a[0] == '0' or a[s-1] + b[s-1] == '00': print('NO') elif a[0] + a[s-1] == '11': print('YES') else: for i in range(s, n): if a[i] == b[i] == '1': print('YES') exit() else: print('NO') ```
output
1
46,205
1
92,411
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home.
instruction
0
46,206
1
92,412
Tags: graphs Correct Solution: ``` tmp = input().split(' ') n = int(tmp[0]) s = int(tmp[1]) a = input().split(' ') b = input().split(' ') tmp = 0 if a[0] == '0': print("NO") elif a[s-1] == '1': print("YES") elif b[s-1] == '1': for i in range(s, n): if (a[i] == '1') & (b[i] == '1'): print("YES") tmp = 1 break if not tmp: print("NO") else: print("NO") ```
output
1
46,206
1
92,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` n, s = list(map(int, input().split(' '))) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) s -= 1 def check(): for i in range(s + 1, n): if (a[i] != 0) and (a[i] == b[i]): return True return False flag = True if a[0] == 0: print('NO') elif a[s] == 1: print('YES') elif b[s] == 0: print('NO') elif check(): print('YES') else: print('NO') ```
instruction
0
46,207
1
92,414
Yes
output
1
46,207
1
92,415
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` n,s=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) if a[0] and (a[s - 1] or b[s - 1] and any([a[i] and b[i] for i in range(s,n)])): print("YES") else: print("NO") ```
instruction
0
46,208
1
92,416
Yes
output
1
46,208
1
92,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` from bisect import bisect_right as br from bisect import bisect_left as bl import sys MAX = sys.maxsize MAXN = 10**6+10 def isprime(n): n = abs(int(n)) if n < 2: return False if n == 2: return True if not n & 1: return False for x in range(3, int(n**0.5) + 1, 2): if n % x == 0: return False return True def mhd(a,b,x,y): return abs(a-x)+abs(b-y) def numIN(): return(map(int,sys.stdin.readline().strip().split())) def charIN(): return(sys.stdin.readline().strip().split()) n,s = numIN() a = list(numIN()) b = list(numIN()) if not a[0] or (a[s-1]==0 and b[s-1]==0): print('NO') exit(0) if a[s-1]: print('YES') exit(0) f = 0 for i in range(s,n): if a[i] and b[i]: f = 1 break if f: if b[s-1]: print('YES') else: print('NO') else: print('NO') ```
instruction
0
46,209
1
92,418
Yes
output
1
46,209
1
92,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` n,s=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) if a[0]==0: print("NO") else: if a[s-1]==1: print("YES") else: if b[s-1]==0: print("NO") else: done=False for i in range(s,n): if a[i]==b[i]==1: print("YES") done=True break if not done: print("NO") ```
instruction
0
46,210
1
92,420
Yes
output
1
46,210
1
92,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` n,s=map(int, input().split()) a=[int(s) for s in input().split()] b=[int(s) for s in input().split()] k=0 if a[0]==0 or b[s-1]==0: print('NO') else: if a[s-1]==1: print('YES') else: for i in range(s,n): if a[i]==b[i] and a[i]==1: print('YES') break else: print('NO') ```
instruction
0
46,211
1
92,422
No
output
1
46,211
1
92,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` b = True n,alice = map(int,(input().split())) lst = list(map(int,input().split())) lst2 = list(map(int,input().split())) if (lst[alice-1] == 0 and lst2[alice-1] == 0) or lst[0] == 0: print("NO") b = False else: for i in range(n): if lst[i] == lst2[i] and i >= alice: print("YES") b = False break if b == True: print("NO") ```
instruction
0
46,212
1
92,424
No
output
1
46,212
1
92,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` n, s = map(int,input().split()) n1 = list(map(int, input().split())) n2 = list(map(int, input().split())) if n1[s-1]==1 and n1[0]==1: print("YES") elif n1[s-1:].count(1)>1 and n1[0]==1 and n2[s-1]==1: print("YES") else: print("NO") ```
instruction
0
46,213
1
92,426
No
output
1
46,213
1
92,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice lives near the station with number s. The metro line has two tracks. Trains on the first track go from the station 1 to the station n and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that. Some stations are not yet open at all and some are only partially open β€” for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it. When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport. Input The first line contains two integers n and s (2 ≀ s ≀ n ≀ 1000) β€” the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station 1. Next lines describe information about closed and open stations. The second line contains n integers a_1, a_2, …, a_n (a_i = 0 or a_i = 1). If a_i = 1, then the i-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track. The third line contains n integers b_1, b_2, …, b_n (b_i = 0 or b_i = 1). If b_i = 1, then the i-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track. Output Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). Examples Input 5 3 1 1 1 1 1 1 1 1 1 1 Output YES Input 5 4 1 0 0 0 1 0 1 1 1 1 Output YES Input 5 2 0 1 1 1 1 1 1 1 1 1 Output NO Note In the first example, all stations are opened, so Bob can simply travel to the station with number 3. In the second example, Bob should travel to the station 5 first, switch to the second track and travel to the station 4 then. In the third example, Bob simply can't enter the train going in the direction of Alice's home. Submitted Solution: ``` # #948A # import numpy as np # r, c = map(int, input().split()) # data = [] # for _ in range(r): # data.append(list(input())) # arr = np.array(data) # counter = 0 # for i in range(r): # for j in range(c): # if arr[i][j] == 'W': # if arr[i][j-1] == 'S' or arr[i][j+1] == 'S' or arr[i-1][j] == 'S' or arr[i+1][j] == 'S': # counter = 1 # else: # pass # if counter == 0: # print('Yes') # arr[arr == '.'] = 'D' # for k in range(r): # print("".join(arr[k])) # else: # print('No') #1055A n, s =map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if a[0] == 0: print("NO") else: if a[s-1] == 1 or b[s-1] == 1: print("YES") else: print('NO') ```
instruction
0
46,214
1
92,428
No
output
1
46,214
1
92,429
Provide tags and a correct Python 3 solution for this coding contest problem. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61
instruction
0
46,327
1
92,654
Tags: dfs and similar, dp, dsu, graphs, greedy, trees Correct Solution: ``` import sys input = sys.stdin.readline n,m=map(int,input().split()) W=[0]+list(map(int,input().split())) E=[tuple(map(int,input().split())) for i in range(m)] S=int(input()) ELIST=[[] for i in range(n+1)] EW=[0]*(n+1) for x,y in E: ELIST[x].append(y) ELIST[y].append(x) EW[x]+=1 EW[y]+=1 #print(ELIST,EW) from collections import deque Q=deque() USED=[0]*(n+1) for i in range(1,n+1): if EW[i]==1 and i!=S: USED[i]=1 Q.append(i) #print(Q) EW[S]+=1<<50 USED[S]=1 while Q: x=Q.pop() EW[x]-=1 #print(x,EW) for to in ELIST[x]: if USED[to]==1: continue EW[to]-=1 if EW[to]==1 and USED[to]==0: Q.append(to) USED[to]=1 #print(EW) LOOP=[] ANS=0 for i in range(1,n+1): if EW[i]!=0: ANS+=W[i] LOOP.append(i) #print(LOOP) SCORE=[0]*(n+1) USED=[0]*(n+1) for l in LOOP: SCORE[l]=ANS USED[l]=1 #print(USED) Q=deque(LOOP) #print(Q) while Q: x=Q.pop() #print(x,ELIST[x],USED) for to in ELIST[x]: if USED[to]==1: continue SCORE[to]=W[to]+SCORE[x] Q.append(to) USED[to]=1 print(max(SCORE)) ```
output
1
46,327
1
92,655
Provide tags and a correct Python 3 solution for this coding contest problem. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61
instruction
0
46,328
1
92,656
Tags: dfs and similar, dp, dsu, graphs, greedy, trees Correct Solution: ``` import sys input = sys.stdin.readline n,m=map(int,input().split()) W=[0]+list(map(int,input().split())) E=[tuple(map(int,input().split())) for i in range(m)] S=int(input()) ELIST=[[] for i in range(n+1)] EW=[0]*(n+1) for x,y in E: ELIST[x].append(y) ELIST[y].append(x) EW[x]+=1 EW[y]+=1 from collections import deque Q=deque() USED=[0]*(n+1) for i in range(1,n+1): if EW[i]==1 and i!=S: USED[i]=1 Q.append(i) EW[S]+=1<<50 USED[S]=1 while Q: x=Q.pop() EW[x]-=1 for to in ELIST[x]: if USED[to]==1: continue EW[to]-=1 if EW[to]==1 and USED[to]==0: Q.append(to) USED[to]=1 #print(EW) LOOP=[] ANS=0 for i in range(1,n+1): if EW[i]!=0: ANS+=W[i] LOOP.append(i) SCORE=[0]*(n+1) USED=[0]*(n+1) for l in LOOP: SCORE[l]=ANS USED[l]=1 Q=deque(LOOP) while Q: x=Q.pop() for to in ELIST[x]: if USED[to]==1: continue SCORE[to]=W[to]+SCORE[x] Q.append(to) USED[to]=1 print(max(SCORE)) ```
output
1
46,328
1
92,657
Provide tags and a correct Python 3 solution for this coding contest problem. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61
instruction
0
46,329
1
92,658
Tags: dfs and similar, dp, dsu, graphs, greedy, trees Correct Solution: ``` from collections import defaultdict def get_neighbors(edges): neighbors = defaultdict(set, {}) for v1, v2 in edges: neighbors[v1].add(v2) neighbors[v2].add(v1) return dict(neighbors) def get_component(neighbors_map, root): if root not in neighbors_map: return {root} horizon = set(neighbors_map[root]) component = {root} while horizon: new_node = horizon.pop() if new_node in component: continue component.add(new_node) new_neighbors = neighbors_map[new_node].difference(component) horizon |= new_neighbors return component def fn(weights, edges, root): neihgbors_map = get_neighbors(edges) if root not in neihgbors_map: return weights[root] first_component = get_component(neihgbors_map, root) neihgbors_map = {k: v for k, v in neihgbors_map.items() if k in first_component} degrees = {} leaves = [] for n, neigh in neihgbors_map.items(): degrees[n] = len(neigh) if len(neigh) == 1 and n != root: leaves.append(n) extra_values = defaultdict(int, {}) max_extra = 0 removed_set = set() while leaves: leaf = leaves.pop() value = weights[leaf] + extra_values[leaf] parent = neihgbors_map.pop(leaf).pop() neihgbors_map[parent].remove(leaf) degrees[parent] -= 1 if degrees[parent] == 1 and parent != root: leaves.append(parent) mm = max(extra_values[parent], value) extra_values[parent] = mm max_extra = max(mm, max_extra) removed_set.add(leaf) return sum(weights[n] for n in neihgbors_map) + max_extra def print_answer(source): n, m = map(int, source().split()) weights = list(map(int, source().split())) edges = [[int(k) - 1 for k in source().split()] for _ in range(m)] root = int(source()) - 1 print(fn(weights, edges, root)) print_answer(input) if False: from string_source import string_source print_answer(string_source("""3 2 1 1335 2 2 1 3 2 2""")) from string_source import string_source print_answer(string_source("""1 0 1000000000 1""")) print_answer(string_source("""10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6""")) print_answer(string_source( """5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2""")) source = string_source("""3 2 1 1335 2 2 1 3 2 2""") n, m = map(int, source().split()) weights = list(map(int, source().split())) edges = [[int(k) - 1 for k in source().split()] for _ in range(m)] root = int(source()) fn(weights, edges, root) from graphviz import Graph dot = Graph(format="png", name="xx", filename=f"_files/temp/graph.png") for idx, w in enumerate(weights): dot.node(str(idx), label=f"{idx} - {w}") for s,e in edges: dot.edge(str(s),str(e)) dot.view(cleanup=True) sum(weights) ```
output
1
46,329
1
92,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61 Submitted Solution: ``` n,m = map(int,input().split()) score = [0] + list(map(int,input().split())) dic = dict() for i in range(1,n+1): dic[i] = list() for i in range(m): c1, c2 = map(int,input().split()) dic[c1].append(c2) dic[c2].append(c1) start = int(input()) max_count = 0 used = [0 for i in range(n+1)] count_dic = [0] + [len(dic[i]) for i in dic] count = 0 def search(start,last,used,count): global max_count if used[start]==0: count+=score[start] used[start]+=1 def stop(start,last,used): if used[start]>count_dic[start]*2: return True if dic[start]==[last]: return True if stop(start,last,used): if count>max_count: max_count = count return else: values = dic[start] for value in values: if value==last: continue search(value,start,used,count) search(start,0,used[:],count) print(max_count) ```
instruction
0
46,330
1
92,660
No
output
1
46,330
1
92,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61 Submitted Solution: ``` def Scanner(): z=list(map(int,input().split(' '))) return z[0] if len(z)==1 else z #from ensias import Scanner if __name__=="__main__": n,m=Scanner() Scores=Scanner() if m==0: print(Scores) else: Graphe=[[0 for j in range(n)] for i in range(n)] Arrets=[] Deg=list(n*[0]) S=set() for i in range(m): a,b=Scanner() a-=1 b-=1 Deg[a]+=1 Deg[b]+=1 Graphe[a][b]=Graphe[b][a]=1 S.add(a) S.add(b) ini=Scanner() ini-=1 Sco=[0 for i in range(n) ] acy=[i for i in range(n) if Deg[i]==1 and ini!=i and i in S] while (len(acy)!=0): V={i:Graphe[i].index(1) for i in acy} for i in acy: Sco[i]=max(Scores[i]+Sco[V[i]],Sco[V[i]]) for i in acy: j=V[i] Graphe[j][i]=0 S.remove(i) Deg[j]-=1 acy=[i for i in range(n) if Deg[i]==1 and ini!=i and i in S] if Sco==[]: print(sum([Scores[i] for i in S])) else: print(max(Sco)+sum([Scores[i] for i in S])) ```
instruction
0
46,331
1
92,662
No
output
1
46,331
1
92,663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61 Submitted Solution: ``` def goto(v, t, q, d): g = 0 for k in range(n): if (v, k + 1) in r and not (v, k + 1) in q: g = g + 1 q.add((v, k + 1)) if k + 1 not in d: t = t + w[k] d.add(k + 1) goto(k + 1, t, q.copy(), d.copy()) if (k + 1, v) in r and not (k + 1, v) in q: g = g + 1 q.add((k + 1, v)) if k + 1 not in d: t = t + w[k] d.add(k + 1) goto(k + 1, t, q.copy(), d.copy()) if g == 0: global h if h < t: h = t n, m = map(int, input().split()) w = list(map(int, input().split())) r = set() for i in range(m): u, v = map(int, input().split()) r.add((u, v)) s = int(input()) h = 0 goto(s, w[s - 1], set(), {s}) print(h) ```
instruction
0
46,332
1
92,664
No
output
1
46,332
1
92,665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to Alex. Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city v from city u, he may choose as the next city in the trip any city connected with v by the road, except for the city u. Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. Input First line of input contains two integers n and m, (1 ≀ n ≀ 2 β‹… 10^5, 0 ≀ m ≀ 2 β‹… 10^5) which are numbers of cities and roads in the country. Second line contains n integers w_1, w_2, …, w_n (0 ≀ w_i ≀ 10^9) which are scores of all cities. The following m lines contain description of the roads. Each of these m lines contains two integers u and v (1 ≀ u, v ≀ n) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer s (1 ≀ s ≀ n), which is the number of the initial city. Output Output single integer which is the maximum possible sum of scores of visited cities. Examples Input 5 7 2 2 8 6 9 1 2 1 3 2 4 3 2 4 5 2 5 1 5 2 Output 27 Input 10 12 1 7 1 9 3 3 6 30 1 10 1 2 1 3 3 5 5 7 2 3 5 4 6 9 4 6 3 7 6 8 9 4 9 10 6 Output 61 Submitted Solution: ``` n, m = map(int, input().split()) s = list(map(int, input().split())) n_d = [0 for i in range(n)] for i in range(m): a, b = map(int, input().split()) n_d[a-1] += 1 n_d[b-1] += 1 start = int(input())-1 summ = 0 ones = [0] for i, el in enumerate(n_d): if el > 1: summ += s[i] elif el == 1: ones.append(s[i]) summ += max(ones) if n_d[start] == 1: if s[start] == max(ones): ones.remove(s[start]) summ += max(ones) else: summ += s[start] elif n_d[start] == 0: summ = s[start] print(summ) ```
instruction
0
46,333
1
92,666
No
output
1
46,333
1
92,667
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,629
1
93,258
Tags: math Correct Solution: ``` from collections import defaultdict import math n=int(input()) a=list(map(int,input().split())) node=[a[0],1,0]# 10a+bx-10c toadd=a[0] xrange=[0,10]# a<=x<b # print(node,xrange) a=[0]+a for i in range(1,n+1): #after fuling at station i+1 if(node[0]>=a[i]-a[i-1]): node[0]-=a[i]-a[i-1] else: node[2]=a[i]-a[i-1]-node[0] node[0]=0 if(node[2]==0): node[0]+=toadd xrange[1]=min(xrange[1],10/node[1]) else: xrange[0]=max(xrange[0],(node[2]*10)/node[1]) xrange[1]=min(xrange[1],((node[2]+1)*10)/node[1]) node[0]=toadd-node[2] node[2]=0 node[1]+=1 # print(node,xrange) # temp=node[1]-1 # xrange[1]=10/temp # xrange[0]=10/node[1] # print(node,xrange) # node contains fuel after filling at last station if((xrange[0]*node[1])//10==(xrange[1]*node[1])//10): print("unique") print(int(a[n]+(xrange[0]*node[1])//10)+node[0]) else: # print(((xrange[1]*node[1])//10)-((xrange[0]*node[1])//10)==1) if((xrange[1]*node[1])%10==0 and((xrange[1]*node[1])//10)-((xrange[0]*node[1])//10)==1): print("unique") print(int(a[n]+(xrange[0]*node[1])//10)+node[0]) else: print("not unique") ```
output
1
46,629
1
93,259
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,630
1
93,260
Tags: math Correct Solution: ``` from re import * from sys import stderr def readint(): return int(input()) def readfloat(): return float(input()) def readarray(N, foo=input): return [foo() for i in range(N)] def readlinearray(foo=int): return map(foo, input().split()) def NOD(a, b): while b: a,b = b, a%b return a def gen_primes(max): primes = [1]*(max+1) for i in range(2, max+1): if primes[i]: for j in range(i+i, max+1, i): primes[j] = 0 primes[0] = 0 return [x for x in range(max+1) if primes[x]] def is_prime(N): i = 3 if not(N % 2): return 0 while i*i < N: if not(N % i): return 0 i += 3 return 1 n = readint() s = readlinearray() k = 1 mina = 0 maxa = 999999 prev = 0 for c in s: mina = max(c / k, mina) maxa = min((c + 1) / k - 1e-10, maxa) k += 1 #print(mina, maxa) first = int(mina * (n + 1)) last = int(maxa * (n + 1)) #print(first, last) if first == last: print("unique\n%d" % (first, )) else: print("not unique") ```
output
1
46,630
1
93,261
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,631
1
93,262
Tags: math Correct Solution: ``` n = int(input()) stops = list(map(int, input().split())) low = 10 high = stops[0] * 10 + 10 i = 0 for mile in range(1, stops[-1] + 1): if stops[i] == mile: high = min(high, (mile * 10 + 10) / (i + 1)) i += 1 else: low = max(low, (mile * 10 + 10) / (i + 1)) a = int((low + len(stops) * low - stops[-1] * 10) / 10) b = int((high + len(stops) * high - stops[-1] * 10) / 10 - 1e-9) #print(low, a) #print(high, b) if a == b: print('unique') print(stops[-1] + a) else: print('not unique') # Made By Mostafa_Khaled ```
output
1
46,631
1
93,263
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,632
1
93,264
Tags: math Correct Solution: ``` n = int(input()) stops = list(map(int, input().split())) low = 10 high = stops[0] * 10 + 10 i = 0 for mile in range(1, stops[-1] + 1): if stops[i] == mile: high = min(high, (mile * 10 + 10) / (i + 1)) i += 1 else: low = max(low, (mile * 10 + 10) / (i + 1)) a = int((low + len(stops) * low - stops[-1] * 10) / 10) b = int((high + len(stops) * high - stops[-1] * 10) / 10 - 1e-9) #print(low, a) #print(high, b) if a == b: print('unique') print(stops[-1] + a) else: print('not unique') ```
output
1
46,632
1
93,265
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,633
1
93,266
Tags: math Correct Solution: ``` n = int(input()) zap = list(map(int, input().split())) upperbound = float('inf') lowerbound = -float('inf') counter = 1 for item in zap: upperbound = min(upperbound, 10/counter + 10 * item / counter) counter += 1 k = 1 for item in zap: lowerbound = max(lowerbound, item * 10 / k) k += 1 benzonthelastmax = (1 + len(zap)) * (upperbound - 10**(-6)) - 10 * zap[-1] benzonthelastmin = (1 + len(zap)) * (lowerbound + 10**(-6)) - 10 * zap[-1] if(benzonthelastmin // 10 == benzonthelastmax // 10): print("unique") print(int(zap[-1] + benzonthelastmin // 10)) else: print("not unique") ```
output
1
46,633
1
93,267
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,634
1
93,268
Tags: math Correct Solution: ``` #codeforces 48c: the race: math import math def readGen(trans): while 1: for x in input().split(): yield(trans(x)) readint=readGen(int) n=next(readint) a=[0]+[next(readint) for i in range(n)] p=max((n+1)*a[i]/i-1 for i in range(1,n+1)) q=min((n+1)*(a[i]+1)/i for i in range(1,n+1)) eps=1e-8 u=math.floor(q-eps) l=math.ceil(p+eps) #print(p,q,l,u) if (l<u): print("not unique") else: print("unique\n%d"%l) ```
output
1
46,634
1
93,269
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,635
1
93,270
Tags: math Correct Solution: ``` # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): n = int(input()) a = list(map(int ,input().split())) lb = 10 ub = 1e9 for i in range(n): lb = max(lb , 10 * a[i] / (i + 1)) ub = min(ub , 10 * (a[i] + 1)/(i + 1)) # print(lb , ub) minimumstageitcanreach = a[-1] + ((n + 1)*lb - a[-1]*10)//10 ns = minimumstageitcanreach + 1 # print(ns) minalpha = ns * 10 / (n + 1) # print(minalpha) if abs(minalpha - ub) >= 1e-6: if minalpha < ub: print("not unique") else: print("unique") print(int(minimumstageitcanreach)) else: print("unique") print(int(minimumstageitcanreach)) return if __name__ == "__main__": main() ```
output
1
46,635
1
93,271
Provide tags and a correct Python 3 solution for this coding contest problem. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4.
instruction
0
46,636
1
93,272
Tags: math Correct Solution: ``` eps=10**(-9) mn=10 mx=100000000 n=int(input()) arr=list(map(int,input().split())) for i in range(n): mn = max(mn,(arr[i]*10)/(i+1)) mx = min(mx,((arr[i]+1)*10)/(i+1)) ans1=((n+1)*mn)//10 ans2=((n+1)*(mx-eps))//10 if ans2>ans1: print('not unique') else: print('unique') print(int(ans1)) ```
output
1
46,636
1
93,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4. Submitted Solution: ``` from collections import defaultdict import math n=int(input()) a=list(map(int,input().split())) node=[a[0],1,0]# 10a+bx-10c toadd=a[0] xrange=[0,10]# a<=x<b # print(node,xrange) a=[0]+a for i in range(1,n+1): #after fuling at station i+1 if(node[0]>=a[i]-a[i-1]): node[0]-=a[i]-a[i-1] else: node[2]=a[i]-a[i-1]-node[0] node[0]=0 if(node[2]==0): node[0]+=toadd xrange[1]=10/node[1] else: xrange[0]=(node[2]*10)/node[1] node[0]=toadd-node[2] node[2]=0 node[1]+=1 # print(node,xrange) # temp=node[1]-1 # xrange[1]=10/temp # xrange[0]=10/node[1] # node contains fuel after filling at last station if((xrange[0]*node[1])//10==(xrange[1]*node[1])//10): print("unique") print(a[n]+(xrange[0]*node[1])//10) else: if((xrange[1]*node[1])%10==0 and ((xrange[1]*node[1])//10)-((xrange[1]*node[1])//10)==1 ): print("unique") print(int(a[n]+(xrange[0]*node[1])//10)) else: print("not unique") ```
instruction
0
46,637
1
93,274
No
output
1
46,637
1
93,275
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4. Submitted Solution: ``` from collections import defaultdict import math n=int(input()) a=list(map(int,input().split())) node=[a[0],1,0]# 10a+bx-10c toadd=a[0] xrange=[0,10]# a<=x<b # print(node,xrange) a=[0]+a for i in range(1,n+1): #after fuling at station i+1 if(node[0]>=a[i]-a[i-1]): node[0]-=a[i]-a[i-1] else: node[2]=a[i]-a[i-1]-node[0] node[0]=0 if(node[2]==0): node[0]+=toadd xrange[1]=10/node[1] else: xrange[0]=(node[2]*10)/node[1] node[0]=toadd-node[2] node[2]=0 node[1]+=1 # temp=node[1]-1 # xrange[1]=10/temp # xrange[0]=10/node[1] # node contains fuel after filling at last station if((xrange[0]*node[1])//10==(xrange[1]*node[1])//10): print("unique") print(a[n]+(xrange[0]*node[1])//10) else: if((xrange[1]*node[1])%10==0): print("unique") print(int(a[n]+(xrange[0]*node[1])//10)) else: print("not unique") ```
instruction
0
46,638
1
93,276
No
output
1
46,638
1
93,277
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4. Submitted Solution: ``` from collections import defaultdict import math n=int(input()) a=list(map(int,input().split())) node=[a[0],1,0]# 10a+bx-10c toadd=a[0] xrange=[0,10]# a<=x<b # print(node,xrange) a=[0]+a for i in range(1,n+1): #after fuling at station i+1 if(node[0]>=a[i]-a[i-1]): node[0]-=a[i]-a[i-1] else: node[2]=a[i]-a[i-1]-node[0] node[0]=0 if(node[2]==0): node[0]+=toadd xrange[1]=min(xrange[1],10/node[1]) else: xrange[0]=max(xrange[0],(node[2]*10)/node[1]) xrange[1]=min(xrange[1],((node[2]+1)*10)/node[1]) node[0]=toadd-node[2] node[2]=0 node[1]+=1 # print(node,xrange) # temp=node[1]-1 # xrange[1]=10/temp # xrange[0]=10/node[1] # print(node,xrange) # node contains fuel after filling at last station if((xrange[0]*node[1])//10==(xrange[1]*node[1])//10): print("unique") print(int(a[n]+(xrange[0]*node[1])//10)) else: # print(((xrange[1]*node[1])//10)-((xrange[0]*node[1])//10)==1) if((xrange[1]*node[1])%10==0 and((xrange[1]*node[1])//10)-((xrange[0]*node[1])//10)==1): print("unique") print(int(a[n]+(xrange[0]*node[1])//10)) else: print("not unique") ```
instruction
0
46,639
1
93,278
No
output
1
46,639
1
93,279
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name β€” The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with Ξ± liters of petrol (Ξ± β‰₯ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with Ξ± liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if Ξ± = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage. One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the Ξ± number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be. Input The first line contains an integer n (1 ≀ n ≀ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number Ξ± β‰₯ 10, to which such a succession of stops corresponds. Output Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique". Examples Input 3 1 2 4 Output unique 5 Input 2 1 2 Output not unique Note In the second example the answer is not unique. For example, if Ξ± = 10, we'll have such a sequence as 1, 2, 3, and if Ξ± = 14, the sequence will be 1, 2, 4. Submitted Solution: ``` #codeforces 48c: the race: math import math def readGen(trans): while 1: for x in input().split(): yield(trans(x)) readint=readGen(int) n=next(readint) a=[0]+[next(readint) for i in range(n)] p=max((n+1)*a[i]/i-1 for i in range(1,n+1)) q=min((n+1)*(a[i]+1)/i for i in range(1,n+1)) eps=1e-10 u=math.floor(q-eps) l=math.ceil(p+eps) if (l<u): print("not unique") else: print("unique\n%d"%l) ```
instruction
0
46,640
1
93,280
No
output
1
46,640
1
93,281
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n cities in the country. Two candidates are fighting for the post of the President. The elections are set in the future, and both candidates have already planned how they are going to connect the cities with roads. Both plans will connect all cities using n - 1 roads only. That is, each plan can be viewed as a tree. Both of the candidates had also specified their choice of the capital among n cities (x for the first candidate and y for the second candidate), which may or may not be same. Each city has a potential of building a port (one city can have at most one port). Building a port in i-th city brings a_i amount of money. However, each candidate has his specific demands. The demands are of the form: * k x, which means that the candidate wants to build exactly x ports in the subtree of the k-th city of his tree (the tree is rooted at the capital of his choice). Find out the maximum revenue that can be gained while fulfilling all demands of both candidates, or print -1 if it is not possible to do. It is additionally guaranteed, that each candidate has specified the port demands for the capital of his choice. Input The first line contains integers n, x and y (1 ≀ n ≀ 500, 1 ≀ x, y ≀ n) β€” the number of cities, the capital of the first candidate and the capital of the second candidate respectively. Next line contains integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100 000) β€” the revenue gained if the port is constructed in the corresponding city. Each of the next n - 1 lines contains integers u_i and v_i (1 ≀ u_i, v_i ≀ n, u_i β‰  v_i), denoting edges between cities in the tree of the first candidate. Each of the next n - 1 lines contains integers u'_i and v'_i (1 ≀ u'_i, v'_i ≀ n, u'_i β‰  v'_i), denoting edges between cities in the tree of the second candidate. Next line contains an integer q_1 (1 ≀ q_1 ≀ n), denoting the number of demands of the first candidate. Each of the next q_1 lines contains two integers k and x (1 ≀ k ≀ n, 1 ≀ x ≀ n) β€” the city number and the number of ports in its subtree. Next line contains an integer q_2 (1 ≀ q_2 ≀ n), denoting the number of demands of the second candidate. Each of the next q_2 lines contain two integers k and x (1 ≀ k ≀ n, 1 ≀ x ≀ n) β€” the city number and the number of ports in its subtree. It is guaranteed, that given edges correspond to valid trees, each candidate has given demand about each city at most once and that each candidate has specified the port demands for the capital of his choice. That is, the city x is always given in demands of the first candidate and city y is always given in the demands of the second candidate. Output Print exactly one integer β€” the maximum possible revenue that can be gained, while satisfying demands of both candidates, or -1 if it is not possible to satisfy all of the demands. Examples Input 4 1 2 1 2 3 4 1 2 1 3 3 4 1 2 2 3 1 4 2 1 3 4 1 1 2 3 Output 9 Input 5 1 1 3 99 99 100 2 1 2 1 3 3 4 3 5 1 3 1 2 2 4 2 5 2 1 2 3 1 2 1 2 2 1 Output 198 Input 4 1 2 1 2 3 4 1 2 1 3 3 4 2 1 2 4 4 3 1 1 4 2 4 1 2 4 Output -1 Note In the first example, it is optimal to build ports in cities 2, 3 and 4, which fulfills all demands of both candidates and gives revenue equal to 2 + 3 + 4 = 9. In the second example, it is optimal to build ports in cities 2 and 3, which fulfills all demands of both candidates and gives revenue equal to 99 + 99 = 198. In the third example, it is not possible to build ports in such way, that all demands of both candidates are specified, hence the answer is -1. Submitted Solution: ``` print('9') ```
instruction
0
47,042
1
94,084
No
output
1
47,042
1
94,085
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy β€” no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. Input The input file consists of a single line containing two space-separated numbers n and m (0 ≀ n, m ≀ 105) β€” the number of the grown-ups and the number of the children in the bus, correspondingly. Output If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers β€” the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes). Examples Input 1 2 Output 2 2 Input 0 5 Output Impossible Input 2 2 Output 2 3 Note In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: * Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. * One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
instruction
0
47,301
1
94,602
Tags: greedy, math Correct Solution: ``` def solve(grownups, children): if grownups == 0 and children == 0: return [0, 0] if grownups == 0: return [] if children == 0: return [grownups, grownups] most = children + grownups - 1 least = grownups + max(0, children - grownups) return [least, most] n, m = [int(s) for s in input().split()] ans = solve(n, m) if ans: print(ans[0], ans[1]) else: print("Impossible") ```
output
1
47,301
1
94,603
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy β€” no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. Input The input file consists of a single line containing two space-separated numbers n and m (0 ≀ n, m ≀ 105) β€” the number of the grown-ups and the number of the children in the bus, correspondingly. Output If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers β€” the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes). Examples Input 1 2 Output 2 2 Input 0 5 Output Impossible Input 2 2 Output 2 3 Note In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: * Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. * One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
instruction
0
47,302
1
94,604
Tags: greedy, math Correct Solution: ``` a,b=map(int,input().split(' ')) if(b==0): print(a,a) elif(a==0): print("Impossible") elif(a>=b): print(a,a+b-1) elif(b>a): print(b,a+b-1) ```
output
1
47,302
1
94,605
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy β€” no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. Input The input file consists of a single line containing two space-separated numbers n and m (0 ≀ n, m ≀ 105) β€” the number of the grown-ups and the number of the children in the bus, correspondingly. Output If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers β€” the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes). Examples Input 1 2 Output 2 2 Input 0 5 Output Impossible Input 2 2 Output 2 3 Note In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: * Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. * One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
instruction
0
47,303
1
94,606
Tags: greedy, math Correct Solution: ``` n, m = map(int, input().split()) if n == 0: if m == 0: print('0 0') else: print('Impossible') else: if m == 0: print(str(n) + ' ' +str(n)) # elif n == m: # print(str(max(n,m)) + ' ' + str(max(n,m) + 1)) else: print(str(max(n,m)) + ' ' + str(n + m - 1)) ```
output
1
47,303
1
94,607
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy β€” no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. Input The input file consists of a single line containing two space-separated numbers n and m (0 ≀ n, m ≀ 105) β€” the number of the grown-ups and the number of the children in the bus, correspondingly. Output If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers β€” the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes). Examples Input 1 2 Output 2 2 Input 0 5 Output Impossible Input 2 2 Output 2 3 Note In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: * Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. * One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
instruction
0
47,304
1
94,608
Tags: greedy, math Correct Solution: ``` n, m = map(int, input().split()) print(*[[n+m-min(m, n), [n,m+n-1][m>0]],['Impossible']][n==0 and m>0]) ```
output
1
47,304
1
94,609
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride. The bus fare equals one berland ruble in High Bertown. However, not everything is that easy β€” no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble. We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups. Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total. Input The input file consists of a single line containing two space-separated numbers n and m (0 ≀ n, m ≀ 105) β€” the number of the grown-ups and the number of the children in the bus, correspondingly. Output If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers β€” the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print "Impossible" (without the quotes). Examples Input 1 2 Output 2 2 Input 0 5 Output Impossible Input 2 2 Output 2 3 Note In the first sample a grown-up rides with two children and pays two rubles. In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: * Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. * One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.
instruction
0
47,305
1
94,610
Tags: greedy, math Correct Solution: ``` def f(l): n,m = l if n==0: return ['Impossible'] if m>0 else [0,0] return [max(m,n), n+m-1 if m>0 else n+m] l = list(map(int,input().split())) print(*f(l)) ```
output
1
47,305
1
94,611