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. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7
instruction
0
13,728
14
27,456
Tags: greedy Correct Solution: ``` n = int(input()) data = list(map(int, input().split())) a = 0 answer = [] start = 1 finish = 1 help_set = set() for i in range(n): if data[i] in help_set: answer.append([start, finish]) help_set = set() start = finish + 1 finish += 1 else: finish += 1 help_set.add(data[i]) if len(answer) == 0: print(-1) else: answer[-1][-1] = n print(len(answer)) for i in range(len(answer)): print(*answer[i]) ```
output
1
13,728
14
27,457
Provide tags and a correct Python 3 solution for this coding contest problem. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7
instruction
0
13,729
14
27,458
Tags: greedy Correct Solution: ``` n = int(input()) index = 1 memory = set() counter = 0 segments = [[0, 0]] for number in input().split(): if number not in memory: memory.add(number) else: counter += 1 segments.append([segments[-1][1] + 1, index]) memory = set() index += 1 segments[-1][1] = n if counter != 0: print(counter) segments.remove([0, 0]) print('\n'.join('{0} {1}'.format(p, q) for (p, q) in segments)) else: print(-1) ```
output
1
13,729
14
27,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` n = int(input()) a = list(map(int, input().split(' '))) ans = [] s = 0 mark = set([a[0]]) for i in range(1, n): if a[i] in mark: mark = set() ans.append([s+1, i+1]) s = i+1 else: mark.add(a[i]) if len(ans) == 0: print(-1) else: ans[-1][1] = n print(len(ans)) for line in ans: print(line[0], line[1]) ```
instruction
0
13,730
14
27,460
Yes
output
1
13,730
14
27,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` n = int(input()) s = input().split() initial_pos = 0 ans = 0 ans_list = [] l = set() for i in range(n): if s[i] in l: ans += 1 ans_list.append([initial_pos+1, i+1]) initial_pos = i+1 l = set() else: l.add(s[i]) if ans == 0: print(-1) else: if not ans_list[-1][1] == n: ans_list[-1][1] = n print(ans) for i in ans_list: print(' '.join(str(e) for e in i)) ```
instruction
0
13,731
14
27,462
Yes
output
1
13,731
14
27,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` #! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2016 missingdays <missingdays@missingdays> # # Distributed under terms of the MIT license. """ """ def good(nums): for num in nums: if nums[num] > 1: return True return False n = int(input()) a = [int(i) for i in input().split()] s = [] l, r = 0, 0 nums = {} for i in range(n): num = a[i] if num in nums: break else: nums[num] = True else: print(-1) exit() nums = {} while r < n: while r < n: num = a[r] if num in nums: r += 1 break else: nums[num] = True r += 1 r -= 1 s.append([l, r]) r += 1 l = r nums = {} length = len(s) last = s[length-1] for i in range(last[0], last[1]+1): num = a[i] if num in nums: print(length) break else: nums[num] = True else: s.pop() s[length-2][1] = n-1 print(length-1) for st in s: for c in st: print(c+1, end=" ") print() ```
instruction
0
13,732
14
27,464
Yes
output
1
13,732
14
27,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` n = int(input()) li = list(map(int,input().split())) s=set() otv=[] l=0 r=-1 for i in range(n): if li[i] in s: otv.append([l+1,i+1]) s = set() l = i+1 r=1 else: s.add(li[i]) if r==-1: print(-1) else: print(len(otv)) otv[len(otv)-1][1]=n for i in otv: print(*i) # Made By Mostafa_Khaled ```
instruction
0
13,733
14
27,466
Yes
output
1
13,733
14
27,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` n = int(input()) a = [k for k in (input()).split(' ')] answer = -1 l = [] dict = {} i = 0 for j in range(len(a)): if dict.get(a[j]): dict = {} answer+=1 l.append(i) l.append(j) i = j+1 else: dict.update({a[j] : 1}) if answer == -1: print(answer) else: print(int(answer+1)) for p in l: print(str(p+1)+' ') ```
instruction
0
13,734
14
27,468
No
output
1
13,734
14
27,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) s=set() ans=[] for i in range(n): if l[i] in s: if ans: ans.append((ans[-1][1]+1,i+1)) else: ans=[(1,i+1)] s=set() else: s.add(l[i]) if ans: print(len(ans)) for i in ans: print(i[0],i[1]) else: print(-1) ```
instruction
0
13,735
14
27,470
No
output
1
13,735
14
27,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl. Output On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Examples Input 5 1 2 3 4 1 Output 1 1 5 Input 5 1 2 3 4 5 Output -1 Input 7 1 2 1 3 1 2 1 Output 2 1 3 4 7 Submitted Solution: ``` n=int(input()) ar=list(map(int,input().split())) s=set() ans=[] p=1 for i in range(len(ar)): if ar[i] not in s: s.add(ar[i]) else: ans.append([p,i+1]) p=i+2 s.clear() if len(ans)!=0 and len(s): ans.append([p,len(ar)]) if len(ans): print(len(ans)) for i in ans: print(i[0],i[1]) else: print(-1) ```
instruction
0
13,736
14
27,472
No
output
1
13,736
14
27,473
Provide a correct Python 3 solution for this coding contest problem. Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message `hoge`; another user replied to it with `fuga`; yet another user also replied to the opening post with `piyo`; someone else replied to the second post (i.e. `fuga`”) with `foobar`; and the fifth user replied to the same post with `jagjag`. The tree of this thread would look like: hoge ├─fuga │ ├─foobar │ └─jagjag └─piyo For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: hoge .fuga ..foobar ..jagjag .piyo Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. Input Input contains a single dataset in the following format: n k_1 M_1 k_2 M_2 : : k_n M_n The first line contains an integer n (1 ≤ n ≤ 1,000), which is the number of posts in the thread. Then 2n lines follow. Each post is represented by two lines: the first line contains an integer k_i (k_1 = 0, 1 ≤ k_i < i for 2 ≤ i ≤ n) and indicates the i-th post is a reply to the k_i-th post; the second line contains a string M_i and represents the message of the i-th post. k_1 is always 0, which means the first post is not replying to any other post, i.e. it is an opening post. Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters. Output Print the given n messages as specified in the problem statement. Sample Input 1 1 0 icpc Output for the Sample Input 1 icpc Sample Input 2 5 0 hoge 1 fuga 1 piyo 2 foobar 2 jagjag Output for the Sample Input 2 hoge .fuga ..foobar ..jagjag .piyo Sample Input 3 8 0 jagjag 1 hogehoge 1 buhihi 2 fugafuga 4 ponyoponyo 5 evaeva 4 nowawa 5 pokemon Output for the Sample Input 3 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi Sample Input 4 6 0 nakachan 1 fan 2 yamemasu 3 nennryou2 4 dannyaku4 5 kouzai11 Output for the Sample Input 4 nakachan .fan ..yamemasu ...nennryou2 ....dannyaku4 .....kouzai11 Sample Input 5 34 0 LoveLive 1 honoka 2 borarara 2 sunohare 2 mogyu 1 eri 6 kasikoi 7 kawaii 8 eriichika 1 kotori 10 WR 10 haetekurukotori 10 ichigo 1 umi 14 love 15 arrow 16 shoot 1 rin 18 nyanyanya 1 maki 20 6th 20 star 22 nishikino 1 nozomi 24 spiritual 25 power 1 hanayo 27 darekatasukete 28 chottomattete 1 niko 30 natsuiro 30 nikkonikkoni 30 sekaino 33 YAZAWA Output for the Sample Input 5 LoveLive .honoka ..borarara ..sunohare ..mogyu .eri ..kasikoi ...kawaii ....eriichika .kotori ..WR ..haetekurukotori ..ichigo .umi ..love ...arrow ....shoot .rin ..nyanyanya .maki ..6th ..star ...nishikino .nozomi ..spiritual ...power .hanayo ..darekatasukete ...chottomattete .niko ..natsuiro ..nikkonikkoni ..sekaino ...YAZAWA Sample Input 6 6 0 2ch 1 1ostu 1 2get 1 1otsu 1 1ostu 3 pgr Output for the Sample Input 6 2ch .1ostu .2get ..pgr .1otsu .1ostu Example Input 1 0 icpc Output icpc
instruction
0
14,097
14
28,194
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: n = I() a = [] e = collections.defaultdict(list) for i in range(n): k = I() l = S() e[k].append(i+1) a.append(l) f = [None] * n def ff(i,d): f[i-1] = 1 r = ['.' * d + a[i-1]] for j in e[i]: r += ff(j,d+1) return r for i in range(n): if f[i]: continue rr += ff(i+1,0) break return '\n'.join(map(str, rr)) print(main()) ```
output
1
14,097
14
28,195
Provide a correct Python 3 solution for this coding contest problem. Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message `hoge`; another user replied to it with `fuga`; yet another user also replied to the opening post with `piyo`; someone else replied to the second post (i.e. `fuga`”) with `foobar`; and the fifth user replied to the same post with `jagjag`. The tree of this thread would look like: hoge ├─fuga │ ├─foobar │ └─jagjag └─piyo For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: hoge .fuga ..foobar ..jagjag .piyo Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. Input Input contains a single dataset in the following format: n k_1 M_1 k_2 M_2 : : k_n M_n The first line contains an integer n (1 ≤ n ≤ 1,000), which is the number of posts in the thread. Then 2n lines follow. Each post is represented by two lines: the first line contains an integer k_i (k_1 = 0, 1 ≤ k_i < i for 2 ≤ i ≤ n) and indicates the i-th post is a reply to the k_i-th post; the second line contains a string M_i and represents the message of the i-th post. k_1 is always 0, which means the first post is not replying to any other post, i.e. it is an opening post. Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters. Output Print the given n messages as specified in the problem statement. Sample Input 1 1 0 icpc Output for the Sample Input 1 icpc Sample Input 2 5 0 hoge 1 fuga 1 piyo 2 foobar 2 jagjag Output for the Sample Input 2 hoge .fuga ..foobar ..jagjag .piyo Sample Input 3 8 0 jagjag 1 hogehoge 1 buhihi 2 fugafuga 4 ponyoponyo 5 evaeva 4 nowawa 5 pokemon Output for the Sample Input 3 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi Sample Input 4 6 0 nakachan 1 fan 2 yamemasu 3 nennryou2 4 dannyaku4 5 kouzai11 Output for the Sample Input 4 nakachan .fan ..yamemasu ...nennryou2 ....dannyaku4 .....kouzai11 Sample Input 5 34 0 LoveLive 1 honoka 2 borarara 2 sunohare 2 mogyu 1 eri 6 kasikoi 7 kawaii 8 eriichika 1 kotori 10 WR 10 haetekurukotori 10 ichigo 1 umi 14 love 15 arrow 16 shoot 1 rin 18 nyanyanya 1 maki 20 6th 20 star 22 nishikino 1 nozomi 24 spiritual 25 power 1 hanayo 27 darekatasukete 28 chottomattete 1 niko 30 natsuiro 30 nikkonikkoni 30 sekaino 33 YAZAWA Output for the Sample Input 5 LoveLive .honoka ..borarara ..sunohare ..mogyu .eri ..kasikoi ...kawaii ....eriichika .kotori ..WR ..haetekurukotori ..ichigo .umi ..love ...arrow ....shoot .rin ..nyanyanya .maki ..6th ..star ...nishikino .nozomi ..spiritual ...power .hanayo ..darekatasukete ...chottomattete .niko ..natsuiro ..nikkonikkoni ..sekaino ...YAZAWA Sample Input 6 6 0 2ch 1 1ostu 1 2get 1 1otsu 1 1ostu 3 pgr Output for the Sample Input 6 2ch .1ostu .2get ..pgr .1otsu .1ostu Example Input 1 0 icpc Output icpc
instruction
0
14,098
14
28,196
"Correct Solution: ``` import sys sys.setrecursionlimit(10000) n=int(input()) a=[] b=[[]for _ in [0]*n] def f(i,x): print('.'*x+a[i]) for j in b[i]: f(j,x+1) for i in range(n): c=int(input()) a+=[input()] if c!=0:b[c-1]+=[i] f(0,0) ```
output
1
14,098
14
28,197
Provide a correct Python 3 solution for this coding contest problem. Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message `hoge`; another user replied to it with `fuga`; yet another user also replied to the opening post with `piyo`; someone else replied to the second post (i.e. `fuga`”) with `foobar`; and the fifth user replied to the same post with `jagjag`. The tree of this thread would look like: hoge ├─fuga │ ├─foobar │ └─jagjag └─piyo For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: hoge .fuga ..foobar ..jagjag .piyo Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. Input Input contains a single dataset in the following format: n k_1 M_1 k_2 M_2 : : k_n M_n The first line contains an integer n (1 ≤ n ≤ 1,000), which is the number of posts in the thread. Then 2n lines follow. Each post is represented by two lines: the first line contains an integer k_i (k_1 = 0, 1 ≤ k_i < i for 2 ≤ i ≤ n) and indicates the i-th post is a reply to the k_i-th post; the second line contains a string M_i and represents the message of the i-th post. k_1 is always 0, which means the first post is not replying to any other post, i.e. it is an opening post. Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters. Output Print the given n messages as specified in the problem statement. Sample Input 1 1 0 icpc Output for the Sample Input 1 icpc Sample Input 2 5 0 hoge 1 fuga 1 piyo 2 foobar 2 jagjag Output for the Sample Input 2 hoge .fuga ..foobar ..jagjag .piyo Sample Input 3 8 0 jagjag 1 hogehoge 1 buhihi 2 fugafuga 4 ponyoponyo 5 evaeva 4 nowawa 5 pokemon Output for the Sample Input 3 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi Sample Input 4 6 0 nakachan 1 fan 2 yamemasu 3 nennryou2 4 dannyaku4 5 kouzai11 Output for the Sample Input 4 nakachan .fan ..yamemasu ...nennryou2 ....dannyaku4 .....kouzai11 Sample Input 5 34 0 LoveLive 1 honoka 2 borarara 2 sunohare 2 mogyu 1 eri 6 kasikoi 7 kawaii 8 eriichika 1 kotori 10 WR 10 haetekurukotori 10 ichigo 1 umi 14 love 15 arrow 16 shoot 1 rin 18 nyanyanya 1 maki 20 6th 20 star 22 nishikino 1 nozomi 24 spiritual 25 power 1 hanayo 27 darekatasukete 28 chottomattete 1 niko 30 natsuiro 30 nikkonikkoni 30 sekaino 33 YAZAWA Output for the Sample Input 5 LoveLive .honoka ..borarara ..sunohare ..mogyu .eri ..kasikoi ...kawaii ....eriichika .kotori ..WR ..haetekurukotori ..ichigo .umi ..love ...arrow ....shoot .rin ..nyanyanya .maki ..6th ..star ...nishikino .nozomi ..spiritual ...power .hanayo ..darekatasukete ...chottomattete .niko ..natsuiro ..nikkonikkoni ..sekaino ...YAZAWA Sample Input 6 6 0 2ch 1 1ostu 1 2get 1 1otsu 1 1ostu 3 pgr Output for the Sample Input 6 2ch .1ostu .2get ..pgr .1otsu .1ostu Example Input 1 0 icpc Output icpc
instruction
0
14,099
14
28,198
"Correct Solution: ``` import sys sys.setrecursionlimit(1010) N = int(input()) src = [] for i in range(N): k = int(input()) s = input() src.append((s,[])) if i == 0: continue src[k-1][1].append(i) def dfs(i,depth): s,ch = src[i] print('.'*depth + s) for c in ch: dfs(c,depth+1) dfs(0,0) ```
output
1
14,099
14
28,199
Provide a correct Python 3 solution for this coding contest problem. Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message `hoge`; another user replied to it with `fuga`; yet another user also replied to the opening post with `piyo`; someone else replied to the second post (i.e. `fuga`”) with `foobar`; and the fifth user replied to the same post with `jagjag`. The tree of this thread would look like: hoge ├─fuga │ ├─foobar │ └─jagjag └─piyo For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: hoge .fuga ..foobar ..jagjag .piyo Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. Input Input contains a single dataset in the following format: n k_1 M_1 k_2 M_2 : : k_n M_n The first line contains an integer n (1 ≤ n ≤ 1,000), which is the number of posts in the thread. Then 2n lines follow. Each post is represented by two lines: the first line contains an integer k_i (k_1 = 0, 1 ≤ k_i < i for 2 ≤ i ≤ n) and indicates the i-th post is a reply to the k_i-th post; the second line contains a string M_i and represents the message of the i-th post. k_1 is always 0, which means the first post is not replying to any other post, i.e. it is an opening post. Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters. Output Print the given n messages as specified in the problem statement. Sample Input 1 1 0 icpc Output for the Sample Input 1 icpc Sample Input 2 5 0 hoge 1 fuga 1 piyo 2 foobar 2 jagjag Output for the Sample Input 2 hoge .fuga ..foobar ..jagjag .piyo Sample Input 3 8 0 jagjag 1 hogehoge 1 buhihi 2 fugafuga 4 ponyoponyo 5 evaeva 4 nowawa 5 pokemon Output for the Sample Input 3 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi Sample Input 4 6 0 nakachan 1 fan 2 yamemasu 3 nennryou2 4 dannyaku4 5 kouzai11 Output for the Sample Input 4 nakachan .fan ..yamemasu ...nennryou2 ....dannyaku4 .....kouzai11 Sample Input 5 34 0 LoveLive 1 honoka 2 borarara 2 sunohare 2 mogyu 1 eri 6 kasikoi 7 kawaii 8 eriichika 1 kotori 10 WR 10 haetekurukotori 10 ichigo 1 umi 14 love 15 arrow 16 shoot 1 rin 18 nyanyanya 1 maki 20 6th 20 star 22 nishikino 1 nozomi 24 spiritual 25 power 1 hanayo 27 darekatasukete 28 chottomattete 1 niko 30 natsuiro 30 nikkonikkoni 30 sekaino 33 YAZAWA Output for the Sample Input 5 LoveLive .honoka ..borarara ..sunohare ..mogyu .eri ..kasikoi ...kawaii ....eriichika .kotori ..WR ..haetekurukotori ..ichigo .umi ..love ...arrow ....shoot .rin ..nyanyanya .maki ..6th ..star ...nishikino .nozomi ..spiritual ...power .hanayo ..darekatasukete ...chottomattete .niko ..natsuiro ..nikkonikkoni ..sekaino ...YAZAWA Sample Input 6 6 0 2ch 1 1ostu 1 2get 1 1otsu 1 1ostu 3 pgr Output for the Sample Input 6 2ch .1ostu .2get ..pgr .1otsu .1ostu Example Input 1 0 icpc Output icpc
instruction
0
14,100
14
28,200
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): n,h,w = LI() x = LI() t = [0 for i in range(w*n+1)] for i in range(n): if not i%2: t[i*w+x[i]] += 1 t[(i+1)*w+x[i]] -= 1 else: t[i*w-x[i]] += 1 t[(i+1)*w-x[i]] -= 1 for i in range(w*n): t[i+1] += t[i] ans = 0 for i in t[:-1]: if i == 0: ans += h print(ans) return #B def B(): def dfs(d,x): for i in range(d): print(".",end = "") print(lis[x]) for y in v[x]: dfs(d+1,y) n = I() v = [[] for i in range(n)] lis = [None for i in range(n)] for i in range(n): k = I() lis[i] = input() if k > 0: v[k-1].append(i) dfs(0,0) return #C def C(): return #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #I def I_(): return #J def J(): return #Solve if __name__ == "__main__": B() ```
output
1
14,100
14
28,201
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,154
14
28,308
Tags: brute force, implementation Correct Solution: ``` n = int(input()) main = [] for i in range(n): arr = list(map(int, input().split())) main.append(arr) outdated = set() for i in range(len(main) - 1): for j in range(i + 1, len(main)): if main[i][0] < main[j][0] and main[i][1] < main[j][1] and main[i][2] < main[j][2]: outdated.add(i) if main[j][0] < main[i][0] and main[j][1] < main[i][1] and main[j][2] < main[i][2]: outdated.add(j) print(min([i for i in range(len(main)) if i not in outdated], key = lambda x: main[x][3]) + 1) ```
output
1
14,154
14
28,309
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,155
14
28,310
Tags: brute force, implementation Correct Solution: ``` import sys n = int(sys.stdin.readline().strip()) t = [] for i in range(n): c = [int(x) for x in sys.stdin.readline().strip().split()] c[3] = -c[3] t.append(c) #print(c) #print(t) id = -1 best = 1e9 for i, c in enumerate(t): ok = True for d in t: less = True for j in range(3): if c[j] >= d[j]: less = False break if less: ok = False break #print(i, ok) if ok and -c[3] < best: best = -c[3] id = i + 1 print(id) ```
output
1
14,155
14
28,311
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,156
14
28,312
Tags: brute force, implementation Correct Solution: ``` n = int(input()) s = [[int(i) for i in input().split()]+[1] for i in range(n)] speed,ram,hdd=0,0,0 num = 1001 for i in range(n): for j in range(n): if s[i][0]>s[j][0] and s[i][1]>s[j][1] and s[i][2]>s[j][2]: s[j][4]=0 for i in range(n): if s[i][4]: if s[i][3]<num: num = s[i][3] ans = i+1 print(ans) ```
output
1
14,156
14
28,313
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,157
14
28,314
Tags: brute force, implementation Correct Solution: ``` a=[] n=int(input()) for i in range(n): s,r,h,c=map(int,input().split()) a.append([s,r,h,c]) ans=-1 for i in range(n): flag=True for j in range(n): if a[i][0]<a[j][0] and a[i][1]<a[j][1] and a[i][2]<a[j][2]: flag=False break if flag: if ans==-1: ans=i else: if a[ans][3]>a[i][3]: ans=i print(ans+1) ```
output
1
14,157
14
28,315
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,158
14
28,316
Tags: brute force, implementation Correct Solution: ``` n=int(input()) a=0 b=0 c=0 g=[] v=[0]*n for _ in range(n): l=list(map(int,input().split())) g.append(l) l=[] for i in range(n): f=0 for j in range(n): if(g[i][1]<g[j][1] and g[i][2]<g[j][2] and g[i][0]<g[j][0]): f=1 break if(f==0): l.append((g[i][3],i+1)) l.sort(key=lambda x:(x[0],x[1])) print(l[0][1]) ```
output
1
14,158
14
28,317
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,159
14
28,318
Tags: brute force, implementation Correct Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) ans = [1] * n for i in range(n): for j in range(n): if all(t[i][k] < t[j][k] for k in range(3)): ans[i] = 0 break k, p = 0, 1001 for i in range(n): if ans[i] and t[i][3] < p: p, k = t[i][3], i print(k + 1) ```
output
1
14,159
14
28,319
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,160
14
28,320
Tags: brute force, implementation Correct Solution: ``` def choosing_laptop(n,specs): index = 0 length = n not_outdated = [] while index < length : sub_index = 0 assign = 1 speed , ram , hdd, cost = specs[index] for speed2,ram2,hdd2, cost2 in specs : if speed < speed2 and ram < ram2 and hdd < hdd2 : assign = 0 break if assign == 1 : not_outdated.append(tuple([cost,index+1])) index += 1 not_outdated.sort(key= lambda x : x[0]) return not_outdated[0][1] n = int(input()) specs = [] for x in range(n) : specs.append(list(map(int,input().split()))) print (choosing_laptop(n,specs)) ```
output
1
14,160
14
28,321
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, * speed, ram, hdd and cost are integers * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz * 256 ≤ ram ≤ 4096 the RAM volume in megabytes * 1 ≤ hdd ≤ 500 is the HDD in gigabytes * 100 ≤ cost ≤ 1000 is price in tugriks All laptops have different prices. Output Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data. Examples Input 5 2100 512 150 200 2000 2048 240 350 2300 1024 200 320 2500 2048 80 300 2000 512 180 150 Output 4 Note In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
instruction
0
14,161
14
28,322
Tags: brute force, implementation Correct Solution: ``` from sys import* input= stdin.readline t=int(input()) l=[] cost=[] for i in range(t): a,b,c,d=map(int,input().split()) l.append([a,b,c]) cost.append(d) for i in range(t): for j in range(t): if(i!=j): if(l[i][0]<l[j][0] and l[i][1]<l[j][1] and l[i][2]<l[j][2]): cost[i]=10000 break print(cost.index(min(cost))+1) ```
output
1
14,161
14
28,323
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,624
14
29,248
Tags: implementation, math Correct Solution: ``` def Swap(a,b): return (b,a) a,b = map(int,input().split()) if a > b: a,b = Swap(a,b) print("%d %d" %(a,(b - a) //2)) ```
output
1
14,624
14
29,249
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,625
14
29,250
Tags: implementation, math Correct Solution: ``` import math n,m=map(int,input().split()) if n>m: print(m,int((n-m)/2)) elif m>n: print(n,int((m-n)/2)) else: print(n,0) ```
output
1
14,625
14
29,251
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,626
14
29,252
Tags: implementation, math Correct Solution: ``` z = [int(s) for s in input().split()] a, b = z[0], z[1] if a > b: print(b, (a - b) // 2) elif a<b: print(a, (b - a) // 2) elif a == b: print(a, 0) ```
output
1
14,626
14
29,253
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,627
14
29,254
Tags: implementation, math Correct Solution: ``` n,m=map(int,input().split(" ")) a=0 if n>=m: a=m else: a=n b=(max(n,m)-a)//2 print(f"{a} {b}") ```
output
1
14,627
14
29,255
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,628
14
29,256
Tags: implementation, math Correct Solution: ``` a, b = map(int, input().split()) first = min(a, b) second = max((a-first)//2, (b-first)//2) print(first, second) ```
output
1
14,628
14
29,257
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,629
14
29,258
Tags: implementation, math Correct Solution: ``` n, m = map(int, input().split()) print(min(n, m), end = ' ') print((max(n, m) - min(n, m)) // 2) ```
output
1
14,629
14
29,259
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,630
14
29,260
Tags: implementation, math Correct Solution: ``` a = input().split() b = int(a[1]) a = int(a[0]) print(min(a,b),abs(a-b)//2) ```
output
1
14,630
14
29,261
Provide tags and a correct Python 3 solution for this coding contest problem. One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. Output Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Examples Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 Note In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
instruction
0
14,631
14
29,262
Tags: implementation, math Correct Solution: ``` def main(b, r): minim = min([b,r]) maxim = max([b,r]) if(b!=r): if ((maxim - minim) % 2 != 0): cols = int((maxim - minim - 1) / 2) else: cols = int((maxim - minim) /2) return ' '.join([str(minim), str(cols)]) else: return ' '.join([str(b), str('0')]) inp = input().split(' ') blue = int(inp[0]) red = int(inp[1]) print(main(blue, red)) ```
output
1
14,631
14
29,263
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,640
14
29,280
Tags: constructive algorithms, implementation Correct Solution: ``` n, k = map(int, input().split()) print(int((((n * (k - 1) + 1)) + ((n - 1) * (n - k + 1)) / 2) * n)) for i in range(n): curr = [] for j in range(n): if j + 1 == k: curr.append((n * (k - 1) + 1) + i * (n - k + 1)) elif j + 1 > k: curr.append((n * (k - 1) + 1) + i * (n - k + 1) + (j + 1 - k)) else: curr.append(i * (k - 1) + j + 1) print(' '.join(map(str, curr))) ```
output
1
14,640
14
29,281
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,641
14
29,282
Tags: constructive algorithms, implementation Correct Solution: ``` sLine = input() sSplit = sLine.split() n = int(sSplit[0]) k = int(sSplit[1]) v = [] for i in range(n) : v.append([]) for j in range(n) : v[i].append(0) x1 = n * n x2 = 1 for i in range(n) : for j in range(n-1, (k-1)-1, -1) : v[i][j] = x1 x1 -= 1 for j in range(0, (k-1), 1) : v[i][j] = x2 x2 += 1 nSum = 0 for i in range(n) : nSum += v[i][k-1] print(nSum) for i in range(n) : for j in range(n) : print(v[i][j], end='') if j == n - 1 : print('') else : print(' ', end='') ```
output
1
14,641
14
29,283
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,642
14
29,284
Tags: constructive algorithms, implementation Correct Solution: ``` n, k = map(int, input().split()) k -= 1 answer = [[0] * n for i in range(n)] cur = 1 for i in range(n): for j in range(k): answer[i][j] = cur cur += 1 for i in range(n): for j in range(k, n): answer[i][j] = cur cur += 1 summa = 0 for i in range(n): summa += answer[i][k] print(summa) for i in range(n): print(*answer[i]) ```
output
1
14,642
14
29,285
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,643
14
29,286
Tags: constructive algorithms, implementation Correct Solution: ``` n, k = map(int, input().split()) a = [] for i in range(1, (n*(k-1)) + 1): a.append(i) a = a[::-1] lst = [] for i in range((n*(k-1)) + 1, (n*n) + 1): lst.append(i) lst = lst[::-1] s = 0 ans = "" for i in range(1, n + 1): for j in range(1, n + 1): if j < k: ans += str(a.pop()) + " " else: if j == k: s += lst[-1] ans += str(lst.pop()) + " " ans += "\n" print(s) print(ans) ```
output
1
14,643
14
29,287
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,645
14
29,290
Tags: constructive algorithms, implementation Correct Solution: ``` n, m = map(int, input().split()) n1, n2 = 1, (m - 1) * n + 1 ans = 0 print(n * (n - 1) // 2 * (n - m + 1) + n2 * n) for i in range(n): j = 0 while j < m - 1: print(n1, end=' ') n1 += 1 j += 1 while j < n: print(n2, end=' ') n2 += 1 j += 1 print() ```
output
1
14,645
14
29,291
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,646
14
29,292
Tags: constructive algorithms, implementation Correct Solution: ``` n,k=map(int,input().split()) ans=((n*n)-(n-k)) test=ans op=[n*n-(n-k)] op2=[] count=[] for i in range(1,n): ans+=test-i*(n-k+1) op.append(test-i*(n-k+1)) print(ans) for i in range(n): count.append(k+i*n) pos=1 j=1 op=sorted(op) #print(op) if n==1 and k==1: print('1') else: if k==1: for i in range(n): print(op[i],end= ' ') for q in range(n-2): print(op[i]+q+1,end= ' ') print(op[i]+n-1) elif k==n: for i in range(n): for q in range(i*(n-1)+1,(i+1)*(n-1)+1): print(q,end=' ') print(op[i]) else: while j<=(k-1)*n: for i in range(k-1): print(j,end=' ') pos+=1 j+=1 #print('pos is',pos) print(op[pos//n],end=' ') now=op[pos//n] pos+=1 for i in range(k+1,n): now+=1 print(now,end=' ') pos+=1 print(now+1) pos+=1 ```
output
1
14,646
14
29,293
Provide tags and a correct Python 3 solution for this coding contest problem. People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied: * every integer from 1 to n2 appears in the table exactly once; * in each row numbers are situated in increasing order; * the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Input 4 1 Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Input 5 3 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
instruction
0
14,647
14
29,294
Tags: constructive algorithms, implementation Correct Solution: ``` n, k = map(int, input().split()) a=[] for i in range(n): a.append([]) for j in range(n): a[i].append(0) c = 1 for i in range(n): for j in range(k - 1): a[i][j] = c c += 1 for i in range(n): for j in range(k - 1, n): a[i][j] = c c += 1 ans = 0 for i in range(n): ans += a[i][k - 1] print(ans) for i in range(n): print (" ".join(map(str, a[i]))) ```
output
1
14,647
14
29,295
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,708
14
29,416
Tags: implementation Correct Solution: ``` #!/bin/python import collections import random import sys n = int(input()) day = 0 for i in range(n): s, d = map(int, input().split()) day = max(day + 1, s) if (day - s) % d != 0: day += d - (day - s) % d print(day) ```
output
1
14,708
14
29,417
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,709
14
29,418
Tags: implementation Correct Solution: ``` r=0 for _ in[0]*int(input()): s,d=map(int,input().split()) r=[(r-s+d)//d*d+s,s][r<s] print(r) ```
output
1
14,709
14
29,419
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,710
14
29,420
Tags: implementation Correct Solution: ``` n = int(input()) s, d = map(int, input().split()) t = s + 1; for i in range(n - 1): s, d = map(int, input().split()) if s >= t: t = s + 1; elif (t - s) % d == 0: t += 1; else: t += d - (t - s) % d + 1; print(t - 1) ```
output
1
14,710
14
29,421
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,711
14
29,422
Tags: implementation Correct Solution: ``` n = int(input()) for i in range(n): si, di = list(map(int, input().split())) if i == 0: sum = si else: if si <= sum: if si + di <= sum: nd = ((sum - (si + di)) // di) + 1 sum = (si + di) + nd * di else:sum = si + di else:sum=si print(sum) ```
output
1
14,711
14
29,423
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,712
14
29,424
Tags: implementation Correct Solution: ``` def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) n = ii() a = [mi() for i in range(n)] p = 0 for i in range(n): s, d = a[i] if s>p: p = s else: q = p - s p = s + d*(q//d + 1) print(p) ```
output
1
14,712
14
29,425
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,713
14
29,426
Tags: implementation Correct Solution: ``` #!/usr/bin/python from math import ceil n = int(input()) c = 1 for _ in range(n): s, d = list(map(int, input().split())) if s >= c: c = s + 1 else: i = ceil((c - s) / d) c = s + i * d + 1 print(c - 1) ```
output
1
14,713
14
29,427
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,714
14
29,428
Tags: implementation Correct Solution: ``` count = 0 for _ in range(int(input())): s,d = map(int,input().split()) if count == 0: count += s else: if s>count: count = s else: if (count-s)%d==0: count += d else: count = s+((count-s)//d+1)*d print(count) ```
output
1
14,714
14
29,429
Provide tags and a correct Python 3 solution for this coding contest problem. It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, .... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples Input 3 2 2 1 2 2 2 Output 4 Input 2 10 1 6 5 Output 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
instruction
0
14,715
14
29,430
Tags: implementation Correct Solution: ``` import math n = int(input().strip()) day = 0 for _ in range(n): day += 1 ai, di = map(int, input().strip().split()) if ai <= day: t = math.ceil((day - ai)/di) day = ai + t * di else: day = ai print(day) ```
output
1
14,715
14
29,431
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,812
14
29,624
"Correct Solution: ``` n, k = map(int, input().split()) s = list(input()) L = [0] R = [] for i, (a, b) in enumerate(zip(s, s[1:])): if (a, b) == ('0', '1'): L.append(i+1) if (a, b) == ('1', '0'): R.append(i) else: R.append(n-1) ans = R[0]-L[0]+1 if s[0] == '0': k -= 1 k = min(k, len(R)-1) for l, r in zip(L, R[k:]): x = r-l+1 if ans < x: ans = x print(ans) ```
output
1
14,812
14
29,625
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,813
14
29,626
"Correct Solution: ``` n,k=map(int,input().split()) s='1'+input() i=0 for j in range(n):k-='10'==s[j:j+2];i+=k<0;k+=k<0and'01'==s[i:i+2] print(n-i) ```
output
1
14,813
14
29,627
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,814
14
29,628
"Correct Solution: ``` import sys def input(): return sys.stdin.readline()[:-1] N,K=map(int,input().split()) S=input() l=[0] t="1" for i in S: if t==i: l[-1]+=1 else: l.append(1) if t=="1": t="0" else: t="1" if t=="0": l.append(0) a=sum(l[:2*K+1]) A=a for i in range(2*K+2,len(l),2): a+=l[i]+l[i-1] a-=l[i-2*K-2]+l[i-2*K-1] A=max(A,a) print(A) ```
output
1
14,814
14
29,629
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,815
14
29,630
"Correct Solution: ``` n,k=map(int,input().split()) s='1'+input() i=j=0 while j<n:k-='10'==s[j:j+2];i+=k<0;k+=k<0and'01'==s[i:i+2];j+=1 print(n-i) ```
output
1
14,815
14
29,631
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,816
14
29,632
"Correct Solution: ``` n,k=map(int,input().split()) s=input() list10 = {'0':[],'1':[]} pre_c='1' c_c = 0 cur_sum = 0 cur_max = 0 for c in s: if c==pre_c: c_c += 1 else: list10[pre_c].append(c_c) cur_sum += c_c c_c = 1 pre_c = c if len(list10['1'])== k+1: cur_max = max(cur_max,cur_sum) cur_sum -= (list10['0'].pop(0) + list10['1'].pop(0)) print(max(cur_max,cur_sum+c_c)) ```
output
1
14,816
14
29,633
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,817
14
29,634
"Correct Solution: ``` N,K=map(int,input().split()) S=list(input()) l = [0,0] if (S[0] == '0') else [0] l += [i for i in range(1,N) if S[i-1] != S[i]] l += [N] if (S[-1] == '1') else [N,N] ll=len(l) p=2*K+1 if ll<p: print(N) else: print(max(l[p+i]-l[i] for i in range(0,ll-p+1,2))) ```
output
1
14,817
14
29,635