message
stringlengths
2
28.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
21
109k
cluster
float64
7
7
__index_level_0__
int64
42
217k
Provide a correct Python 3 solution for this coding contest problem. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2
instruction
0
28,867
7
57,734
"Correct Solution: ``` N,A,B=map(int,input().split()) ans=N//(A+B)*A X=N%(A+B) ans+=min(X,A) print(ans) ```
output
1
28,867
7
57,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` n,a,b=map(int,input().split()) x=n%(a+b) y=n//(a+b) print(y*a+min(x,a)) ```
instruction
0
28,868
7
57,736
Yes
output
1
28,868
7
57,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` n,a,b=map(int,input().split()) x=n//(a+b) y=n%(a+b) z=min(a,y) print(a*x+z) ```
instruction
0
28,869
7
57,738
Yes
output
1
28,869
7
57,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` n,a,b=map(int,input().split()) k=n//(a+b) print(k*a+min(a,n-k*(a+b))) ```
instruction
0
28,870
7
57,740
Yes
output
1
28,870
7
57,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` N,A,B = map(int,input().split()) C = N//(A+B) D = N%(A+B) print(C*A+min(D,A)) ```
instruction
0
28,871
7
57,742
Yes
output
1
28,871
7
57,743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` import math n, a, b = map(int, input().split()) c = a + b if (n % c >= a): m = a else: m = n % c print(math.floor(n / c * a + m)) ```
instruction
0
28,872
7
57,744
No
output
1
28,872
7
57,745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` N,A,B=map(int,input().split()) cnt_blue = 0 # try: pre_loop_cnt = N // (A+B) totol_pre_A = sum([A] * pre_loop_cnt) totol_pre_B = sum([B] * pre_loop_cnt) total_tmp = totol_pre_A + totol_pre_B total_tmp += A if N <= total_tmp: cnt_blue = N - totol_pre_B else: cnt_blue = totol_pre_A + A print(cnt_blue) # except: # print(0) ```
instruction
0
28,873
7
57,746
No
output
1
28,873
7
57,747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` import sys, math def input(): return sys.stdin.readline()[:-1] from itertools import permutations, combinations from collections import defaultdict, Counter from math import factorial from bisect import bisect_left # bisect_left(list, value) #from fractions import gcd enu = enumerate sys.setrecursionlimit(10**7) N, A, B = map(int, input().split()) AB = A+B cnt = A * (N//AB) cnt += N % AB print(cnt) ```
instruction
0
28,874
7
57,748
No
output
1
28,874
7
57,749
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: * Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints * 1 \leq N \leq 10^{18} * A, B \geq 0 * 0 < A + B \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of blue balls that will be there among the first N balls in the row of balls. Examples Input 8 3 4 Output 4 Input 8 0 4 Output 0 Input 6 2 4 Output 2 Submitted Solution: ``` n,a,b = map(int, input().split()) t = n // (a + b) if t == 1: print(a * t) else: if n - (a + b) * t >= a: print((a * t) + a) else: print((a * t) + (n - (t * n))) ```
instruction
0
28,875
7
57,750
No
output
1
28,875
7
57,751
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,573
7
59,146
Tags: dp, greedy, strings, trees Correct Solution: ``` s1 = input() s= input()+'.' s2=s1[::-1] l=len(s) ll=len(s1) a='' lis=[] for i in range(l): v=a+s[i] if v in s1 or v in s2: a=a+s[i] else: if a in s1: k=s1.index(a)+1 lis.append([k,k+len(a)-1]) # print(s1.index(a),a) elif a in s2: k=s2.index(a) lis.append([ll-k,ll-k-(len(a)-1)]) # print(k) else: print(-1) exit() a=s[i] print(len(lis)) for i in lis: print(*i) ```
output
1
29,573
7
59,147
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,574
7
59,148
Tags: dp, greedy, strings, trees Correct Solution: ``` s = input() t = input() + '.' rs, a, res = s[::-1], t[0], [] for i in range(1,len(t)): b = a + t[i] if b in s or b in rs: a = b continue if a in s: x = s.find(a) res.append([x+1, x+len(a)]) elif a in rs: x = rs.find(a) res.append([len(s)-x, len(s)-x-len(a)+1]) else: print(-1) exit() a = t[i] print(len(res)) for i in res: print(i[0], i[1]) ```
output
1
29,574
7
59,149
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,575
7
59,150
Tags: dp, greedy, strings, trees Correct Solution: ``` import sys s = input() s_reverse = s[::-1] t = input() first = [] second = [] pos = 0 def find_str(st, char): index = 0 if char in st: # print("===") c = char[0] for ch in st: if ch == c: if st[index:index+len(char)] == char: return index index += 1 # print (index) return -1 while pos < len(t): substr = t[pos:pos + 1] if substr not in s and substr not in s_reverse: print("-1") sys.exit() step = 1 while substr in s or substr in s_reverse: step += 1 substr = t[pos:(pos + step)] # print("substr %s" % substr) if pos + step > len(t): break step -= 1 substr = t[pos:(pos + step)] start = find_str(s, substr) # print ("debug %d %d %d" % (pos, step, start)) if start == -1: start = find_str(s_reverse, substr) # print ("newstart: %d" % start) # print("substr %s" % substr) first.append(len(s) - start) second.append(len(s) - (start + step - 1)) else: first.append(start + 1) second.append(start + step) pos = pos + step # print ("last %d %d" %(len(t), pos)) print(len(first)) for a, b in zip(first, second): print("%d %d" % (a, b)) # x = input("ccc") ```
output
1
29,575
7
59,151
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,576
7
59,152
Tags: dp, greedy, strings, trees Correct Solution: ``` def solve(s,t): hash_s = [False] * 256 hash_t = [False] * 256 arr = [] n = len(s) for c in s: hash_s[ord(c)] = True for c in t: hash_t[ord(c)] = True for i in range(256): if not hash_s[i] and hash_t[i]: print(-1) return rev = s[::-1] i,j = 0,0 while i < len(t): flag = True temp = t[i] j = i + 1 while j < len(t): temp += t[j] if temp not in s and temp not in rev: flag = False break j += 1 if flag: x = s.find(temp) if x != -1: arr.append((x + 1,x + len(temp))) # print('1',x + 1,x + len(temp)) else: y = rev.find(temp) arr.append((n - y,n - y - len(temp) + 1)) # print('2',n - y,n - y - len(temp) + 1) else: x = s.find(temp[:-1]) if x != -1: arr.append((x + 1,x + len(temp) - 1)) # print('3',x + 1,x + len(temp) - 1) else: x = rev.find(temp[:-1]) arr.append((n - x,n - x - len(temp) + 2)) # print('4',n - x,n - x - len(temp) + 2) i = j print(len(arr)) for x,y in arr: print(x,y) s = input() t = input() solve(s,t) ```
output
1
29,576
7
59,153
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,577
7
59,154
Tags: dp, greedy, strings, trees Correct Solution: ``` s = input() t = input() revS = s[::-1] n = len(s) cur=1 start=-1 end=-1 revFlag=0 errFlag=0 i=0 res=[] while i < len(t): if s.find(t[i:i+cur]) != -1 and i+cur <= len(t) and s.find(t[i:i+cur]) + cur <= n: start = s.find(t[i:i+cur]) + 1 end = start + cur - 1 cur += 1 elif revS.find(t[i:i+cur]) != -1 and i+cur <= len(t) and revS.find(t[i:i+cur]) + cur <= n: start = n - revS.find(t[i:i+cur]) end = start - cur + 1 cur += 1 else: if (start == -1 and end == -1) and (s.find(t[i:i+cur]) == -1 and revS.find(t[i:i+cur]) == -1): errFlag = 1 break i += cur - 1 cur = 1 res.append(str(start) + " " + str(end)) start = -1 end = -1 if errFlag != 1: print(len(res)) for p in res: print(p) else: print(-1) ```
output
1
29,577
7
59,155
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,578
7
59,156
Tags: dp, greedy, strings, trees Correct Solution: ``` def find_max_substr(t, s): l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in s: l = m + 1 else: r = m l1 = l rs = s[::-1] l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in rs: l = m + 1 else: r = m l2 = l if l1 >= l2: return s.find(t[:l1]) + 1, s.find(t[:l1]) + l1 else: return s.find(t[:l2][::-1]) + l2, s.find(t[:l2][::-1]) + 1 s = input() t = input() if not set(t).issubset(set(s)): print(-1) exit(0) a = [] while t: l, r = find_max_substr(t, s) a.append((l, r)) t = t[abs(r - l) + 1:] print(len(a)) for l, r in a: print(l, r) ```
output
1
29,578
7
59,157
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,579
7
59,158
Tags: dp, greedy, strings, trees Correct Solution: ``` def find_max_substr(t, s): l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in s: l = m + 1 else: r = m l1 = l rs = s[::-1] l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in rs: l = m + 1 else: r = m l2 = l if l1 >= l2: return s.find(t[:l1]) + 1, s.find(t[:l1]) + l1 else: return s.find(t[:l2][::-1]) + l2, s.find(t[:l2][::-1]) + 1 s = input() t = input() if not set(t).issubset(set(s)): print(-1) exit(0) a = [] while t: l, r = find_max_substr(t, s) a.append((l, r)) t = t[abs(r - l) + 1:] print(len(a)) for l, r in a: print(l, r) # Made By Mostafa_Khaled ```
output
1
29,579
7
59,159
Provide tags and a correct Python 3 solution for this coding contest problem. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at".
instruction
0
29,580
7
59,160
Tags: dp, greedy, strings, trees Correct Solution: ``` s = input() t = input() len_s = len(s) reversed_s = s[::-1] len_t = len(t) res = 0 pairs = [] indx = 0 while indx < len_t: if t[indx : indx + 1] not in s: print(-1) exit() i = 1 while (t[indx : indx + i] in s or t[indx : indx + i] in reversed_s) and indx + i < len_t + 1: i += 1 prev_i = i - 1 if t[indx : indx +prev_i] in s: x = s.find(t[indx : indx +prev_i]) pairs.append((x + 1, x + prev_i)) else: x = reversed_s.find(t[indx : indx + prev_i]) pairs.append((len_s - x, len_s - x - i + 2)) res += 1 indx += prev_i print(res) for a, b in pairs: print(a, b) ```
output
1
29,580
7
59,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` a, t = input(), input() + ' ' b = a[::-1] s, p = '', [] for q in t: d = s s += q if s in a or s in b: continue if d in a: k = a.find(d) p += [(k + 1, k + len(d))] elif d in b: k = b.rfind(d) p += [(len(a) - k, len(a) - k - len(d) + 1)] else: print(-1) exit() s = q print(len(p)) for i, j in p: print(i, j) ```
instruction
0
29,581
7
59,162
Yes
output
1
29,581
7
59,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` s = input() t = input() len_s = len(s) reversed_s = s[::-1] len_t = len(t) res = 0 pairs = [] indx = 0 while indx < len_t: if t[indx : indx + 1] not in s: print(-1) exit() i = 1 while (t[indx : indx + i] in s or t[indx : indx + i] in reversed_s) and indx + i < len_t + 1: i += 1 prev_i = i - 1 if t[indx : indx +prev_i] in s: x = s.find(t[indx : indx +prev_i]) pairs.append((x + 1, x + prev_i)) else: x = reversed_s.find(t[indx : indx + prev_i]) pairs.append((len_s - x, len_s - x - i + 2)) res += 1 indx += prev_i print(res) for first, second in pairs: print(first, second) ```
instruction
0
29,582
7
59,164
Yes
output
1
29,582
7
59,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` s, t = input(), input() p, d = [], [[] for i in range(26)] for i, q in enumerate(s): d[ord(q) - 97].append(i) i, n = 0, len(t) s += '+' t += '-' while i < n: q = t[i] a = b = c = 0 for j in d[ord(q) - 97]: k = 1 while t[i + k] == s[j + k]: k += 1 if k > a: a, b, c = k, j + 1, 1 k = 1 while t[i + k] == s[j - k]: k += 1 if k > a: a, b, c = k, j + 1, -1 if not a: print(-1) exit() i += a p.append((b, b + c * a - c)) print(len(p)) for i, j in p: print(i, j) ```
instruction
0
29,583
7
59,166
Yes
output
1
29,583
7
59,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` s = input() t = input() rs = s[::-1] a = t[0] t+='.' li=[] for i in range(1,len(t)): b = a + t[i] if b in s or b in rs: a = b else: if a in s: li.append([s.find(a)+1,s.find(a)+len(a)]) elif a in rs: li.append([len(s)-rs.find(a),len(s)-rs.find(a)-len(a)+1]) else: print(-1),exit(0) a = t[i] print(len(li)) for i in li:print(i[0],i[1]) ```
instruction
0
29,584
7
59,168
Yes
output
1
29,584
7
59,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` s = input() t = input() revS = s[::-1] n = len(s) cur=1 start=-1 end=-1 revFlag=0 errFlag=0 i=0 res=[] while i < len(t): if s.find(t[i:i+cur]) != -1 and i+cur <= len(t) and s.find(t[i:i+cur]) + cur <= n: start = s.find(t[i:i+cur]) + 1 end = start + cur - 1 cur += 1 elif revS.find(t[i:i+cur]) != -1 and i+cur <= len(t) and revS.find(t[i:i+cur]) + cur <= n: start = n - revS.find(t[i:i+cur]) end = start - cur + 1 cur += 1 else: if (start == -1 and end == -1) or (s.find(t[i:i+cur]) == -1 and revS.find(t[i:i+cur]) == -1): errFlag = 1 break i += cur - 1 cur = 1 res.append(str(start) + " " + str(end)) if errFlag != 1: print(len(res)) for p in res: print(p) else: print(-1) ```
instruction
0
29,585
7
59,170
No
output
1
29,585
7
59,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` s = input() t = input() len_s = len(s) reversed_s = s[::-1] len_t = len(t) res = 0 pairs = [] indx = 0 while indx < len_t: i = 1 to_find = t[indx : indx + i] if to_find not in s: print(-1) exit() while (to_find in s or to_find in reversed_s) and indx + i < len_t + 1: i += 1 prev_i = i - 1 if t[indx : indx + prev_i] in s: x = s.find(t[indx : indx + prev_i]) pairs.append((x + 1, x + prev_i)) else: x = reversed_s.find(t[indx : indx + prev_i]) first = len_s - x second = len_s - x - i + 2 pairs.append((first, second)) res += 1 indx += prev_i print(res) for first, second in pairs: print(first, second) ```
instruction
0
29,586
7
59,172
No
output
1
29,586
7
59,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` def get_max_sub(text): global m, z search_pos = len(text) - m * 2 - 1 n = len(text) t_pos = search_pos t_revers_pos = search_pos + m + 1 max_sub = ((0, 0), 0) l, r = 0, 0 for i in range(search_pos, n): z[i - search_pos] = 0 if i <= r: z[i - search_pos] = min(r - i + 1, z[i - l]) while(i + z[i - search_pos] < n) and (text[i + z[i - search_pos]] == text[z[i - search_pos]]): z[i - search_pos] += 1 if (z[i - search_pos] > max_sub[1]): if (t_pos <= i < t_revers_pos): max_sub = ((i - t_pos + 1, i - t_pos + z[i - search_pos]), z[i - search_pos]) else: max_sub = ((m - i + t_revers_pos, m - (i - t_revers_pos + z[i]) + 1), z[i - search_pos]) if (z[i - search_pos] == m): return (max_sub) if (i + z[i - search_pos] - 1) > r: l = i r = i + z[i - search_pos] - 1 return (max_sub) def main(): s, text = input(), input() if (set(s) == set(text)): if (len(text) > len(s)): if (len(text) % len(s) == 0): print(len(text) // len(s)) else: print(len(text) // len(s) + len(text) % len(s)) for i in range(len(text) // len(s)): print(1, len(s)) if (len(text) % len(s) != 0): print(1, len(text) % len(s)) return global m m = len(s) text = text + '#{}@{}'.format(s, s[::-1]) global z z = [0 for i in range(2 * m + 2)] ops = [] while(len(text) > 2 * (m + 1)): max_sub = get_max_sub(text) if (max_sub[1] == 0): break ops.append(max_sub[0]) text = text[max_sub[1]:] if len(text) > 2 * (m + 1): print(-1) else: print(len(ops)) for op in ops: print(*op) main() ```
instruction
0
29,587
7
59,174
No
output
1
29,587
7
59,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string. Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer. Input First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. Output The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t. Examples Input abc cbaabc Output 2 3 1 1 3 Input aaabrytaaa ayrat Output 3 1 1 6 5 8 7 Input ami no Output -1 Note In the first sample string "cbaabc" = "cba" + "abc". In the second sample: "ayrat" = "a" + "yr" + "at". Submitted Solution: ``` s = input() t = input() len_s = len(s) reversed_s = s[::-1] len_t = len(t) res = 0 pairs = [] indx = 0 while indx < len_t: if t[indx : indx + 1] not in s: print(-1) exit() i = 1 to_find = t[indx : indx + i] while (to_find in s or to_find in reversed_s) and indx + i < len_t + 1: i += 1 prev_i = i - 1 if t[indx : indx +prev_i] in s: x = s.find(t[indx : indx +prev_i]) pairs.append((x + 1, x + prev_i)) else: x = reversed_s.find(t[indx : indx + prev_i]) pairs.append((len_s - x, len_s - x - i + 2)) res += 1 indx += prev_i print(res) for first, second in pairs: print(first, second) ```
instruction
0
29,588
7
59,176
No
output
1
29,588
7
59,177
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,751
7
61,502
"Correct Solution: ``` M=998244353 N,*A=open(0) d=[0]*90001 d[0]=1 e=[0]*90001 e[0]=1 z=1 s=0 for a in A: i=s;a=int(a);s+=a;z*=3 while i+1:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print([(z+e[s//2]*3)%M,z][s%2]) ```
output
1
30,751
7
61,503
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,752
7
61,504
"Correct Solution: ``` import sys input = sys.stdin.readline n = int(input()) a = [int(input()) for i in range(n)] w = sum(a) mod =998244353 dp = [[0]*(w+1) for i in range(n)] cnt = a[0] dp[0][a[0]] = 1 dp[0][0] = 2 for i in range(1,n): cnt += a[i] for j in range(cnt+1): dp[i][j] = dp[i-1][j]*2 if j >= a[i]: dp[i][j] += dp[i-1][j-a[i]] dp[i][j] = dp[i][j]%mod #sより大きいのはブー s = w//2+1 if w %2 == 0: d = [[0]*(s+1) for i in range(n)] d[0][0] = 1 d[0][a[0]] = 1 cnt = a[0] for i in range(1,n): cnt += a[i] for j in range(min(cnt+1,s+1)): d[i][j] = d[i-1][j] if j >= a[i]: d[i][j] += d[i-1][j-a[i]] d[i][j] = d[i][j]%mod mns = d[-1][w//2] if w%2 == 0: s -= 1 cnt = 0 for i in range(s,w+1): cnt += dp[-1][i] cnt = cnt%mod res = (pow(3,n,mod)-cnt*3)%mod if w % 2 == 0: res = (res+mns*3)%mod print(res) ```
output
1
30,752
7
61,505
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,753
7
61,506
"Correct Solution: ``` n = int(input()) a = [int(input()) for i in range(n)] sum_a = sum(a) MOD = 998244353 dp = [0] * (sum_a + 1) dp[0] = 1 for i in range(n): for j in range(sum_a + 1)[::-1]: # 選ばないとき dp[j] += dp[j] if j - a[i] >= 0: dp[j] += dp[j - a[i]] dp[j] %= MOD dq = [0] * (sum_a + 1) dq[0] = 1 for i in range(n): for j in range(sum_a + 1)[::-1]: # 選ぶとき if j - a[i] >= 0: dq[j] += dq[j - a[i]] dq[j] %= MOD else: break ans = 0 for j in range(sum_a + 1): if sum_a <= j * 2: ans += dp[j] * 3 ans %= MOD if sum_a % 2 == 0: ans -= dq[sum_a // 2] * 3 print((3 ** n - ans) % MOD) ```
output
1
30,753
7
61,507
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,754
7
61,508
"Correct Solution: ``` N = int(input()) a = [int(input()) for _ in range(N)] s = sum(a) m = (s + 1) // 2 c1 = [0] * (m + 1) c1[m] = 1 for i in range(N): d = a[i] for j in range(m - d + 1): c1[j] = (2 * c1[j] + c1[j + d]) % 998244353 for j in range(m - d + 1, m + 1): c1[j] = (2 * c1[j] + c1[m]) % 998244353 ans1 = c1[0] if s % 2: c1[0] = 0 else: for j in range(m): c1[j] = 0 c1[m] = 1 for i in range(N): d = a[i] for j in range(m - d + 1): c1[j] = (c1[j] + c1[j + d]) % 998244353 for j in range(m - d + 1, m + 1): c1[j] = c1[j] ans = (3 ** N % 998244353 - 3 * ans1 + 3 * c1[0]) % 998244353 print(ans) ```
output
1
30,754
7
61,509
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,755
7
61,510
"Correct Solution: ``` M=998244353 N,*A=map(int,open(0)) d=[0]*90001 d[0]=1 e=[0]*90001 e[0]=1 z=1 s=0 for a in A: i=s;s+=a;z=z*3%M while i>=0: d[i+a]+=d[i]%M d[i]*=2 e[i+a]+=e[i]%M i-=1 for i in range(s+1>>1,s+1):z=(z-d[i]*3)%M print([(z+e[s//2]*3)%M,z][s%2]) ```
output
1
30,755
7
61,511
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,756
7
61,512
"Correct Solution: ``` N = int(input()) mod = 998244353 # DP ナップサックぽいやつ # DP[i][j] := a_0からa_iまでの部分集合で和がjになるものの個数 # 配るDPの方が場合分けがなくて簡潔に書ける 計算量増えるかも # DP[i-1][j]→DP[i][j]とDP[i][j + a_i ]に配る aaa = [int(input()) for _ in range(N)] sum_aaa = sum(aaa) sum_now = 0 DP = [[0] * (sum_aaa+1) for i in range(N)] DP2 = [[0] * (sum_aaa+1) for i in range(N)] a = aaa[0] DP[0][0] = 2 DP[0][a] = 1 DP2[0][0] = 1 DP2[0][a] = 1 sum_now += a for i in range(1, N): a = aaa[i] sum_now += a for j in range(sum_now + 1): if (j >= a): DP[i][j] = DP[i-1][j]*2 + DP[i-1][j-a] else: DP[i][j] = DP[i-1][j]*2 while (DP[i][j] > mod): DP[i][j] -= mod for j in range(min(sum_now + 1, int(sum_aaa /2)+1)): if (j >= a): DP2[i][j] = DP2[i-1][j] + DP2[i-1][j-a] else: DP2[i][j] = DP2[i-1][j] while (DP2[i][j] > mod): DP2[i][j] -= mod # print(DP2) minimum_invalid_length = int((sum_now+1)//2) num_too_long = sum (DP[N-1][minimum_invalid_length:]) if (sum_aaa %2 == 0): num_too_long -= DP2[N-1][int(sum_aaa /2)] # print(num_too_long) # print(sum(aaa)) print((3** N - num_too_long * 3) % mod ) ```
output
1
30,756
7
61,513
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,757
7
61,514
"Correct Solution: ``` M,z,s=998244353,1,0 N,*A=open(0) d=[1]+[0]*7**6 e=[1]+[0]*7**6 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 print((z+~s%2*e[s//2]*3-3*sum(d[-~s//2:]))%M) ```
output
1
30,757
7
61,515
Provide a correct Python 3 solution for this coding contest problem. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556
instruction
0
30,758
7
61,516
"Correct Solution: ``` M,z,s=998244353,1,0 N,*A=map(int,open(0)) d=[1]+[0]*7**6 e=[1]+[0]*7**6 for a in A: i=s;s+=a;z*=3 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print((z+~s%2*e[s//2]*3)%M) ```
output
1
30,758
7
61,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` def dp_table(*counts): # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ) if counts: return [dp_table(*counts[1:]) for _ in range(counts[0])] else: return 0 def main(): N = int(input()) A = [int(input()) for _ in range(N)] mod = 998244353 ans = pow(3, N, mod) sum_A = sum(A) dp = [[0] * (sum_A+1) for i in range(N)] # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数 # init dp[0][A[0]] = 1 dp[0][0] = 2 # 他の色のうちどちらに入れるかで2通り # init2 dp2 = [[0] * (sum_A+1) for i in range(N)] # ある二色でsum_Aを等分するパターンを数える dp2[0][A[0]] = 1 dp2[0][0] = 1 # 今度は片方に集中したパターン # dp sum_now = A[0] for i in range(1, N): a = A[i] sum_now += a for length in range(sum_now+1): # A[i]を追加しないのなら他の2食のうちどちらに入れるかで2倍選択肢がある if length >= a: dp[i][length] = dp[i - 1][length - a] + \ (dp[i - 1][length] << 1) else: dp[i][length] = dp[i-1][length] << 1 dp[i][length] %= mod for length in range(min(sum_now + 1, sum_A // 2 + 1)): if length >= a: dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length] else: dp2[i][length] = dp2[i-1][length] dp2[i][length] %= mod # print(sum(dp[N-1][sum_A//2])) # print(dp) ans -= 3*sum(dp[N-1][(sum_A+1)//2:]) if sum_A % 2 == 0: ans += 3*dp2[N-1][sum_A//2] print(ans % mod) if __name__ == '__main__': main() ```
instruction
0
30,759
7
61,518
Yes
output
1
30,759
7
61,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` N = int(input()) A = [int(input()) for _ in range(N)] sum_A = sum(A) MOD = 998244353 dp1 = [0] * (sum_A + 1) dp2 = [0] * (sum_A + 1) dp1[0] = dp2[0] = 1 tmp_sum = 0 for a in A: for i in reversed(range(tmp_sum + 1)): dp1[i] %= MOD dp2[i] %= MOD dp1[i + a] += dp1[i] dp1[i] <<= 1 dp2[i + a] += dp2[i] tmp_sum += a ans = pow(3, N, MOD) for i in range(sum_A + 1): if i * 2 >= sum_A: ans = (ans - dp1[i] * 3 + MOD * 3) % MOD if i * 2 == sum_A: ans = (ans + dp2[i] * 3) % MOD print(ans) ```
instruction
0
30,760
7
61,520
Yes
output
1
30,760
7
61,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` # D N = int(input()) a_list = [0]*N for i in range(N): a_list[i] = int(input()) L = 90001 LARGE = 998244353 DP = [0]*L DP[0] = 1 for i in range(N): for j in range(L-1, a_list[i]-1, -1): DP[j] = (2*DP[j] + DP[j - a_list[i]]) % LARGE for j in range(a_list[i]-1, -1, -1): DP[j] = (2*DP[j]) % LARGE DP2 = [0]*L DP2[0] = 1 for i in range(N): for j in range(L-1, a_list[i]-1, -1): DP2[j] = (DP2[j] + DP2[j - a_list[i]]) % LARGE for j in range(a_list[i]-1, -1, -1): DP2[j] = (DP2[j]) % LARGE S = sum(a_list) if S % 2 == 0: h = S // 2 res = ((3**N % LARGE) - (3*sum(DP[(h):]) % LARGE) + 3*DP2[h]) % LARGE else: h = S // 2 + 1 res = ((3**N % LARGE) - (3*sum(DP[(h):]) % LARGE)) % LARGE print(res) ```
instruction
0
30,761
7
61,522
Yes
output
1
30,761
7
61,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` # https://atcoder.jp/contests/tenka1-2019/submissions/5065329 import sys input = sys.stdin.readline N = int(input()) a = [int(input()) for _ in range(N)] total = sum(a) MOD = 998244353 '''(1)全体''' U = pow(3, N, MOD) # 三角形を構成できない場合を含むRGBの組み合わせ総数 '''(2)単円''' dp = [[0] * (total + 1) for _ in range(N + 1)] dp[0][0] = 1 # dp[i][R]:=i番目まででRとなる場合の数 for i in range(N): for r in range(total + 1): if r - a[i] >= 0: dp[i + 1][r] += dp[i][r - a[i]] dp[i + 1][r] += 2 * dp[i][r] dp[i + 1][r] %= MOD # g, bに加算する分で、2回起こる # print(dp) single_circle = 0 for r in range(total + 1): if r >= (total / 2): single_circle += dp[N][r] # print(single_circle) '''(3)2円の積集合''' if total % 2 == 0: dp2 = [[0] * (total + 1) for _ in range(N + 1)] dp2[0][0] = 1 # dp[i][R]:=i番目まででRとなる場合の数 for i in range(N): for r in range(int(total / 2) + 1): if r - a[i] >= 0: dp2[i + 1][r] += dp2[i][r - a[i]] dp2[i + 1][r] += dp2[i][r] dp2[i + 1][r] %= MOD # print(dp2) two_circle_intersect = dp2[N][int(total / 2)] if total % 2 == 0 else 0 '''(3)3円の積集合''' three_circle_intersect = 0 '''(4)解答''' ans = 0 ans += U ans %= MOD ans -= 3 * single_circle ans %= MOD ans += 3 * two_circle_intersect ans %= MOD ans -= three_circle_intersect ans %= MOD print(ans) ```
instruction
0
30,762
7
61,524
Yes
output
1
30,762
7
61,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` M=998244353 N,*A=open(0) d=[1]+[0]*7**6 e=[1]+[0]*7**6 z=1 s=0 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a];e[i]+=e[i-a];i-=1 i=s while i*2>=s:z-=d[i]*3;i-=1 print((z+~s%2*e[s//2]*3)%M) ```
instruction
0
30,763
7
61,526
No
output
1
30,763
7
61,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` def dp_table(*counts): # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ) if counts: return [dp_table(*counts[1:]) for _ in range(counts[0])] else: return 0 def main(): N = int(input()) A = [int(input()) for i in range(N)] mod = 998244353 ans = pow(3, N, mod) sum_A = sum(A) dp = dp_table(N, sum_A + 1) # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数 # init dp[0][A[0]] = 1 dp[0][0] = 2 # 他の色のうちどちらに入れるかで2通り # init2 dp2 = dp_table(N, sum_A+1) # ある二色でsum_Aを等分するパターンを数える dp2[0][A[0]] = 1 dp2[0][0] = 1 # 今度は片方に集中したパターン # dp sum_now = A[0] for i in range(1, N): a = A[i] sum_now += a for length in range(0, sum_now+1): # A[i]を追加しないのなら他の2食のうちどちらに入れるかで2倍選択肢がある if length >= a: dp[i][length] = dp[i - 1][length - a] + dp[i - 1][length] << 1 else: dp[i][length] = dp[i-1][length] << 1 dp[i][length] %= mod for length in range(min(sum_now + 1, sum_A // 2 + 1)): if length >= a: dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length] else: dp2[i][length] = dp2[i-1][length] dp2[i][length] %= mod # print(sum(dp[N-1][sum_A//2])) # print(dp) ans -= 3*sum(dp[N-1][(sum_A+1)//2:]) if sum_A % 2 == 0: ans += 3*dp2[N-1][sum_A//2] print(ans % mod) if __name__ == '__main__': main() ```
instruction
0
30,764
7
61,528
No
output
1
30,764
7
61,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` import sys def input(): return sys.stdin.readline()[:-1] N = int(input()) A = [int(input()) for i in range(N)] A.sort() cumA = [0] for a in A: cumA.append(a+cumA[-1]) from functools import lru_cache mod = 998244353 @lru_cache(maxsize=None) def solve(i, s, m): if i==-1: if s==0 and m==0: return 1 else: return 0 if s<0 or m<0: return 0 if s>cumA[i+1] or m>cumA[i+1]: return 0 return (solve(i-1, s, m) + solve(i-1, s-A[i], m) + solve(i-1, s, m-A[i])) % mod ans = 0 su = sum(A) for sm in range(su//2+1, su*2//3+1): l = su - sm for s in range(max(1, su-l-l), sm//2+1): m = sm - s if not (s <= m <= l): #print("a") continue if s==m==l: mul = 1 elif s==m or m==l: mul = 3 else: mul = 6 ans += solve(N-1, s, m) * mul ans %= mod print(ans) ```
instruction
0
30,765
7
61,530
No
output
1
30,765
7
61,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied: * Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B. Constraints * 3 \leq N \leq 300 * 1 \leq a_i \leq 300(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 : a_N Output Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied. Examples Input 4 1 1 1 2 Output 18 Input 6 1 3 2 3 5 2 Output 150 Input 20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 Output 563038556 Submitted Solution: ``` LEN = 1000 N = int(input()) A = [] for _ in range(N): A.append(int(input())) dp = [[[0 for i in range(LEN)] for j in range(LEN)] for k in range(LEN)] dp[0][0][0] = 1 s = 0 for a in A: for i in range(s+1): for j in range(s+1-i): k = s - i - j dp[i+a][j][k] += dp[i][j][k] dp[i][j+a][k] += dp[i][j][k] dp[i][j][k+a] += dp[i][j][k] s += a res = 0 for i in range(1, LEN): for j in range(1, LEN): k = s - i - j if k>0 and i+j>k and j+k>i and k+i>j: res += dp[i][j][k] print(res%998244353) ```
instruction
0
30,766
7
61,532
No
output
1
30,766
7
61,533
Provide tags and a correct Python 3 solution for this coding contest problem. There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color. Help Anya find the longest segment with this property. Input The first line contains two integers n and k — the number of houses and the number of colors (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 100 000). The next line contains n integers a_1, a_2, …, a_n — the colors of the houses along the road (1 ≤ a_i ≤ k). Output Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color. Example Input 8 3 1 2 3 3 2 1 2 2 Output 4 Note In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3, 2, 1, 2] and its length is 4 houses.
instruction
0
30,994
7
61,988
Tags: implementation Correct Solution: ``` n,m = map(int,input().split()) a = list(map(int,input().split())) max = 1 count = 1 for i in range(len(a)-1): if a[i] != a[i+1]: count+=1 if max<count: max = count else: count = 1 print(max) ```
output
1
30,994
7
61,989
Provide tags and a correct Python 3 solution for this coding contest problem. There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color. Help Anya find the longest segment with this property. Input The first line contains two integers n and k — the number of houses and the number of colors (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 100 000). The next line contains n integers a_1, a_2, …, a_n — the colors of the houses along the road (1 ≤ a_i ≤ k). Output Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color. Example Input 8 3 1 2 3 3 2 1 2 2 Output 4 Note In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3, 2, 1, 2] and its length is 4 houses.
instruction
0
30,995
7
61,990
Tags: implementation Correct Solution: ``` a = list(map(int, input().split())) b = list(map(int, input().split())) k = 1 t = [] if len(b) > 1: for j in range(len(b) - 1): if b[j] != b[j + 1]: k = k + 1 t.append(k) elif b[j] == b[j + 1]: t.append(k) k = 1 print(max(t)) else: print(len(b)) ```
output
1
30,995
7
61,991
Provide tags and a correct Python 3 solution for this coding contest problem. There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color. Help Anya find the longest segment with this property. Input The first line contains two integers n and k — the number of houses and the number of colors (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 100 000). The next line contains n integers a_1, a_2, …, a_n — the colors of the houses along the road (1 ≤ a_i ≤ k). Output Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color. Example Input 8 3 1 2 3 3 2 1 2 2 Output 4 Note In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3, 2, 1, 2] and its length is 4 houses.
instruction
0
30,996
7
61,992
Tags: implementation Correct Solution: ``` def iter_from_input(): return map(int, input().split()) def solve(n, k, colors): colors = iter(colors) previous_color = next(colors) current_length = 1 max_length = current_length for color in colors: if color == previous_color: max_length = max(max_length, current_length) current_length = 1 else: current_length += 1 previous_color = color # For last iteration max_length = max(max_length, current_length) return max_length def test(): assert (solve(4,1, (1,1,1,1)) == 1) assert (solve(4,2, (1,1,1,2)) == 2) assert (solve(4,2, (2,1,2,1)) == 4) # test() def main(): n, k = iter_from_input() colors = list(iter_from_input()) result = solve(n, k, colors) print(result) main() ```
output
1
30,996
7
61,993
Provide tags and a correct Python 3 solution for this coding contest problem. There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color. Help Anya find the longest segment with this property. Input The first line contains two integers n and k — the number of houses and the number of colors (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 100 000). The next line contains n integers a_1, a_2, …, a_n — the colors of the houses along the road (1 ≤ a_i ≤ k). Output Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color. Example Input 8 3 1 2 3 3 2 1 2 2 Output 4 Note In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3, 2, 1, 2] and its length is 4 houses.
instruction
0
30,999
7
61,998
Tags: implementation Correct Solution: ``` n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] count = 1 m = 0 for i in range(n-1): if a[i] != a[i+1]: count += 1 else: if count > m: m = count count = 1 if count > m: m = count print(m) ```
output
1
30,999
7
61,999
Provide tags and a correct Python 3 solution for this coding contest problem. There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color. Help Anya find the longest segment with this property. Input The first line contains two integers n and k — the number of houses and the number of colors (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 100 000). The next line contains n integers a_1, a_2, …, a_n — the colors of the houses along the road (1 ≤ a_i ≤ k). Output Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color. Example Input 8 3 1 2 3 3 2 1 2 2 Output 4 Note In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3, 2, 1, 2] and its length is 4 houses.
instruction
0
31,000
7
62,000
Tags: implementation Correct Solution: ``` n,k=map(int,input().split()) array=list(map(int,input().split())) array.append(0) count=0 ar=[1] for i in range(len(array)-1): if(array[i]==array[i+1]): count+=1 ar.append(count) count=0 else: count+=1 if(i==(len(array)-2)): ar.append(count) print(max(ar)) ```
output
1
31,000
7
62,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost. Input The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid. Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white. Output Print a single integer — the minimum total cost to paint all cells in white. Examples Input 3 ### #.# ### Output 3 Input 3 ... ... ... Output 0 Input 4 #... .... .... #... Output 2 Input 5 #...# .#.#. ..... .#... #.... Output 5 Note The examples and some of optimal solutions are shown on the pictures below. <image> Submitted Solution: ``` def extract_zero_boundary(array, r1, c1, r2, c2): up = r1 while(sum(array[up]) == 0): up += 1 down = r2 while(sum(array[down]) == 0): down -= 1 new_array = list(map(list, zip(*array[up: down + 1]))) left = c1 while(sum(new_array[left]) == 0): left += 1 right = c2 while(sum(new_array[right]) == 0): right -= 1 return (up, left, down, right) def minimal_cost(array, x1, y1, x2, y2, d = {}): if (x1, y1, x2, y2) in d: return d[(x1, y1, x2, y2)] if sum(map(sum, array)) == 0: d[(x1, y1, x2, y2)] = 0 return d[(x1, y1, x2, y2)] (r1, c1, r2, c2) = extract_zero_boundary(array, x1, y1, x2, y2) if (r1, c1, r2, c2) in d: d[(x1, y1, x2, y2)] = d[(r1, c1, r2, c2)] return d[(r1, c1, r2, c2)] transposed = 0 arr = array if r2-r1 < c2-c1: r1, c1, r2, c2 = c1, r1, c2, r2 transposed = 1 arr = list(map(list, zip(*array))) zero_row = [] #row indices that corespond to zero_rows (splitting rows) temp = -5 for i in range(r1, r2+1): if sum(arr[i]) == 0: if i != temp + 1: zero_row.append(i) temp = i if not zero_row: #if there is no zero_rows, then cover entirely if transposed == 0: d[(r1, c1, r2, c2)] = d[(x1, y1, x2, y2)] = r2-r1+1 if transposed == 1: d[(c1, r1, c2, r2)] = d[(x1, y1, x2, y2)] = r2-r1+1 return r2-r1+1 if zero_row: result = r2-r1+1 for j in range(len(zero_row)): if transposed == 0: result = min(result, minimal_cost(array, r1, c1, zero_row[j]-1, c2, d) + minimal_cost(array, zero_row[j]+1, c1, r2, c2, d)) d[(x1, y1, x2, y2)] = d[(r1, c1, r2, c2)] = result if transposed == 1: result = min(result, minimal_cost(array, c1, r1, c2, zero_row[j]-1, d) + minimal_cost(array, c1, zero_row[j]+1, c2, r2, d)) d[(x1, y1, x2, y2)] = d[(c1, r1, c2, r2)] = result return result n = int(input()) array = list(list(input()) for _ in range(n)) for i in range(n): for j in range(n): array[i][j] = 1 if array[i][j] == '#' else 0 if n != 50: print(minimal_cost(array, 0, 0, n-1, n-1, {})) else: a = [] for i in range(n): temp = [0] for j in range(n): if array[i][j] == 1: temp.append(j) a.append(temp) print(a) ```
instruction
0
31,047
7
62,094
No
output
1
31,047
7
62,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost. Input The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid. Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white. Output Print a single integer — the minimum total cost to paint all cells in white. Examples Input 3 ### #.# ### Output 3 Input 3 ... ... ... Output 0 Input 4 #... .... .... #... Output 2 Input 5 #...# .#.#. ..... .#... #.... Output 5 Note The examples and some of optimal solutions are shown on the pictures below. <image> Submitted Solution: ``` def count_black(A): res=0 indi=0 for i in range(len(A)): if A[i]=='#': res=res+1 indi=i return res, indi def process(A, n): F=[None for x in range(n+1)] F[1], max_indi=count_black(A[1]) for i in range(2, n+1): temp, temp_ind=count_black(A[i]) max_indi=max(max_indi, temp_ind) # print(max_indi) F[i]=min(F[i-1]+temp, max(i, max_indi)) return F[n] def generation(x, n): A=['.' for i in range(n)] a=x//2 A[a]='#' A[a+1]='#' A[a+3]='#' A[a+4]='#' return A n=int(input()) A=[[None for i in range(n)]] for i in range(n): A.append([x for x in input()]) # for i in range(1, n+1): # if i%2!=1: # A.append(['.' for x in range(n)]) # else: # A.append(generation(i, n)) # for i in reversed(process(A,n)): # print(i) print(process(A,n)) ```
instruction
0
31,048
7
62,096
No
output
1
31,048
7
62,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost. Input The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid. Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white. Output Print a single integer — the minimum total cost to paint all cells in white. Examples Input 3 ### #.# ### Output 3 Input 3 ... ... ... Output 0 Input 4 #... .... .... #... Output 2 Input 5 #...# .#.#. ..... .#... #.... Output 5 Note The examples and some of optimal solutions are shown on the pictures below. <image> Submitted Solution: ``` def count_black(A): res=0 for i in A: if i=='#': res=res+1 return res def process(A, n): F=[None for x in range(n+1)] F[1]=count_black(A[1]) for i in range(2, n+1): temp=count_black(A[i]) F[i]=min(F[i-1]+temp, max(i, n)) return F[n] n=int(input()) A=[[None for i in range(n)]] for i in range(n): A.append([x for x in input()]) # for i in reversed(process(A,n)): # print(i) print(process(A,n)) ```
instruction
0
31,049
7
62,098
No
output
1
31,049
7
62,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost. Input The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid. Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white. Output Print a single integer — the minimum total cost to paint all cells in white. Examples Input 3 ### #.# ### Output 3 Input 3 ... ... ... Output 0 Input 4 #... .... .... #... Output 2 Input 5 #...# .#.#. ..... .#... #.... Output 5 Note The examples and some of optimal solutions are shown on the pictures below. <image> Submitted Solution: ``` def extract_zero_boundary(array, r1, c1, r2, c2): up = r1 while(sum(array[up]) == 0): up += 1 down = r2 while(sum(array[down]) == 0): down -= 1 new_array = list(map(list, zip(*array[up: down + 1]))) left = c1 while(sum(new_array[left]) == 0): left += 1 right = c2 while(sum(new_array[right]) == 0): right -= 1 return (up, left, down, right) def minimal_cost(array, x1, y1, x2, y2, d = {}): if (x1, y1, x2, y2) in d: return d[(x1, y1, x2, y2)] if sum(map(sum, array)) == 0: d[(x1, y1, x2, y2)] = 0 return d[(x1, y1, x2, y2)] (r1, c1, r2, c2) = extract_zero_boundary(array, x1, y1, x2, y2) if (r1, c1, r2, c2) in d: d[(x1, y1, x2, y2)] = d[(r1, c1, r2, c2)] return d[(r1, c1, r2, c2)] transposed = 0 arr = array if r2-r1 < c2-c1: r1, c1, r2, c2 = c1, r1, c2, r2 transposed = 1 arr = list(map(list, zip(*array))) zero_row = [] #row indices that corespond to zero_rows (splitting rows) temp = -5 for i in range(r1, r2+1): if sum(arr[i]) == 0: if i != temp + 1: zero_row.append(i) temp = i if not zero_row: #if there is no zero_rows, then cover entirely if transposed == 0: d[(r1, c1, r2, c2)] = d[(x1, y1, x2, y2)] = r2-r1+1 if transposed == 1: d[(c1, r1, c2, r2)] = d[(x1, y1, x2, y2)] = r2-r1+1 return r2-r1+1 if zero_row: result = r2-r1+1 for j in range(len(zero_row)): if transposed == 0: result = min(result, minimal_cost(array, r1, c1, zero_row[j]-1, c2, d) + minimal_cost(array, zero_row[j]+1, c1, r2, c2, d)) d[(x1, y1, x2, y2)] = d[(r1, c1, r2, c2)] = result if transposed == 1: result = min(result, minimal_cost(array, c1, r1, c2, zero_row[j]-1, d) + minimal_cost(array, c1, zero_row[j]+1, c2, r2, d)) d[(x1, y1, x2, y2)] = d[(c1, r1, c2, r2)] = result return result n = int(input()) array = list(list(input()) for _ in range(n)) for i in range(n): for j in range(n): array[i][j] = 1 if array[i][j] == '#' else 0 if n != 50: print(minimal_cost(array, 0, 0, n-1, n-1, {})) else: a = [] for i in range(n): temp = [] for j in range(n): if array[i][j] == 1: temp.append(j) a.append(temp) print(a) ```
instruction
0
31,050
7
62,100
No
output
1
31,050
7
62,101