message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2
instruction
0
38,809
14
77,618
Tags: implementation Correct Solution: ``` n = int(input()) to_sb = list(map(int, input().split())) dict1 = {i + 1: to_sb[i] for i in range(len(to_sb))} dict2 = dict(sorted(dict1.items(), key=lambda d: d[1], reverse=False)) from_sb = sorted(dict1.items(), key=lambda d: d[1], reverse=False) end_p = [from_sb[i][0] for i in range(n)] for j in end_p: print(j, end=' ') ```
output
1
38,809
14
77,619
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2
instruction
0
38,810
14
77,620
Tags: implementation Correct Solution: ``` n = int(input()) lis = [int(_) for _ in input().split()] dic = {} for i,x in enumerate(lis): dic[x] = i+1 print(' '.join([str(dic[_+1]) for _ in range(n)])) ```
output
1
38,810
14
77,621
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2
instruction
0
38,811
14
77,622
Tags: implementation Correct Solution: ``` n=int(input()) l=input().split() l1=len(l) for i in range(n): l[i]=int(l[i]) i=0 j=1 while(j<l1+1): if(l[i]==j): j+=1 print(i+1,"", end="") i=-1 i+=1 ```
output
1
38,811
14
77,623
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2
instruction
0
38,812
14
77,624
Tags: implementation Correct Solution: ``` k = int(input()) n = list(map(int, input().split())) m = 0 for i in range(1, k+1): m = n.index(i) + 1 print(m) ```
output
1
38,812
14
77,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` n=int(input()) s=input().split(' ') a=[int(s[i]) for i in range(0,n)] b=[0 for i in range(0,n)] for i in range(0,n): b[a[i]-1]=i+1 print(b[0],sep='',end='') for i in range(1,n): print(' ',b[i],sep='',end='') ```
instruction
0
38,813
14
77,626
Yes
output
1
38,813
14
77,627
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` a=int(input()) b = input().split() c=[0]*a for i in range(a): c[int(b[i])-1] = i+1 for i in range(a): print(c[i], end=" ") ```
instruction
0
38,814
14
77,628
Yes
output
1
38,814
14
77,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` n = int(input()) x = input().split(" ") t = "" for i in range(1, n + 1): for j in range(len(x)): if i == int(x[j]): t += str(j+1) + " " print(t) ```
instruction
0
38,815
14
77,630
Yes
output
1
38,815
14
77,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` n = int(input()) arr = list(map(int, input().split())) ans = [0] * n i = 0 while(i < n): temp = arr[i] ans[temp-1] = i+1 i=i+1 i=0 while(i < n): print(ans[i], end=" ") i=i+1 ```
instruction
0
38,816
14
77,632
Yes
output
1
38,816
14
77,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` from collections import defaultdict n = int(input()) arr = input().split() arr = [int(c) for c in arr] g = defaultdict(int) for i, d in enumerate(arr): if arr[i] not in g.keys(): g[arr[i]] = arr[arr[i]] g[arr[arr[i]]] = arr[i] vals = [] for i in range(len(arr)): vals.append(g[arr[i]]) for v in vals: print(v, end= " ") ```
instruction
0
38,817
14
77,634
No
output
1
38,817
14
77,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` n = int(input()) list_of_friends = list(map(int, input().split())) length = len(list_of_friends) output = [0 for i in range(length)] for i in range(length): output[list_of_friends[i]-1] = i+1 print(output) ```
instruction
0
38,818
14
77,636
No
output
1
38,818
14
77,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` s=[] x=int(input()) l=list(map(int, input().split())) for i in range(1,(len(l))): res=(l.index(i))+1 s.append(res) print(s) ```
instruction
0
38,819
14
77,638
No
output
1
38,819
14
77,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend i the number of a friend who has given him a gift. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi β€” the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i. Examples Input 4 2 3 4 1 Output 4 1 2 3 Input 3 1 3 2 Output 1 3 2 Input 2 1 2 Output 1 2 Submitted Solution: ``` n = int(input()) n1 = list(map(int,input().split())) print(n1) resultado = [] for i in range(1,n + 1): resultado.append(str(n1.index(i) + 1)) print(" ".join(resultado)) ```
instruction
0
38,820
14
77,640
No
output
1
38,820
14
77,641
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,026
14
78,052
Tags: binary search, dp, greedy, implementation Correct Solution: ``` import sys import string import math from collections import defaultdict from functools import lru_cache from collections import Counter from fractions import Fraction def mi(s): return map(int, s.strip().split()) def lmi(s): return list(mi(s)) def tmi(s): return tuple(mi(s)) def mf(f, s): return map(f, s) def lmf(f, s): return list(mf(f, s)) def js(lst): return " ".join(str(d) for d in lst) def jsns(lst): return "".join(str(d) for d in lst) def line(): return sys.stdin.readline().strip() def linesp(): return line().split() def iline(): return int(line()) def mat(n): matr = [] for _ in range(n): matr.append(linesp()) return matr def matns(n): mat = [] for _ in range(n): mat.append([c for c in line()]) return mat def mati(n): mat = [] for _ in range(n): mat.append(lmi(line())) return mat def pmat(mat): for row in mat: print(js(row)) def main(): n = iline() requests = [] for _ in range(n): requests.append(tmi(line())) line() tables = list(enumerate(lmi(line()))) tables.sort(key=lambda x: x[1]) max_size = tables[-1][1] requests = [ (e + 1, request[0], request[1]) for e, request in enumerate(requests) if request[0] <= max_size ] requests.sort(key=lambda x: x[2], reverse=True) # So we have the largest request now. total = 0 used = [] for number, size, money in requests: # Check if there exists a table which # can fit this. for e, tab_data in enumerate(tables): tab_num, tab_size = tab_data if tab_size is not None and tab_size >= size: tables[e] = (tab_num, None) total += money used.append((number, tab_num + 1)) break print(len(used), total) for num, tab_num in used: print(num, tab_num) main() ```
output
1
39,026
14
78,053
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,027
14
78,054
Tags: binary search, dp, greedy, implementation Correct Solution: ``` from bisect import bisect_left as lower def put(): return map(int, input().split()) n = int(input()) c,p = [],[] for i in range(n): ci,pi = put() c.append(ci) p.append(pi) k = int(input()) rr = list(put()) l = [] for i in range(n): l.append((p[i], c[i], i+1)) l.sort() r = [] for i,v in enumerate(rr): r.append((v,i+1)) r.sort() t = k x,y = 0,0 vis =[0]*k ans = [] while t>0 and l: p,c,a = l.pop() j = lower(r, (c,0)) while j<k and vis[j]: j+=1 if j<k: x+= 1 y+= p vis[j]=1 t-=1 ans.append((a, r[j][1])) print(x,y) for a,b in ans: print(a,b) ```
output
1
39,027
14
78,055
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,028
14
78,056
Tags: binary search, dp, greedy, implementation Correct Solution: ``` import heapq n=int(input()) req=[] for i in range(n): c,p=map(int,input().split()) req.append((c,p,i+1)) req.sort() x=int(input()) r1=list(map(int,input().split())) r=[] for i in range(x): r.append((r1[i],i+1)) r.sort() l1=[] z=0 ans=0 anslist=[] #heapq.heapify(l1) for i in range(x): while z<n and req[z][0]<=r[i][0]: heapq.heappush(l1,(-req[z][1],req[z][2])) z+=1 if len(l1)>0: f=l1[0] ans-=f[0] heapq.heappop(l1) anslist.append(str(f[1])+" "+str(r[i][1])) print(len(anslist),ans) print('\n'.join(anslist)) ```
output
1
39,028
14
78,057
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,029
14
78,058
Tags: binary search, dp, greedy, implementation Correct Solution: ``` def main(): F = lambda : map(int, input().split()) n = int(input()) groups = [list(F())[::-1] + [i] for i in range(n)] k = int(input()) tables = list(F()) tables = [[tables[i], i] for i in range(k)] tables = sorted(tables) groups = sorted(groups) count = 0 SUM = 0 res = [] for i in range(n-1, -1, -1): for j in range(len(tables)): if tables: if groups[i][1] <= tables[j][0]: res.append([groups[i][2], tables[j][1]]) count += 1 SUM += groups[i][0] tables.pop(j) break else: return [count, SUM, res] return [count, SUM, res] answer = main() print(answer[0], answer[1]) for x in answer[2]: print(x[0] + 1, x[1] + 1) ```
output
1
39,029
14
78,059
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,030
14
78,060
Tags: binary search, dp, greedy, implementation Correct Solution: ``` import sys from math import log2,floor,ceil,sqrt # import bisect # from collections import deque Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10**9+7 n =int(ri()) vis = [] for i in range(n): c,p = Ri() vis.append([c,p,i]) t = int(ri()) r = Ri() r = [[r[i],i] for i in range(t)] r.sort(key = lambda x : x[0]) vis.sort(key = lambda x : (x[1],-x[0]),reverse = True) ans = 0 flag = [True]*t tcus = [] for i in range(n): tf= -1 cus= vis[i] for j in range(t): if cus[0] <= r[j][0] and flag[j]: tf = j break if tf != -1: flag[tf] = False ans+=cus[1] tcus.append([i,tf]) print(len(tcus),ans) for i in range(len(tcus)): cus = tcus[i][0] t = tcus[i][1] print(vis[cus][2]+1, r[t][1]+1) ```
output
1
39,030
14
78,061
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,031
14
78,062
Tags: binary search, dp, greedy, implementation Correct Solution: ``` n = int(input()) g = [list(map(int, input().split())) + [i] for i in range(n)] k = int(input()) r = [(v, i) for i, v in enumerate(list(map(int, input().split())))] b = [None] * n sg = sorted(g, key=lambda x: x[1], reverse=True) sr = sorted(r) count = 0 money = 0 for v in sg: for w in sr: if w[0] < v[0]: continue b[v[2]] = w[1] count += 1 money += v[1] sr.remove(w) break print(count, money) for i in range(n): if b[i] == None: continue print(i + 1, b[i] + 1) ```
output
1
39,031
14
78,063
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,032
14
78,064
Tags: binary search, dp, greedy, implementation Correct Solution: ``` n = int(input()) R = [] for r in range(n): c, p = list(map(int, input().split())) R.append((p, c, r+1)) m = int(input()) T = list(map(int, input().split())) T = sorted([[c, i+1] for i,c in enumerate(T)]) R = sorted(R, reverse=True) ans = 0 B = [] for p, c, r in R: for i in range(m): if T[i][0] >= c: B.append((r, T[i][1])) T[i][0] = -1 ans += p break print(len(B), ans) for r, t in B: print(r, t) ```
output
1
39,032
14
78,065
Provide tags and a correct Python 3 solution for this coding contest problem. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2
instruction
0
39,033
14
78,066
Tags: binary search, dp, greedy, implementation Correct Solution: ``` import bisect, sys input = sys.stdin.readline def binary_search(array, value, l = 0, h = None): array = [i[0] for i in array] if not h: h = len(array) index = bisect.bisect_left(array, value, l, h) if index != h and array[index] >= value: return index else: return -1 people = [[int(i) for i in input().split()] + [j] for j in range(int(input()))] k, tables = int(input()), [int(i) for i in input().split()] tables, money, accepted_num, accepted = [[tables[i]] + [i] for i in range(k)], 0, 0, [] people.sort(key = lambda x: x[1], reverse = True) tables.sort(key = lambda x: x[0]) for i in range(len(people)): ree = binary_search(tables, people[i][0]) if ree != -1: accepted_num += 1 money += people[i][1] accepted.append([people[i][2] + 1, tables[ree][1] + 1]) del(tables[ree]) print(accepted_num, money) for i in range(len(accepted)): print(*accepted[i]) ```
output
1
39,033
14
78,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` import sys input = sys.stdin.readline read_tuple = lambda _type: map(_type, input().split(' ')) def solve(): # input n = int(input()) c_p = [] for i in range(n): c_i, p_i = read_tuple(int) c_p.append((c_i, p_i, i + 1)) k = int(input()) r = [(r_i, i + 1) for i, r_i in enumerate(read_tuple(int))] # solution c_p.sort(key=lambda x: x[1]) r.sort(key=lambda x: x[0]) m = 0 s = 0 info = [] while c_p and r: c_i, p_i, i = c_p[-1] if c_i > r[-1][0]: c_p.pop() else: idx = 0 r_j, j = r[idx] while r_j < c_i: idx += 1 r_j, j = r[idx] m += 1 s += p_i info.append((i, j)) c_p.pop() r.pop(idx) print(m, s) for i, j in sorted(info): print(i, j) if __name__ == '__main__': solve() ```
instruction
0
39,034
14
78,068
Yes
output
1
39,034
14
78,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` import bisect def ans(n,k): if dp[n][k] != -1: return dp[n][k] if k == 0 and n!=0: return ans(n-1,k) if n == 0: return 0 if l[n-1][0]<=lll[k-1]: dp[n][k] = max(l[n-1][1] + ans(n-1,k-1),ans(n-1,k),ans(n,k-1)) return max(l[n-1][1] + ans(n-1,k-1),ans(n-1,k),ans(n,k-1)) else: dp[n][k] = max(ans(n-1,k),ans(n,k-1)) return max(ans(n-1,k),ans(n,k-1)) n = int(input()) l = [] ll = [] for i in range(n): l1 = list(map(int,input().split())) l1.append(i) l.append(l1) k = int(input()) lll = list(map(int,input().split())) dp = [] '''for i in range(tt+1): q = [] for j in range(ttt+1): q.append(-1) dp.append(q)''' l1 = [] l2 = [] ans = [] count = 0 l2 = sorted(lll) l.sort(key = lambda x: x[1]) anss = 0 for i in l[-1::-1]: index = bisect.bisect_left(l2,i[0]) if index < len(l2): anss+=i[1] count+=1 qq = lll.index(l2[index]) lll[qq] = 0 l2.pop(index) ans.append([i[2]+1,qq+1]) print(count,anss) for i in ans: print(*i) ```
instruction
0
39,035
14
78,070
Yes
output
1
39,035
14
78,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))) l[i]+=[i+1] k=int(input()) s=list(map(int,input().split())) for i in range(k): s[i]=[i+1,s[i]] def fun(itm): return itm[1] l.sort(reverse=True,key=fun) s.sort(key=fun) ans=0 ansl=[] for i in l: for j in s: if i[0]<=j[1]: ans+=i[1] s.remove(j) ansl.append([i[2],j[0]]) break # print(i) # print(l) # print(s) # print(ans) print(len(ansl),ans) for i in ansl: print(i[0],i[1]) ```
instruction
0
39,036
14
78,072
Yes
output
1
39,036
14
78,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` from sys import stdin,stdout import bisect n=int(input()) size=[] money=[] for _ in range(n): ci,pi=map(int,stdin.readline().split(' ')) size.append(ci);money.append(pi) groupno=[i+1 for i in range(n)] k=int(input()) table=list(map(int,stdin.readline().split(' '))) tid=[i+1 for i in range(k+1)] td={} t1=sorted(zip(table,tid)) table=[x for x,y in t1] tid=[y for x,y in t1] for i in range(k): td[i+1]=-1 t1=sorted(zip(money,size,groupno)) size=[y for x,y,z in t1] groupno=[z for x,y,z in t1] money=[x for x,y,z in t1] money.reverse();groupno.reverse();size.reverse() ans=0;ans1=0 for i in range(len(money)): t1=bisect.bisect_left(table,size[i]) #print(i,t1) if t1!=len(table): td[tid[t1]]=groupno[i] ans+=money[i];ans1+=1 tid.pop(t1);table.pop(t1) print(ans1,ans) for i in td: if td[i]!=-1: stdout.write(str(td[i])+" "+str(i)+"\n") ```
instruction
0
39,037
14
78,074
Yes
output
1
39,037
14
78,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` import heapq def binarySearch(ele, lst, l=None, h=None): if l == None: l = 0 if h == None: h = len(lst) - 1 while h >= l: m = l + (h - l) // 2 if lst[m][0] > ele: h = m - 1 if lst[m][0] <= ele: l = m + 1 return h def main(): req = int(input()) items = [] for index in range(req): c, p = map(int, input().split(" ")) items.append((c, -1 * p, index + 1)) # inverting values to use minheap _ = input() tables = list(map(int, input().split(" "))) # pick a lowest table out and binary search for the highest $ that can be obtained. # alternatively create a max heap of prices and add elements to the max heap as you go # we can binary search for the index of the max element fulfilling property of being <= table tables.sort() items.sort() heap = [] total = 0 accepted = 0 ans = [] startingIndex = 0 for table, ele in enumerate(tables): index = binarySearch(ele, items) for i in range(startingIndex, index + 1): heapq.heappush(heap, (items[i][1], items[i][2])) startingIndex = index + 1 if heap: t = table + 1 value, request = heapq.heappop(heap) accepted += 1 total += value ans.append((request, t)) print(accepted, abs(total)) for req, table in ans: print(req, table) main() ```
instruction
0
39,038
14
78,076
No
output
1
39,038
14
78,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` #------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- from collections import deque def countGreater(arr, n, k): l = 0 r = n - 1 leftGreater = n while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 else: l = m + 1 return (n - leftGreater) def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z n=int(input()) c=[0]*n p=[0]*n ind=[0]*n for i in range(n): c[i],p[i]=map(int,input().split()) ind[i]=i c=sort_list(c,p) ind=sort_list(ind,p) ind.reverse() p.sort(reverse=True) c.reverse() ans=0 cost=0 k=int(input()) l=list(map(int,input().split())) ind1=dict() for i in range(len(l)): if l[i] not in ind1: ind1.update({l[i]:deque([i])}) else: ind1[l[i]].append(i) l.sort() d=dict() for i in range(n): inde=countGreater(l,len(l),c[i]) #print(l,inde,p[i]) if inde==0: continue else: inde=len(l)-inde ans+=1 cost+=p[i] if n==944 and c[i]==918: print(c[i],l[inde]) d.update({ind[i]+1:ind1[l[inde]][0]+1}) ind1[l[inde]].popleft() l.pop(inde) if len(l)==0: break print(ans,cost) for i in sorted(d.keys()): print(i,d[i]) ```
instruction
0
39,039
14
78,078
No
output
1
39,039
14
78,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` n = int(input()) s = [] for i in range(n): me = list(map(int, input().split())) me[0] = -me[0] s.append(me) z = s[:] k = int(input()) m = list(map(int, input().split())) s.sort(key=lambda x: (x[1], x[0])) s.reverse() answ = 0 summ = 0 sisok = [] for i in range(n): for j in range(k): if -s[i][0] <= m[j]: m[j] = -m[j] summ += s[i][1] answ += 1 sisok.append([z.index(s[i]) + 1, j + 1]) break print(answ, summ) for i in range(answ): print(sisok[i][0], end = " ") print(sisok[i][1]) ```
instruction
0
39,040
14
78,080
No
output
1
39,040
14
78,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi β€” the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are k tables in the restaurant. For each table, we know ri β€” the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input The first line of the input contains integer n (1 ≀ n ≀ 1000) β€” the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≀ ci, pi ≀ 1000) β€” the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≀ k ≀ 1000) β€” the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≀ ri ≀ 1000) β€” the maximum number of people that can sit at each table. Output In the first line print two integers: m, s β€” the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines β€” each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Examples Input 3 10 50 2 100 5 30 3 4 6 9 Output 2 130 2 1 3 2 Submitted Solution: ``` import sys # request number n = int(sys.stdin.readline()) request = [] for i in range(1,n+1): people, cost = map(int, sys.stdin.readline().split()) request.append((i,people, cost)) k = int(sys.stdin.readline()) tables = [] for tmp in zip(range(1,k+1), [int(s) for s in sys.stdin.readline().split()]): tables.append(tmp) sorted(tables, key=lambda item: item[1]) total = 0 ans = [] used = set() for i, t in tables: max_price = 0 request_id = -1 for j, c, p in request: if p > max_price and c <= t and j not in used: max_price = p request_id = j if request_id > 0: used.add( request_id ) ans.append( (request_id, i) ) total += max_price print( str(len(used)) + " " + str(total) ) for request_id, i in ans: print( str(request_id) + " " + str(i) ) ```
instruction
0
39,041
14
78,082
No
output
1
39,041
14
78,083
Provide tags and a correct Python 3 solution for this coding contest problem. A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure. As part of this task, we assume that the social network is 4n processes running on the n servers. All servers are absolutely identical machines, each of which has a volume of RAM of 1 GB = 1024 MB (1). Each process takes 100 MB of RAM on the server. At the same time, the needs of maintaining the viability of the server takes about 100 more megabytes of RAM. Thus, each server may have up to 9 different processes of social network. Now each of the n servers is running exactly 4 processes. However, at the moment of peak load it is sometimes necessary to replicate the existing 4n processes by creating 8n new processes instead of the old ones. More formally, there is a set of replication rules, the i-th (1 ≀ i ≀ 4n) of which has the form of ai β†’ (bi, ci), where ai, bi and ci (1 ≀ ai, bi, ci ≀ n) are the numbers of servers. This means that instead of an old process running on server ai, there should appear two new copies of the process running on servers bi and ci. The two new replicated processes can be on the same server (i.e., bi may be equal to ci) or even on the same server where the original process was (i.e. ai may be equal to bi or ci). During the implementation of the rule ai β†’ (bi, ci) first the process from the server ai is destroyed, then appears a process on the server bi, then appears a process on the server ci. There is a set of 4n rules, destroying all the original 4n processes from n servers, and creating after their application 8n replicated processes, besides, on each of the n servers will be exactly 8 processes. However, the rules can only be applied consecutively, and therefore the amount of RAM of the servers imposes limitations on the procedure for the application of the rules. According to this set of rules determine the order in which you want to apply all the 4n rules so that at any given time the memory of each of the servers contained at most 9 processes (old and new together), or tell that it is impossible. Input The first line of the input contains integer n (1 ≀ n ≀ 30 000) β€” the number of servers of the social network. Next 4n lines contain the rules of replicating processes, the i-th (1 ≀ i ≀ 4n) of these lines as form ai, bi, ci (1 ≀ ai, bi, ci ≀ n) and describes rule ai β†’ (bi, ci). It is guaranteed that each number of a server from 1 to n occurs four times in the set of all ai, and eight times among a set that unites all bi and ci. Output If the required order of performing rules does not exist, print "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes), and in the second line β€” a sequence of 4n numbers from 1 to 4n, giving the numbers of the rules in the order they are applied. The sequence should be a permutation, that is, include each number from 1 to 4n exactly once. If there are multiple possible variants, you are allowed to print any of them. Examples Input 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 1 1 Output YES 1 2 5 6 3 7 4 8 Input 3 1 2 3 1 1 1 1 1 1 1 1 1 2 1 3 2 2 2 2 2 2 2 2 2 3 1 2 3 3 3 3 3 3 3 3 3 Output YES 2 3 4 6 7 8 10 11 12 1 5 9 Note (1) To be extremely accurate, we should note that the amount of server memory is 1 GiB = 1024 MiB and processes require 100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 230 bytes and a mebibyte (MiB) is the amount of RAM of 220 bytes. In the first sample test the network uses two servers, each of which initially has four launched processes. In accordance with the rules of replication, each of the processes must be destroyed and twice run on another server. One of the possible answers is given in the statement: after applying rules 1 and 2 the first server will have 2 old running processes, and the second server will have 8 (4 old and 4 new) processes. After we apply rules 5 and 6, both servers will have 6 running processes (2 old and 4 new). After we apply rules 3 and 7, both servers will have 7 running processes (1 old and 6 new), and after we apply rules 4 and 8, each server will have 8 running processes. At no time the number of processes on a single server exceeds 9. In the second sample test the network uses three servers. On each server, three processes are replicated into two processes on the same server, and the fourth one is replicated in one process for each of the two remaining servers. As a result of applying rules 2, 3, 4, 6, 7, 8, 10, 11, 12 each server would have 7 processes (6 old and 1 new), as a result of applying rules 1, 5, 9 each server will have 8 processes. At no time the number of processes on a single server exceeds 9.
instruction
0
39,106
14
78,212
Tags: constructive algorithms, greedy Correct Solution: ``` from collections import deque import random class CodeforcesTask566BSolution: def __init__(self): self.result = '' self.n = 0 self.rules = [] def read_input(self): self.n = int(input()) self.rules = [[int(x) for x in input().split(" ")] + [y + 1] for y in range(self.n * 4)] def process_task(self): loads = [4] * self.n random.shuffle(self.rules) to_use = deque(self.rules) order = [] res = True ba = 0 while to_use and res: moving = to_use.popleft() loads[moving[0] - 1] -= 1 if loads[moving[1] - 1] < 9 and loads[moving[2] - 1] < 9 + (-1 if moving[2] == moving[1] else 0): ba = 0 loads[moving[1] - 1] += 1 loads[moving[2] - 1] += 1 order.append(moving[3]) else: ba += 1 loads[moving[0] - 1] += 1 to_use.append(moving) if ba > self.n * 12: res = False self.result = "NO" if not res else f"YES\n{' '.join([str(x) for x in order])}" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask566BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
39,106
14
78,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure. As part of this task, we assume that the social network is 4n processes running on the n servers. All servers are absolutely identical machines, each of which has a volume of RAM of 1 GB = 1024 MB (1). Each process takes 100 MB of RAM on the server. At the same time, the needs of maintaining the viability of the server takes about 100 more megabytes of RAM. Thus, each server may have up to 9 different processes of social network. Now each of the n servers is running exactly 4 processes. However, at the moment of peak load it is sometimes necessary to replicate the existing 4n processes by creating 8n new processes instead of the old ones. More formally, there is a set of replication rules, the i-th (1 ≀ i ≀ 4n) of which has the form of ai β†’ (bi, ci), where ai, bi and ci (1 ≀ ai, bi, ci ≀ n) are the numbers of servers. This means that instead of an old process running on server ai, there should appear two new copies of the process running on servers bi and ci. The two new replicated processes can be on the same server (i.e., bi may be equal to ci) or even on the same server where the original process was (i.e. ai may be equal to bi or ci). During the implementation of the rule ai β†’ (bi, ci) first the process from the server ai is destroyed, then appears a process on the server bi, then appears a process on the server ci. There is a set of 4n rules, destroying all the original 4n processes from n servers, and creating after their application 8n replicated processes, besides, on each of the n servers will be exactly 8 processes. However, the rules can only be applied consecutively, and therefore the amount of RAM of the servers imposes limitations on the procedure for the application of the rules. According to this set of rules determine the order in which you want to apply all the 4n rules so that at any given time the memory of each of the servers contained at most 9 processes (old and new together), or tell that it is impossible. Input The first line of the input contains integer n (1 ≀ n ≀ 30 000) β€” the number of servers of the social network. Next 4n lines contain the rules of replicating processes, the i-th (1 ≀ i ≀ 4n) of these lines as form ai, bi, ci (1 ≀ ai, bi, ci ≀ n) and describes rule ai β†’ (bi, ci). It is guaranteed that each number of a server from 1 to n occurs four times in the set of all ai, and eight times among a set that unites all bi and ci. Output If the required order of performing rules does not exist, print "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes), and in the second line β€” a sequence of 4n numbers from 1 to 4n, giving the numbers of the rules in the order they are applied. The sequence should be a permutation, that is, include each number from 1 to 4n exactly once. If there are multiple possible variants, you are allowed to print any of them. Examples Input 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 1 1 Output YES 1 2 5 6 3 7 4 8 Input 3 1 2 3 1 1 1 1 1 1 1 1 1 2 1 3 2 2 2 2 2 2 2 2 2 3 1 2 3 3 3 3 3 3 3 3 3 Output YES 2 3 4 6 7 8 10 11 12 1 5 9 Note (1) To be extremely accurate, we should note that the amount of server memory is 1 GiB = 1024 MiB and processes require 100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 230 bytes and a mebibyte (MiB) is the amount of RAM of 220 bytes. In the first sample test the network uses two servers, each of which initially has four launched processes. In accordance with the rules of replication, each of the processes must be destroyed and twice run on another server. One of the possible answers is given in the statement: after applying rules 1 and 2 the first server will have 2 old running processes, and the second server will have 8 (4 old and 4 new) processes. After we apply rules 5 and 6, both servers will have 6 running processes (2 old and 4 new). After we apply rules 3 and 7, both servers will have 7 running processes (1 old and 6 new), and after we apply rules 4 and 8, each server will have 8 running processes. At no time the number of processes on a single server exceeds 9. In the second sample test the network uses three servers. On each server, three processes are replicated into two processes on the same server, and the fourth one is replicated in one process for each of the two remaining servers. As a result of applying rules 2, 3, 4, 6, 7, 8, 10, 11, 12 each server would have 7 processes (6 old and 1 new), as a result of applying rules 1, 5, 9 each server will have 8 processes. At no time the number of processes on a single server exceeds 9. Submitted Solution: ``` print('1') ```
instruction
0
39,107
14
78,214
No
output
1
39,107
14
78,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure. As part of this task, we assume that the social network is 4n processes running on the n servers. All servers are absolutely identical machines, each of which has a volume of RAM of 1 GB = 1024 MB (1). Each process takes 100 MB of RAM on the server. At the same time, the needs of maintaining the viability of the server takes about 100 more megabytes of RAM. Thus, each server may have up to 9 different processes of social network. Now each of the n servers is running exactly 4 processes. However, at the moment of peak load it is sometimes necessary to replicate the existing 4n processes by creating 8n new processes instead of the old ones. More formally, there is a set of replication rules, the i-th (1 ≀ i ≀ 4n) of which has the form of ai β†’ (bi, ci), where ai, bi and ci (1 ≀ ai, bi, ci ≀ n) are the numbers of servers. This means that instead of an old process running on server ai, there should appear two new copies of the process running on servers bi and ci. The two new replicated processes can be on the same server (i.e., bi may be equal to ci) or even on the same server where the original process was (i.e. ai may be equal to bi or ci). During the implementation of the rule ai β†’ (bi, ci) first the process from the server ai is destroyed, then appears a process on the server bi, then appears a process on the server ci. There is a set of 4n rules, destroying all the original 4n processes from n servers, and creating after their application 8n replicated processes, besides, on each of the n servers will be exactly 8 processes. However, the rules can only be applied consecutively, and therefore the amount of RAM of the servers imposes limitations on the procedure for the application of the rules. According to this set of rules determine the order in which you want to apply all the 4n rules so that at any given time the memory of each of the servers contained at most 9 processes (old and new together), or tell that it is impossible. Input The first line of the input contains integer n (1 ≀ n ≀ 30 000) β€” the number of servers of the social network. Next 4n lines contain the rules of replicating processes, the i-th (1 ≀ i ≀ 4n) of these lines as form ai, bi, ci (1 ≀ ai, bi, ci ≀ n) and describes rule ai β†’ (bi, ci). It is guaranteed that each number of a server from 1 to n occurs four times in the set of all ai, and eight times among a set that unites all bi and ci. Output If the required order of performing rules does not exist, print "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes), and in the second line β€” a sequence of 4n numbers from 1 to 4n, giving the numbers of the rules in the order they are applied. The sequence should be a permutation, that is, include each number from 1 to 4n exactly once. If there are multiple possible variants, you are allowed to print any of them. Examples Input 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 1 1 Output YES 1 2 5 6 3 7 4 8 Input 3 1 2 3 1 1 1 1 1 1 1 1 1 2 1 3 2 2 2 2 2 2 2 2 2 3 1 2 3 3 3 3 3 3 3 3 3 Output YES 2 3 4 6 7 8 10 11 12 1 5 9 Note (1) To be extremely accurate, we should note that the amount of server memory is 1 GiB = 1024 MiB and processes require 100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 230 bytes and a mebibyte (MiB) is the amount of RAM of 220 bytes. In the first sample test the network uses two servers, each of which initially has four launched processes. In accordance with the rules of replication, each of the processes must be destroyed and twice run on another server. One of the possible answers is given in the statement: after applying rules 1 and 2 the first server will have 2 old running processes, and the second server will have 8 (4 old and 4 new) processes. After we apply rules 5 and 6, both servers will have 6 running processes (2 old and 4 new). After we apply rules 3 and 7, both servers will have 7 running processes (1 old and 6 new), and after we apply rules 4 and 8, each server will have 8 running processes. At no time the number of processes on a single server exceeds 9. In the second sample test the network uses three servers. On each server, three processes are replicated into two processes on the same server, and the fourth one is replicated in one process for each of the two remaining servers. As a result of applying rules 2, 3, 4, 6, 7, 8, 10, 11, 12 each server would have 7 processes (6 old and 1 new), as a result of applying rules 1, 5, 9 each server will have 8 processes. At no time the number of processes on a single server exceeds 9. Submitted Solution: ``` from collections import deque import random class CodeforcesTask566BSolution: def __init__(self): self.result = '' self.n = 0 self.rules = [] def read_input(self): self.n = int(input()) self.rules = [[int(x) for x in input().split(" ")] + [y + 1] for y in range(self.n * 4)] def process_task(self): loads = [4] * self.n random.shuffle(self.rules) to_use = deque(self.rules) order = [] res = True ba = 0 while to_use and res: moving = to_use.popleft() loads[moving[0] - 1] -= 1 if loads[moving[1] - 1] < 9 and loads[moving[2] - 1] < 9 + (1 if moving[2] == moving[3] else 0): ba = 0 loads[moving[1] - 1] += 1 loads[moving[2] - 1] += 1 order.append(moving[3]) else: ba += 1 loads[moving[0] - 1] += 1 to_use.append(moving) if ba > self.n * 12: res = False self.result = "NO" if not res else f"YES\n{' '.join([str(x) for x in order])}" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask566BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
instruction
0
39,108
14
78,216
No
output
1
39,108
14
78,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure. As part of this task, we assume that the social network is 4n processes running on the n servers. All servers are absolutely identical machines, each of which has a volume of RAM of 1 GB = 1024 MB (1). Each process takes 100 MB of RAM on the server. At the same time, the needs of maintaining the viability of the server takes about 100 more megabytes of RAM. Thus, each server may have up to 9 different processes of social network. Now each of the n servers is running exactly 4 processes. However, at the moment of peak load it is sometimes necessary to replicate the existing 4n processes by creating 8n new processes instead of the old ones. More formally, there is a set of replication rules, the i-th (1 ≀ i ≀ 4n) of which has the form of ai β†’ (bi, ci), where ai, bi and ci (1 ≀ ai, bi, ci ≀ n) are the numbers of servers. This means that instead of an old process running on server ai, there should appear two new copies of the process running on servers bi and ci. The two new replicated processes can be on the same server (i.e., bi may be equal to ci) or even on the same server where the original process was (i.e. ai may be equal to bi or ci). During the implementation of the rule ai β†’ (bi, ci) first the process from the server ai is destroyed, then appears a process on the server bi, then appears a process on the server ci. There is a set of 4n rules, destroying all the original 4n processes from n servers, and creating after their application 8n replicated processes, besides, on each of the n servers will be exactly 8 processes. However, the rules can only be applied consecutively, and therefore the amount of RAM of the servers imposes limitations on the procedure for the application of the rules. According to this set of rules determine the order in which you want to apply all the 4n rules so that at any given time the memory of each of the servers contained at most 9 processes (old and new together), or tell that it is impossible. Input The first line of the input contains integer n (1 ≀ n ≀ 30 000) β€” the number of servers of the social network. Next 4n lines contain the rules of replicating processes, the i-th (1 ≀ i ≀ 4n) of these lines as form ai, bi, ci (1 ≀ ai, bi, ci ≀ n) and describes rule ai β†’ (bi, ci). It is guaranteed that each number of a server from 1 to n occurs four times in the set of all ai, and eight times among a set that unites all bi and ci. Output If the required order of performing rules does not exist, print "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes), and in the second line β€” a sequence of 4n numbers from 1 to 4n, giving the numbers of the rules in the order they are applied. The sequence should be a permutation, that is, include each number from 1 to 4n exactly once. If there are multiple possible variants, you are allowed to print any of them. Examples Input 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 1 1 Output YES 1 2 5 6 3 7 4 8 Input 3 1 2 3 1 1 1 1 1 1 1 1 1 2 1 3 2 2 2 2 2 2 2 2 2 3 1 2 3 3 3 3 3 3 3 3 3 Output YES 2 3 4 6 7 8 10 11 12 1 5 9 Note (1) To be extremely accurate, we should note that the amount of server memory is 1 GiB = 1024 MiB and processes require 100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 230 bytes and a mebibyte (MiB) is the amount of RAM of 220 bytes. In the first sample test the network uses two servers, each of which initially has four launched processes. In accordance with the rules of replication, each of the processes must be destroyed and twice run on another server. One of the possible answers is given in the statement: after applying rules 1 and 2 the first server will have 2 old running processes, and the second server will have 8 (4 old and 4 new) processes. After we apply rules 5 and 6, both servers will have 6 running processes (2 old and 4 new). After we apply rules 3 and 7, both servers will have 7 running processes (1 old and 6 new), and after we apply rules 4 and 8, each server will have 8 running processes. At no time the number of processes on a single server exceeds 9. In the second sample test the network uses three servers. On each server, three processes are replicated into two processes on the same server, and the fourth one is replicated in one process for each of the two remaining servers. As a result of applying rules 2, 3, 4, 6, 7, 8, 10, 11, 12 each server would have 7 processes (6 old and 1 new), as a result of applying rules 1, 5, 9 each server will have 8 processes. At no time the number of processes on a single server exceeds 9. Submitted Solution: ``` n = int(input()) comm = [[-1, -1, -1]]*(4*n) load = [4]*(n+1) for i in range(4*n): a, b, c = [int(x) for x in input().split()] for j in range(4): if comm[(a-1)*4+j][0] == -1: comm[(a-1)*4+j] = [a, b, c] break i = 0 consumed = 0 answer = "" while consumed < 4*n: while i < 4*n and comm[i][0] == -1: i += 1 if i >= 4*n: i=0 else: answer += str(i+1) + " " consumed += 1 a = comm[i][0] b = comm[i][1] c = comm[i][2] load[a] -= 1 load[b] += 1 load[c] += 1 if load[a] > 9 or load[b] > 9 or load[c] > 9: print("NO") exit() comm[i][0] = -1 if load[b] > load[c]: i = (b-1)*4 else: i = (c-1)*4 print("YES") print(answer) ```
instruction
0
39,109
14
78,218
No
output
1
39,109
14
78,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure. As part of this task, we assume that the social network is 4n processes running on the n servers. All servers are absolutely identical machines, each of which has a volume of RAM of 1 GB = 1024 MB (1). Each process takes 100 MB of RAM on the server. At the same time, the needs of maintaining the viability of the server takes about 100 more megabytes of RAM. Thus, each server may have up to 9 different processes of social network. Now each of the n servers is running exactly 4 processes. However, at the moment of peak load it is sometimes necessary to replicate the existing 4n processes by creating 8n new processes instead of the old ones. More formally, there is a set of replication rules, the i-th (1 ≀ i ≀ 4n) of which has the form of ai β†’ (bi, ci), where ai, bi and ci (1 ≀ ai, bi, ci ≀ n) are the numbers of servers. This means that instead of an old process running on server ai, there should appear two new copies of the process running on servers bi and ci. The two new replicated processes can be on the same server (i.e., bi may be equal to ci) or even on the same server where the original process was (i.e. ai may be equal to bi or ci). During the implementation of the rule ai β†’ (bi, ci) first the process from the server ai is destroyed, then appears a process on the server bi, then appears a process on the server ci. There is a set of 4n rules, destroying all the original 4n processes from n servers, and creating after their application 8n replicated processes, besides, on each of the n servers will be exactly 8 processes. However, the rules can only be applied consecutively, and therefore the amount of RAM of the servers imposes limitations on the procedure for the application of the rules. According to this set of rules determine the order in which you want to apply all the 4n rules so that at any given time the memory of each of the servers contained at most 9 processes (old and new together), or tell that it is impossible. Input The first line of the input contains integer n (1 ≀ n ≀ 30 000) β€” the number of servers of the social network. Next 4n lines contain the rules of replicating processes, the i-th (1 ≀ i ≀ 4n) of these lines as form ai, bi, ci (1 ≀ ai, bi, ci ≀ n) and describes rule ai β†’ (bi, ci). It is guaranteed that each number of a server from 1 to n occurs four times in the set of all ai, and eight times among a set that unites all bi and ci. Output If the required order of performing rules does not exist, print "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes), and in the second line β€” a sequence of 4n numbers from 1 to 4n, giving the numbers of the rules in the order they are applied. The sequence should be a permutation, that is, include each number from 1 to 4n exactly once. If there are multiple possible variants, you are allowed to print any of them. Examples Input 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 1 1 Output YES 1 2 5 6 3 7 4 8 Input 3 1 2 3 1 1 1 1 1 1 1 1 1 2 1 3 2 2 2 2 2 2 2 2 2 3 1 2 3 3 3 3 3 3 3 3 3 Output YES 2 3 4 6 7 8 10 11 12 1 5 9 Note (1) To be extremely accurate, we should note that the amount of server memory is 1 GiB = 1024 MiB and processes require 100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 230 bytes and a mebibyte (MiB) is the amount of RAM of 220 bytes. In the first sample test the network uses two servers, each of which initially has four launched processes. In accordance with the rules of replication, each of the processes must be destroyed and twice run on another server. One of the possible answers is given in the statement: after applying rules 1 and 2 the first server will have 2 old running processes, and the second server will have 8 (4 old and 4 new) processes. After we apply rules 5 and 6, both servers will have 6 running processes (2 old and 4 new). After we apply rules 3 and 7, both servers will have 7 running processes (1 old and 6 new), and after we apply rules 4 and 8, each server will have 8 running processes. At no time the number of processes on a single server exceeds 9. In the second sample test the network uses three servers. On each server, three processes are replicated into two processes on the same server, and the fourth one is replicated in one process for each of the two remaining servers. As a result of applying rules 2, 3, 4, 6, 7, 8, 10, 11, 12 each server would have 7 processes (6 old and 1 new), as a result of applying rules 1, 5, 9 each server will have 8 processes. At no time the number of processes on a single server exceeds 9. Submitted Solution: ``` n = int(input()) comm = [[-1, -1, -1]]*(4*n) load = [4]*(n+1) for i in range(4*n): a, b, c = [int(x) for x in input().split()] for j in range(4): if comm[(a-1)*4+j][0] == -1: comm[(a-1)*4+j] = [a, b, c] break i = 0 consumed = 0 answer = "" while consumed < 4*n: while i < 4*n and comm[i][0] == -1: i += 1 if i >= 4*n: i=0 else: answer += str(i+1) + " " consumed += 1 a = comm[i][0] b = comm[i][1] c = comm[i][2] load[a] -= 1 load[b] += 1 load[c] += 1 if load[a] > 9 or load[b] > 9 or load[c] > 9: print("NO") exit() comm[i][0] = -1 i = (c-1)*4 print("YES") print(answer) ```
instruction
0
39,110
14
78,220
No
output
1
39,110
14
78,221
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,180
14
78,360
Tags: implementation, math Correct Solution: ``` seatposition=input() rownumber = int(seatposition[0:-1]) colnumber = seatposition[-1] colorder = {'f': 1, 'e':2, 'd':3, 'a':4, 'b':5, 'c': 6} blocknumber = (rownumber-1)//4 detailnumber = rownumber%4 waitnumber = 0 if detailnumber %2 == 0: waitnumber = 7 print(16*blocknumber + waitnumber + colorder[colnumber]) ```
output
1
39,180
14
78,361
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,181
14
78,362
Tags: implementation, math Correct Solution: ``` import sys fin = sys.stdin fout = sys.stdout temp = fin.readline().strip() n = int(temp[:len(temp) - 1]) s = temp[-1] ans = 0 if n % 2 == 0: if n % 4 == 0: ans += ((n - 1) // 2) * 6 + (n - 3) else: ans += (n // 2) * 6 + (n - 1) else: if n % 4 == 1: ans += ((n - 1) // 2) * 6 + (n - 1) else: ans += ((n - 3) // 2) * 6 + (n - 3) if s == 'f': ans += 1 elif s == 'e': ans += 2 elif s == 'd': ans += 3 elif s == 'a': ans += 4 elif s == 'b': ans += 5 elif s == 'c': ans += 6 fout.write(str(ans)) ```
output
1
39,181
14
78,363
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,182
14
78,364
Tags: implementation, math Correct Solution: ``` # You lost the game. s = str(input()) l = s[len(s)-1] r = int(s[:len(s)-1]) - 1 D = {} D["f"] = 1 D["e"] = 2 D["d"] = 3 D["a"] = 4 D["b"] = 5 D["c"] = 6 q = r // 4 b = r % 4 if b % 2 == 0: print(D[l]+16*q) else: print(D[l]+16*q+7) ```
output
1
39,182
14
78,365
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,183
14
78,366
Tags: implementation, math Correct Solution: ``` s = input() p = s[-1] s = int(s[:-1]) ans1 = 0 if p == 'f': ans1 = 1 if p == 'e': ans1 = 2 if p == 'd': ans1 = 3 if p == 'a': ans1 = 4 if p == 'b': ans1 = 5 if p == 'c': ans1 = 6 ans = 16 * ((s - 1) // 4) temp = s while s % 4 != 0: s -= 1 temp -= s s = temp if s == 1 or s == 3: print(ans + ans1) else: print(ans + 6 + 1 + ans1) ```
output
1
39,183
14
78,367
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,184
14
78,368
Tags: implementation, math Correct Solution: ``` from math import * ns = input() n = int(ns[:-1]) s = 'fedabc'.index(ns[-1]) + 1 n1 = n if not n % 4: n1 -= 1 lvl = n1 // 4 ans = lvl * 16 if not n % 2: ans += 7 print(ans + s) ```
output
1
39,184
14
78,369
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,185
14
78,370
Tags: implementation, math Correct Solution: ``` s = input() n, ch = int(s[:-1]), s[-1] D = {'a':4, 'b':5, 'c':6, 'd':3, 'e':2, 'f':1} if n % 4 == 0 or (n+1) % 4 == 0: x = n//2 x = x if x != 0 else 1 res = n-3 + (x-1)*6 + D[ch] else: x = n//2 res = n-1 + (x)*6 + D[ch] print(res) ```
output
1
39,185
14
78,371
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,186
14
78,372
Tags: implementation, math Correct Solution: ``` def get_ans(start): t = (start - 1) // 4 ret = t * 16 if (start - 1) % 4 in (1, 3): ret += 7 return ret s = input() seat = int(s[:-1]) p = s[-1] ans = get_ans(seat) if p == 'f': ans += 0 elif p == 'e': ans += 1 elif p == 'd': ans += 2 elif p == 'a': ans += 3 elif p == 'b': ans += 4 elif p == 'c': ans += 5 ans += 1 print(ans) ```
output
1
39,186
14
78,373
Provide tags and a correct Python 3 solution for this coding contest problem. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
instruction
0
39,187
14
78,374
Tags: implementation, math Correct Solution: ``` s = input() n = int(s[:len(s) - 1]) n -= 1 ans = (n // 4) * 16 n %= 4 if n % 2 == 1: ans += 6 + 1 d = {'a':4,'f':1,'e':2,'d':3,'b':5,'c':6} print(ans + d[s[-1]]) ```
output
1
39,187
14
78,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` #!/usr/bin/env python3 col2num = {'f':1, 'e':2, 'd':3, 'a':4, 'b':5, 'c':6} instr = input() row = int(instr[0:-1]) col = col2num[instr[-1]] print(((row -1)//4)*16 + ((row-1)%2)*7 + col) ```
instruction
0
39,188
14
78,376
Yes
output
1
39,188
14
78,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` s = input() l = s[-1] n = int(s[:-1]) tot = 16 * ((n - 1) // 4) seats = { 'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6, } if n % 2 == 0: tot += 7 tot += seats[l] print (tot) ```
instruction
0
39,189
14
78,378
Yes
output
1
39,189
14
78,379
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` import sys import math m = {'f' : 1, 'e' : 2, 'd' : 3, 'a' : 4, 'b' : 5, 'c' : 6} ns = sys.stdin.readline().split()[0] letter = ns[-1] ns = ns[:-1] row = int(ns) ans = 16 * ((row - 1) // 4) if row % 2 == 0: ans += 7 ans += m[letter] print(ans) ```
instruction
0
39,190
14
78,380
Yes
output
1
39,190
14
78,381
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1} x=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n print(x-1 if (n-1)%4<2 else x-3) ```
instruction
0
39,191
14
78,382
Yes
output
1
39,191
14
78,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` seat= input() number= int(seat[:-1]) letter= seat[-1] time=0 pair="first or second" if number%2 == 0: Q=number/2 if Q%2==0: pair="second" else: pair="first" else: Q=int(number/2 - 0.5) if Q%2==0: pair="first" else: pair="second" if pair == "first": time+= 6 * ((number//2)) + (number//2) else: time+= 6 * ((number//2)-1) + (number//2)-1 order=["f","e","d","a","b","c"] time += order.index(letter) + 1 print(time) ```
instruction
0
39,192
14
78,384
No
output
1
39,192
14
78,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` import math inp = [x for x in input()] array = [4,5,6,3,2,1] row = 0 altili = inp[len(inp)-1] j = len(inp)-2 k = 1 while j >= 0: r = int(inp[j]) * k row += r k *= 10 j -= 1 miktar = math.ceil(row/8)-1 row = row - (miktar*8) opo = miktar * 32 if row == 2 or row == 4: opo += 7 elif row == 5 or row == 7: opo += 16 elif row == 6 or row == 8: opo += 23 opo += array[ord(altili)-ord('a')] print(opo) ```
instruction
0
39,193
14
78,386
No
output
1
39,193
14
78,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` a = list(input()) h = a[len(a) - 1] n = 0 x = 0 if h == 'f': x = 1 elif h == 'e': x = 2 elif h == 'd': x = 3 elif h == 'a': x = 4 elif h == 'b': x = 5 elif h == 'c': x = 6 for i in range(len(a) - 1): n = 10 * n + int(a[i]) - int('0') n = n // 2 + 1 ^ (((n - 1) // 2) % 2) print(7 * (n - 1) + x) ```
instruction
0
39,194
14
78,388
No
output
1
39,194
14
78,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. <image> It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch. Input The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≀ n ≀ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. Output Print one integer β€” the number of seconds Vasya has to wait until he gets his lunch. Examples Input 1f Output 1 Input 2d Output 10 Input 4a Output 11 Input 5e Output 18 Note In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second. In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. Submitted Solution: ``` def seat_to_sec(n): y = n%2 if (n+y)%4 == 0: return seat_to_sec(n-2) else: if y == 0: return 7+seat_to_sec(n-1) else: return (n//4)*16 x = list(input()) a = int(x[0]) y = x[1] y = y.lower() if y == 'f': b = 1 elif y == 'e': b = 2 elif y == 'd': b = 3 elif y == 'a': b = 4 elif y == 'b': b = 5 elif y == 'c': b = 6 else: b = 7 print(seat_to_sec(a)+b) ```
instruction
0
39,195
14
78,390
No
output
1
39,195
14
78,391
Provide tags and a correct Python 3 solution for this coding contest problem. In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest. Input First line of input contains single integer number n (2 ≀ n ≀ 100 000) β€” number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≀ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down. Output Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. Examples Input 3 1 1 Output 1 Input 5 1 2 2 2 Output 3 Input 18 1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4 Output 4 Note In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them. In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
instruction
0
39,323
14
78,646
Tags: dfs and similar, graphs, trees Correct Solution: ``` from collections import deque n = int(input()) parents = [0, 0] + [int(x) for x in input().split()] children = [set([]) for _ in range(n + 1)] for i, p in enumerate(parents): children[p].add(i) q = deque([(0, 1)]) levels = [0 for _ in range(n + 1)] maxLevel = 0 while len(q) > 0: level, node = q.popleft() levels[node] = level maxLevel = max(maxLevel, level) for i in children[node]: q.append((level + 1, i)) levels2 = [0 for _ in range(maxLevel + 1)] for i in levels[1:]: levels2[i] += 1 print(sum([i % 2 for i in levels2])) ```
output
1
39,323
14
78,647