message
stringlengths
2
39.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
219
108k
cluster
float64
11
11
__index_level_0__
int64
438
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size. During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him. Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size: * the size he wanted, if he specified one size; * any of the two neibouring sizes, if he specified two sizes. If it is possible, the program should find any valid distribution of the t-shirts. Input The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000. The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants. The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring. Output If it is not possible to present a t-shirt to each participant, print «NO» (without quotes). Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input. If there are multiple solutions, print any of them. Examples Input 0 1 0 1 1 0 3 XL S,M XL,XXL Output YES XL M XXL Input 1 1 2 0 1 1 5 S M S,M XXL,XXXL XL,XXL Output NO Submitted Solution: ``` # You lost the game. import sys T = list(map(int, input().split())) L = [[] for _ in range(6)] D = [[] for _ in range(5)] n = int(input()) S = [str(input()) for _ in range(n)] for i in range(n): x = list(S[i].split(",")) if len(x) == 2: if x[0] == "S": D[0] += [i] if x[0] == "M": D[1] += [i] if x[0] == "L": D[2] += [i] if x[0] == "XL": D[3] += [i] if x[0] == "XXL": D[4] += [i] if x[0] == "XXXL": D[5] += [i] else: if x[0] == "S": L[0] += [i] if x[0] == "M": L[1] += [i] if x[0] == "L": L[2] += [i] if x[0] == "XL": L[3] += [i] if x[0] == "XXL": L[4] += [i] if x[0] == "XXXL": L[5] += [i] a = 0 ok = 1 R = ["" for _ in range(n)] # S if len(L[0]) <= T[0]: for x in L[0]: R[x] = "S" T[0] -= len(L[0]) else: print("NO") ok = 0 a = max(0,len(D[0]) - T[0]) for i in range(min(len(D[0]),T[0])): R[D[0][i]] = "S" # M if a+len(L[1]) <= T[1]: for i in range(len(D[0])-a,len(D[0])): R[D[0][i]] = "M" for x in L[1]: R[x] = "M" T[1] -= len(L[1])+a else: print("NO") ok = 0 a = max(0,len(D[1]) - T[1]) for i in range(min(len(D[1]),T[1])): R[D[1][i]] = "M" # L if a+len(L[2]) <= T[2]: for i in range(len(D[1])-a,len(D[1])): R[D[1][i]] = "L" for x in L[2]: R[x] = "L" T[2] -= len(L[2])+a else: print("NO") ok = 0 a = max(0,len(D[2]) - T[2]) for i in range(min(len(D[2]),T[2])): R[D[2][i]] = "L" # XL if a+len(L[3]) <= T[3]: for i in range(len(D[2])-a,len(D[2])): R[D[2][i]] = "XL" for x in L[3]: R[x] = "XL" T[3] -= len(L[3])+a else: print("NO") ok = 0 a = max(0,len(D[3]) - T[3]) for i in range(min(len(D[3]),T[3])): R[D[3][i]] = "XL" # XXL if a+len(L[4]) <= T[4]: for i in range(len(D[3])-a,len(D[3])): R[D[3][i]] = "XXL" for x in L[4]: R[x] = "XXL" T[4] -= len(L[4])+a else: print("NO") ok = 0 a = max(0,len(D[4]) - T[4]) for i in range(min(len(D[4]),T[4])): R[D[4][i]] = "XXL" # XXXL if a+len(L[5]) <= T[5]: for i in range(len(D[4])-a,len(D[4])): R[D[4][i]] = "XXXL" for x in L[5]: R[x] = "XXXL" else: print("NO") ok = 0 if ok: print("YES") for i in range(n): print(R[i]) ```
instruction
0
25,247
11
50,494
Yes
output
1
25,247
11
50,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size. During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him. Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size: * the size he wanted, if he specified one size; * any of the two neibouring sizes, if he specified two sizes. If it is possible, the program should find any valid distribution of the t-shirts. Input The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000. The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants. The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring. Output If it is not possible to present a t-shirt to each participant, print «NO» (without quotes). Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input. If there are multiple solutions, print any of them. Examples Input 0 1 0 1 1 0 3 XL S,M XL,XXL Output YES XL M XXL Input 1 1 2 0 1 1 5 S M S,M XXL,XXXL XL,XXL Output NO Submitted Solution: ``` s = list(map(int, input().split())) d1, d2, d = {}, {}, {} d1["S"] = 0 d1["M"] = 1 d1["L"] = 2 d1["XL"] = 3 d1["XXL"] = 4 d1["XXXL"] = 5 d2[0] = "S" d2[1] = "M" d2[2] = "L" d2[3] = "XL" d2[4] = "XXL" d2[5] = "XXXL" for i in range(6): d[i] = s[i] n = int(input()) ans = ["" for i in range(n)] ev = [] for i in range(n): s = input().split(",") if len(s) == 1: d[d1[s[0]]] -= 1 ans[i] = s[0] else: ev.append([i, [d1[s[0]], d1[s[1]]]]) for i in range(len(ev)): if d[ev[i][1][0]] > d[ev[i][1][1]] and d[ev[i][1][0]] > 0: d[ev[i][1][0]] -= 1 ans[i+1] = d2[ev[i][1][0]] elif d[ev[i][1][0]] < d[ev[i][1][1]] and d[ev[i][1][1]] > 0: d[ev[i][1][1]] -= 1 ans[i+1] = d2[ev[i][1][1]] else: print("NO") exit(0) print("YES") for i in ans: print(i) ```
instruction
0
25,248
11
50,496
No
output
1
25,248
11
50,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size. During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him. Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size: * the size he wanted, if he specified one size; * any of the two neibouring sizes, if he specified two sizes. If it is possible, the program should find any valid distribution of the t-shirts. Input The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000. The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants. The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring. Output If it is not possible to present a t-shirt to each participant, print «NO» (without quotes). Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input. If there are multiple solutions, print any of them. Examples Input 0 1 0 1 1 0 3 XL S,M XL,XXL Output YES XL M XXL Input 1 1 2 0 1 1 5 S M S,M XXL,XXXL XL,XXL Output NO Submitted Solution: ``` s = list(input().split(' ')) num = int(input()) size = list() ans = '' for _ in range(num): size += (input().split(',')) for i in range(len(size)): if size [i] == 'S': a = 0 elif size [i] == 'M': a = 1 elif size [i] == 'L': a = 2 elif size [i] == 'XL': a = 3 elif size [i] == 'XXL': a = 4 elif size [i] == 'XXXL': a = 5 if int(s[a]) != 0: s[a] = int(s[a]) - 1 ans += str(size[i]) + '\n' num -= 1 if num == 0: print('YES') print(ans[:len(ans)-1]) else: print('NO') ```
instruction
0
25,249
11
50,498
No
output
1
25,249
11
50,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size. During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him. Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size: * the size he wanted, if he specified one size; * any of the two neibouring sizes, if he specified two sizes. If it is possible, the program should find any valid distribution of the t-shirts. Input The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000. The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants. The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring. Output If it is not possible to present a t-shirt to each participant, print «NO» (without quotes). Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input. If there are multiple solutions, print any of them. Examples Input 0 1 0 1 1 0 3 XL S,M XL,XXL Output YES XL M XXL Input 1 1 2 0 1 1 5 S M S,M XXL,XXXL XL,XXL Output NO Submitted Solution: ``` s = list(map(int,input().split())) n = int(input()) f = 1 S = 0 M = 0 L = 0 XL = 0 XXL = 0 XXXL = 0 por = [] for i in range(n): a = input() if a == "S": if S < s[0]: S += 1 por.append("S") else: f = 0 elif a == "S,M": if S >= s[0] and M >= s[1]: f = 0 elif S >= s[0]: M += 1 por.append("M") elif M >= s[1]: S += 1 por.append("S") if a == "M": if M < s[1]: M += 1 por.append("M") else: f= 0 elif a == "M,L": if L >= s[2] and M >= s[1]: f = 0 elif M >= s[1]: L += 1 por.append("L") elif L >= s[2]: M += 1 por.append("M") if a == "L": if L < s[2]: L += 1 por.append("L") else: f = 0 elif a == "L,XL": if L >= s[2] and XL >= s[3]: f= 0 elif L >= s[2]: XL += 1 por.append("XL") elif XL >= s[3]: L += 1 por.append("L") if a == "XL": if XL < s[3]: XL += 1 por.append("XL") else: f= 0 elif a == "XL,XXL": if XL >= s[3] and XXL >= s[4]: f = 0 elif XL >= s[3]: XXL += 1 por.append("XXL") elif XXL >= s[4]: XL += 1 por.append("XL") if a == "XXL": if XXL < s[4]: XXL += 1 por.append("XXL") else: f = 0 elif a == "XXL,XXXL": if XXL >= s[4] and XXXL >= s[5]: f = 0 elif XXL >= s[4]: XXXL += 1 por.append("XXXL") elif XXXL >= s[5]: XXL += 1 por.append("XXL") if a == "XXXL": if XXXL < s[5]: XXXL += 1 por.append("XXXL") else: f = 0 if f== 0: print("NO") else: print("YES") for i in por: print(i) ```
instruction
0
25,250
11
50,500
No
output
1
25,250
11
50,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size. During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him. Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size: * the size he wanted, if he specified one size; * any of the two neibouring sizes, if he specified two sizes. If it is possible, the program should find any valid distribution of the t-shirts. Input The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000. The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants. The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring. Output If it is not possible to present a t-shirt to each participant, print «NO» (without quotes). Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input. If there are multiple solutions, print any of them. Examples Input 0 1 0 1 1 0 3 XL S,M XL,XXL Output YES XL M XXL Input 1 1 2 0 1 1 5 S M S,M XXL,XXXL XL,XXL Output NO Submitted Solution: ``` def distribution(available, wish): people = [] for w in wish: if w.count(',') == 0: if available[w] > 0: available[w] -= 1 people.append(w) else: return ['NO'] else: people.append(w) for p in people: if p.count(',') > 0: lack = True for size in p.split(','): if available[size] > 0: available[size] -= 1 people[people.index(p)] = size lack = False break if lack: return ['NO'] return ['YES', people] def stock(): return {size: amount for size, amount in zip(['S', 'M', 'L', 'XL', 'XXL', 'XXXL'], map(int, input().split()))} def request(): return [input() for i in range(int(input()))] def solution(n): return [input() for i in range(n)] def answer(): ans = distribution(stock(), request()) if ans[0] == 'YES': print('YES') for p in ans[1]: print(p) else: print('NO') def check(s, l): for size in l: if size not in s: return False else: s[size] -= 1 if s[size] < 0: return False return True def compare(): s = stock() r = request() ans = distribution(s.copy(), r) try: usr = input() if usr == 'YES': l = solution(len(r)) elif usr == 'NO': l = [] else: print(0) print('Нарушен формат вывода') exit(0) except EOFError: print(0) print('Нарушен формат вывода') exit(0) if usr != ans[0] or ans[0] == 'YES' and not check(s.copy(), l): print(0) print('Failed. T-shirts:', s, '. Request:', ';'.join(r), '. Your solution:', usr, ' - ', ';'.join(l)) else: print(1) print('Ok') answer() ```
instruction
0
25,251
11
50,502
No
output
1
25,251
11
50,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7 Submitted Solution: ``` N=int(input()) dic={'M':0,'A':0,'R':0,'C':0,'H':0} k = dic.keys() for i in range(N): s=input() if s[0] in k: dic[s[0]]+=1 from itertools import combinations ans=0 for p,q,r in combinations(k,3): ans+=dic[p]*dic[q]*dic[r] print(ans) ```
instruction
0
25,425
11
50,850
Yes
output
1
25,425
11
50,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7 Submitted Solution: ``` from itertools import combinations as c n=int(input());l=[input() for _ in range(n)];m="MARCH";p=[0]*5;r=0 for s in l: for i in range(5): if s[0]==m[i]:p[i]+=1 for d in c(p,3):r+=d[0]*d[1]*d[2] print(r) ```
instruction
0
25,426
11
50,852
Yes
output
1
25,426
11
50,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7 Submitted Solution: ``` from itertools import*;d=[0]*91 for s in open(0).readlines():d[ord(s[0])]+=1 print(sum(d[p]*d[q]*d[r]for p,q,r in combinations(map(ord,'MARCH'),3))) ```
instruction
0
25,427
11
50,854
Yes
output
1
25,427
11
50,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7 Submitted Solution: ``` from itertools import combinations N = int(input()) s = [input()[0] for _ in range(N)] s.sort() x = [s.count('M'), s.count('A'), s.count('R'), s.count('C'), s.count('H')] ans = 0 for v in combinations(x, 3): ans += v[0] * v[1] * v[2] print(ans) ```
instruction
0
25,428
11
50,856
Yes
output
1
25,428
11
50,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choose three people, disregarding order? Note that the answer may not fit into a 32-bit integer type. Constraints * 1 \leq N \leq 10^5 * S_i consists of uppercase English letters. * 1 \leq |S_i| \leq 10 * S_i \neq S_j (i \neq j) Input Input is given from Standard Input in the following format: N S_1 : S_N Output If there are x ways to choose three people so that the given conditions are met, print x. Examples Input 5 MASHIKE RUMOI OBIRA HABORO HOROKANAI Output 2 Input 4 ZZ ZZZ Z ZZZZZZZZZZ Output 0 Input 5 CHOKUDAI RNG MAKOTO AOKI RINGO Output 7 Submitted Solution: ``` N=int(input()) S=[input() for _ in range(N)] cnt=[0]*N cnt2=[] flag=0 for i in range(N): if S[i][0]=='M': cnt[0]+=1 elif S[i][0]=='A': cnt[1]+=1 elif S[i][0]=='R': cnt[2]+=1 elif S[i][0]=='C': cnt[3]+=1 elif S[i][0]=='H': cnt[4]+=1 for i in range(N): if cnt[i]!=0: cnt2.append(cnt[i]) import math import itertools ans=0 for v in itertools.combinations(cnt2, 3): ans+=v[0]*v[1]*v[2] print(ans) ```
instruction
0
25,429
11
50,858
No
output
1
25,429
11
50,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` INF = float('inf') def trace_back(sink, predecessors): p = predecessors[sink] while p is not None: v, i = p yield edges[v][i] p = predecessors[v] def min_cost_flow(source, sink, required_flow): res = 0 while required_flow: dist = [INF] * n dist[source] = 0 predecessors = [None] * n while True: updated = False for v in range(n): if dist[v] == INF: continue for i, (remain, target, cost, _) in enumerate(edges[v]): new_dist = dist[v] + cost if remain and dist[target] > new_dist: dist[target] = new_dist predecessors[target] = (v, i) updated = True if not updated: break if dist[sink] == INF: return -1 aug = min(required_flow, min(e[0] for e in trace_back(sink, predecessors))) required_flow -= aug res += aug * dist[sink] for e in trace_back(sink, predecessors): remain, target, cost, idx = e e[0] -= aug edges[target][idx][0] += aug return res n, m, f = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): s, t, c, d = map(int, input().split()) es, et = edges[s], edges[t] ls, lt = len(es), len(et) es.append([c, t, d, lt]) et.append([0, s, -d, ls]) print(min_cost_flow(0, n - 1, f)) ```
instruction
0
25,571
11
51,142
Yes
output
1
25,571
11
51,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` import sys readline = sys.stdin.readline from heapq import heappop as hpp, heappush as hp class MinCostFlowwithDijkstra: INF = 1<<31 def __init__(self, N): self.N = N self.Edge = [[] for _ in range(N)] def add_edge(self, st, en, cap, cost): self.Edge[st].append([en, cap, cost, len(self.Edge[en])]) self.Edge[en].append([st, 0, -cost, len(self.Edge[st])-1]) def get_mf(self, so, si, fl): N = self.N INF = self.INF res = 0 Pot = [0]*N geta = N prv = [None]*N prenum = [None]*N while fl: dist = [INF]*N dist[so] = 0 Q = [so] while Q: cost, vn = divmod(hpp(Q), geta) if dist[vn] < cost: continue for enum in range(len(self.Edge[vn])): vf, cap, cost, _ = self.Edge[vn][enum] cc = dist[vn] + cost - Pot[vn] + Pot[vf] if cap > 0 and dist[vf] > cc: dist[vf] = cc prv[vf] = vn prenum[vf] = enum hp(Q, cc*geta + vf) if dist[si] == INF: return -1 for i in range(N): Pot[i] -= dist[i] cfl = fl vf = si while vf != so: cfl = min(cfl, self.Edge[prv[vf]][prenum[vf]][1]) vf = prv[vf] fl -= cfl res -= cfl*Pot[si] vf = si while vf != so: e = self.Edge[prv[vf]][prenum[vf]] e[1] -= cfl self.Edge[vf][e[3]][1] += cfl vf = prv[vf] return res N, M, F = map(int, readline().split()) T = MinCostFlowwithDijkstra(N) for _ in range(M): u, v, cap, cost = map(int, readline().split()) T.add_edge(u, v, cap, cost) print(T.get_mf(0, N-1, F)) ```
instruction
0
25,572
11
51,144
Yes
output
1
25,572
11
51,145
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` from collections import defaultdict v_num, e_num, flow = (int(n) for n in input().split(" ")) edges = defaultdict(list) for _ in range(e_num): s1, t1, cap, cost = (int(n) for n in input().split(" ")) edges[s1].append([t1, cap, cost, len(edges[t1])]) edges[t1].append([s1, 0, -cost, len(edges[s1]) - 1]) answer = 0 before_vertice = [float("inf") for n in range(v_num)] before_edge = [float("inf") for n in range(v_num)] sink = v_num - 1 while True: distance = [float("inf") for n in range(v_num)] distance[0] = 0 updated = 1 while updated: updated = 0 for v in range(v_num): if distance[v] == float("inf"): continue for i, (target, cap, cost, trace_i) in enumerate(edges[v]): if cap > 0 and distance[target] > distance[v] + cost: distance[target] = distance[v] + cost before_vertice[target] = v before_edge[target] = i updated = 1 if distance[sink] == float("inf"): print(-1) break decreased = flow trace_i = sink while trace_i != 0: decreased = min(decreased, edges[before_vertice[trace_i]][before_edge[trace_i]][1]) trace_i = before_vertice[trace_i] flow -= decreased trace_i = sink while trace_i != 0: this_edge = edges[before_vertice[trace_i]][before_edge[trace_i]] this_edge[1] -= decreased answer += this_edge[2] * decreased edges[trace_i][this_edge[3]][1] += decreased trace_i = before_vertice[trace_i] if flow <= 0: print(answer) break ```
instruction
0
25,574
11
51,148
Yes
output
1
25,574
11
51,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` from heapq import heappop, heappush def trace(source, edge_trace): v = source for i in edge_trace: e = edges[v][i] yield e v = e[1] def min_cost_flow(source, sink, required_flow): res = 0 while required_flow: visited = set() queue = [(0, source, tuple())] while queue: total_cost, v, edge_memo = heappop(queue) if v in visited: continue elif v == sink: dist = total_cost edge_trace = edge_memo break for i, (remain, target, cost, _) in enumerate(edges[v]): if remain and target not in visited: heappush(queue, (total_cost + cost, target, edge_memo + (i,))) else: return -1 aug = min(required_flow, min(e[0] for e in trace(source, edge_trace))) required_flow -= aug res += aug * dist for e in trace(source, edge_trace): remain, target, cost, idx = e e[0] -= aug edges[target][idx][0] += aug return res n, m, f = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): s, t, c, d = map(int, input().split()) es, et = edges[s], edges[t] ls, lt = len(es), len(et) es.append([c, t, d, lt]) et.append([0, s, d, ls]) print(min_cost_flow(0, n - 1, f)) ```
instruction
0
25,575
11
51,150
No
output
1
25,575
11
51,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` from collections import defaultdict v_num, e_num, flow = (int(n) for n in input().split(" ")) edges = defaultdict(list) for _ in range(e_num): s1, t1, cap, cost = (int(n) for n in input().split(" ")) edges[s1].append([t1, cap, cost, len(edges[t1])]) edges[t1].append([s1, cap, cost, len(edges[s1])]) answer = 0 before_vertice = [float("inf") for n in range(v_num)] before_edge = [float("inf") for n in range(v_num)] sink = v_num - 1 while True: distance = [float("inf") for n in range(v_num)] distance[0] = 0 updated = 1 while updated: updated = 0 for v in range(v_num): if distance[v] == float("inf"): continue for i, (target, cap, cost, trace_i) in enumerate(edges[v]): if cap > 0 and distance[target] > distance[v] + cost: distance[target] = distance[v] + cost before_vertice[target] = v before_edge[target] = i updated = 1 if distance[sink] == float("inf"): print(-1) break decreased = flow trace_i = sink while trace_i != 0: decreased = min(decreased, edges[before_vertice[trace_i]][before_edge[trace_i]][1]) trace_i = before_vertice[trace_i] flow -= decreased answer += decreased * distance[sink] trace_i = sink while trace_i != 0: this_edge = edges[before_vertice[trace_i]][before_edge[trace_i]] this_edge[1] -= decreased trace_i = before_vertice[trace_i] edges[trace_i][this_edge[3]][1] += decreased if flow <= 0: print(answer) break ```
instruction
0
25,576
11
51,152
No
output
1
25,576
11
51,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` from heapq import heappop, heappush def trace(source, edge_trace): v = source for i in edge_trace: e = edges[v][i] yield e v = e[1] def min_cost_flow(source, sink, required_flow): res = 0 while required_flow: dist = [-1] * n queue = [(0, source, tuple())] edge_trace = None while queue: total_cost, v, edge_memo = heappop(queue) if dist[v] != -1: continue dist[v] = total_cost if v == sink: edge_trace = edge_memo break for i, (remain, target, cost, _) in enumerate(edges[v]): if remain and dist[target] == -1: heappush(queue, (total_cost + cost, target, edge_memo + (i,))) if dist[sink] == -1: return -1 aug = min(required_flow, min(e[0] for e in trace(source, edge_trace))) required_flow -= aug res += aug * dist[sink] for e in trace(source, edge_trace): remain, target, cost, idx = e e[0] -= aug edges[target][idx][0] += aug return res n, m, f = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): s, t, c, d = map(int, input().split()) es, et = edges[s], edges[t] ls, lt = len(es), len(et) es.append([c, t, d, lt]) et.append([0, s, d, ls]) print(min_cost_flow(0, n - 1, f)) ```
instruction
0
25,577
11
51,154
No
output
1
25,577
11
51,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output Submitted Solution: ``` from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, used, all_weight, connect): max_weight = all_weight max_source = source used[source] = 1 for target, weight in connect[source]: if not used[target]: now_weight = all_weight + weight this_source, this_weight = dfs(target, used, now_weight, connect) if max_weight < this_weight: max_weight = this_weight max_source = this_source return [max_source, max_weight] vertice = int(input()) connect = defaultdict(list) for _ in range(vertice - 1): v1, v2, weight = (int(n) for n in input().split(" ")) connect[v1].append([v2, weight]) connect[v2].append([v1, weight]) answer = 0 start_v = 0 for i in range(2): used = [0 for n in range(vertice)] start_v, answer = dfs(start_v, used, 0, connect) print(answer) ```
instruction
0
25,578
11
51,156
No
output
1
25,578
11
51,157
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,731
11
51,462
Tags: constructive algorithms, implementation Correct Solution: ``` t = int(input()) for case in range(t): sud =[] change = [0,3,6] digit =["1","2","3","4","5","6","7","8","9"] for i in range(9): row = list(input()) col_set = i//3 row_set = change[i%3] tot_set = col_set+row_set ofset = 1 if tot_set==8: ofset-=1 c = row[tot_set] for d in digit: if d!=c: row[tot_set]=d break sud.append("".join(row)) for r in sud: print(r) ```
output
1
25,731
11
51,463
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,732
11
51,464
Tags: constructive algorithms, implementation Correct Solution: ``` import sys import io, os def main(): input=sys.stdin.readline t=int(input()) for i in range(t): sudoku=[] for i in range(9): r=[int(i) for i in input() if i!='\n'] sudoku.append(r) #print(sudoku) sudoku[0][0]=sudoku[0][0]+1 if sudoku[0][0]==10: sudoku[0][0]=1 sudoku[1][3]=sudoku[1][3]+1 if sudoku[1][3]==10: sudoku[1][3]=1 sudoku[2][6]=sudoku[2][6]+1 if sudoku[2][6]==10: sudoku[2][6]=1 sudoku[3][1]=sudoku[3][1]+1 if sudoku[3][1]==10: sudoku[3][1]=1 sudoku[4][4]=sudoku[4][4]+1 if sudoku[4][4]==10: sudoku[4][4]=1 sudoku[5][7]=sudoku[5][7]+1 if sudoku[5][7]==10: sudoku[5][7]=1 sudoku[6][2]=sudoku[6][2]+1 if sudoku[6][2]==10: sudoku[6][2]=1 sudoku[7][5]=sudoku[7][5]+1 if sudoku[7][5]==10: sudoku[7][5]=1 sudoku[8][8]=sudoku[8][8]+1 if sudoku[8][8]==10: sudoku[8][8]=1 for i in sudoku: i=''.join(map(str,i)) sys.stdout.write(i+'\n') if __name__ == "__main__": main() ```
output
1
25,732
11
51,465
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,733
11
51,466
Tags: constructive algorithms, implementation Correct Solution: ``` """ Author: Q.E.D Time: 2020-04-13 10:20:12 """ T = int(input()) for _ in range(T): s = [] for _ in range(9): tmp = input() s.append(list(map(int, list(tmp)))) for i in range(3): d = i for j in range(3): x = i * 3 + d y = j * 3 + d v = s[i * 3 + (d + 1) % 3][j * 3 + (d + 1) % 3] s[x][y] = v d = (d + 1) % 3 print('\n'.join([''.join(list(map(str, s[i]))) for i in range(9)])) ```
output
1
25,733
11
51,467
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,734
11
51,468
Tags: constructive algorithms, implementation Correct Solution: ``` for i in range(int(input())): result = [] for j in range(9): l1 = list(input()) a = l1.index('2') l1[a] = '1' result.append(l1) for k in range(9): print("".join(result[k])) ```
output
1
25,734
11
51,469
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,735
11
51,470
Tags: constructive algorithms, implementation Correct Solution: ``` def hhh(i, j): x[i][j] += 1 if x[i][j] == 10: x[i][j] = 1 for t in range(int(input())): x = [] for a in range(9): a = list(map(int, list(input()))) x.append(a) hhh(0, 0) hhh(1, 3) hhh(2, 6) hhh(3, 1) hhh(4, 4) hhh(5, 7) hhh(6, 2) hhh(7, 5) hhh(8, 8) for i in range(9): print(''.join(map(str, x[i]))) ```
output
1
25,735
11
51,471
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,736
11
51,472
Tags: constructive algorithms, implementation Correct Solution: ``` t = int(input()) for _ in range(t): m = [] for i in range(9): s = input() n = '' for j in range(9): if s[j] == '1': n += '2' else: n += s[j] m.append(n) for i in m: print(i) ```
output
1
25,736
11
51,473
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563
instruction
0
25,737
11
51,474
Tags: constructive algorithms, implementation Correct Solution: ``` for t in range(int(input())): c=0 for i in range(1,10): st=input() newst=st[0:c]+str(int(st[c])%9+1)+st[c+1:9] print(newst) if i%3==0: c = c%3+1 else: c = c + 3 ```
output
1
25,737
11
51,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` from sys import stdin t = int(stdin.readline()) for _ in range(t): n = 9 a=[] for _ in range(n): a+=[list(map(int,list(stdin.readline())[:-1]))] for i in range(n): j = i//3 + 3*(i%3) a[i][j] = 1+(a[i][j]+1)%9 for i in range(n): print(''.join(map(str,a[i]))) ```
instruction
0
25,738
11
51,476
Yes
output
1
25,738
11
51,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") t=int(input()) for _ in range(t): x=[] for _ in range(9): a=input() a=a.replace('1','2') x.append(a) for i in x: print(i) ```
instruction
0
25,739
11
51,478
Yes
output
1
25,739
11
51,479
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` test = int(input()) def solve(): r = [] for x in range(9): s = input() m = s.replace("1","2") r.append(m) for y in r: print(y) for x in range(test): solve() ```
instruction
0
25,740
11
51,480
Yes
output
1
25,740
11
51,481
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` t=int(input()) a=1 for i in range(t*9): b=input() print(b.replace('1','7')) a=a+1 ```
instruction
0
25,741
11
51,482
Yes
output
1
25,741
11
51,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` from math import * def main(): for _ in range(int(input())): c=0 for i in range(9): row=list(map(int,input())) row[c]=(row[c]+1)%9 if row[c]==0: row[c]=1 for e in row: print(e,end='') c+=1 print() main() ```
instruction
0
25,742
11
51,484
No
output
1
25,742
11
51,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` t=int(input()) for tt in range(t): sudoku=[] for i in range(9): x=input() arr=[] for j in x: arr.append(int(j)) sudoku.append(arr) sudoku[0][0]=9-sudoku[0][0] sudoku[1][3]=9-sudoku[1][3] sudoku[2][6]=9-sudoku[2][6] sudoku[3][1]=9-sudoku[3][1] sudoku[4][4]=9-sudoku[4][4] sudoku[5][7]=9-sudoku[5][7] sudoku[6][2]=9-sudoku[6][2] sudoku[7][5]=9-sudoku[7][5] sudoku[8][8]=9-sudoku[8][8] for i in sudoku: for j in i: print(j,end='') print() ```
instruction
0
25,743
11
51,486
No
output
1
25,743
11
51,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` """ Template written to be used by Python Programmers. Use at your own risk!!!! Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces). """ import sys from functools import lru_cache from heapq import merge, heapify, heappop, heappush from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf from collections import defaultdict as dd, deque, Counter as c from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect # sys.setrecursionlimit(2*pow(10, 6)) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = pow(10, 9) + 7 mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(var): sys.stdout.write(str(var)) def outln(var): sys.stdout.write(str(var)+"\n") def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] for _ in range(int(data())): mat = [] for i in range(9): mat.append(list(data())) mat[0][0] = str(10 - int(mat[0][0])) mat[5][5] = str(10 - int(mat[5][5])) mat[7][7] = str(10 - int(mat[7][7])) mat[3][6] = str(10 - int(mat[3][6])) mat[4][1] = str(10 - int(mat[4][1])) mat[6][3] = str(10 - int(mat[6][3])) mat[8][2] = str(10 - int(mat[8][2])) mat[2][8] = str(10 - int(mat[2][8])) mat[1][4] = str(10 - int(mat[1][4])) for i in mat: outln(''.join(i)) ```
instruction
0
25,744
11
51,488
No
output
1
25,744
11
51,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose some 1 ≤ i, j ≤ 9 and change the number at the position (i, j) to any other number in range [1; 9]) to make it anti-sudoku. The anti-sudoku is the 9 × 9 field, in which: * Any number in this field is in range [1; 9]; * each row contains at least two equal elements; * each column contains at least two equal elements; * each 3 × 3 block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow. Each test case consists of 9 lines, each line consists of 9 characters from 1 to 9 without any whitespaces — the correct solution of the sudoku puzzle. Output For each test case, print the answer — the initial field with at most 9 changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists. Example Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 Output 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 Submitted Solution: ``` #!/usr/bin/env python3 import atexit import io import sys _I_B = sys.stdin.read().splitlines() input = iter(_I_B).__next__ _O_B = io.StringIO() sys.stdout = _O_B @atexit.register def write(): sys.__stdout__.write(_O_B.getvalue()) def main(): for _ in range(int(input())): so=[] r=[1]*9 c=[1]*9 for i in range(9): so.append(list(input().strip())) for i in range(9): for j in range(9): if so[i][j]!="1": if r[i] and c[j]: so[i][j]="1" r[i]=0 c[j]=0 for i in so: print("".join(i)) if __name__=='__main__': main() ```
instruction
0
25,745
11
51,490
No
output
1
25,745
11
51,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` def fun1(xx): # [[x1,y1],[x2,y2],[x3,y3],[x4,y4]] global ar,ans,mai zer=[] one=[] for i in xx: if(ar[i[0]][i[1]]==0): zer.append([i[0],i[1]]) else: one.append([i[0],i[1]]) ans+=2 mai.append([]) for i in zer: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=1 for i in one: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=0 break del one[0] mai.append([]) for i in zer: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=0 for i in one: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=0 def fun2(xx): global ar,ans,mai zer=[] one=[] for i in xx: if(ar[i[0]][i[1]]==0): zer.append([i[0],i[1]]) else: one.append([i[0],i[1]]) ans+=1 mai.append([]) zer.pop() for i in zer: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=1 for i in one: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=0 fun1(xx) def fun3(xx): global ar,ans,mai zer=[] one=[] for i in xx: if(ar[i[0]][i[1]]==0): zer.append([i[0],i[1]]) else: one.append([i[0],i[1]]) ans+=1 mai.append([]) for i in one: mai[-1].append(i[0]+1) mai[-1].append(i[1]+1) ar[i[0]][i[1]]=0 for _ in range(int(input())): n,m=map(int,input().split()) ar=[] ans=0 mai=[] for i in range(n): ar.append(list(map(int,list(input())))) for i in range(n-1): for j in range(m-1): zero=0 one=0 if(ar[i][j]==0): zero+=1 else: one+=1 if(ar[i+1][j]==0): zero+=1 else: one+=1 if(ar[i][j+1]==0): zero+=1 else: one+=1 if(ar[i+1][j+1]==0): zero+=1 else: one+=1 if(one==4): ans+=1 mai.append([]) mai[-1].append(i+1) mai[-1].append(j+1) mai[-1].append(i+2) mai[-1].append(j+1) mai[-1].append(i+1) mai[-1].append(j+2) ar[i][j]=0 ar[i][j+1]=0 ar[i+1][j]=0 elif(one==2 and zero==2): fun1([[i,j],[i,j+1],[i+1,j],[i+1,j+1]]) elif(zero==3 and one==1): fun2([[i,j],[i,j+1],[i+1,j],[i+1,j+1]]) elif(one==3): fun3([[i,j],[i,j+1],[i+1,j],[i+1,j+1]]) zero=0 one=0 if(ar[i][j]==0): zero+=1 else: one+=1 if(ar[i+1][j]==0): zero+=1 else: one+=1 if(ar[i][j+1]==0): zero+=1 else: one+=1 if(ar[i+1][j+1]==0): zero+=1 else: one+=1 if(one==4): ans+=1 mai.append([]) mai[-1].append(i+1) mai[-1].append(j+1) mai[-1].append(i+2) mai[-1].append(j+1) mai[-1].append(i+1) mai[-1].append(j+2) ar[i][j]=0 ar[i][j+1]=0 ar[i+1][j]=0 elif(one==2 and zero==2): fun1([[i,j],[i,j+1],[i+1,j],[i+1,j+1]]) elif(zero==3 and one==1): fun2([[i,j],[i,j+1],[i+1,j],[i+1,j+1]]) elif(one==3): fun3([[i,j],[i,j+1],[i+1,j],[i+1,j+1]]) print(ans) for i in mai: print(*i) ```
instruction
0
25,806
11
51,612
Yes
output
1
25,806
11
51,613
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` # Author : raj1307 - Raj Singh # Date : 14.09.2020 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def msi(): return map(str,input().strip().split(" ")) def li(): return list(mi()) def dmain(): sys.setrecursionlimit(1000000) threading.stack_size(1024000) thread = threading.Thread(target=main) thread.start() #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace #from math import log,sqrt,factorial,cos,tan,sin,radians #from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right #from decimal import * #import threading #from itertools import permutations #Copy 2D list m = [x[:] for x in mark] .. Avoid Using Deepcopy abc='abcdefghijklmnopqrstuvwxyz' abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def getKey(item): return item[1] def sort2(l):return sorted(l, key=getKey,reverse=True) def d2(n,m,num):return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo (x): return (x and (not(x & (x - 1))) ) def decimalToBinary(n): return bin(n).replace("0b","") def ntl(n):return [int(i) for i in str(n)] def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def ceil(x,y): if x%y==0: return x//y else: return x//y+1 def powerMod(x,y,p): res = 1 x %= p while y > 0: if y&1: res = (res*x)%p y = y>>1 x = (x*x)%p return res def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def main(): I = lambda : list(map(int,input().split())) A,B,C,D=[0,0],[0,1],[1,0],[1,1] def ch(a,b,c,d): a,b,c,d=int(a),int(b),int(c),int(d) x=a+b+c+d zz=A*(not a)+B*(not b)+C*(not c)+D*(not d) oo=A*a+B*b+C*c+D*d ar=[] if x==1: ar.append(oo+zz[2:]) ar.append(oo+zz[:2]+zz[4:]) ar.append(oo+zz[:4]) elif x==2: ar.append(zz+oo[:2]) ar.append(zz+oo[2:]) elif x==3: ar.append(A*a+B*b+C*c+D*d) elif x==4: ar.append(oo[2:]) zz=oo[2:];oo=oo[:2] ar.append(oo+zz[2:]) ar.append(oo+zz[:2]+zz[4:]) ar.append(oo+zz[:4]) return ar for tc in range(int(input())): n,m=I() l=[] for i in range(n): l.append(list(input().strip()) ) an=[] """ Last time I wrecked it, last time I whipped around Last time I did the whippets (yeah), last time I live reverse (yeah, yeah, ooh) Pour the brown, hit the reverend (yeah), last time I hit your crib (yeah) Last time there was no tenants I done went back in myself, felt like hell Fuck, I risked it, patience sell (yeah) Found you livin', know you thrillin', not for sinnin' (yeah) How I got my stripes in business, backin' out in the street (yeah) What is wild, let it be, ragers out, gotta eat (yeah) Not a vibe (yeah), but a wave, with the sound by the way Count it down, by the days (ooh) """ for i in range(0,n-1): for j in range(0,m-1): x=ch(l[i][j],l[i][j+1],l[i+1][j],l[i+1][j+1]) for pp in x: for k in range(6): pp[k]+=1+i*(k%2==0)+j*(k%2) an+=x l[i][j],l[i][j+1],l[i+1][j],l[i+1][j+1]=list("0000") """ Move in 'verse on my turf, I'm outta line, I put in work I draw the line and cross it first I need the time, I need the search It's just like wine, it make it worse Skrrt, skrrt in the 'vert, skrrt, skrrt Ride on land, Boeing jet, make it land It's slow motion when I dance In your eyes, I see your trance I run away and then you prance If I show the hideaway, would you hide out and let it blam? Ain't no time, I'm facin' scams, nah, nah (yeah) """ print(len(an)) for i in an: print(*i) # region fastio # template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py 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") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main() #dmain() # Comment Read() ```
instruction
0
25,807
11
51,614
Yes
output
1
25,807
11
51,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` for _ in range(int(input())): n, m = map(int, input().split()) cnt, A = 0, [] for i in range(n): A.append(input()) cnt += A[i].count('1') print(3*cnt) for i in range(n): for j in range(m): if A[i][j] == '1': x, y = 1, 1 if i==n-1:x=-1 if j==m-1:y=-1 print(i+1, j+1, i+x+1, j+1, i+1, j+y+1) print(i+1, j+1, i+x+1, j+y+1, i+1, j+y+1) print(i+1, j+1, i+x+1, j+1, i+x+1, j+y+1) ```
instruction
0
25,808
11
51,616
Yes
output
1
25,808
11
51,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` t=int(input()) for _ in range(t): n,m=map(int,input().split()) l=[] for i in range(n): l.append(list(input())) o=0 a=[] for i in range(n): for j in range(m): if l[i][j]=='1' and j!=m-1 and i!=n-1: o+=3 a.append([i+1,j+1,i+1,j+1+1,i+1+1,j+1]) a.append([i+1,j+1,i+1,j+1+1,i+1+1,j+1+1]) a.append([i+1,j+1,i+1+1,j+1,i+1+1,j+1+1]) elif l[i][j]=='1' and j==m-1 and i!=n-1: o+=3 a.append([i+1,j+1,i+1,j,i+2,j+1]) a.append([i+1,j+1,i+1,j,i+2,j]) a.append([i+1,j+1,i+2,j+1,i+2,j]) elif l[i][j]=='1' and i==n-1 and j!=m-1: o+=3 a.append([i+1,j+1,i,j+1,i+1,j+2]) a.append([i+1,j+1,i+1,j+2,i,j+2]) a.append([i+1,j+1,i,j+1,i,j+2]) elif l[i][j]=='1' and i==n-1 and j==m-1: o+=3 a.append([i+1,j+1,i+1,j,i,j+1]) a.append([i+1,j+1,i+1,j,i,j]) a.append([i+1,j+1,i,j+1,i,j]) print(o) for i in range(len(a)): for j in range(6): print(a[i][j],end=' ') print('') ```
instruction
0
25,809
11
51,618
Yes
output
1
25,809
11
51,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` t=int(input()) for _ in range(t): n,m=map(int,input().split()) l=[] for i in range(n): l.append(list(input())) o=0 a=[] for i in range(n): for j in range(m): if l[i][j]=='1' and j!=m-1 and i!=n-1: o+=3 a.append([i+1,j+1,i+1,j+1+1,i+1+1,j+1]) a.append([i+1,j+1,i+1,j+1+1,i+1+1,j+1+1]) a.append([i+1,j+1,i+1+1,j+1,i+1+1,j+1+1]) elif l[i][j]=='1' and j==m-1: o+=3 a.append([i+1,j+1,i+1,j,i+2,j+1]) a.append([i+1,j+1,i+1,j,i+2,j]) a.append([i+1,j+1,i+2,j+1,i+2,j]) elif l[i][j]=='1' and i==n-1: o+=3 a.append([i+1,j+1,i,j+1,i+1,j+2]) a.append([i+1,j+1,i+1,j+2,i,j+2]) a.append([i+1,j+1,i,j+1,i,j+2]) print(o) for i in range(len(a)): for j in range(6): print(a[i][j],end=' ') print('') ```
instruction
0
25,810
11
51,620
No
output
1
25,810
11
51,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` #list(map(int, input().rstrip().split())) t = int(input()) for test in range(t): [n,m] = list(map(int, input().rstrip().split())) g = [[0 for _ in range(m)] for _ in range(n)] for i in range(n): s = input() for j in range(m): g[i][j] = int(s[j]) o = 0 op = list() for i in range(n-2): for j in range(m-2): if g[i][j] == 1: o += 1 op.append([i, j, i+1, j, i, j+1]) g[i+1][j] = 1 - g[i+1][j] g[i][j+1] = 1 - g[i][j+1] for i in range(n-2): if g[i][m-2] == 1: o += 1 if g[i][m-1] == 1: op.append([i, m-2, i, m-1, i+1, m-2]) g[i+1][m-2] = 1 - g[i+1][m-2] else: op.append([i, m-2, i+1, m-1, i+1, m-2]) g[i+1][m-2] = 1 - g[i+1][m-2] g[i+1][m-1] = 1 - g[i+1][m-1] for j in range(m-2): if g[n-2][j] == 1: o += 1 if g[n-1][j] == 1: op.append([n-2, j, n-1, j, n-2, j+1]) g[n-2][j+1] = 1 - g[n-2][j+1] else: op.append([n-2, j, n-1, j+1, n-2, j+1]) g[n-2][j+1] = 1 - g[n-2][j+1] g[n-1][j+1] = 1 - g[n-1][j+1] d = {0: [], 1: []} for i in range(n-2, n): for j in range(m-2, m): d[g[i][j]].append([i,j]) if len(d[1]) == 4: o += 4 op.append([n-2, m-2, n-1, m-2, n-2, m-1]) op.append([n-1, m-1, n-2, m-2, n-1, m-2]) op.append([n-2, m-1, n-1, m-1, n-2, m-2]) op.append([n-1, m-2, n-2, m-1, n-1, m-1]) elif len(d[1]) == 3: o += 1 oper = [] l = d[1] for x, y in l: oper.append(x) oper.append(y) op.append(oper) elif len(d[1]) == 2: o += 2 oper = [] l = d[0] for x, y, in l: oper.append(x) oper.append(y) oper.append(d[1][0][0]) oper.append(d[1][0][1]) op.append(oper) oper = [] for x, y, in l: oper.append(x) oper.append(y) oper.append(d[1][1][0]) oper.append(d[1][1][1]) op.append(oper) elif len(d[1]) == 1: o += 3 oper = [] oper.append(d[1][0][0]) oper.append(d[1][0][1]) oper.append(d[0][0][0]) oper.append(d[0][0][1]) oper.append(d[0][1][0]) oper.append(d[0][1][1]) op.append(oper) newd = {0: [d[1][0], d[0][2]], 1: [d[0][0], d[0][1]]} d = newd oper = [] l = d[0] for x, y, in l: oper.append(x) oper.append(y) oper.append(d[1][0][0]) oper.append(d[1][0][1]) op.append(oper) oper = [] for x, y, in l: oper.append(x) oper.append(y) oper.append(d[1][1][0]) oper.append(d[1][1][1]) op.append(oper) print(o) for i in range(o): print(" ".join(map(str, op[i]))) ```
instruction
0
25,811
11
51,622
No
output
1
25,811
11
51,623
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` from sys import stdout,stdin from collections import defaultdict,deque import math d=defaultdict(tuple) d[('1','1','1','1')]=('0','0','1','0') d[('1','1','1','0')]=('0','0','0','0') d[('1','1','0','1')]=('0','0','0','0') d[('1','1','0','0')]=('0','0','1','0') d[('1','0','1','1')]=('0','0','0','0') d[('1','0','1','0')]=('0','0','0','1') d[('1','0','0','1')]=('1','1','1','0') d[('1','0','0','0')]=('0','1','1','0') d[('0','1','1','1')]=('0','0','0','0') d[('0','1','1','0')]=('1','0','1','1') d[('0','1','0','1')]=('1','1','1','0') d[('0','1','0','0')]=('1','0','0','1') d[('0','0','1','1')]=('0','1','0','0') d[('0','0','1','0')]=('1','0','0','1') d[('0','0','0','1')]=('0','1','1','0') d[('0','0','0','0')]=('0','0','0','0') t=int(stdin.readline()) for _ in range(t): #n=int(stdin.readline()) n,m=map(int,stdin.readline().split()) #l=list(map(int,stdin.readline().split())) l=[] for i in range(n): l.append(list(stdin.readline().strip())) x,y=False,False if n%2!=0: n-=1 x=True if m%2!=0: m-=1 y=True an=0 ans=[] for i in range(0,n,2): for j in range(0,m,2): temp=(l[i][j],l[i][j+1],l[i+1][j],l[i+1][j+1]) while(temp!=('0','0','0','0')): an+=1 ll=[] kk=d[temp] if kk[0]!=temp[0]: ll.append(i+1) ll.append(j+1) if kk[1]!=temp[1]: ll.append(i+1) ll.append(j+2) if kk[2]!=temp[2]: ll.append(i+2) ll.append(j+1) if kk[3]!=temp[3]: ll.append(i+2) ll.append(j+2) temp=kk ans.append(ll) #print(ans) if x: for j in range(0,m,2): temp=('0','0',l[n][j],l[n][j+1]) while(temp!=('0','0','0','0')): an+=1 ll=[] kk=d[temp] if kk[0]!=temp[0]: ll.append(n+1) ll.append(j+1) if kk[1]!=temp[1]: ll.append(n+1) ll.append(j+2) if kk[2]!=temp[2]: ll.append(n+2) ll.append(j+1) if kk[3]!=temp[3]: ll.append(n+2) ll.append(j+2) temp=kk ans.append(ll) if y: for j in range(0,n,2): temp=('0',l[i][m],'0',l[i+1][m]) while(temp!=('0','0','0','0')): an+=1 ll=[] kk=d[temp] if kk[0]!=temp[0]: ll.append(i+1) ll.append(m+1) if kk[1]!=temp[1]: ll.append(i+1) ll.append(m+2) if kk[2]!=temp[2]: ll.append(i+2) ll.append(m+1) if kk[3]!=temp[3]: ll.append(i+2) ll.append(m+2) temp=kk ans.append(ll) if(x&y): temp=('0','0','0',l[n][m]) while(temp!=('0','0','0','0')): an+=1 ll=[] kk=d[temp] if kk[0]!=temp[0]: ll.append(n+1) ll.append(m+1) if kk[1]!=temp[1]: ll.append(n+1) ll.append(m+2) if kk[2]!=temp[2]: ll.append(n+2) ll.append(m+1) if kk[3]!=temp[3]: ll.append(n+2) ll.append(m+2) temp=kk ans.append(ll) print(an) for i in range(an): print(*ans[i]) ```
instruction
0
25,812
11
51,624
No
output
1
25,812
11
51,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` import sys ii = lambda: sys.stdin.readline().strip() idata = lambda: [int(qw) for qw in ii().split()] def check(a, b, c, d, x, y): if a == b == c == d == '0': return [] if a == b == c == d == '1': return [[x, y, x + 1, y, x, y + 1], [x + 1, y, x, y + 1, x + 1, y + 1], [x + 1, y, x, y, x + 1, y + 1], [x, y, x + 1, y + 1, x, y + 1]] if int(a) + int(b) + int(c) + int(d) == 1: if a == '1': return [[x, y, x + 1, y, x, y + 1], [x, y, x + 1, y + 1, x + 1, y], [x, y, x + 1, y + 1, x, y + 1]] if d == '1': return [[x + 1, y + 1, x + 1, y, x, y + 1], [x, y, x + 1, y + 1, x + 1, y], [x, y, x + 1, y + 1, x, y + 1]] if b == '1': return [[x + 1, y, x, y, x + 1, y + 1], [x, y, x + 1, y, x, y + 1], [x, y + 1, x + 1, y + 1, x + 1, y]] return [[x, y + 1, x, y, x + 1, y + 1], [x, y, x + 1, y, x, y + 1], [x, y + 1, x + 1, y + 1, x + 1, y]] if int(a) + int(b) + int(c) + int(d) == 2: if a == d == '0': return [[x + 1, y, x, y, x + 1, y + 1], [x, y, x + 1, y + 1, x, y + 1]] if c == b == '0': return [[x, y, x + 1, y, x, y + 1], [x + 1, y, x, y + 1, x + 1, y + 1]] if a == b == '0': return [[x, y, x + 1, y, x, y + 1], [x + 1, y, x, y, x + 1, y + 1]] if c == d == '0': return [[x, y, x + 1, y + 1, x, y + 1], [x + 1, y, x, y + 1, x + 1, y + 1]] if a == c == '0': return [[x + 1, y, x, y, x, y + 1], [x, y, x, y + 1, x + 1, y + 1]] return [[x, y, x + 1, y, x + 1, y + 1], [x + 1, y, x + 1, y + 1, x, y + 1]] if int(a) + int(b) + int(c) + int(d) == 3: if a == '0': return [[x + 1, y, x, y + 1, x + 1, y + 1]] if b == '0': return [[x, y, x + 1, y + 1, x, y + 1]] if c == '0': return [[x + 1, y, x, y, x + 1, y + 1]] return [[x, y, x + 1, y, x, y + 1]] def solve(): n, m = idata() data = [] moves = [] for i in range(n): data += [list(ii())] for i in range(0, n - 1, 2): for j in range(0, m - 1, 2): d = check(data[i][j], data[i][j + 1], data[i + 1][j], data[i + 1][j + 1], i + 1, j + 1) for e in d: a1, a2, a3, a4, a5, a6 = e moves += [[a2, a1, a4, a3, a6, a5]] if n % 2 == 0 and m % 2 == 0: print(len(moves)) for i in range(len(moves)): print(*moves[i]) else: if n % 2 == 0: for i in range(n - 1): data[i][-2] = '0' for i in range(0, n - 1, 2): d = check(data[i][-2], data[i][-1], data[i + 1][-2], data[i + 1][-1], i + 1, m - 1) for e in d: a1, a2, a3, a4, a5, a6 = e moves += [[a2, a1, a4, a3, a6, a5]] elif m % 2 == 0: for i in range(m - 1): data[-2][i] = '0' for i in range(0, m - 1, 2): d = check(data[-2][i], data[-2][i + 1], data[-1][i], data[-1][i + 1], n - 1, i + 1) for e in d: a1, a2, a3, a4, a5, a6 = e moves += [[a2, a1, a4, a3, a6, a5]] else: for i in range(n - 1): data[i][-2] = '0' for i in range(m - 1): data[-2][i] = '0' for i in range(0, n - 1, 2): d = check(data[i][-2], data[i][-1], data[i + 1][-2], data[i + 1][-1], i + 1, m - 1) for e in d: a1, a2, a3, a4, a5, a6 = e moves += [[a2, a1, a4, a3, a6, a5]] data[-2][-2] = '0' data[-2][-1] = '0' for i in range(0, m - 1, 2): d = check(data[-2][i], data[-2][i + 1], data[-1][i], data[-1][i + 1], n - 1, i + 1) for e in d: a1, a2, a3, a4, a5, a6 = e moves += [[a2, a1, a4, a3, a6, a5]] data[-1][-2] = '0' d = check(data[-2][-2], data[-2][-1], data[-1][-2], data[-1][-1], n - 1, m - 1) for e in d: a1, a2, a3, a4, a5, a6 = e moves += [[a2, a1, a4, a3, a6, a5]] print(len(moves)) for i in range(len(moves)): print(*moves[i]) return for _t in range(int(ii())): solve() ```
instruction
0
25,813
11
51,626
No
output
1
25,813
11
51,627
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,235
11
52,470
"Correct Solution: ``` def f(a,d,T): try: return T.index(a,d+1) except ValueError: return len(T) def g(a,d,T): try: return (d-1)-T[d-1::-1].index(a) except ValueError: return 0 A=26 D=int(input()) C=[0]+list(map(int,input().split())) #減る満足度のベース S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度 for i in range(1,D+1): S[i]=[0]+list(map(int,input().split())) T=[0] for i in range(D): T.append(int(input())) X=0 L=[0]*(A+1) for d in range(1,D+1): X+=S[d][T[d]] for j in range(1,A+1): if j!=T[d]: L[j]+=1 X-=C[j]*L[j] else: L[j]=0 M=int(input()) for _ in range(M): d,q=map(int,input().split()) p=T[d] Y=(d-g(p,d,T))*(f(p,d,T)-d) Z=(d-g(q,d,T))*(f(q,d,T)-d) T[d]=q X+=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p] print(X) ```
output
1
26,235
11
52,471
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,236
11
52,472
"Correct Solution: ``` def f(a,d,T): try: return T[d:].index(a)+d except ValueError: return len(T) from random import randint A=26 D=int(input()) C=[0]+list(map(int,input().split())) #減る満足度のベース S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度 for i in range(1,D+1): S[i]=[0]+list(map(int,input().split())) T=[0] for i in range(D): T.append(int(input())) L=[[0]*(A+1) for _ in range(D+1)] for x in range(1,D+1): t=T[x] for j in range(1,A+1): if t!=j: L[x][j]=L[x-1][j]+1 else: L[x][j]=0 X=0 for d in range(1,D+1): X+=S[d][T[d]] for j in range(1,A+1): X-=C[j]*L[d][j] M=int(input()) for _ in range(M): d,q=map(int,input().split()) p=T[d] a=f(p,d+1,T) b=f(q,d+1,T) Y=0 h=L[d-1][p] for i in range(d,a): h+=1 Y+=h-L[i][p] L[i][p]=h m=0 Z=0 for j in range(d,b): Z-=m-L[j][q] L[j][q]=m m+=1 X+=(S[d][q]-S[d][p])+Z*C[q]-Y*C[p] print(X) T[d]=q ```
output
1
26,236
11
52,473
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,237
11
52,474
"Correct Solution: ``` import sys sys.setrecursionlimit(300000) from collections import defaultdict def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') D = I() C = LMI() S = [LMI() for _ in range(D)] T = [I() - 1 for _ in range(D)] M = I() last = [[i + 1] * 26 for i in range(D)] for d in range(D): i = T[d] j = 0 for dd in range(d, D): last[dd][i] = j j += 1 def eval(d, q): i = T[d] val = S[d][q] - S[d][i] contrib = 0 if d == 0: j = 1 else: j = last[d - 1][i] + 1 for dd in range(d, D): if dd > d and last[dd][i] == 0: break contrib += j - last[dd][i] last[dd][i] = j j += 1 val -= contrib * C[i] contrib = 0 j = 0 for dd in range(d, D): if last[dd][q] == 0: break contrib += last[dd][q] - j last[dd][q] = j j += 1 val += contrib * C[q] T[d] = q return val def score0(T): last = defaultdict(int) ans = 0 for d in range(D): ans += S[d][T[d]] last[T[d]] = d + 1 for i in range(26): ans -= C[i] * (d + 1 - last[i]) return ans score = score0(T) for d, q in [tuple(MI0()) for _ in range(M)]: val = eval(d, q) score += val print(score) ```
output
1
26,237
11
52,475
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,238
11
52,476
"Correct Solution: ``` def P(s): i,R,P,*L=[0]*29 while i<D:t=I[i+D][0]-1;P+=s-(i+1-L[t])*C[t];R+=I[i][t]-P;i+=1;L[t]=i return R (D,),C,*I=[[*map(int,t.split())]for t in open(0)] for d,q in I[D-~D:]:I[d-1+D][0]=q;print(P(sum(C))) ```
output
1
26,238
11
52,477
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,239
11
52,478
"Correct Solution: ``` import sys from bisect import bisect_left def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 9 + 7 EPS = 10 ** -10 def get_sum(a, d, n): """ 等差数列の和:(初項a, 公差d, 項数n) """ return (2*a + (n-1)*d) * n // 2 D = INT() M = 26 C = LIST() S = [[]] * (D+1) S[0] = [0] * M for i in range(1, D+1): S[i] = LIST() adjli = [[0] for i in range(M)] T = [0] + [t-1 for t in LIST(D)] for d, t in enumerate(T[1:], 1): adjli[t].append(d) for i in range(M): adjli[i].append(D+1) def check(T): score = 0 for a in range(M): for i in range(1, len(adjli[a])): curd = adjli[a][i-1] nxtd = adjli[a][i] cnt = nxtd - curd score += S[curd][a] score -= C[a] * get_sum(0, 1, cnt) return score # day日目のコンテストをaからbに変更する def change(day, a, b): res = 0 # コンテストaのコストを再計算 res -= S[day][a] di = adjli[a].index(day) for i in range(di, di+2): curd = adjli[a][i-1] nxtd = adjli[a][i] cnt = nxtd - curd res += C[a] * get_sum(0, 1, cnt) adjli[a].pop(di) curd = adjli[a][di-1] nxtd = adjli[a][di] cnt = nxtd - curd res -= C[a] * get_sum(0, 1, cnt) # コンテストbのコストを再計算 res += S[day][b] di = bisect_left(adjli[b], day) curd = adjli[b][di-1] nxtd = adjli[b][di] cnt = nxtd - curd res += C[b] * get_sum(0, 1, cnt) adjli[b].insert(di, day) for i in range(di, di+2): curd = adjli[b][i-1] nxtd = adjli[b][i] cnt = nxtd - curd res -= C[b] * get_sum(0, 1, cnt) return res score = check(T) Q = INT() for i in range(Q): d, q = MAP() q -= 1 score += change(d, T[d], q) print(score) T[d] = q ```
output
1
26,239
11
52,479
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,240
11
52,480
"Correct Solution: ``` import random D=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for i in range(D)] plus=0 minus=0 data=[[1 for i in range(D)] for j in range(26)] ans=[0]*D for i in range(D): t=int(input()) ans[i]=t plus+=s[i][t-1] if i!=0: for j in range(26): data[j][i]=data[j][i-1]+1 data[t-1][i]=0 minus+=sum(c[j]*data[j][i] for j in range(26)) #for i in range(26): #print(data[i]) M=int(input()) for _ in range(M): d,q=map(int,input().split()) plus+=s[d-1][q-1]-s[d-1][ans[d-1]-1] pre=ans[d-1] #print("pre",pre) ans[d-1]=q for j in range(d-1,D): if data[q-1][j]!=0: if j==d-1: minus+=0*c[q-1]-data[q-1][d-1]*c[q-1] data[q-1][d-1]=0 else: minus+=(data[q-1][j-1]+1-data[q-1][j])*c[q-1] data[q-1][j]=data[q-1][j-1]+1 else: break for j in range(d-1,D): if data[pre-1][j]!=0 or j==d-1: if j==0: minus+=c[pre-1] data[pre-1][0]=1 else: minus+=(data[pre-1][j-1]+1-data[pre-1][j])*c[pre-1] data[pre-1][j]=data[pre-1][j-1]+1 else: break print(plus-minus) #for i in range(26): #print(data[i]) ```
output
1
26,240
11
52,481
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,241
11
52,482
"Correct Solution: ``` from bisect import bisect_left D = int(input()) C = [0]+list(map(int, input().split())) S = [0]+[[0] + list(map(int, input().split())) for _ in range(D)] contest = [[0] for _ in range(27)] #SL:満足度、sch:スケジュール SL, sch = 0, [0] #tの日程でコンテストを行った時の満足度を計算 for d in range(1, D+1): t = int(input()) sch.append(t) #コンテストの開催日時を記録 contest[t].append(d) SL += S[d][t] for i in range(1, 27): SL -= C[i]*(d-contest[i][-1]) for i in range(1, 27): contest[i].append(D+1) # print("contest", contest) # print("sch", sch) # print(S) M = int(input()) for i in range(M): d, q = map(int, input().split()) SL += S[d][q]-S[d][sch[d]] # print("1", contest[sch[d]]) ind = bisect_left(contest[sch[d]], d) # print("2", ind) k = d-contest[sch[d]][ind-1] l = contest[sch[d]][ind+1]-d SL -= C[sch[d]]*k*l del contest[sch[d]][ind] ind = bisect_left(contest[q], d) contest[q].insert(ind, d) k = d-contest[q][ind-1] l = contest[q][ind+1]-d SL += C[q]*k*l sch[d] = q print(SL) ```
output
1
26,241
11
52,483
Provide a correct Python 3 solution for this coding contest problem. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884
instruction
0
26,242
11
52,484
"Correct Solution: ``` import bisect D = int(input()) c = [0] + list(map(int, input().split())) s = [0] + [[0] + list(map(int, input().split())) for _ in range(D)] held = [[0] for _ in range(27)] SL, sch = 0, [0] for d in range(1, D+1): t = int(input()) sch.append(t) held[t].append(d) SL += s[d][t] for i in range(1, 27): SL -= c[i] * (d - held[i][-1]) for i in range(1, 27): held[i].append(D+1) M = int(input()) for i in range(M): d, q = map(int, input().split()) SL += s[d][q] - s[d][sch[d]] ind = bisect.bisect_left(held[sch[d]], d) k = d - held[sch[d]][ind-1] l = held[sch[d]][ind+1] - d SL -= c[sch[d]] * k * l del held[sch[d]][ind] ind = bisect.bisect_left(held[q], d) held[q].insert(ind, d) k = d - held[q][ind-1] l = held[q][ind+1] - d SL += c[q] * k * l sch[d] = q print(SL) ```
output
1
26,242
11
52,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884 Submitted Solution: ``` from random import randint import sys input = sys.stdin.readline INF = 9223372036854775808 def calc_score(D, C, S, T): """ 開催日程Tを受け取ってそこまでのスコアを返す コンテストi 0-indexed d 0-indexed """ score = 0 last = [0]*26 # コンテストiを前回開催した日 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] return score def update_score(D, C, S, T, score, ct, ci): """ ct日目のコンテストをコンテストciに変更する スコアを差分更新する ct: change t 変更日 0-indexed ci: change i 変更コンテスト 0-indexed """ new_score = score last = [0]*26 # コンテストiを前回開催した日 prei = T[ct] # 変更前に開催する予定だったコンテストi for d, t in enumerate(T, start=1): last[t] = d new_score += (d - last[prei])*C[prei] new_score += (d - last[ci])*C[ci] last = [0]*26 T[ct] = ci for d, t in enumerate(T, start=1): last[t] = d new_score -= (d - last[prei])*C[prei] new_score -= (d - last[ci])*C[ci] new_score -= S[ct][prei] new_score += S[ct][ci] return new_score def local_search(): pass def main(D, C, S): T = [] for d in range(D): # d日目終了時点で満足度が一番高くなるようなコンテストiを開催する max_score = -INF best_i = 1 for i in range(26): T.append(i) score = calc_score(D, C, S, T) if max_score < score: max_score = score best_i = i T.pop() T.append(best_i) return T if __name__ == '__main__': D = int(input()) C = [int(i) for i in input().split()] S = [[int(i) for i in input().split()] for j in range(D)] T = [int(input())-1 for i in range(D)] M = int(input()) DQ = [[int(i)-1 for i in input().split()] for j in range(M)] score = calc_score(D, C, S, T) for d, q in DQ: score = update_score(D, C, S, T, score, d, q) T[d] = q print(score) ```
instruction
0
26,243
11
52,486
Yes
output
1
26,243
11
52,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That is, the i-th query is applied to the new schedule obtained by the (i-1)-th query. Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D M d_1 q_1 d_2 q_2 \vdots d_M q_M * The constraints and generation methods for the input part are the same as those for Problem A. * For each d=1,\ldots,D, t_d is an integer generated independently and uniformly at random from {1,2,\ldots,26}. * The number of queries M is an integer satisfying 1\leq M\leq 10^5. * For each i=1,\ldots,M, d_i is an integer generated independently and uniformly at random from {1,2,\ldots,D}. * For each i=1,\ldots,26, q_i is an integer satisfying 1\leq q_i\leq 26 generated uniformly at random from the 25 values that differ from the type of contest on day d_i. Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Output Let v_i be the final satisfaction at the end of day D on the schedule after applying the i-th query. Print M integers v_i to Standard Output in the following format: v_1 v_2 \vdots v_M Example Input 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 5 1 7 4 11 3 4 5 24 4 19 Output 72882 56634 38425 27930 42884 Submitted Solution: ``` import sys input = lambda: sys.stdin.buffer.readline() L = 26 D = int(input()) C = list(map(int, input().split())) S = [list(map(int, input().split())) for _ in range(D)] T = [int(input()) for _ in range(D)] M = int(input()) class BinaryIndexedTree: def __init__(self, n): self.n = n self.data = [0] * (self.n+1) def sum(self, i): res = 0 while i > 0: res += self.data[i] i -= i & -i return res def add(self, i, x): if i <= 0: raise IndexError while i <= self.n: self.data[i] += x i += i & -i def lower_bound(self, x): if x <= 0: return 0 cur, s, k = 0, 0, 1 << (self.n.bit_length()-1) while k: nxt = cur + k if nxt <= self.n and s + self.data[nxt] < x: s += self.data[nxt] cur = nxt k >>= 1 return cur + 1 def rsum(x): return x*(x+1)//2 b = [BinaryIndexedTree(D) for _ in range(L)] score = 0 for d, cont in enumerate(T): cont -= 1 b[cont].add(d+1, 1) score += S[d][cont] for i in range(L): m = b[i].sum(D) tmp = 0 s = [0] for j in range(1, m+1): s.append(b[i].lower_bound(j)) s.append(D+1) for j in range(len(s)-1): x = s[j+1] - s[j] - 1 tmp += rsum(x) score -= tmp*C[i] def chg(d, q): diff = 0 p = T[d]-1 d += 1 o = b[p].sum(d) d1 = b[p].lower_bound(o-1) d2 = b[p].lower_bound(o+1) diff += rsum(d-d1) * C[p] diff += rsum(d2-d) * C[p] diff -= rsum(d2-d1) * C[p] o = b[q].sum(d) d1 = b[q].lower_bound(o) d2 = b[q].lower_bound(o+1) diff += rsum(d2-d1) * C[q] diff -= rsum(d-d1) * C[q] diff -= rsum(d2-d) * C[q] b[p].add(d, -1) b[q].add(d, 1) d -= 1 T[d] = q+1 diff -= S[d][p] diff += S[d][q] return diff for _ in range(M): d, q = map(lambda x: int(x)-1, input().split()) diff = chg(d, q) score += diff print(score) ```
instruction
0
26,244
11
52,488
Yes
output
1
26,244
11
52,489