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. Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance. One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory. Input The first line consists of an integer n (1 ≤ n ≤ 10^5), the number of events in Amugae's memory. The second line consists of a string of length n describing the events in chronological order. Each character represents: * 'L': A customer arrives from the left entrance. * 'R': A customer arrives from the right entrance. * '0', '1', ..., '9': The customer in room x (0, 1, ..., 9 respectively) leaves. It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (0, 1, ..., 9) is given. Also, all the rooms are initially empty. Output In the only line, output the hotel room's assignment status, from room 0 to room 9. Represent an empty room as '0', and an occupied room as '1', without spaces. Examples Input 8 LLRL1RL1 Output 1010000011 Input 9 L0L0LLRR9 Output 1100000010 Note In the first example, hotel room's assignment status after each action is as follows. * First of all, all rooms are empty. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * L: one more customer from the left entrance. Assignment status is 1110000001. * 1: the customer in room 1 leaves. Assignment status is 1010000001. * R: one more customer from the right entrance. Assignment status is 1010000011. * L: one more customer from the left entrance. Assignment status is 1110000011. * 1: the customer in room 1 leaves. Assignment status is 1010000011. So after all, hotel room's final assignment status is 1010000011. In the second example, hotel room's assignment status after each action is as follows. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * R: one more customer from the right entrance. Assignment status is 1100000011. * 9: the customer in room 9 leaves. Assignment status is 1100000010. So after all, hotel room's final assignment status is 1100000010.
instruction
0
7,654
14
15,308
Tags: brute force, data structures, implementation Correct Solution: ``` n=int(input()) s=input() l=[0]*10 z=9 k=0 i=0 while i<len(s): if s[i]=='L' and l[k]==0: l[k]=1 k+=1 i+=1 elif s[i]=='R' and l[z]==0: l[z]=1 z-=1 i+=1 elif s[i] in '0123456789': x=s[i] l[int(x)]=0 for j in l: if j==0: k=j break j=9 while j>=0: if l[j]==0: z=j break j-=1 i+=1 else: if s[i]=='L' and l[k]==1: k+=1 if s[i]=='R' and l[z]==1: z-=1 print(''.join(map(str, l))) ```
output
1
7,654
14
15,309
Provide tags and a correct Python 3 solution for this coding contest problem. Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance. One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory. Input The first line consists of an integer n (1 ≤ n ≤ 10^5), the number of events in Amugae's memory. The second line consists of a string of length n describing the events in chronological order. Each character represents: * 'L': A customer arrives from the left entrance. * 'R': A customer arrives from the right entrance. * '0', '1', ..., '9': The customer in room x (0, 1, ..., 9 respectively) leaves. It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (0, 1, ..., 9) is given. Also, all the rooms are initially empty. Output In the only line, output the hotel room's assignment status, from room 0 to room 9. Represent an empty room as '0', and an occupied room as '1', without spaces. Examples Input 8 LLRL1RL1 Output 1010000011 Input 9 L0L0LLRR9 Output 1100000010 Note In the first example, hotel room's assignment status after each action is as follows. * First of all, all rooms are empty. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * L: one more customer from the left entrance. Assignment status is 1110000001. * 1: the customer in room 1 leaves. Assignment status is 1010000001. * R: one more customer from the right entrance. Assignment status is 1010000011. * L: one more customer from the left entrance. Assignment status is 1110000011. * 1: the customer in room 1 leaves. Assignment status is 1010000011. So after all, hotel room's final assignment status is 1010000011. In the second example, hotel room's assignment status after each action is as follows. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * R: one more customer from the right entrance. Assignment status is 1100000011. * 9: the customer in room 9 leaves. Assignment status is 1100000010. So after all, hotel room's final assignment status is 1100000010.
instruction
0
7,655
14
15,310
Tags: brute force, data structures, implementation Correct Solution: ``` n=int(input()) s=input() ans=[0]*10 for i in range(n): if s[i]=='L': for j in range(10): if ans[j]==0: ans[j]=1 break elif s[i]=='R': for j in range(9,-1,-1): if ans[j]==0: ans[j]=1 break else: ans[int(s[i])]=0 print(''.join(map(str,ans))) ```
output
1
7,655
14
15,311
Provide tags and a correct Python 3 solution for this coding contest problem. Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance. One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory. Input The first line consists of an integer n (1 ≤ n ≤ 10^5), the number of events in Amugae's memory. The second line consists of a string of length n describing the events in chronological order. Each character represents: * 'L': A customer arrives from the left entrance. * 'R': A customer arrives from the right entrance. * '0', '1', ..., '9': The customer in room x (0, 1, ..., 9 respectively) leaves. It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (0, 1, ..., 9) is given. Also, all the rooms are initially empty. Output In the only line, output the hotel room's assignment status, from room 0 to room 9. Represent an empty room as '0', and an occupied room as '1', without spaces. Examples Input 8 LLRL1RL1 Output 1010000011 Input 9 L0L0LLRR9 Output 1100000010 Note In the first example, hotel room's assignment status after each action is as follows. * First of all, all rooms are empty. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * L: one more customer from the left entrance. Assignment status is 1110000001. * 1: the customer in room 1 leaves. Assignment status is 1010000001. * R: one more customer from the right entrance. Assignment status is 1010000011. * L: one more customer from the left entrance. Assignment status is 1110000011. * 1: the customer in room 1 leaves. Assignment status is 1010000011. So after all, hotel room's final assignment status is 1010000011. In the second example, hotel room's assignment status after each action is as follows. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * R: one more customer from the right entrance. Assignment status is 1100000011. * 9: the customer in room 9 leaves. Assignment status is 1100000010. So after all, hotel room's final assignment status is 1100000010.
instruction
0
7,656
14
15,312
Tags: brute force, data structures, implementation Correct Solution: ``` n = int(input()) D = [0] * 10 S = input() for i in range(len(S)): if S[i] in ['L', 'R']: if S[i] == 'L': for j in range(10): if D[j] == 0: D[j] = 1 break else: for j in range(9, -1, -1): if D[j] == 0: D[j] = 1 break else: k = int(S[i]) D[k] = 0 print(''.join(map(str, D))) ```
output
1
7,656
14
15,313
Provide tags and a correct Python 3 solution for this coding contest problem. Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance. One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory. Input The first line consists of an integer n (1 ≤ n ≤ 10^5), the number of events in Amugae's memory. The second line consists of a string of length n describing the events in chronological order. Each character represents: * 'L': A customer arrives from the left entrance. * 'R': A customer arrives from the right entrance. * '0', '1', ..., '9': The customer in room x (0, 1, ..., 9 respectively) leaves. It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (0, 1, ..., 9) is given. Also, all the rooms are initially empty. Output In the only line, output the hotel room's assignment status, from room 0 to room 9. Represent an empty room as '0', and an occupied room as '1', without spaces. Examples Input 8 LLRL1RL1 Output 1010000011 Input 9 L0L0LLRR9 Output 1100000010 Note In the first example, hotel room's assignment status after each action is as follows. * First of all, all rooms are empty. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * L: one more customer from the left entrance. Assignment status is 1110000001. * 1: the customer in room 1 leaves. Assignment status is 1010000001. * R: one more customer from the right entrance. Assignment status is 1010000011. * L: one more customer from the left entrance. Assignment status is 1110000011. * 1: the customer in room 1 leaves. Assignment status is 1010000011. So after all, hotel room's final assignment status is 1010000011. In the second example, hotel room's assignment status after each action is as follows. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again. * 0: the customer in room 0 leaves. Assignment status is 0000000000. * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. * L: one more customer from the left entrance. Assignment status is 1100000000. * R: one more customer from the right entrance. Assignment status is 1100000001. * R: one more customer from the right entrance. Assignment status is 1100000011. * 9: the customer in room 9 leaves. Assignment status is 1100000010. So after all, hotel room's final assignment status is 1100000010.
instruction
0
7,657
14
15,314
Tags: brute force, data structures, implementation Correct Solution: ``` n=int(input()) l=list(input()) r=[0]*10 for i in range(n): if l[i]=='L': for j in range(10): if r[j]==0: r[j]=1 break elif l[i]=='R': for j in range(9,-1,-1): if r[j]==0: r[j]=1 break else: r[int(l[i])]=0 r=list(map(str,r)) a=''.join(r) print(a) ```
output
1
7,657
14
15,315
Provide tags and a correct Python 3 solution for this coding contest problem. There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise. Input The first line of input contains integer n denoting the number of psychos, (1 ≤ n ≤ 105). In the second line there will be a list of n space separated distinct integers each in range 1 to n, inclusive — ids of the psychos in the line from left to right. Output Print the number of steps, so that the line remains the same afterward. Examples Input 10 10 9 7 8 6 5 3 4 2 1 Output 2 Input 6 1 2 3 4 5 6 Output 0 Note In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1] → [10 8 4] → [10]. So, there are two steps.
instruction
0
7,883
14
15,766
Tags: data structures, implementation Correct Solution: ``` n = int(input()) aa = list(map(int,input().split())) live = [] ans=0 for i in range(n-1,-1,-1): c = 0 while len(live)!=0 and live[-1][0]<aa[i]: c = max(c+1,live[-1][1]) live.pop() if c>ans: ans =c live.append((aa[i],c)) print(ans) ```
output
1
7,883
14
15,767
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,903
14
15,806
Tags: implementation Correct Solution: ``` #def convert(x): x = str(x); x = x.replace(',', ''); x = x.replace('{', ''); x = x.replace('}', ''); return [int(s) for s in x.split()] set_, hel, min_, max_ = map(int, input().split());ll = [int(x) for x in input().split()]; Err = 0 ko = [];ko.append(min_);ko.append(max_) for i in range(len(ll)): if ll[i] == min_:continue elif ll[i] == max_:continue elif ll[i]<min_:Err=2 elif ll[i]>max_:Err=2 elif min_<=ll[i]<=max_:ko.append(ll[i]) elif set_ < len(ko):Err=2 else:Err=2 if Err>=set_: print('Incorrect') exit() elif Err == 2: print('Incorrect') exit() if set_ < len(ko):Err=2 if Err>=set_: print('Incorrect') exit() elif Err == 2: print('Incorrect') exit() print('Correct') ''' 3 2 1 5 1 6 ''' ```
output
1
7,903
14
15,807
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,904
14
15,808
Tags: implementation Correct Solution: ``` n,m,minn,maxx=map(int,input().split()) L=list(map(int,input().split())) r=0 if(minn not in L): L+=[minn] r+=1 if(maxx not in L): L+=[maxx] r+=1 valid=True for i in range(m): if(L[i]<minn): valid=False if(L[i]>maxx): valid=False if(r>n-m or not valid): print("Incorrect") else: print("Correct") ```
output
1
7,904
14
15,809
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,905
14
15,810
Tags: implementation Correct Solution: ``` (n, m, mi, mx) = map(int, input().split()) a = list(map(int, input().split())) a.sort() if a[0]!=mi: m += 1 if a[-1]!=mx: m += 1 if a[0]<mi: m += n+1 if a[-1]>mx: m += n+1 print(['Incorrect', 'Correct'][m<=n]) ```
output
1
7,905
14
15,811
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,906
14
15,812
Tags: implementation Correct Solution: ``` n, m, minn, maxx = map(int, input().split()) a = sorted(list(map(int, input().split()))) cnt = 0 if minn != a[0]: cnt += 1 if maxx != a[-1]: cnt += 1 if maxx < a[-1]: cnt += 10000000000000000000 if minn > a[0]: cnt += 10000000000000000000 if n - m >= cnt: print("Correct") else: print("Incorrect") ```
output
1
7,906
14
15,813
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,907
14
15,814
Tags: implementation Correct Solution: ``` n, m, mi, ma = map(int, input().split()) t = list(map(int, input().split())) mit = min(t) mat = max(t) if (mi <= mit and ma >= mat) and (n - m >= 2 or (n - m >= 1 and (mit == mi or mat == ma)) or (mit == mi and mat == ma)): print('Correct') else: print('Incorrect') ```
output
1
7,907
14
15,815
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,908
14
15,816
Tags: implementation Correct Solution: ``` #!/usr/bin/python import re import inspect from sys import argv, exit def rstr(): return input() def rstrs(splitchar=' '): return [i for i in input().split(splitchar)] def rint(): return int(input()) def rints(splitchar=' '): return [int(i) for i in rstrs(splitchar)] def varnames(obj, namespace=globals()): return [name for name in namespace if namespace[name] is obj] def pvar(var, override=False): prnt(varnames(var), var) def prnt(*args, override=False): if '-v' in argv or override: print(*args) # Faster IO pq = [] def penq(s): if not isinstance(s, str): s = str(s) pq.append(s) def pdump(): s = ('\n'.join(pq)).encode() os.write(1, s) if __name__ == '__main__': timesteps, ast, mn, mx = rints() to_add = timesteps - ast asts = rints() for t in asts: if t < mn or t > mx: print('Incorrect') exit(0) if mn not in asts: if to_add == 0: print('Incorrect') exit(0) else: to_add -= 1 if mx not in asts: if to_add == 0: print('Incorrect') exit(0) else: to_add -= 1 print('Correct') ```
output
1
7,908
14
15,817
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,909
14
15,818
Tags: implementation Correct Solution: ``` n,m,mi,ma=map(int,input().split()) k=list(map(int,input().split())) if n-m>1 and min(k)>=mi and max(k)<=ma: print("Correct") elif n-m==1 and (min(k)==mi and max(k)<=ma) or (min(k)>=mi and max(k)==ma): print("Correct") else: print("Incorrect") ```
output
1
7,909
14
15,819
Provide tags and a correct Python 3 solution for this coding contest problem. Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. Input The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. Output If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Examples Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect Note In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
instruction
0
7,910
14
15,820
Tags: implementation Correct Solution: ``` n, m, mmin, mmax = map(int, input().split()) s = list(map(int, input().split())) s = sorted(s) if s[0] < mmin or s[m - 1] > mmax: print("Incorrect") elif s[0] == mmin and s[m - 1] == mmax: print("Correct") elif s[0] != mmin and s[m - 1] != mmax: if n - m < 2: print("Incorrect") else: print("Correct") elif s[0] != mmin or s[m - 1] != mmax: if n - m < 1: print("Incorrect") else: print("Correct") ```
output
1
7,910
14
15,821
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,047
14
16,094
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` import sys import math import itertools n = int(input()) l = n.bit_length() A = [float('inf')] * n for i in range(l): digits = map(lambda x: (x>>i)&1, range(1, n+1)) question = list(filter(lambda x: (x>>i)&1, range(1, n+1))) print(len(question)) print(' '.join(map(str, question))) sys.stdout.flush() answer1 = [int(x) for x in input().split()] question = list(filter(lambda x: not (x>>i)&1, range(1, n+1))) print(len(question)) print(' '.join(map(str, question))) sys.stdout.flush() answer2 = [int(x) for x in input().split()] for x, d in enumerate(digits): A[x] = min(A[x], answer2[x]) if d else min(A[x], answer1[x]) print(-1) print(' '.join(map(str, A))) sys.stdout.flush() ```
output
1
8,047
14
16,095
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,048
14
16,096
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` inf = 10 ** 10 n = int(input()) m = 1 while not (n < 2 ** m): m += 1 u = [] v = [] for i in range(m): u.append([]) v.append([]) for j in range(n): if j & (1 << i): u[i].append(j+1) else: v[i].append(j+1) s = [] t = [] for i in range(m): if len(u[i]) == 0: values = [inf] * n else: line = ' '.join(map(str, u[i])) print(len(u[i])) print(line, flush=True) values = list(map(int, input().split())) s.append(values) for i in range(m): if len(v[i]) == 0: values = [inf] * n else: line = ' '.join(map(str, v[i])) print(len(v[i])) print(line, flush=True) values = list(map(int, input().split())) t.append(values) res = [] for j in range(n): r = inf for i in range(m): if j & (1 << i): r = min(r, t[i][j]) else: r = min(r, s[i][j]) res.append(r) print(-1, flush=True) line = ' '.join(map(str, res)) print(line, flush=True) ```
output
1
8,048
14
16,097
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,049
14
16,098
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` import sys n = int(input()) MAX = 2000 * 1000 * 1000 res = [MAX] * n k = 1 while k < n: x = [0] * n output = [] sz = 0 for i in range(0, n, 2 * k): for j in range(0, min(n - i, k)): output.append(i + j + 1) sz += 1 #print(i + j + 1, end = ' ') x[i + j] = 1 print(sz) print(' '.join(map(str, output))) sys.stdout.flush() a = list(map(int, input().split())) for i in range(len(a)): if a[i] != 0 or x[i] == 0: res[i] = min(res[i], a[i]) x = [0] * n output = [] sz = 0 for i in range(k, n, 2 * k): for j in range(0, min(n - i, k)): output.append(i + j + 1) #print(i + j + 1, end = ' ') x[i + j] = 1 sz += 1 print(sz) print(' '.join(map(str, output))) sys.stdout.flush() a = list(map(int, input().split())) for i in range(len(a)): if a[i] != 0 or x[i] == 0: res[i] = min(res[i], a[i]) k *= 2 print(-1) for i in range(n): if res[i] != MAX: print(res[i], end = ' ') else: print(0, end = ' ') print() sys.stdout.flush() # 0 0 0 0 0 # 1 0 2 3 1 # 1 2 0 1 0 # 5 5 5 0 5 # 2 3 4 5 0 ```
output
1
8,049
14
16,099
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,050
14
16,100
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` import sys n = int(input()) MAX = 2000 * 1000 * 1000 res = [MAX] * n k = 1 while k < n: x = [0] * n output = [] sz = 0 for i in range(0, n, 2 * k): for j in range(0, min(n - i, k)): output.append(i + j + 1) sz += 1 #print(i + j + 1, end = ' ') x[i + j] = 1 print(sz, end = ' ') print(' '.join(map(str, output))) sys.stdout.flush() a = list(map(int, input().split())) for i in range(len(a)): if a[i] != 0 or x[i] == 0: res[i] = min(res[i], a[i]) x = [0] * n output = [] sz = 0 for i in range(k, n, 2 * k): for j in range(0, min(n - i, k)): output.append(i + j + 1) #print(i + j + 1, end = ' ') x[i + j] = 1 sz += 1 print(sz, end = ' ') print(' '.join(map(str, output))) sys.stdout.flush() a = list(map(int, input().split())) for i in range(len(a)): if a[i] != 0 or x[i] == 0: res[i] = min(res[i], a[i]) k *= 2 print(-1) for i in range(n): if res[i] != MAX: print(res[i], end = ' ') else: print(0, end = ' ') print() sys.stdout.flush() # 0 0 0 0 0 # 1 0 2 3 1 # 1 2 0 1 0 # 5 5 5 0 5 # 2 3 4 5 0 ```
output
1
8,050
14
16,101
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,051
14
16,102
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` from sys import stdout n = int(input()) ans = [10**10] * n th = 1 while th < n: ask = [i % (2*th) < th for i in range(n)] for _ in range(2): inds = [key for key, value in enumerate(ask) if value] print(len(inds)) print(' '.join([str(i+1) for i in inds])) stdout.flush() reply = list(map(int, input().split(' '))) ans = [ans[i] if ask[i] else min(ans[i], reply[i]) for i in range(n)] ask = [not v for v in ask] th *= 2 print(-1) print(' '.join(map(str, ans))) stdout.flush() ```
output
1
8,051
14
16,103
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,052
14
16,104
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` import sys n = int(input()) mn = [float('inf') for _ in range(n)] ln = len(bin(n)) - 3 cnt = 0 for bit in range(ln, -1, -1): query = [] inv_query = [] for i in range(1, n + 1): if i & (1<<bit): query.append(i) else: inv_query.append(i) print(len(query)) print(' '.join(map(str, query))) sys.stdout.flush() ans = list(map(int, input().split())) for i in inv_query: mn[i - 1] = min(mn[i - 1], ans[i - 1]) print(len(inv_query)) print(' '.join(map(str, inv_query))) sys.stdout.flush() ans = list(map(int, input().split())) for i in query: mn[i - 1] = min(mn[i - 1], ans[i - 1]) print(-1) print(' '.join(map(str, mn))) sys.stdout.flush() ```
output
1
8,052
14
16,105
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,053
14
16,106
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` n = int(input().strip()) import math import sys factor = 1 each_row_min = [10000000000]*n for i in range(int(math.log(n, 2))+1): if factor >= n: break mask = [] comp_mask = [] for j in range(n): if (j//factor)%2 == 0: mask.append(j) else: comp_mask.append(j) print(len(mask)) print(' '.join([str(x+1) for x in mask])) sys.stdout.flush() results = [int(x) for x in input().split()] for row, rowmin in enumerate(results): if row not in mask: each_row_min[row] = min(each_row_min[row], rowmin) #comp mask = comp_mask print(len(mask)) print(' '.join([str(x+1) for x in mask])) sys.stdout.flush() results = [int(x) for x in input().split()] for row, rowmin in enumerate(results): if row not in mask: each_row_min[row] = min(each_row_min[row], rowmin) factor*=2 print(-1) print(' '.join(str(x) for x in each_row_min)) sys.stdout.flush ```
output
1
8,053
14
16,107
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and columns are labeled from 1 to n. The matrix entries are between 0 and 109. In addition, Mi, i = 0 for all valid i. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each i, you must find <image>. To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {w1, w2, ..., wk}, with 1 ≤ k ≤ n. Hongcow will respond with n integers. The i-th integer will contain the minimum value of min1 ≤ j ≤ kMi, wj. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer - 1 on its own line, then n integers on the next line. The i-th integer should be the minimum value in the i-th row of the matrix, excluding the i-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get Wrong Answer verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of k in your question does not lie in the range from 1 to n, inclusive. * Your final answer is not correct. You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). Input The first line of input will contain a single integer n (2 ≤ n ≤ 1, 000). Output To print the final answer, print out the string -1 on its own line. Then, the next line should contain n integers. The i-th integer should be the minimum value of the i-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! Interaction To ask a question, print out a single integer k on its own line, denoting the size of your subset. Then, the next line should contain k integers w1, w2, ... wk. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with n integers. The i-th integer in this line represents the minimum value of Mi, wj where j is between 1 and k. You may only ask a question at most 20 times, otherwise, you will get Wrong Answer. To flush you can use (just after printing an integer and end-of-line): * fflush(stdout) in C++; * System.out.flush() in Java; * stdout.flush() in Python; * flush(output) in Pascal; * See the documentation for other languages. Hacking To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. Examples Input 3 0 0 0 2 7 0 0 0 4 3 0 8 0 5 4 Output 3 1 2 3 1 3 2 1 2 1 2 1 1 -1 2 5 4 Input 2 0 0 0 0 Output 1 2 1 1 -1 0 0 Note In the first sample, Hongcow has the hidden matrix [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
instruction
0
8,054
14
16,108
Tags: bitmasks, divide and conquer, interactive Correct Solution: ``` from sys import stdout n = int(input()) ans = [10**10] * n th = 1 while th < n: ask = [i % (2*th) < th for i in range(n)] for _ in range(2): inds = [key for key, value in enumerate(ask) if value] print(len(inds)) print(' '.join([str(i+1) for i in inds])) stdout.flush() reply = list(map(int, input().split(' '))) ans = [ans[i] if ask[i] else min(ans[i], reply[i]) for i in range(n)] ask = [not v for v in ask] th *= 2 print(-1) print(' '.join(map(str, ans))) stdout.flush() # Made By Mostafa_Khaled ```
output
1
8,054
14
16,109
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,067
14
16,134
Tags: constructive algorithms, greedy Correct Solution: ``` names = [chr(i + 65) + chr(j + 97) for i in range(26) for j in range(26)] n, m = map(int, input().split()) ans = names[:m - 1] j = m - 1 k = 0 for i in input().split(): if i == "YES": ans.append(names[j]) j += 1 else: ans.append(ans[k]) k += 1 print(" ".join(ans)) ```
output
1
8,067
14
16,135
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,068
14
16,136
Tags: constructive algorithms, greedy Correct Solution: ``` import string n, k = list(map(int, input().split())) conds = list(map(str, input().split())) names = list() for i in range(n): names.append(string.ascii_uppercase[i % 26] + string.ascii_lowercase[i // 26]) for j in range(n - k + 1): if conds[j] == "YES": pass else: names[j + k - 1] = names[j] print(*names) ```
output
1
8,068
14
16,137
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,069
14
16,138
Tags: constructive algorithms, greedy Correct Solution: ``` import math, sys, itertools def main(): n,k = map(int, input().split()) lst = input().split() d = [] it = 0 itd = 0 for i in range(k): if (it>25): itd+=1 it = 0 d.append(chr(65+itd)+chr(97+it)) it+=1 ans = [] for i in range(k-1): ans.append(d.pop()) for i in range(k-1,n): if lst[i-(k-1)]=="NO": ans.append(ans[i-(k-1)]) else: ans.append(d.pop()) d.append(ans[i-(k-1)]) for i in range(n): print(ans[i], end=' ') print() if __name__=="__main__": main() ```
output
1
8,069
14
16,139
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,070
14
16,140
Tags: constructive algorithms, greedy Correct Solution: ``` def ntoname(num): c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" l = "abcdefghijklmnopqrstuvwxyz" na = c[num%26] num //= 26 while num: na += l[num%26] num //= 26 return na n, k = map(int, input().split()) L = [True if i == 'YES' else False for i in input().split()] ids = [i for i in range(n)] for i in range(len(L)): if not L[i]: ids[i+k-1] = ids[i] print(*map(ntoname, ids)) ```
output
1
8,070
14
16,141
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,071
14
16,142
Tags: constructive algorithms, greedy Correct Solution: ``` names = list("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Ab Bb Cb Db Eb Fb Gb Hb Ib Jb Kb Lb Mb Nb Ob Pb Qb Rb Sb Tb Ub Vb Wb Xb Gh Rg Df".split()) n, k = map(int, input().split()) A = list(input().split()) find = False ans = [0] * n for i in range(n - k + 1): s = A[i] if find: if s == "YES": c = 0 while (names[c] in ans[i:]): c += 1 ans[i + k - 1] = names[c] else: ans[i + k - 1] = ans[i] else: if s == "NO": ans[i] = names[0] else: now = i for j in range(k): ans[now] = names[j] now += 1 find = True if not find: for i in range(n - k + 1, n): ans[i] = names[0] print(" ".join(ans)) ```
output
1
8,071
14
16,143
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,072
14
16,144
Tags: constructive algorithms, greedy Correct Solution: ``` #===========Template=============== from io import BytesIO, IOBase from math import sqrt import sys,os from os import path inpl=lambda:list(map(int,input().split())) inpm=lambda:map(int,input().split()) inpi=lambda:int(input()) inp=lambda:input() rev,ra,l=reversed,range,len P=print BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def input(): return sys.stdin.readline().rstrip("\r\n") def B(n): return bin(n).replace("0b","") def factors(n): arr=[] for i in ra(2,int(sqrt(n))+1): if n%i==0: arr.append(i) if i*i!=n: arr.append(int(n/i)) return arr def dfs(arr,n): pairs=[[i+1] for i in ra(n)] vis=[0]*(n+1) for i in ra(l(arr)): pairs[arr[i][0]-1].append(arr[i][1]) pairs[arr[i][1]-1].append(arr[i][0]) comp=[] for i in ra(n): stack=[pairs[i]] temp=[] if vis[stack[-1][0]]==0: while len(stack)>0: if vis[stack[-1][0]]==0: temp.append(stack[-1][0]) vis[stack[-1][0]]=1 s=stack.pop() for j in s[1:]: if vis[j]==0: stack.append(pairs[j-1]) else: stack.pop() comp.append(temp) return comp #=========I/p O/p ========================================# from bisect import bisect_left as bl from bisect import bisect_right as br import sys,operator,math,operator from collections import Counter if(path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") import random #==============To chaliye shuru krte he ====================# n,k=inpm() li=input().split() le=len(li) arr=[0]*51 c=65 ans=[0]*n for i in ra(1,27): arr[i]=chr(c) c+=1 c=65 for i in ra(27,51): arr[i]=chr(c)+chr(97) c+=1 for i in ra(le): if li[i]=="NO":li[i]=0 else:li[i]=1 if li[0]==0: ans[0]=1 for i in ra(1,k): ans[i]=i else: for i in ra(k):ans[i]=i+1 for i in ra(1,le): if li[i]==0: ans[i+k-1]=ans[i] else: for j in ra(1,51): if j not in ans[i:i+k-1]: ans[i+k-1]=j break for i in ra(n): P(arr[ans[i]],end=" ") ```
output
1
8,072
14
16,145
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,073
14
16,146
Tags: constructive algorithms, greedy Correct Solution: ``` from sys import stdin, stdout import string n,k = map(int, stdin.readline().rstrip().split()) YesNoList = stdin.readline().rstrip().split() nameList = list(string.ascii_uppercase) + ['A'+letter for letter in string.ascii_lowercase] answerList=[] nl=0 yn=0 if YesNoList.count('YES')==0: answerList=list('A'*n) else: while YesNoList[yn]=='NO': answerList.append(nameList[nl]) yn+=1 for _ in range(k): answerList.append(nameList[nl]) nl+=1 yn+=1 nl-=1 while yn<n-k+1: if YesNoList[yn]=='YES': nl+=1 answerList.append(nameList[nl]) else: answerList.append(answerList[yn]) yn+=1 print(' '.join(answerList)) ```
output
1
8,073
14
16,147
Provide tags and a correct Python 3 solution for this coding contest problem. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".
instruction
0
8,074
14
16,148
Tags: constructive algorithms, greedy Correct Solution: ``` #import time #startTime = time.time() MAS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] def generateName(num): return MAS[num%8] + MAS[int(num/8)].lower() n, k = [int(i) for i in input().split()] mas = [i for i in input().split()] names = [generateName(i) for i in range(n)] for i in range(n-k+1): if mas[i] == 'NO': names[i+k-1] = names[i] print(' '.join(names)) #print('----------%s sec----------' % (time.time() - startTime)) ```
output
1
8,074
14
16,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` n,k=map(int,input().split()) ########### s=[] name=['']*n ptr=0 yesno=[] for i in range(26): s.append(str(chr(65+i))) for i in range(26): s.append(str(chr(65+i))+'a') ########### def f(x): global ptr global name for i in range(x,x+k): if(name[i]==''): name[i]=s[ptr] ptr=ptr+1 l=[] yesno=list(input().split()) #print(yesno) for i in range(n-k+1): if(yesno[i]=='YES'): f(i) #print(name) for i in range(n-k+1): if(yesno[i]=='NO' and i==0): f(i) name[i]=name[i+1] elif(yesno[i]=='NO'): name[i+k-1]=name[i] for i in name: print(i," ",end='') ```
instruction
0
8,075
14
16,150
Yes
output
1
8,075
14
16,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` n, k = map(int, input().split()) sld = input().split() ls = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] names = [str(ls[i // len(ls)]).upper() + ls[i % len(ls)] for i in range(55)] cur = k ans = names[:(k - 1)] for s in sld: if s == 'NO': ans.append(ans[-(k - 1)]) else: ans.append(names[cur]) cur += 1 print(*ans) ```
instruction
0
8,076
14
16,152
Yes
output
1
8,076
14
16,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` names = [chr(ord('A') + i) for i in range(26)] names += ['A' + chr(ord('a') + i) for i in range(26)] n, k = map(int, input().split()) a = input().split() for i, a_i in enumerate(a): if a_i == 'NO': names[i+k-1] = names[i] print(' '.join(names[:n])) ```
instruction
0
8,077
14
16,154
Yes
output
1
8,077
14
16,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` from collections import Counter n, k = map(int, input().split()) arr = input().split() ans = ['a' for _ in range(n)] a = 'b' for i in range(n-k+1): if arr[i] == 'YES': for j in range(i, i+k): if ans[j] == 'a': ans[j] = str(a) if a == 'z': a = 'aa' else: if len(a) == 1: a = chr(ord(a)+1) else: a = a[0] + chr(ord(a[1])+1) for i in range(n-k+1): if arr[i] == 'NO': c = Counter(ans[i:i+k]) for x in c: if c[x] >= 2: break else: x = i+k-1 y = i ans[x] = ans[y] ans = ['A'+x for x in ans] print(*ans) ```
instruction
0
8,078
14
16,156
Yes
output
1
8,078
14
16,157
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` name = ["A","B","C","D","E","F","G","H","I","j","k","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","Aa","Ba","Ca","Da","Ea","Fa","Ga","Ha","Ia","ja","ka","La","Ma","Na","Oa","Pa","Qa","Ra","Sa","Ta","Ua","Va","Wa","Xa","Ya","Za"] n,k = map(int,input().split()) a=list(map(str,input().split())) l = [name[i] for i in range(k-1)] ans = [name[i] for i in range(k-1)] j=k-1 o=k-1 for i in range(n-k+1): l.append(name[o]) o+=1 if a[i]=="YES": ans.append(name[j]) j+=1 else: x=l.pop(0) ans.append(x) print(*ans) ```
instruction
0
8,079
14
16,158
No
output
1
8,079
14
16,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` def numToLet(n): s = "" s += chr(((n+1)%26)+65) n -= n%26 if n > 0: s += 'A' return s s = input().split() n = int(s[0]) k = int(s[1]) isValid = [False]*(n-k+1) names = [-1]*n s = input().split() for i in range(n-k+1): isValid[i] = True if s[i] == "YES" else False if isValid[i]: for j in range(i, i+k): if names[j] == -1: for c in range(50): if c not in names[:i+k]: names[j] = c break for i in range(n): if names[i] == -1: for j in range(i-k, i+k): if j >= 0 and j < n and names[j] != -1: names[i] = names[j] if names[i] == -1: names[i] = 0 for i in range(len(names)-1): print(numToLet(names[i]), end = " ") print(numToLet(names[-1])) ```
instruction
0
8,080
14
16,160
No
output
1
8,080
14
16,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` n, k = map(int, input().split()) s = input().split() d = [] for i in range(26): for j in range(26): d.append(chr(i + ord('a')).upper() + chr(j + ord('a'))) ans = ['Zzz'] * n cnt = 0 for i in range(n - k + 1): if s[i] == 'YES': for j in range(k): ans[i + j] = d[cnt] cnt += 1 for i in range(n - k + 1): if s[i] == 'NO': ans[i] = ans[i + k - 1] print(" ".join(ans)) ```
instruction
0
8,081
14
16,162
No
output
1
8,081
14
16,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO". * The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise). * The string s2 describes a group of soldiers 2 through k + 1. * And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. Input The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise. Output Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Examples Input 8 3 NO NO YES YES YES NO Output Adam Bob Bob Cpqepqwer Limak Adam Bob Adam Input 9 8 YES NO Output R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc Input 3 2 NO NO Output Na Na Na Note In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output: * First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO". * Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO". * Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES". * ..., * Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO". Submitted Solution: ``` names=['A','B','C','D','E','F','G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'Aa','Ab','Ac','Ad','Ae','Af','Ag','Ah','Ai','Aj', 'Ak','Al','Am','An','Ao','Ap','Aq','Ar', 'As','At','Au','Av','Aw','Ax'] i=0 n,k=list(map(int,input().split())) arr=input().split() ans=[] if arr[0]=='NO': ans=names[:k-1]+[names[0]] i=k else: ans=names[:k] i=k arr=arr[1:] k=0 for truth in arr: k+=1 if truth=="YES": ans+=[names[i]] i+=1 else: ans+=ans[k] print(' '.join(ans)) ```
instruction
0
8,082
14
16,164
No
output
1
8,082
14
16,165
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,109
14
16,218
Tags: brute force, constructive algorithms, math Correct Solution: ``` import sys, itertools #f = open('input', 'r') f = sys.stdin def near(i,n,m): x = i//m y = i%m d = [[0, -1], [0, 1], [-1, 0], [1, 0]] ns = [] for dx, dy in d: nx=x+dx ny=y+dy if nx>=0 and nx<n and ny>=0 and ny<m: ns.append(nx*m+ny) return ns def check(p, n, m): d = [[0, -1], [0, 1], [-1, 0], [1, 0]] for x in range(n): for y in range(m): ns = near(p[x*m+y],n,m) for dx, dy in d: nx=x+dx ny=y+dy if nx>=0 and nx<n and ny>=0 and ny<m and p[nx*m+ny] in ns: return True return False n, m = map(int, f.readline().split()) reverse=False if n>m: t1 = list(range(n*m)) t2 = [] for i in range(m): for j in range(n): t2.append(t1[j*m+i]) t=n;n=m;m=t reverse=True def ans(n,m): if m>=5: p = [] for i in range(n): t3 = [] for j in range(m): if j*2+i%2 >= m: break t3.append(j*2+i%2) for j in range(m-len(t3)): if j*2+1-i%2 >= m: break t3.append(j*2+1-i%2) p += [x+i*m for x in t3] return p if n==1 and m==1: return [0] if n==1 and m<=3: return False if n==2 and m<=3: return False if n==3 and m==4: return [4,3,6,1,2,5,0,7,9,11,8,10] if n==4: return [4, 3, 6, 1, 2, 5, 0, 7, 12, 11, 14, 9, 15, 13, 11, 14] for p in list(itertools.permutations(list(range(n*m)), n*m)): failed = check(p,n,m) if not failed: return p return True p = ans(n,m) if p: print('YES') if reverse: for j in range(m): print(' '.join(str(t2[p[i*m+j]]+1) for i in range(n))) else: for i in range(n): print(' '.join(str(p[i*m+j]+1) for j in range(m))) else: print('NO') ```
output
1
8,109
14
16,219
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,110
14
16,220
Tags: brute force, constructive algorithms, math Correct Solution: ``` def transpos(a,n,m): b = [] for i in range(m): b.append([a[j][i] for j in range(n)]) return(b) def printarr(a): for i in range(len(a)): for j in range(len(a[i])): print(a[i][j], end = ' ') print("") n,m = [int(i) for i in input().split()] a = [] for i in range(n): a.append([i*m + j for j in range(1,m+1)]) #printarr(transpos(a,n,m)) transp_flag = False if n > m: tmp = m m = n n = tmp a = transpos(a,m,n) transp_flag = True # m >= n if m < 3 and m != 1: print("NO") elif m == 1: print("YES") print(1) else: if m == 3: if n < 3: print("NO") else: print("YES") printarr([[5,9,3],[7,2,4],[1,6,8]]) elif m == 4: for i in range(n): tmp = a[i][:] if i%2 == 0: a[i] = [tmp[1],tmp[3],tmp[0],tmp[2]] else: a[i] = [tmp[2],tmp[0],tmp[3],tmp[1]] else: for i in range(n): if i%2 == 0: tmp1 = [a[i][j] for j in range(m) if j%2 == 0] tmp2 = [a[i][j] for j in range(m) if j%2 == 1] if i%2 == 1: tmp1 = [a[i][j] for j in range(m) if j%2 == 1] tmp2 = [a[i][j] for j in range(m) if j%2 == 0] a[i] = tmp1 + tmp2 if m > 3: if transp_flag: a = transpos(a,n,m) print("YES") printarr(a) ```
output
1
8,110
14
16,221
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,111
14
16,222
Tags: brute force, constructive algorithms, math Correct Solution: ``` def get_answer(m, n): if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]: return ("NO", []) elif (n == 1): mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)] return ("YES", mat) elif n == 2: bs = [[2, 3], [7, 6], [4, 1], [8, 5]] mat = [] for i in range(m//4): for u in bs: if i % 2 == 0: # like bs mat.append([x + 8*i for x in u]) else: ''' 2 3 7 6 4 1 8 5 11 10 (10 11 is invalid -> flip figure) 14 15 9 12 13 16 ''' mat.append([x + 8*i for x in reversed(u)]) if m % 4 == 1: ''' 2 3 m*n 3 7 6 2 6 4 1 -> 7 1 8 5 4 5 (11 10) 8 m*n-1 (...) (11 10) (...) ''' mat.insert(4, [0, 0]) for i in range(4, 0, -1): mat[i][0] = mat[i-1][0] mat[0][0] = m*n mat[4][1] = m*n-1 elif m % 4 == 2: if (m//4) % 2 == 1: ''' 9 12 2 3 2 3 ... -> ... 8 5 8 5 11 10 ''' mat = [[m*n-3, m*n]] + mat + [[m*n-1, m*n-2]] else: ''' 17 20 2 3 2 3 ... -> ... 13 16 13 16 18 19 ''' mat = [[m*n-3, m*n]] + mat + [[m*n-2, m*n-1]] elif m % 4 == 3: ''' 13 12 2 3 10 3 7 6 2 6 4 1 7 1 8 5 -> 4 5 8 9 11 14 ''' mat.insert(4, [0, 0]) for i in range(4, 0, -1): mat[i][0] = mat[i-1][0] mat[0][0] = m*n-4 mat[4][1] = m*n-5 mat = [[m*n-1, m*n-2]] + mat + [[m*n-3, m*n]] return ("YES", mat) elif n == 3: bs = [[6, 1, 8], [7, 5, 3], [2, 9, 4]] mat = [] for i in range(m//3): for u in bs: mat.append([x + 9*i for x in u]) if m % 3 == 1: ''' 11 1 12 6 1 8 6 10 8 7 5 3 -> 7 5 3 2 9 4 2 9 4 ''' mat = [[m*n-1, m*n-2, m*n]] + mat mat[0][1], mat[1][1] = mat[1][1], mat[0][1] elif m % 3 == 2: ''' 11 1 12 6 1 8 6 10 8 7 5 3 -> 7 5 3 2 9 4 2 13 4 14 9 15 ''' mat = [[m*n-4, m*n-5, m*n-3]] + mat + [[m*n-1, m*n-2, m*n]] mat[0][1], mat[1][1] = mat[1][1], mat[0][1] mat[m-2][1], mat[m-1][1] = mat[m-1][1], mat[m-2][1] return ("YES", mat) mat = [] for i in range(m): if i % 2 == 0: mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)]) else: if n != 4: mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)]) else: mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)]) return ("YES", mat) m, n = input().split() m = int(m) n = int(n) res = get_answer(m, n) print(res[0]) # print(m, n) if res[0] == "YES": for i in range(m): for j in range(n): print(res[1][i][j], end=' ') print() ```
output
1
8,111
14
16,223
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,112
14
16,224
Tags: brute force, constructive algorithms, math Correct Solution: ``` def get_answer(m, n): if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]: return ("NO", []) elif (m == 1): mat = [[i for i in range(2, n+1, 2)] + [i for i in range(1, n+1, 2)]] return ("YES", mat) elif (n == 1): mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)] return ("YES", mat) elif n == 2: bs = [[2, 3], [7, 6], [4, 1], [8, 5]] mat = [] for i in range(m//4): for u in bs: if i % 2 == 0: # like bs mat.append([x + 8*i for x in u]) else: ''' 2 3 7 6 4 1 8 5 11 10 (10 11 is invalid -> flip figure) 14 15 9 12 13 16 ''' mat.append([x + 8*i for x in reversed(u)]) if m % 4 == 1: ''' 2 3 m*n 3 7 6 2 6 4 1 -> 7 1 8 5 4 5 (11 10) 8 m*n-1 (...) (11 10) (...) ''' mat.insert(4, [0, 0]) for i in range(4, 0, -1): mat[i][0] = mat[i-1][0] mat[0][0] = m*n mat[4][1] = m*n-1 elif m % 4 == 2: if (m//4) % 2 == 1: ''' 9 12 2 3 2 3 ... -> ... 8 5 8 5 11 10 ''' mat = [[m*n-3, m*n]] + mat + [[m*n-1, m*n-2]] else: ''' 17 20 2 3 2 3 ... -> ... 13 16 13 16 18 19 ''' mat = [[m*n-3, m*n]] + mat + [[m*n-2, m*n-1]] elif m % 4 == 3: ''' 13 12 2 3 10 3 7 6 2 6 4 1 7 1 8 5 -> 4 5 8 9 11 14 ''' mat.insert(4, [0, 0]) for i in range(4, 0, -1): mat[i][0] = mat[i-1][0] mat[0][0] = m*n-4 mat[4][1] = m*n-5 mat = [[m*n-1, m*n-2]] + mat + [[m*n-3, m*n]] return ("YES", mat) elif n == 3: bs = [[6, 1, 8], [7, 5, 3], [2, 9, 4]] mat = [] for i in range(m//3): for u in bs: mat.append([x + 9*i for x in u]) if m % 3 == 1: ''' 11 1 12 6 1 8 6 10 8 7 5 3 -> 7 5 3 2 9 4 2 9 4 ''' mat = [[m*n-1, m*n-2, m*n]] + mat mat[0][1], mat[1][1] = mat[1][1], mat[0][1] elif m % 3 == 2: ''' 11 1 12 6 1 8 6 10 8 7 5 3 -> 7 5 3 2 9 4 2 13 4 14 9 15 ''' mat = [[m*n-4, m*n-5, m*n-3]] + mat + [[m*n-1, m*n-2, m*n]] mat[0][1], mat[1][1] = mat[1][1], mat[0][1] mat[m-2][1], mat[m-1][1] = mat[m-1][1], mat[m-2][1] return ("YES", mat) mat = [] for i in range(m): if i % 2 == 0: mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)]) else: if n != 4: mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)]) else: mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)]) return ("YES", mat) m, n = input().split() m = int(m) n = int(n) res = get_answer(m, n) print(res[0]) # print(m, n) if res[0] == "YES": for i in range(m): for j in range(n): print(res[1][i][j], end=' ') print() ```
output
1
8,112
14
16,225
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,113
14
16,226
Tags: brute force, constructive algorithms, math Correct Solution: ``` n,m=map(int,input().strip().split(' ')) arr=[] cnt=1 if(n*m==1): print("YES") print(1) elif((n==1 and(m==2 or m==3)) or ((n==2) and (m==1 or m==2 or m==3)) or ((n==3) and (m==1 or m==2 )) ): print("NO") elif(n==3 and m==3): print("YES") print(6,1,8) print(7,5,3) print(2,9,4) else: print("YES") if(m>=n): for i in range(n): l=[] for j in range(m): l.append(cnt) cnt+=1 arr.append(l) ans=[] for i in range(n): l=arr[i] odd=[] even=[] for j in range(m): if((j+1)%2==0): even.append(l[j]) else: odd.append(l[j]) if(((i+1)%2)==1): if(n%2==1 and m%2==1): odd.extend(even) ans.append(odd) elif(m%2==1 and n%2==0): odd.extend(even) ans.append(odd) else: even.extend(odd) ans.append(even) else: if(n%2==1 and m%2==1): even.extend(odd) ans.append(even) elif(m%2==1 and n%2==0): even.extend(odd) ans.append(even) else: even.reverse() odd.reverse() odd.extend(even) ans.append(odd) for i in range(n): for j in range(m): print(ans[i][j],end=' ') print() else: temp=n n=m m=temp cnt=1 for i in range(n): l=[] p=cnt for j in range(m): l.append(p) p+=n cnt+=1 arr.append(l) ans=[] for i in range(n): l=arr[i] odd=[] even=[] for j in range(m): if((j+1)%2==0): even.append(l[j]) else: odd.append(l[j]) if(((i+1)%2)==1): if(n%2==1 and m%2==1): odd.extend(even) ans.append(odd) elif(m%2==1 and n%2==0): odd.extend(even) ans.append(odd) else: even.extend(odd) ans.append(even) else: if(n%2==1 and m%2==1): even.extend(odd) ans.append(even) elif(m%2==1 and n%2==0): even.extend(odd) ans.append(even) else: even.reverse() odd.reverse() odd.extend(even) ans.append(odd) for i in range(m): for j in range(n): print(ans[j][i],end=' ') print() ```
output
1
8,113
14
16,227
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,114
14
16,228
Tags: brute force, constructive algorithms, math Correct Solution: ``` def get_answer(m, n): if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]: return ("NO", []) elif (m == 1): mat = [[i for i in range(2, n+1, 2)] + [i for i in range(1, n+1, 2)]] return ("YES", mat) elif (n == 1): mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)] return ("YES", mat) elif n == 2: bs = [[2, 3], [7, 6], [4, 1], [8, 5]] mat = [] for i in range(m//4): for u in bs: if i % 2 == 0: mat.append([x + 8*i for x in u]) else: mat.append([x + 8*i for x in reversed(u)]) if m % 4 == 1: mat.insert(4, [0, 0]) for i in range(4, 0, -1): mat[i][0] = mat[i-1][0] mat[0][0] = m*n mat[4][1] = m*n-1 elif m % 4 == 2: if (m//4) % 2 == 1: mat = [[m*n-3, m*n]] + mat + [[m*n-1, m*n-2]] else: mat = [[m*n-3, m*n]] + mat + [[m*n-2, m*n-1]] elif m % 4 == 3: mat.insert(4, [0, 0]) for i in range(4, 0, -1): mat[i][0] = mat[i-1][0] mat[0][0] = m*n-4 mat[4][1] = m*n-5 mat = [[m*n-1, m*n-2]] + mat + [[m*n-3, m*n]] return ("YES", mat) elif n == 3: bs = [[6, 1, 8], [7, 5, 3], [2, 9, 4]] mat = [] for i in range(m//3): for u in bs: mat.append([x + 9*i for x in u]) if m % 3 == 1: mat = [[m*n-1, m*n-2, m*n]] + mat mat[0][1], mat[1][1] = mat[1][1], mat[0][1] elif m % 3 == 2: mat = [[m*n-4, m*n-5, m*n-3]] + mat + [[m*n-1, m*n-2, m*n]] mat[0][1], mat[1][1] = mat[1][1], mat[0][1] mat[m-2][1], mat[m-1][1] = mat[m-1][1], mat[m-2][1] return ("YES", mat) mat = [] for i in range(m): if i % 2 == 0: mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)]) else: if n != 4: mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)]) else: mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)]) return ("YES", mat) m, n = input().split() m = int(m) n = int(n) res = get_answer(m, n) print(res[0]) # print(m, n) if res[0] == "YES": for i in range(m): for j in range(n): print(res[1][i][j], end=' ') print() ```
output
1
8,114
14
16,229
Provide tags and a correct Python 3 solution for this coding contest problem. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.
instruction
0
8,115
14
16,230
Tags: brute force, constructive algorithms, math Correct Solution: ``` import bisect def list_output(s): print(' '.join(map(str, s))) def list_input(s='int'): if s == 'int': return list(map(int, input().split())) elif s == 'float': return list(map(float, input().split())) return list(map(str, input().split())) n, m = map(int, input().split()) swapped = False if n > m: n, m = m, n swapped = True def check(M): for i in range(n): for j in range(m): if i-1 >= 0 and M[i-1][j] + m == M[i][j]: return False if i+1 < n and M[i+1][j] == M[i][j] + m: return False if j-1 >= 0 and M[i][j-1] + 1 == M[i][j]: return False if j+1 < m and M[i][j+1] == M[i][j] + 1: return False return True def transpose(M): n = len(M) m = len(M[0]) R = [[0 for i in range(n)] for j in range(m)] for i in range(n): for j in range(m): R[j][i] = M[i][j] return R if n == 1 and m == 1: print('YES') print('1') exit(0) if n <= 2 and m <= 3: print('NO') exit(0) R = list() if n == 3 and m == 3: R.append([4, 3, 8]) R.append([9, 1, 6]) R.append([5, 7, 2]) elif m == 4: if n == 1: R.append([3, 1, 4, 2]) elif n == 2: R.append([5, 4, 7, 2]) R.append([3, 6, 1, 8]) elif n == 3: R.append([5, 4, 7, 2]) R.append([3, 6, 1, 8]) R.append([11, 9, 12, 10]) elif n == 4: R.append([5, 4, 7, 2]) R.append([3, 6, 1, 8]) R.append([11, 9, 12, 10]) R.append([14, 16, 15, 13]) else: M = [[(i-1) * m + j for j in range(1, m+1)] for i in range(1, n+1)] for i in range(n): row = list() if i%2 == 0: for j in range(0, m, 2): row.append(M[i][j]) for j in range(1, m, 2): row.append(M[i][j]) else: for j in range(1, m, 2): row.append(M[i][j]) for j in range(0, m, 2): row.append(M[i][j]) R.append(row) if swapped: M = [[(i-1) * n + j for j in range(1, n+1)] for i in range(1, m+1)] M = transpose(M) S = [[0 for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): r = (R[i][j]-1) // m c = (R[i][j]-1) % m S[i][j] = M[r][c] R = transpose(S) n, m = m, n #print(check(R)) print('YES') for i in range(n): print(' '.join(map(str, R[i]))) ```
output
1
8,115
14
16,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. Submitted Solution: ``` def get_answer(m, n): if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1), (2, 2), (2, 3), (3, 2)]: return ("NO", []) elif m == n == 1: return ("YES", [[1]]) elif (m == 1): mat = [[i for i in range(2, n+1, 2)] + [i for i in range(1, n+1, 2)]] # print(mat) return ("YES", mat) elif (n == 1): mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)] # print(mat) return ("YES", mat) elif n == 2: ''' s = get_answer(2, max(m, n)) res = [] for i in range(m): res.append([0] * n) for j in range(n): res[i][j] = s[1][j][i] return ("YES", res) ''' return ("NO", []) mat = [] for i in range(m): # mat.append([]) # for j in range(n): # mat[i].append(i*n+j+1) if i % 2 == 0: # mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)]) mat.append([i*n+j for j in range(2, n+1, 2)] + [i*n+j for j in range(1, n+1, 2)]) else: if n != 4: mat.append([i*n+j for j in range(1, n+1, 2)] + [i*n+j for j in range(2, n+1, 2)]) else: mat.append([i*n+j for j in range(n-(n%2==0), 0, -2)] + [i*n+j for j in range(n-(n%2==1), 0, -2)]) return ("YES", mat) m, n = input().split() m = int(m) n = int(n) # res = get_answer(min(m, n), max(m, n)) res = get_answer(m, n) # print(res[0]) print(m, n) if res[0] == "YES": # if m <= n: if 1 == 1: for i in range(m): for j in range(n): print(res[1][i][j], end=' ') print() else: for i in range(m): for j in range(n): print(res[1][j][i], end=' ') print() ```
instruction
0
8,116
14
16,232
No
output
1
8,116
14
16,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. Submitted Solution: ``` n,m=map(int,input().strip().split(' ')) arr=[] cnt=1 if(n*m==1): print("YES") print(1) elif((n==1 and(m==2 or m==3)) or ((n==2) and (m==1 or m==2 or m==3)) or ((n==3) and (m==1 or m==2 )) ): print("NO") elif(n==3 and m==3): print("YES") print(6,1,8) print(7,5,3) print(2,9,4) else: print("YES") if(m>=n): for i in range(n): l=[] for j in range(m): l.append(cnt) cnt+=1 arr.append(l) ans=[] for i in range(n): l=arr[i] odd=[] even=[] for j in range(m): if((j+1)%2==0): even.append(l[j]) else: odd.append(l[j]) if(((i+1)%2)==1): if(n%2==1 and m%2==1): odd.extend(even) ans.append(odd) else: even.extend(odd) ans.append(even) else: if(n%2==1 and m%2==1): even.extend(odd) ans.append(even) else: even.reverse() odd.reverse() odd.extend(even) ans.append(odd) for i in range(n): for j in range(m): print(ans[i][j],end=' ') print() else: temp=n n=m m=temp cnt=1 for i in range(n): l=[] p=cnt for j in range(m): l.append(p) p+=n cnt+=1 arr.append(l) ans=[] for i in range(n): l=arr[i] odd=[] even=[] for j in range(m): if((j+1)%2==0): even.append(l[j]) else: odd.append(l[j]) if(((i+1)%2)==1): even.extend(odd) ans.append(even) else: even.reverse() odd.reverse() odd.extend(even) ans.append(odd) for i in range(m): for j in range(n): print(ans[j][i],end=' ') print() ```
instruction
0
8,117
14
16,234
No
output
1
8,117
14
16,235
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. Submitted Solution: ``` def get_answer(m, n): if (m, n) in [(1, 2), (2, 1), (1, 3), (3, 1)]: return ("NO", []) elif m == n == 1: return ("YES", [[1]]) elif (m == 1): mat = [[i for i in range(2, n+1, 2)] + [i for i in range(1, n+1, 2)]] # print(mat) return ("YES", mat) elif (n == 1): mat = [[i] for i in range(2, m+1, 2)] + [[i] for i in range(1, m+1, 2)] # print(mat) return ("YES", mat) mat = [] for i in range(m): mat.append([]) for j in range(n): mat[i].append(i*n+j+1) _mat = [[]] * m lst = 0 for i in range(0, m, 2): _mat[i] = list(mat[i//2]) lst = i//2 # print(lst) for i in range(1, m, 2): _mat[i] = list(mat[lst+(i+1)//2]) mat = list(_mat) # return ("YES", mat) for i in range(m): mat[i] = mat[i][n-i%n:] + mat[i][:n-i%n] # return ("YES", mat) for j in range(n): col = [] for i in range(m): col.append(mat[i][j]) col = col[m-j%m:] + col[:m-j%m] for i in range(m): mat[i][j] = col[i] return ("YES", mat) m, n = input().split() m = int(m) n = int(n) res = get_answer(m, n) print(res[0]) if res[0] == "YES": for i in range(m): for j in range(n): print(res[1][i][j], end=' ') print() ```
instruction
0
8,118
14
16,236
No
output
1
8,118
14
16,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side. Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix. Input The only line contains two integers n and m (1 ≤ n, m ≤ 105; n·m ≤ 105) — the number of rows and the number of columns in the required matrix. Output If there is no such matrix, output "NO" (without quotes). Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix. Examples Input 2 4 Output YES 5 4 7 2 3 6 1 8 Input 2 1 Output NO Note In the first test case the matrix initially looks like this: 1 2 3 4 5 6 7 8 It's easy to see that there are no two students that are adjacent in both matrices. In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. Submitted Solution: ``` n,m=map(int,input().strip().split(' ')) arr=[] cnt=1 if(n*m==1): print("YES") print(1) elif((n==1 and(m==2 or m==3)) or ((n==2) and (m==1 or m==2 or m==3)) or ((n==3) and (m==1 or m==2 or m==3)) ): print("NO") else: print("YES") if(m>=n): for i in range(n): l=[] for j in range(m): l.append(cnt) cnt+=1 arr.append(l) ans=[] for i in range(n): l=arr[i] odd=[] even=[] for j in range(m): if((j+1)%2==0): even.append(l[j]) else: odd.append(l[j]) if(((i+1)%2)==1): even.extend(odd) ans.append(even) else: even.reverse() odd.reverse() odd.extend(even) ans.append(odd) for i in range(n): for j in range(m): print(ans[i][j],end=' ') print() else: temp=n n=m m=temp cnt=1 for i in range(n): l=[] p=cnt for j in range(m): l.append(p) p+=n cnt+=1 arr.append(l) ans=[] for i in range(n): l=arr[i] odd=[] even=[] for j in range(m): if((j+1)%2==0): even.append(l[j]) else: odd.append(l[j]) if(((i+1)%2)==1): even.extend(odd) ans.append(even) else: even.reverse() odd.reverse() odd.extend(even) ans.append(odd) for i in range(m): for j in range(n): print(ans[j][i],end=' ') print() ```
instruction
0
8,119
14
16,238
No
output
1
8,119
14
16,239
Provide a correct Python 3 solution for this coding contest problem. You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret. Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the number of pairs satisfying the condition. Examples Input 6 2 3 3 1 3 1 Output 3 Input 6 5 2 4 2 8 8 Output 0 Input 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 Output 22
instruction
0
8,184
14
16,368
"Correct Solution: ``` N = int(input()) A = list(map(int, input().split())) d = [0]*N ans = 0 for i in range(N): a = A[i] l,r = i+a, i-a if 0 <= l < N: d[l] += 1 if 0 <= r < N: ans += d[r] print(ans) ```
output
1
8,184
14
16,369
Provide a correct Python 3 solution for this coding contest problem. You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret. Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq 10^9\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the number of pairs satisfying the condition. Examples Input 6 2 3 3 1 3 1 Output 3 Input 6 5 2 4 2 8 8 Output 0 Input 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 Output 22
instruction
0
8,185
14
16,370
"Correct Solution: ``` from collections import defaultdict n = int(input()) A = list(map(int, input().split())) cnt = defaultdict(int) ans = 0 for i in range(n): k = i-A[i] ans += cnt[k] cnt[i+A[i]]+=1 print(ans) ```
output
1
8,185
14
16,371