message
stringlengths
2
48.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
318
108k
cluster
float64
8
8
__index_level_0__
int64
636
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,290
8
172,580
Tags: brute force, greedy Correct Solution: ``` import sys from math import ceil n, t, k = map(int, sys.stdin.readline().split()) places = [True for _ in range(n)] for x in map(int, sys.stdin.readline().split()): places[x] = False costs = list(map(int, sys.stdin.readline().split())) if not places[0]: print(-1) sys.exit(0) prev = [i for i in range(n)] last = 0 for i in range(n): if places[i]: last = i prev[i] = last best_cost = float('inf') for lamp in range(k, 0, -1): min_cost = ceil(n/lamp) * costs[lamp-1] if min_cost >= best_cost: continue # try this shit cost = costs[lamp-1] reach = lamp fail = False while reach < n: if prev[reach] + lamp <= reach: fail = True break reach = prev[reach] + lamp cost += costs[lamp - 1] if cost + (ceil((n - reach)/lamp) * costs[lamp-1]) >= best_cost: fail = True break if not fail: best_cost = min(best_cost, cost) print(best_cost if best_cost != float('inf') else -1) ```
output
1
86,290
8
172,581
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,291
8
172,582
Tags: brute force, greedy Correct Solution: ``` import sys n, m, k = map(int, input().split()) s = list(map(int, sys.stdin.readline().split())) # [int(x) for x in input().split()] # blocked a = list(map(int, sys.stdin.readline().split())) # a = [int(x) for x in input().split()] # cost if m > 0 and s[0] == 0: print('-1') else: block = [-1] * n # -1 free, otherwise index of a free one for i in range(m): if block[s[i]-1] == -1: block[s[i]] = s[i]-1 else: block[s[i]] = block[s[i]-1] MAX_COST = 1e13 max_inr = 0 if m > 0: inr = 1 prev = s[0] for i in range(1, m): if s[i] == prev+1: inr += 1 else: if inr > max_inr: max_inr = inr inr = 1 prev = s[i] if inr > max_inr: max_inr = inr best_cost = [] for i in range(k): if i < max_inr: best_cost.append(MAX_COST) else: best_cost.append(a[i]*(-(-n//(i+1)))) #sc = sorted(range(k), key=lambda x: best_cost[x]) # sc = sorted(range(k), key=best_cost.__getitem__) min_cost = MAX_COST for i in range(k): test = i # min(range(len(best_cost)), key=best_cost.__getitem__) if best_cost[test] >= min_cost: continue # if best_cost[test] >= min_cost or best_cost[test] >= MAX_COST: # break t_size = test+1 pos = 0 count = 1 while pos < n: new_pos = pos + t_size if new_pos >= n: break if block[new_pos] != -1: if block[new_pos] <= pos: raise Exception('smth went wrong') new_pos = block[new_pos] pos = new_pos count += 1 min_cost = min(min_cost, a[test]*count) if min_cost < MAX_COST: print(min_cost) else: print('-1') ```
output
1
86,291
8
172,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1 Submitted Solution: ``` import sys from array import array n, m, k = map(int, input().split()) block = list(map(int, input().split())) a = [0] + list(map(int, input().split())) if block and block[0] == 0: print(-1) exit() prev = array('i', list(range(n))) for x in block: prev[x] = -1 for i in range(1, n): if prev[i] == -1: prev[i] = prev[i-1] inf = ans = 10**18 for i in range(1, k+1): s = 0 cost = 0 while True: cost += a[i] t = s+i if t >= n: break if prev[t] == s: cost = inf break s = prev[t] ans = min(ans, cost) print(ans if ans < inf else -1) ```
instruction
0
86,292
8
172,584
Yes
output
1
86,292
8
172,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1 Submitted Solution: ``` import sys from sys import stdin,stdout n,m,k=map(int,stdin.readline().split(' ')) t22=stdin.readline();#print(t22,"t2222") bl=[] if len(t22.strip())==0: bl=[] else: bl=list(map(int,t22.split(' '))) bd={} for i in bl: bd[i]=1 cost=list(map(int,stdin.readline().split(' '))) dp=[-1 for i in range(n)] dp[0]=0 def formdp(): global dp for i in range(1,n): if i in bd: t1=i while dp[t1]==-1: t1-=1 dp[i]=dp[t1] else: dp[i]=i def get(i): #print("\t",i) f=1;p=0 while p+i<n: if dp[p+i]==p: return -1 else: p=dp[p+i];f+=1 #print(p,f) return f try: if 0 in bd: print(-1) else: formdp() #print(dp) minf=[0 for i in range(k+1)] for i in range(1,k+1): minf[i]=get(i) #print(minf) ans=sys.maxsize for i in range(1,len(minf)): if minf[i]!=-1: ans=min(ans,minf[i]*cost[i-1]) if ans==sys.maxsize: print(-1) else: print(ans) except Exception as e: print(e) ```
instruction
0
86,293
8
172,586
No
output
1
86,293
8
172,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1 Submitted Solution: ``` import sys from array import array from itertools import groupby n, m, k = map(int, input().split()) block = list(map(int, input().split())) a = [0] + list(map(int, input().split())) if block and block[0] == 0: print(-1) exit() ok = array('b', [1]) * n for x in block: ok[x] = 0 block_len = 0 for key, v in groupby(ok): if key == 0: block_len = max(block_len, len(list(v))) block_len += 1 if k < block_len: print(-1) exit() for i in range(k, 0, -1): if a[i-1] > a[i]: a[i-1] = a[i] def solve(x): prev, prev_ok, cost = 0, 0, a[x] for i in range(n): if ok[i]: prev_ok = i if prev + x == i: cost += a[x] prev = prev_ok if prev + x == i: return 10**18 return cost left, right = block_len, k while (right - left) > 10: ml, mr = (left*2 + right) // 3, (left + right*2) // 3 if solve(ml) < solve(mr): right = mr else: left = ml ans = min(solve(i) for i in range(left, right+1)) print(ans) ```
instruction
0
86,294
8
172,588
No
output
1
86,294
8
172,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1 Submitted Solution: ``` n, m, k = map(int, input().split()) free = [True] * n for i in list(map(int, input().split())): free[i] = False a = list(map(int, input().split())) last_lamp = [-1] * n for i in range(n): if free[i]: last_lamp[i] = i if i > 0 and not free[i]: last_lamp[i] = last_lamp[i - 1] ans = int(1E100) for i in range(1, k + 1): last, prev = 0, -1 cur = 0 while last < n: if last_lamp[last] <= prev: ur = None break prev = last_lamp[last] last = prev + i cur += 1 if cur is not None: ans = min(ans, a[i - 1] * cur) if ans == int(1E100): print(-1) else: print(ans) ```
instruction
0
86,295
8
172,590
No
output
1
86,295
8
172,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1 Submitted Solution: ``` if __name__=='__main__': n,m,k = [int(i) for i in input().split()] blocked_pos = [int(i) for i in input().split()] avail_lamp_pos = [int(i) for i in range(n)] if blocked_pos[0] == 0: print(-1) quit() pos_blocked = [False for i in range(n)] cost = [int(i) for i in input().split()] for i in range(m): pos_blocked[blocked_pos[i]] = True # print(pos_blocked) cnt = 0 if blocked_pos: max_cnt = 1 cnt = 1 for i in range(1,n): # if not pos_blocked[i]: continue if pos_blocked[i]: avail_lamp_pos[i] = avail_lamp_pos[i-1] if pos_blocked[i] == pos_blocked[i-1]: cnt += 1 else: max_cnt = max(cnt,max_cnt) cnt = 1 max_cnt = max(cnt, max_cnt) # print(avail_lamp_pos,max_cnt) min_power = max_cnt+1 if min_power > k: print(-1) quit() pos = 0 cnt = 1 tot = 1e13 for power in range(min_power,k+1): cnt = 1 while pos + power < n: pos = avail_lamp_pos[pos+power] cnt += 1 if pos != 0: cnt += 1 tot = min(tot,cnt*cost[power-1]) print(tot) ```
instruction
0
86,296
8
172,592
No
output
1
86,296
8
172,593
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,345
8
172,690
"Correct Solution: ``` N, M = map(int, input().split()) List = [int(input()) for _ in range(M)] P = 10**9+7 dp = [1]*(N+1) for i in List: dp[i]=0 for j in range(1, N): if dp[j+1]!=0: dp[j+1] = dp[j]+dp[j-1] print(dp[N]%P) ```
output
1
86,345
8
172,691
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,346
8
172,692
"Correct Solution: ``` import sys N,M=map(int,input().split()) S=set(map(int,sys.stdin)) a,b=0,1 for i in range(1,N+1): if i in S: a,b=b,0 else: a,b=b,a+b print(b%(10**9+7)) ```
output
1
86,346
8
172,693
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,347
8
172,694
"Correct Solution: ``` n,b,*a=map(int,open(0).read().split()) a=set(a) d=i=0 c=1 while i<n:i+=1;b=(c+d)%(10**9+7)*(not i in a);c,d=b,c print(b) ```
output
1
86,347
8
172,695
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,348
8
172,696
"Correct Solution: ``` n,m=map(int,input().split()) a=set(int(input()) for i in range(m)) mod=10**9+7 dp=[0]*(n+1) dp[0]=1 if 1 not in a: dp[1]=1 for i in range(2,n+1): if i not in a: dp[i]+=(dp[i-2]+dp[i-1])%mod print(dp[-1]) ```
output
1
86,348
8
172,697
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,349
8
172,698
"Correct Solution: ``` n,m=map(int,input().split()) a=set(int(input()) for _ in range(m)) dp=[0]*(n+2) dp[0]=1 for i in range(n): if i in a: continue dp[i+1]+=dp[i] dp[i+2]+=dp[i] print(dp[n]%1000000007) ```
output
1
86,349
8
172,699
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,350
8
172,700
"Correct Solution: ``` N,M=map(int,input().split()) a=[int(input()) for _ in range(M)]+[10**6] A=[0]*(N+2) A[0:2]=[0,1] j=0 for i in range(N): if i+1 != a[j]: A[i+2]=(A[i]+A[i+1])%(10**9+7) else: j+=1 print(A[N+1]) ```
output
1
86,350
8
172,701
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,351
8
172,702
"Correct Solution: ``` MOD=10**9+7 N,M=map(int,input().split()) dp=[1]*(N+1) for i in range(M): dp[int(input())]=0 for n in range(2,N+1): if dp[n]!=0: dp[n]=(dp[n-1]+dp[n-2]) print(dp[N]%MOD) ```
output
1
86,351
8
172,703
Provide a correct Python 3 solution for this coding contest problem. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469
instruction
0
86,352
8
172,704
"Correct Solution: ``` N, M = map(int,input().split()) a = [1] * (N+1) for i in range(M): a[int(input())] = 0 mod = 1000000007 ans = [0] * (N+1) ans[0] = 1 for i in range(1,N+1): ans[i] = (ans[i-2]*a[i-2] + ans[i-1]*a[i-1]) % mod print(ans[N]) ```
output
1
86,352
8
172,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` n, m = map(int, input().split()) mod = 1_000_000_007 A = [1] * (n+1) for i in range(m): A[int(input())] = 0 for i in range(2, n+1): if A[i]!=0: A[i] = (A[i-1] + A[i-2])%mod print(A[-1]) ```
instruction
0
86,353
8
172,706
Yes
output
1
86,353
8
172,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` N, M=map(int, input().split()) A = [int(input()) for _ in range(M)] mod = 10**9 + 7 step = [1]*(N+1) for a in A: step[a]=0 for i in range(2, N+1): step[i]=(step[i-1]+step[i-2])%mod*step[i] print(step[-1]) ```
instruction
0
86,354
8
172,708
Yes
output
1
86,354
8
172,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` n,m=map(int,input().split()) a={int(input()) for i in range(m)} mod=10**9+7 x=1 if 1 not in a else 0 dp=[1,x]+[0]*(n-1) for i in range(2,n+1): if i in a: continue dp[i]=(dp[i-1]+dp[i-2]) print(dp[-1]%mod) ```
instruction
0
86,355
8
172,710
Yes
output
1
86,355
8
172,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` n,m=map(int,input().split()) a=[int(input()) for i in range(m)] b=set(a) dp=[0]*(n+2) dp[0]=0 dp[1]=1 for j in range(n): if j+1 not in b: dp[j+2]=(dp[j]+dp[j+1])%(10**9+7) else: dp[j+2]=0 print(dp[j+2]%(10**9+7)) ```
instruction
0
86,356
8
172,712
Yes
output
1
86,356
8
172,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` N, M = [int(i) for i in input().split()] a=[] for i in range(M): a +=[int(input())] ways=[] for i in range(N+1): if i in a: a=a[1:] ways+=[0] elif i==0: ways +=[1] elif i==1: ways +=[1] else: ways+=[(ways[i-2]+ways[i-1])%1000000007] print(ways[-1]) ```
instruction
0
86,357
8
172,714
No
output
1
86,357
8
172,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` import sys input = sys.stdin.readline MOD = 10 ** 9 + 7 def main(): N, M = map(int, input().split()) memo = [0] * (N + 1) a = [0] * M memo[0] = 0 memo[1] = 1 memo[2] = 2 for i in range(3, N+1): memo[i] = memo[i-1] + memo[i-2] # print(memo) ans = 1 for i in range(M): a[i] = int(input()) if i != 0 and abs(a[i] - a[i-1]) == 1: print(0) return if a[i] == 1: ans *= 1 elif i == 0: ans *= memo[a[i] - 1] ans %= MOD # print(a[i], ans, a[i] - 1) else: ans *= memo[a[i] - a[i-1] - 2] ans %= MOD # print(a[i], ans, a[i] - a[i-1] - 2) ans *= memo[N - a[M-1] - 1] ans %= MOD # print(ans, N - a[M-1] - 1) print(ans) if __name__ == '__main__': main() ```
instruction
0
86,358
8
172,716
No
output
1
86,358
8
172,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` def fib_memo(n): """メモ化フィボナッチ""" memo = [0]*(n+1) def _fib(n): if n <= 1: return n if memo[n] != 0: return memo[n] memo[n] = _fib(n-1) + _fib(n-2) return memo[n] return _fib(n) N, M = map(int, input().split()) A = [int(input()) for _ in range(M)] B = [0]*(M-1) for i in range(M): diff = 0 if i == 0: diff = A[i] - 1 B[0] = fib_memo(diff + 1) else if i == (M - 1): diff = N - A[M-1] -1 B[M-1] = fib_memo(diff + 1) else: diff = A[i] - A[i-1] B[i] = fib_memo(diff + 1) Ans = reduce(lambda a, b: a*b, B) print(Ans % 1000000007) ```
instruction
0
86,359
8
172,718
No
output
1
86,359
8
172,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. Constraints * 1 \leq N \leq 10^5 * 0 \leq M \leq N-1 * 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. Examples Input 6 1 3 Output 4 Input 10 2 4 5 Output 0 Input 100 5 1 23 45 67 89 Output 608200469 Submitted Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- from functools import lru_cache @lru_cache(maxsize=None) def fib(n): if n == 0: return 1 elif n == 1: return 1 else: return fib(n-1) + fib(n-2) PRIME = 10 ** 9 + 7 N, M = list(map(int, input().split())) broken_stairs = [] for _ in range(M): broken_stairs.append(int(input())) prev_broken = -1 cannot = False ans = 1 for a in broken_stairs: if a - prev_broken == 1: cannot = True break ans *= fib(a - prev_broken - 2) ans %= PRIME prev_broken = a ans *= fib(N - prev_broken - 1) ans %= PRIME if cannot: print(0) else: print(ans) ```
instruction
0
86,360
8
172,720
No
output
1
86,360
8
172,721
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon.
instruction
0
86,907
8
173,814
Tags: shortest paths Correct Solution: ``` n, k = map(int, input().split()) lzid = input() dzid = input() zidovi = [lzid, dzid] q = [[-1, [False,0]]] #koraci, [zid, visina] izasao = 0 bio = [[0 for i in range(n+k+100)], [0 for i in range(n+k+100)]] while len(q) != 0: trenutni = q.pop(0) korak = trenutni[0] pozicija = trenutni[1] tren_zid = pozicija[0] tren_visina = pozicija[1] if bio[tren_zid][tren_visina] == 0: bio[tren_zid][tren_visina] = 1 if tren_visina > n-1: print("YES") izasao = 1 break elif tren_visina == n-1 and zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak: print("YES") izasao = 1 break elif zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak: q.append([korak+1, [tren_zid, tren_visina-1]]) q.append([korak+1, [tren_zid, tren_visina+1]]) q.append([korak+1, [not(tren_zid), tren_visina+k]]) ## if tren_visina - 1 > korak+1: ## if zidovi[tren_zid][tren_visina-1] != 'X': ## q.append([korak+1, [tren_zid, tren_visina-1]]) ## if tren_visina + 1 > korak: ## if tren_visina + k <= n-1: ## if zidovi[tren_zid][tren_visina+1] != 'X': ## q.append([korak+1, [tren_zid, tren_visina+1]]) ## else: ## print("YES") ## izasao = 1 ## break ## if tren_visina + k > korak: ## if tren_visina + k <= n-1: ## if zidovi[not(tren_zid)][tren_visina+k] != 'X': ## q.append([korak+1, [not(tren_zid), tren_visina+k]]) ## else: ## print("YES") ## izasao = 1 if izasao == 0: print("NO") ```
output
1
86,907
8
173,815
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon.
instruction
0
86,908
8
173,816
Tags: shortest paths Correct Solution: ``` n, k = map(int, input().split()) lzid = input() dzid = input() zidovi = [lzid, dzid] q = [[-1, [False,0]]] #[koraci, [zid, visina]] izasao = 0 bio = [[0 for i in range(n+k+100)], [0 for i in range(n+k+100)]] while len(q) != 0: trenutni = q.pop(0) korak = trenutni[0] pozicija = trenutni[1] tren_zid = pozicija[0] tren_visina = pozicija[1] if bio[tren_zid][tren_visina] == 0: bio[tren_zid][tren_visina] = 1 if tren_visina > n-1: print("YES") izasao = 1 break elif tren_visina == n-1 and zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak: print("YES") izasao = 1 break elif zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak: q.append([korak+1, [tren_zid, tren_visina-1]]) q.append([korak+1, [tren_zid, tren_visina+1]]) q.append([korak+1, [not(tren_zid), tren_visina+k]]) ## if tren_visina - 1 > korak+1: ## if zidovi[tren_zid][tren_visina-1] != 'X': ## q.append([korak+1, [tren_zid, tren_visina-1]]) ## if tren_visina + 1 > korak: ## if tren_visina + k <= n-1: ## if zidovi[tren_zid][tren_visina+1] != 'X': ## q.append([korak+1, [tren_zid, tren_visina+1]]) ## else: ## print("YES") ## izasao = 1 ## break ## if tren_visina + k > korak: ## if tren_visina + k <= n-1: ## if zidovi[not(tren_zid)][tren_visina+k] != 'X': ## q.append([korak+1, [not(tren_zid), tren_visina+k]]) ## else: ## print("YES") ## izasao = 1 if izasao == 0: print("NO") ```
output
1
86,908
8
173,817
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon.
instruction
0
86,909
8
173,818
Tags: shortest paths Correct Solution: ``` from sys import stdin, stdout from collections import deque n, k = map(int, stdin.readline().split()) maps = [] maps.append(list(stdin.readline() + '-')) maps.append(list(stdin.readline() + '-')) visit = [[0, 0] for i in range(n + 1)] visit[0][0] = 1 queue = deque() label = 0 queue.append((0, -1, 0))#твой уровень, уровень воды, номер стены while queue: mine, line, num = queue.popleft() if line >= mine: continue if mine + k >= n: label = 1 if mine + 1 < n and not visit[mine + 1][num] and maps[num][mine + 1] == '-': queue.append((mine + 1, line + 1, num)) visit[mine + 1][num] = 1 if mine and mine - line > 1 and not visit[mine - 1][num] and maps[num][mine - 1] == '-': queue.append((mine - 1, line + 1, num)) visit[mine - 1][num] = 1 if mine + k < n and not visit[mine + k][(num + 1) % 2] and maps[(num + 1) % 2][mine + k] == '-': queue.append((min(mine + k, n), line + 1, (num + 1) % 2)) visit[min(mine + k, n)][(num + 1) % 2] = 1 if label: stdout.write('YES') else: stdout.write('NO') ```
output
1
86,909
8
173,819
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon.
instruction
0
86,910
8
173,820
Tags: shortest paths Correct Solution: ``` from collections import deque l, j = [int(i) for i in input().split(' ')] wallA = list(input()) wallB = list(input()) g = {} for i in range(l): # Each 4-tuple represents: (Visited?, Current Height, Current Water Height, Drowned?) if wallA[i] == '-': g[(1,i+1)] = (-1, 0, 0, False) if wallB[i] == '-': g[(-1,i+1)] = (-1, 0, 0, False) g[(1, 1)] = ('VISITED', 1, 0, False) q = deque([(1, 1)]) while q: c = q.popleft() up = (c[0], c[1]+1) down = (c[0], c[1]-1) jump = (c[0]*-1, c[1] + j) if g[c][1] <= g[c][2]: g[c] = (g[c][0], g[c][1], g[c][2], True) if up in g and g[up][0] == -1: q.append(up) g[up] = ('VISITED', g[c][1] + 1, g[c][2] + 1, g[c][3]) if down in g and g[down][0] == -1: q.append(down) g[down] = ('VISITED', g[c][1] - 1, g[c][2] + 1, g[c][3]) if jump in g and g[jump][0] == -1: q.append(jump) g[jump] = ('VISITED', g[c][1] + j, g[c][2] + 1, g[c][3]) def graphHasEscape(graph): for node in graph: result = graph[node] if result[0] == 'VISITED' and ((result[1] + 1 > l) or (result[1] + j > l)) and not result[3]: return True break return False if graphHasEscape(g): print('YES') else: print('NO') ```
output
1
86,910
8
173,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Submitted Solution: ``` n, k = map(int, input().split()) lzid = input() dzid = input() zidovi = [lzid, dzid] q = [[-1, [False,0]]] #[koraci, [zid, visina]] izasao = 0 while len(q) != 0: trenutni = q.pop(0) korak = trenutni[0] pozicija = trenutni[1] tren_zid = pozicija[0] tren_visina = pozicija[1] print("Korak:", korak) print("pozicija:", pozicija) if pozicija[1] == n-1: print("YES") izasao = 1 break if tren_visina - 1 > korak+1: if zidovi[tren_zid][tren_visina-1] != 'X': q.append([korak+1, [tren_zid, tren_visina-1]]) if tren_visina + 1 > korak: if tren_visina + k <= n-1: if zidovi[tren_zid][tren_visina+1] != 'X': q.append([korak+1, [tren_zid, tren_visina+1]]) else: print("YES") izasao = 1 break if tren_visina + k > korak: if tren_visina + k <= n-1: if zidovi[not(tren_zid)][tren_visina+k] != 'X': q.append([korak+1, [not(tren_zid), tren_visina+k]]) else: print("YES") izasao = 1 if izasao == 0: print("NO") ```
instruction
0
86,911
8
173,822
No
output
1
86,911
8
173,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Submitted Solution: ``` from collections import deque l, j = [int(i) for i in input().split(' ')] wallA = list(input()) wallB = list(input()) g = {} for i in range(l): # Each 3-tuple represents: (Visited?, Current Height, Current Water Height) if wallA[i] == '-': g[(1,i+1)] = (-1, 0, 0) if wallB[i] == '-': g[(-1,i+1)] = (-1, 0, 0) g[(1, 1)] = ('VISITED', 1, 0) q = deque([(1, 1)]) while q: c = q.popleft() up = (c[0], c[1]+1) down = (c[0], c[1]-1) jump = (c[0]*-1, c[1] + j) if c[1] + 1 > l or c[1] + j > l and g[c][2] < c[1]: print('YES') break if c[1] <= g[c][2]: print('NO') break if up in g and g[up][0] == -1: q.append(up) g[up] = ('VISITED', g[c][1] + 1, g[c][2] + 1) if down in g and g[down][0] == -1: q.append(down) g[down] = ('VISITED', g[c][1] - 1, g[c][2] + 1) if jump in g and g[jump][0] == -1: q.append(jump) g[jump] = ('VISITED', g[c][1] + j, g[c][2] + 1) ```
instruction
0
86,912
8
173,824
No
output
1
86,912
8
173,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Submitted Solution: ``` from collections import deque l, j = [int(i) for i in input().split(' ')] wallA = list(input()) wallB = list(input()) g = {} for i in range(l): # Each 3-tuple represents: (Visited?, Current Height, Current Water Height) if wallA[i] == '-': g[(1,i+1)] = (-1, 0, 0) if wallB[i] == '-': g[(-1,i+1)] = (-1, 0, 0) g[(1, 1)] = ('VISITED', 1, 0) q = deque([(1, 1)]) escape = False while q: c = q.popleft() up = (c[0], c[1]+1) down = (c[0], c[1]-1) jump = (c[0]*-1, c[1] + j) if c[1] + 1 > l or c[1] + j > l and g[c][2] < c[1]: escape = True break if c[1] <= g[c][2]: break if up in g and g[up][0] == -1: q.append(up) g[up] = ('VISITED', g[c][1] + 1, g[c][2] + 1) if down in g and g[down][0] == -1: q.append(down) g[down] = ('VISITED', g[c][1] - 1, g[c][2] + 1) if jump in g and g[jump][0] == -1: q.append(jump) g[jump] = ('VISITED', g[c][1] + j, g[c][2] + 1) if escape: print('YES') else: print('NO') ```
instruction
0
86,913
8
173,826
No
output
1
86,913
8
173,827
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,016
8
174,032
Tags: graphs, greedy, sortings Correct Solution: ``` n, m = map(int, input().split()) cs = [0] + list(map(int, input().split())) mls = [0 for i in range(n+1)] for i in range(m): x, y = map(int, input().split()) if cs[y] < cs[x]: x, y = y, x mls[x] += 1 print(sum([cs[i]*mls[i] for i in range(n+1)])) ```
output
1
87,016
8
174,033
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,017
8
174,034
Tags: graphs, greedy, sortings Correct Solution: ``` l2=input().split() n=int(l2[0]) m=int(l2[1]) l=[int(y) for y in input().split()] sum=0 for i in range(m): l1=[int(x) for x in input().split()] sum = sum + min(l[l1[0]-1],l[l1[1]-1]) print(sum) ```
output
1
87,017
8
174,035
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,018
8
174,036
Tags: graphs, greedy, sortings Correct Solution: ``` from collections import * from sys import stdin def arr_enu(): return [[i + 1, int(x)] for i, x in enumerate(stdin.readline().split())] def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return [str(x) for x in stdin.readline().split()] def calulate_cost(): cost = {} for i in range(1, n + 1): tem = 0 for j in toy.gdict[i]: tem += energy[j - 1][1] cost[i] = tem return cost def change(v): for i in toy.gdict[v]: try: cost[i] -= dic[v] except: continue class graph: # initialize graph def __init__(self, gdict=None): if gdict is None: gdict = defaultdict(list) self.gdict, self.edges = gdict, [] # Get verticies def get_vertices(self): return list(self.gdict.keys()) # add edge def add_edge(self, node1, node2): self.gdict[node1].append(node2) self.gdict[node2].append(node1) self.edges.append([node1, node2]) n, m = arr_inp(1) toy, energy = graph(), arr_enu() for i in range(m): u, v = arr_inp(1) toy.add_edge(u, v) cost, ans, dic = calulate_cost(), 0, {i: j for i, j in energy} energy.sort(key=lambda x: x[1]) for i in range(n): ma = energy[-1][0] ans += cost[ma] change(ma) del cost[ma] energy.pop() print(ans) ```
output
1
87,018
8
174,037
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,019
8
174,038
Tags: graphs, greedy, sortings Correct Solution: ``` import math n,m=map(int,input().split()) v=list(map(int,input().split())) res=0 for i in range(m): x,y=map(int,input().split()) x-=1;y-=1 res+=min(v[x],v[y]) print(res) ```
output
1
87,019
8
174,039
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,020
8
174,040
Tags: graphs, greedy, sortings Correct Solution: ``` n,k = map(int, input().split()) arr = list(map(int, input().split())) ans=0 for _ in range(k): u,v = map(int, input().split()) ans+=min(arr[u-1],arr[v-1]) print(ans) ```
output
1
87,020
8
174,041
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,021
8
174,042
Tags: graphs, greedy, sortings Correct Solution: ``` #! /usr/bin/env python n, m = [int(x) for x in input().split()] v = [int(x) for x in input().split()] sv = [(x + 1, v[x]) for x in range(n)] v = [0] + v edges = {i:set() for i in range(1, n+1)} for i in range(m): f, t = [int(x) for x in input().split()] edges[f].add(t) edges[t].add(f) ans = 0 sv.sort(key=lambda x: -x[1]) removed = [False] * (n + 1) for i, vi in sv: removed[i] = True for f in edges[i]: if not removed[f]: ans += v[f] print(ans) ```
output
1
87,021
8
174,043
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,022
8
174,044
Tags: graphs, greedy, sortings Correct Solution: ``` n, m = map(int, input().split()) u = list(map(int, input().split())) v = list(enumerate(u, 1)) v.sort(key = lambda x: x[1], reverse = True) s, u = 0, [0] + u p = [[] for i in range(n + 1)] for i in range(m): x, y = map(int, input().split()) p[x].append(y) p[y].append(x) for x, f in v: for y in p[x]: s += u[y] u[x] = 0 print(s) ```
output
1
87,022
8
174,045
Provide tags and a correct Python 3 solution for this coding contest problem. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
instruction
0
87,023
8
174,046
Tags: graphs, greedy, sortings Correct Solution: ``` n, m = map(int,input().split()) e = list(map(int, input().split())) res = 0 for _ in range(m): u,v = map(int, input().split()) res+= min(e[u-1], e[v-1]) print(res) ```
output
1
87,023
8
174,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` def main(): n,m = map(int,input().split()) l = [int(i) for i in input().split()] ans = 0 for i in range(m): a,b = map(int,input().split()) ans += min(l[a-1],l[b-1]) print(ans) if __name__ == "__main__": main() ```
instruction
0
87,024
8
174,048
Yes
output
1
87,024
8
174,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` n, m = map(int, input().split()) v = [0] + list(map(int, input().split())) en = 0 for i in range(m): a, b = map(int, input().split()) en += min(v[a], v[b]) print(en) ```
instruction
0
87,025
8
174,050
Yes
output
1
87,025
8
174,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` def Sol2(cost,cost2,G): mk = [0 for _ in range(len(cost)) ] sum = 0 for node in cost: for i in G[node[1]]: mk[i]+=1 c = len(G[node[1]]) - mk[node[1]] sum += c*node[0] return sum if __name__ == '__main__': n,m = map(int,input().split()) cost2 = [int(x) for x in input().split()] cost = [(cost2[i],i) for i in range(len(cost2))] arist = [] graf = [[]for i in range(n)] for i in range(m): x,y = map(int,input().split()) arist.append((x-1,y-1)) graf[x-1].append(y-1) graf[y-1].append(x-1) sort = sorted(cost,key=lambda parameter_list: parameter_list[0], reverse=False) a = Sol2(sort,cost2,graf) print(a) ```
instruction
0
87,026
8
174,052
Yes
output
1
87,026
8
174,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` def main(): n,m = map(int,input().split()) cur = list(map(int,input().split())) tab = [] graph = [[] for x in range(n)] for x in range(n): tab.append((cur[x],x)) for x in range(m): a,b = map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) tab.sort() tab = tab[::-1] v = [0]*n s = 0 for x in range(n): for nei in graph[tab[x][1]]: if not v[nei]: s += cur[nei] v[tab[x][1]] = 1 print(s) main() ```
instruction
0
87,027
8
174,054
Yes
output
1
87,027
8
174,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` def dfs(edges,energy,node,visited): stack = [node] cost = 0 while stack: curr = stack.pop() if curr not in visited: visited.add(curr) if curr in edges.keys(): for kid in edges[curr]: if kid not in visited: cost += min(energy[curr-1],energy[kid-1]) stack.append(kid) return cost def Solve(edges,energy): n = len(edges) cost = 0 visited = set() for i in range(1,n+1): if i not in visited: cost += dfs(edges,energy,i,visited) print(cost) def main(): n,m = map(int,input().split()) energy = list(map(int,input().split())) edges = {} for i in range(m): a,b = map(int,input().split()) if a not in edges.keys(): edges[a] = [b] else: edges[a].append(b) if b not in edges.keys(): edges[b] = [a] else: edges[b].append(a) Solve(edges,energy) main() ```
instruction
0
87,028
8
174,056
No
output
1
87,028
8
174,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` n, m = map(int, input().split()) r = 0 w = [0] + list(map(int, input().split())) g = {x+1: [] for x in range(n)} polz = {x+1: 0 for x in range(n)} def cut(node): global r, dpolz, w, g for i in g[node]: r += w[i] g[i].remove(node) dpolz[i] += w[node] dpolz[i] -= w[i] del g[node] del dpolz[node] for i in range(m): f, t = map(int, input().split()) g[f].append(t) g[t].append(f) for i in g.keys(): polz[i] = w[i] * len(g[i]) for j in g[i]: polz[i] -= w[j] dpolz = polz while len(polz): polz = sorted(dpolz.items(), key=lambda x: x[1], reverse=True) dpolz = dict(polz) #print(polz) cut(polz.pop(0)[0]) print(r) ```
instruction
0
87,029
8
174,058
No
output
1
87,029
8
174,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` n, m = map(int, input().split()) v = [0] + [int(i) for i in input().split()] sums = [1e9] + [0] * n sums2 = [-1] + [0] * n adj = {} for i in range(n): adj[i + 1] = [] for i in range(m): a, b = map(int, input().split()) adj[a].append(b) adj[b].append(a) sums[a] += v[b] sums[b] += v[a] sums2[a] += v[a] - v[b] sums2[b] += v[b] - v[a] energy = 0 for i in range(n): ma2 = max(sums2) part = sums2.index(ma2) adj_nodes = adj[part] energy += sum([v[node] for node in adj_nodes]) for node in adj_nodes: sums2[node] += v[part] adj[node].remove(part) sums2[part] = -1 print (energy) ```
instruction
0
87,030
8
174,060
No
output
1
87,030
8
174,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all n parts. Input The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n. Output Output the minimum total energy the child should spend to remove all n parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Output 40 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Output 400 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Output 160 Note One of the optimal sequence of actions in the first sample is: * First, remove part 3, cost of the action is 20. * Then, remove part 2, cost of the action is 10. * Next, remove part 4, cost of the action is 10. * At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts. Submitted Solution: ``` ans=0 def dfs(i): global ans x=i vis[i]=1 for j in grid[i]: ans+=min(l[x-1],l[j-1]) if vis[j]==0: dfs(j) for _ in range(1): n,k=map(int,input().split()) l=list(map(int,input().split())) grid=[[] for i in range(n+1)] for i in range(k) : a,b=map(int,input().split()) grid[a].append(b) grid[b].append(a) print(grid) vis=[0]*(n+1) for i in range(1,n+1): if vis[i]==0: dfs(i) print(ans//2) ```
instruction
0
87,031
8
174,062
No
output
1
87,031
8
174,063
Provide a correct Python 3 solution for this coding contest problem. Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried. Mr. Kobou’s ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 × 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "#" the two series of numbers become "0,2,2,1,1" and "1,1,1,3". | 0| 2| 2| 1| 1 ---|---|---|---|---|--- 1| | | #| | 1| | #| | | 1| | | | | # 3| | #| #| #| Mr. Kobou’s ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 × 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information. Given the set of information written on the pieces of paper, make a program to judge if the information is relevant. Input The input is given in the following format. $W$ $H$ $a_1$ $a_2$ $...$ $a_W$ $b_1$ $b_2$ $...$ $b_H$ The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$). Output Output "1" if the information written on the paper is relevant, or "0" otherwise. Examples Input 5 4 0 2 2 1 1 1 1 1 3 Output 1 Input 5 5 3 2 3 0 0 4 2 0 0 2 Output 0
instruction
0
87,443
8
174,886
"Correct Solution: ``` import sys,heapq _,a,q=[[-int(e) for e in sys.stdin.readline().split() if e!='0'] for _ in[0]*3] heapq.heapify(q) for e in a: t=[] for _ in [0]*-e: if not q:print(0);exit() if q[0]!=-1:heapq.heappush(t,q[0]+1) heapq.heappop(q) while t:heapq.heappush(q,t[0]);heapq.heappop(t) print(int(not q)) ```
output
1
87,443
8
174,887
Provide a correct Python 3 solution for this coding contest problem. Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried. Mr. Kobou’s ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 × 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "#" the two series of numbers become "0,2,2,1,1" and "1,1,1,3". | 0| 2| 2| 1| 1 ---|---|---|---|---|--- 1| | | #| | 1| | #| | | 1| | | | | # 3| | #| #| #| Mr. Kobou’s ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 × 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information. Given the set of information written on the pieces of paper, make a program to judge if the information is relevant. Input The input is given in the following format. $W$ $H$ $a_1$ $a_2$ $...$ $a_W$ $b_1$ $b_2$ $...$ $b_H$ The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$). Output Output "1" if the information written on the paper is relevant, or "0" otherwise. Examples Input 5 4 0 2 2 1 1 1 1 1 3 Output 1 Input 5 5 3 2 3 0 0 4 2 0 0 2 Output 0
instruction
0
87,444
8
174,888
"Correct Solution: ``` w, h = map(int, input().split()) lst1 = sorted(map(int, input().split())) lst2 = sorted(map(int, input().split())) while lst1: num = lst1.pop() for i in range(-1, -num - 1, -1): lst2[i] -= 1 lst2.sort() if sum(lst2) == 0 and min(lst2) == 0: print(1) else: print(0) ```
output
1
87,444
8
174,889
Provide a correct Python 3 solution for this coding contest problem. Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried. Mr. Kobou’s ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 × 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "#" the two series of numbers become "0,2,2,1,1" and "1,1,1,3". | 0| 2| 2| 1| 1 ---|---|---|---|---|--- 1| | | #| | 1| | #| | | 1| | | | | # 3| | #| #| #| Mr. Kobou’s ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 × 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information. Given the set of information written on the pieces of paper, make a program to judge if the information is relevant. Input The input is given in the following format. $W$ $H$ $a_1$ $a_2$ $...$ $a_W$ $b_1$ $b_2$ $...$ $b_H$ The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$). Output Output "1" if the information written on the paper is relevant, or "0" otherwise. Examples Input 5 4 0 2 2 1 1 1 1 1 3 Output 1 Input 5 5 3 2 3 0 0 4 2 0 0 2 Output 0
instruction
0
87,445
8
174,890
"Correct Solution: ``` import sys w,h = map(int, input().split()) sumC = 0 sumR = 0 col = list(map(int, input().split())) row = list(map(int, input().split())) for c in col : sumC += c for r in row : sumR += r if sumR != sumC : print(0) sys.exit(0) for i in range(w): row.sort(reverse=True) for j in range(h): if not col[i] or not row[j] : break row[j] -= 1 col[i] -= 1 if col[i] > 0 : print(0) sys.exit(0) print(1) ```
output
1
87,445
8
174,891
Provide a correct Python 3 solution for this coding contest problem. Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried. Mr. Kobou’s ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 × 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "#" the two series of numbers become "0,2,2,1,1" and "1,1,1,3". | 0| 2| 2| 1| 1 ---|---|---|---|---|--- 1| | | #| | 1| | #| | | 1| | | | | # 3| | #| #| #| Mr. Kobou’s ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 × 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information. Given the set of information written on the pieces of paper, make a program to judge if the information is relevant. Input The input is given in the following format. $W$ $H$ $a_1$ $a_2$ $...$ $a_W$ $b_1$ $b_2$ $...$ $b_H$ The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$). Output Output "1" if the information written on the paper is relevant, or "0" otherwise. Examples Input 5 4 0 2 2 1 1 1 1 1 3 Output 1 Input 5 5 3 2 3 0 0 4 2 0 0 2 Output 0
instruction
0
87,446
8
174,892
"Correct Solution: ``` W, H = map(int, input().split()) *A, = map(int, input().split()) *B, = map(int, input().split()) A.sort(reverse=1) ok =+ (sum(A) == sum(B)) for a in A: B.sort(reverse=1) for i in range(a): if i >= len(B) or B[i] == 0: ok = 0 break B[i] -= 1 print(ok) ```
output
1
87,446
8
174,893