text
stringlengths
198
433k
conversation_id
int64
0
109k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` s = input() n = len(s) ok = s[0] == '1' and s[n-1] == '0' for i in range(n-1): ok = ok and s[i] == s[n-2-i] if not ok: print(-1) exit() s2 = s[:n//2] i = s2.rindex('1') for k in range(i, n-1): print(n, k+1) while i > 0: j = i - 1 while s[j] != '1': j -= 1 for k in range(j, i): print(i+1, k+1) i = j ``` Yes
600
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` import sys input = sys.stdin.readline s = list(map(int, list(input())[: -1])) if s[0] == 0 or s[-1] == 1: print(-1) exit(0) n = len(s) for i in range(n - 1): if s[i] != s[-2 - i]: print(-1) exit(0) res = [] temp = [] s[-1] = 1 for i in range(n): if s[i] == 0 or i == 0: temp.append(i + 1) else: if len(res): p = res[-1][0] res.append((i + 1, p)) if len(temp): while len(temp): res.append((i + 1, temp.pop())) for _ in range(len(res)): print(*res.pop()) ``` Yes
601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` s=input() n=len(s) def check(): if s[0]=="0" or s[-1] =="1": return False for i in range(n): if s[i] != s[n-i-2]: return False return True if not check(): print(-1) exit() now=1 for i in range(n-1): print(now,i+2) if s[i]=="1": now=i+2 ``` Yes
602
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` s = input() if s[0]=='0' or s[-1]=='1': print(-1) exit() for i in range(len(s)//2): if s[i]=='1' and s[-i-2]=='0': print(-1) exit() par = len(s) for i in range(len(s)-2,-1,-1): if s[i]=='1': print(i+1,par) par = i+1 else: print(i+1,par) ``` No
603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = list(sr()) N = len(S) if S[-1] == '1' or S[0] == '0': print(-1); exit() S = ['-'] + S def solve(S): prev = 1 graph = [] for i in range(1, N//2 + 1): if S[i] != S[N-i]: print(-1); exit() if S[i] == '0': continue for x in range(prev, i): print(x, i) prev = i for x in range(prev, N): print(x, N) graph = solve(S) ``` No
604
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` #!/usr/bin/python3 import math import sys DEBUG = False def inp(): return sys.stdin.readline().rstrip() def dprint(*value, sep=' ', end='\n'): if DEBUG: print(*value, sep=sep, end=end) def solve(S): N = len(S) if S[0] == '0' or S[-1] == '1': return None for i in range((N - 1) // 2): if S[i] != S[-2 - i]: return None mxsz = 1 for i in range((N - 2) // 2): if S[i] == '0' and S[i + 1] == '1': return None if S[i + 1] == '1': mxsz = i + 2 G = [] # print(mxsz) for i in range(2, mxsz + 2): G.append((i - 1, i)) for i in range(mxsz + 2, N + 1): G.append((1, i)) return G def main(): ans = solve(inp()) if ans is None: print('-1') return for (p, q) in ans: print(p, q) if __name__ == '__main__': main() ``` No
605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by removing one edge from the tree. * If the i-th character in s is `0`, we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints * 2 \leq n \leq 10^5 * s is a string of length n consisting of `0` and `1`. Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print `-1`. If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i-th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Examples Input 1111 Output -1 Input 1110 Output 1 2 2 3 3 4 Input 1010 Output 1 2 1 3 1 4 Submitted Solution: ``` from bisect import * from collections import * from fractions import gcd from math import factorial from itertools import * S=input() if S[-1]=="1" or S[0]=="0": print(-1) exit() length=(len(S)-1)//2 for i in range(length): if S[i]!=S[-2-i]: print(-1) exit() odds=[] even=[] lst=[] for i in range(1,length+1+(len(S)%2==0)): if S[i-1]=="1": if i%2==1: odds.append(i) else: even.append(i) ``` No
606
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` A=[0]*4 for i in range(4): A[i]=int(input()) print(min(A[0],A[1])+min(A[2],A[3])) ```
607
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` x = [int(input()) for _ in range(4)] res = min(x[0], x[1]) + min(x[2], x[3]) print(res) ```
608
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` a,b,c,d = map(int, [input() for i in range(4)]) print(min(a,b) + min(c,d)) ```
609
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` a,b,c,d=[int(input())for i in"abcd"];print(min(a,b)+min(c,d)) ```
610
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` a, b, c, d = (int(input()) for n in range(0, 4)) print(min(a, b) + min(c, d)) ```
611
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` a,b,c,d=[int(input()) for i in range(4)] print(min(a+c,a+d,b+c,b+d)) ```
612
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` a=[int(input()) for i in range(4)] print(min(a[:2])+min(a[2:])) ```
613
Provide a correct Python 3 solution for this coding contest problem. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 "Correct Solution: ``` A,B,C,D = [int(input()) for i in range(4)] x = [A,B] y = [C,D] print(min(x) + min(y)) ```
614
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` #A a,b,c,d=map(int,[input() for i in range(4)]) print(min(a,b)+min(c,d)) ``` Yes
615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` a,b,c,d=list(int(input()) for _ in range(4)) print(min(a,b)+min(c,d)) ``` Yes
616
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` a=int(input()) b=int(input()) x=int(input()) y=int(input()) print(min(a,b)+min(x,y)) ``` Yes
617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` x = [int(input()) for i in range(4)] print(sum(list(map(min, [x[:2], x[2:]])))) ``` Yes
618
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` import math A, B = map(int, input().split()) A_row = math.ceil((A-1)/50) if A_row == 0: A_row = 1 A_row_full = (A-1)//50 B_row = math.ceil((B-1)/50) if B_row == 0: B_row = 1 B_row_full = (B-1)//50 print("100 ", (A_row+B_row)*2) A_mod = (A-1)%50 B_mod = (B-1)%50 if A_row == A_row_full: A_add = '' else: A_add = '.#' if B_row == B_row_full: B_add = '' else: B_add = '.#' for i in range(50): print('.#'*A_row_full + (A_add if i < A_mod else '##') + '.#'*B_row_full + (B_add if i < B_mod else '..')) print('##'*A_row + '..'*B_row) ``` No
619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` A, B, C, D = map(int, input().split()) num = 0 if A <= B: if C <= D: print(B+D) else: print(B+C) else: if C<= D: print(A+D) else: print(A+C) ``` No
620
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` print(min(int(input(),int(input()))+min(int(input(),int(input()))) ``` No
621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints * 1 \leq A \leq 1 000 * 1 \leq B \leq 1 000 * 1 \leq C \leq 1 000 * 1 \leq D \leq 1 000 * All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Examples Input 600 300 220 420 Output 520 Input 555 555 400 200 Output 755 Input 549 817 715 603 Output 1152 Submitted Solution: ``` fares=[int(input()) for _ in range(5)] print(min(fares[0],fares[1])+min(fares[2],fares[3])) ``` No
622
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` N =int(input()) K =int(input()) a =1 for i in range(N): a += min(a,K) print(a) ```
623
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` n=int(input()) k=int(input()) a=1 for i in range(n): a += min(a,k) print(a) ```
624
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` n = int(input()) k = (int(input())) a = [(1<<x)+k*(n-x) for x in range(n+1)] print(min(a)) ```
625
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` N=int(input()) K=int(input()) data=1 for i in range (N): data=min(data+K,data*2) print(data) ```
626
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` n=int(input());k=int(input());r=1 for _ in[0]*n:r+=min(r,k) print(r) ```
627
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` N = int(input()) K = int(input()) a = 1 for n in range(N): a+=min(a,K) print(a) ```
628
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` N = int(input()) K = int(input()) tmp = 1 for _ in range(N): tmp = min(tmp*2,tmp+K) print(tmp) ```
629
Provide a correct Python 3 solution for this coding contest problem. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 "Correct Solution: ``` N = int(input()) K = int(input()) n = 1 for i in range(N): n = min(n * 2, n + K) print(n) ```
630
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` N = int(input()) K = int(input()) ans = 1 for _ in range(N): ans += min(ans, K) print(ans) ``` Yes
631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` N=int(input()) K=int(input()) x=1 for _ in range(N): x=min(2*x,x+K) print(x) ``` Yes
632
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` n,k=int(input()),int(input()) ans=1 for i in range(n): ans=min(ans*2,ans+k) print(ans) ``` Yes
633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` n=int(input()) m=int(input()) s=1 for i in range(n): s = min(s*2, s+m) print(s) ``` Yes
634
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` from sys import stdin N=int(stdin.readline().rstrip()) K=int(stdin.readline().rstrip()) num = 1 cnt = 0 while num < N: num = num * 2 cnt += 1 for _ in range(N-cnt): num += K print(num) ``` No
635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` n = int(input()) k = int(input()) num = 2**n list = [format(str(i),"b").zfill(n) for i in range(num)] result = [] for i in list: a = 1 for j in len(i): if i[j] == "0": a *= 2 else: a += k result.apppend(a) print(max(result)) ``` No
636
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` import math N = int(input()) K = int(input()) twice_count = int(math.log2(K)) + 1 print(2**twice_count + K*(N - twice_count)) ``` No
637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. Constraints * 1 \leq N, K \leq 10 * All input values are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible value displayed in the board after N operations. Examples Input 4 3 Output 10 Input 10 10 Output 76 Submitted Solution: ``` n=int(input()) k=int(input()) a=1 for i in range(n): if a*2>a+k: a=a*2 else: a=a+k print(a) ``` No
638
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` A,B,C = map(int,input().split()) print('Yes') if A<=C<=B else print('No') ```
639
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` a,b,c=map(int,input().split()) print("YNeos"[a>c or c>b::2]) ```
640
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` a, b, c = map(int,input().split()) print('Yes') if a <= c <= b else print('No') ```
641
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` A, B, C = map(int, input().split()) print("Yes") if A <= C and C <= B else print("No") ```
642
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` a,b,c = map(int,input().split()) print("Yes" if a <= c and c <= b else "No") ```
643
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` a,b,c = map(int,input().split()) print(('No','Yes')[a<=c and c<=b]) ```
644
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` a,b,c=map(int,input().split()) if (a<=c<=b): print("Yes") else: print("No") ```
645
Provide a correct Python 3 solution for this coding contest problem. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes "Correct Solution: ``` A, B, C = map(int, input().split()) ans = 'Yes' if A <= C <= B else 'No' print(ans) ```
646
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` A,B,C=map(int,input().split()) if A<=C and C<=B: print('Yes') else: print('No') ``` Yes
647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` a, b, c = map(int,input().split()) ans = 'Yes' if a <= c <= b else 'No' print(ans) ``` Yes
648
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` #061_A a,b,c=map(int,input().split()) print('Yes' if a<=c<=b else 'No') ``` Yes
649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` a,b,c = map(int,input().split()) if a<=c<=b: print("Yes") else: print("No") ``` Yes
650
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` a,b,c=map(int,input().split());print(' NYoe s'[a<=c<=b::2]) ``` No
651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` A,B,C = input().split() print('Yes' if A <= C <= B else 'No') ``` No
652
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` a, b, c = map(int, input().split()) if a <= c <= b: print("Yse") else: print("No") ``` No
653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. Examples Input 1 3 2 Output Yes Input 6 5 4 Output No Input 2 2 2 Output Yes Submitted Solution: ``` print('YNeos'[eval(input().replace(' ','<='))::2]) ``` No
654
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` from math import acos, tan, hypot def getRad1(s12, s13, s23): return acos((s12*s12 + s13*s13 - s23*s23) / (2*s12*s13)) def getMaxR(s12, rad1, rad2): tan1 = tan(rad1 / 2) tan2 = tan(rad2 / 2) h = s12 * (tan1*tan2) / (tan1+tan2) return h * (tan1+tan2) / (2*tan1*tan2 + tan1 + tan2) x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) s12 = hypot(x1-x2, y1-y2) s23 = hypot(x2-x3, y2-y3) s31 = hypot(x3-x1, y3-y1) rad1 = getRad1(s12, s31, s23) rad2 = getRad1(s23, s12, s31) rad3 = getRad1(s31, s23, s12) maxRs = [ getMaxR(s12, rad1, rad2), getMaxR(s23, rad2, rad3), getMaxR(s31, rad3, rad1) ] print(max(maxRs)) ```
655
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` xy = [list(map(int, input().split())) for _ in range(3)] d = [((xy[i][0] - xy[i + 1][0]) ** 2 + (xy[i][1] - xy[i + 1][1]) ** 2) ** .5 for i in range(-1, 2)] s = abs((xy[1][0] - xy[0][0]) * (xy[2][1] - xy[0][1]) -(xy[2][0] - xy[0][0]) * (xy[1][1] - xy[0][1])) / 2 k = max(d) r = 2 * s / sum(d) x = k * r / (k + 2 * r) print('{:.10f}'.format(x)) ```
656
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from math import sqrt points = [tuple(li()) for _ in range(3)] # 3つの辺を求める sides = [] angles = [] for i in range(3): p1,p2 = points[i], points[(i+1)%3] sides.append(sqrt((p2[0]-p1[0])**2 + (p2[1]-p1[1])**2)) # 内接円の半径 s = (sum(sides)) / 2 a,b,c = sides area = sqrt(s* (s-a) * (s-b) * (s-c)) r = 2*area / sum(sides) print(max(sides)*r / (2*r + max(sides))) ```
657
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) e12 = ((x2-x1)**2 + (y2-y1)**2)**0.5 e23 = ((x3-x2)**2 + (y3-y2)**2)**0.5 e31 = ((x1-x3)**2 + (y1-y3)**2)**0.5 s = (e12 + e23 + e31)/2 S = (s * (s-e12) * (s-e23) * (s-e31)) ** 0.5 r=2*S/(e12+e23+e31) A=max(e12,e23,e31) print(A*r/(2*r+A)) ```
658
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` import sys input = sys.stdin.readline #import heapq #from fractions import gcd #from collections import defaultdict #sys.setrecursionlimit(10**9) #map(int,input().split()) def main(): li=[list(map(int,input().split())) for i in range(3)] li.append(li[0]) d=[0]*3 for i in range(3): d[i]=((li[i][0]-li[i+1][0])**2+(li[i][1]-li[i+1][1])**2)**0.5 dmax=max(d) dsum=sum(d) s=dsum/2 S=(s*(s-d[0])*(s-d[1])*(s-d[2]))**0.5 r=2*S/dsum print((r*dmax)/(2*r+dmax)) if __name__ == '__main__': main() ```
659
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` p1 = list(map(int, input().split())) p2 = list(map(int, input().split())) p3 = list(map(int, input().split())) len1 = ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5 len2 = ((p2[0] - p3[0]) ** 2 + (p2[1] - p3[1]) ** 2) ** 0.5 len3 = ((p3[0] - p1[0]) ** 2 + (p3[1] - p1[1]) ** 2) ** 0.5 l = (len1 + len2 + len3) / 2 s = (l * (l - len1) * (l - len2) * (l - len3)) ** 0.5 r = 2 * s /(len1 + len2 + len3) def solve(mid): return (1 - mid / r) * max(len1, len2, len3) >= 2 * mid ok = 0 ng = 10 ** 9 cnt = 0 while True: mid = (ok + ng) / 2 if solve(mid): ok = mid else: ng = mid cnt += 1 if cnt > 60: break print(ok) ```
660
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` a,b,c,d,e,f=map(int,open(0).read().split()) a,b,c=sorted((s*s+t*t)**.5for s,t in((a-c,b-d),(c-e,d-f),(e-a,f-b))) d=a+b+c s=d/2 s=(s*(s-a)*(s-b)*(s-c))**.5 print(c/(2+c/2/s*d)) ```
661
Provide a correct Python 3 solution for this coding contest problem. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 "Correct Solution: ``` def OuterProduct(one, two): tmp = one.conjugate() * two return tmp.imag def Area(dots): res = 0 for i in range(len(dots)-1): res += OuterProduct(dots[i], dots[i+1]) res += OuterProduct(dots[-1], dots[0]) return res/2 d = [list(map(int, input().split())) for _ in range(3)] x = complex(d[0][0], d[0][1]) y = complex(d[1][0], d[1][1]) z = complex(d[2][0], d[2][1]) s = abs(Area([x, y, z])) a, b, c = abs(x-y), abs(y-z), abs(z-x) print(2*s/(a+b+c+(4*s/max(a, b, c)))) ```
662
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) j, k = x2-x1, y2-y1 l, m = x3-x1, y3-y1 a = ( j**2 + k**2 )**0.5 b = ( l**2 + m**2 )**0.5 c = ( (j-l)**2 + (k-m)**2 )**0.5 S = abs(j*m-k*l)/2 T = (a+b+c)/2 M = max(a, b, c) r = S / (2*S/M + T) print(r) ``` Yes
663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` a=[list(map(int,input().split()))for i in range(3)] s,t,u=((a[0][0]-a[1][0])**2+(a[0][1]-a[1][1])**2)**0.5,((a[2][0]-a[1][0])**2+(a[2][1]-a[1][1])**2)**0.5,((a[0][0]-a[2][0])**2+(a[0][1]-a[2][1])**2)**0.5 p=(s+t+u)/2 q=(p*(p-s)*(p-t)*(p-u))**0.5 r=2*q/(s+t+u) g=max(s,t,u) print(g/(2+g/r)) ``` Yes
664
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` from math import hypot p = [list(map(int, input().split())) for i in range(3)] x1 = p[1][0] - p[0][0] y1 = p[1][1] - p[0][1] x2 = p[2][0] - p[0][0] y2 = p[2][1] - p[0][1] s2 = abs(x1*y2-x2*y1) s = 0 m = 0 for i in range(3): x = p[i-1][0]-p[i][0] y = p[i-1][1]-p[i][1] l = hypot(x, y) s += l m = max(m, l) r = s2/s x = m*r/(2*r+m) print(x) ``` Yes
665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` p = [[int(i) for i in input().split()] for i in range(3)] a = [] for i in range(3): a.append((p[i][0]-p[(i+1)%3][0])**2+(p[i][1]-p[(i+1)%3][1])**2) a.sort() print(a[2]**0.5/ (((2*(a[0]*a[2])**0.5+a[0]+a[2]-a[1])/(2*(a[0]*a[2])**0.5-a[0]-a[2]+a[1]))**0.5+ ((2*(a[1]*a[2])**0.5+a[1]+a[2]-a[0])/(2*(a[1]*a[2])**0.5-a[1]-a[2]+a[0]))**0.5+2)) ``` Yes
666
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` def euclid(a,b,c,d): return ( (a-c)**2 + (b-d)**2 )**0.5 def triangle_area(p1,p2,p3): dx1, dx2 = p3[0] - p1[0], p2[0] - p1[0] dy1, dy2 = p3[1] - p1[1], p2[1] - p1[1] return dy2*dx1 - dy1*dx2 x1, y1 = [ int(v) for v in input().split() ] x2, y2 = [ int(v) for v in input().split() ] x3, y3 = [ int(v) for v in input().split() ] a = euclid(x1, y1, x2, y2) b = euclid(x2, y2, x3, y3) c = euclid(x3, y3, x1, y1) l = a + b + c s = triangle_area((x1,y1),(x2,y2),(x3,y3)) ar = s / ( l + (2*s / a) ) br = s / ( l + (2*s / b) ) cr = s / ( l + (2*s / c) ) print(max(ar,br,cr)) ``` No
667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` def norm(x1, y1, x2, y2): return ((x1-x2)**2 + (y1-y2)**2)**0.5 def d(a, b, c, x, y): return abs(a*x + b*y + c) / (a**2 + b**2)**0.5 def points2line(x1, y1, x2, y2): la = y1 - y2 lb = x2 - x1 lc = x1 * (y2 - y1) + y1 * (x1 - x2) return la, lb, lc #from numpy import argmax def argmax(L): return max(enumerate(L), key=lambda x: x[1])[0] x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) a = norm(x3, y3, x2, y2) b = norm(x1, y1, x3, y3) c = norm(x1, y1, x2, y2) xc = (a*x1 + b*x2 + c*x3)/(a+b+c) yc = (a*y1 + b*y2 + c*y3)/(a+b+c) iw = argmax([a, b, c]) w = [a, b, c][int(iw)] L = [[x1, y1], [x2, y2], [x3, y3]] del L[int(iw)] h = d(*points2line(*L[0], *L[1]), xc, yc) print(w*h/(2*h + w)) ``` No
668
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` ai = lambda: list(map(int, input().split())) import numpy as np import math def calc(A,B,C): a = np.linalg.norm(B - C) b = np.linalg.norm(C - A) c = np.linalg.norm(A - B) cosC = np.inner(A-C, B-C)/(b*a) if cosC <= 0: return 0 tanC = math.sqrt(1/(cosC**2)-1) return (1 - 1/cosC + tanC) * (a+b-c)/4 a = np.array(ai()) b = np.array(ai()) c = np.array(ai()) print(max(calc(a,b,c),calc(b,c,a),calc(c,a,b))) ``` No
669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. Constraints * 0 ≤ x_i, y_i ≤ 1000 * The coordinates are integers. * The three points are not on the same line. Input The input is given from Standard Input in the following format: x_1 y_1 x_2 y_2 x_3 y_3 Output Print the maximum possible radius of the circles. The absolute error or the relative error must be at most 10^{-9}. Examples Input 0 0 1 1 2 0 Output 0.292893218813 Input 3 1 1 5 4 9 Output 0.889055514217 Submitted Solution: ``` import numpy as np import math def calc(A,B,C): a = np.linalg.norm(B - C) b = np.linalg.norm(C - A) c = np.linalg.norm(A - B) cosC = np.inner(A-C, B-C)/(b*a) if cosC <= 0: return 0 tanC = math.sqrt(1/(cosC**2)-1) return (1 - 1/cosC + tanC) * (a+b-c)/4 a = np.array(ai()) b = np.array(ai()) c = np.array(ai()) print(max(calc(a,b,c),calc(b,c,a),calc(c,a,b))) ``` No
670
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` H, W, A, B = map(int, input().split()) P = 10**9+7 fa = [1] for i in range(1, 202020): fa.append(fa[-1] * i % P) fainv = [pow(fa[-1], P-2, P)] for i in range(1, 202020)[::-1]: fainv.append(fainv[-1] * i % P) fainv = fainv[::-1] calc = lambda a, b: fa[a+b] * fainv[a] * fainv[b] % P ans = 0 for i in range(H-A): ans = (ans + calc(B-1, i) * calc(H-1-i, W-B-1) )% P print(ans) ```
671
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` def solve(): h,w,a,b = map(int, input().split()) mx = max(h,w) mod = 10**9+7 fac = [1]*(h+w+1) for i in range(1,h+w+1): fac[i] = fac[i-1]*i%mod inv = [1]*(mx+1) inv[-1] = pow(fac[mx], mod-2, mod) for i in range(mx-1, -1, -1): inv[i] = inv[i+1]*(i+1)%mod const = inv[h-a-1]*inv[a-1]%mod ans = sum(fac[h-a+i-1]*inv[i]*fac[a+w-2-i]*inv[w-i-1]%mod for i in range(b,w)) print(ans*const%mod) if __name__=="__main__":solve() ```
672
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` from sys import exit from itertools import count def read(): return [int(x) for x in input().split()] P = 10**9 + 7 def inv(x): return pow(x, P-2, P) def comb(n, r): res = 1 for i in range(r): res = (res * (n-i) * inv(i+1)) % P return res (H, W, A, B) = read() result = 0 c1 = comb(H-A-1+B, B) c2 = comb(W-B-1+A, A) for i in range(1, min(H-A+1, W-B+1)): # print(c1, c2) result = (result + c1 * c2) % P c1 = (c1 * (H-A-i) * inv(B+i)) % P c2 = (c2 * (W-B-i) * inv(A+i)) % P print(result) ```
673
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` def inpl(): return [int(i) for i in input().split()] mod = 10**9+7 H, W, A, B = inpl() fac = [1 for _ in range(H+W-1)] for i in range(H+W-2): fac[i+1] = (i+1)*fac[i]%mod inv = [1 for _ in range(H+W-1)] for i in range(2,H+W-2): inv[i] = (-(mod//i) * inv[mod%i]) %mod facinv = [1 for _ in range(H+W-1)] for i in range(H+W-2): facinv[i+1] = inv[i+1]*facinv[i]%mod ans = 0 for i in range(W-B): ans += (fac[H+B-A-1+i] * fac[W+A-B-2-i] * facinv[H-A-1] * facinv[B+i]\ * facinv[A-1] * facinv[W-B-1-i] )%mod print(ans%mod) ```
674
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` #!/usr/bin/env python3 import sys MOD = 1000000007 # type: int def solve(H: int, W: int, A: int, B: int): F = [0] * (H + W + 1) F[0] = 1 for i in range(1, H + W + 1): F[i] = (F[i-1] * i) % MOD F2 = [0] * (H + W + 1) F2[0] = 1 for i in range(1, H+W+1): F2[i] = (F2[i-1] * pow(i, MOD-2, MOD)) % MOD def nck(a, b): if a == 0 and b == 0: return 1 return (F2[a-b] * F2[b] % MOD) * F[a] % MOD total = nck(H+W-2, H-1) removed = 0 for k in range(A): removed += nck(H-k-1+B-1, H-k-1) * nck(k+W-B-1, k) removed %= MOD res = (total - removed) % MOD print(res) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int solve(H, W, A, B) if __name__ == '__main__': main() ```
675
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` H, W, A, B = map(int, input().split()) mod = 10**9 + 7 N = 200001 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod ans = 0 for i in range(1, H-A+1): ans += (cmb(B+i-2, B-1, mod)) * cmb((W-B-1) + (H-i), W-B-1, mod) ans %= mod print(ans) ```
676
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` from operator import mul from functools import reduce from fractions import gcd import math import bisect import itertools import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline INF = float("inf") MOD = 1000000007 class Combination(object): def __init__(self, N, MOD): self.fac = [0] * (N + 1) self.inv = [0] * (N + 1) self.finv = [0] * (N + 1) self.fac[0] = 1 self.finv[0] = 1 if N > 0: self.fac[1] = 1 self.inv[1] = 1 self.finv[1] = 1 # 前計算 for i in range(2, N + 1): self.fac[i] = self.fac[i - 1] * i % MOD self.inv[i] = self.inv[MOD % i] * (MOD - (MOD // i)) % MOD self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD def com(self, N, k): return (self.fac[N] * self.finv[k] * self.finv[N - k]) % MOD def main(): H, W, A, B = map(int, input().split()) Com = Combination(H+W, MOD) ans = 0 for i in range(B, W): ans += Com.com((H-A-1)+i, i) * Com.com((A-1)+(W-i-1), A-1) ans %= MOD print(ans) if __name__ == '__main__': main() ```
677
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 "Correct Solution: ``` from sys import stdin, stdout, stderr, setrecursionlimit from functools import lru_cache setrecursionlimit(10**7) mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = map(int, input().split()) ans = 0 modfact = [1] * (h + w) factinv = [1] * (h + w) for i in range(1, h + w): modfact[i] = (i * modfact[i - 1]) % mod factinv[i] = (pow(i, mod - 2, mod) * factinv[i - 1]) % mod for i in range(h - a): ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod ans %= mod print(ans) ''' @lru_cache(maxsize=None) def binom(n, k): res = (modfact(n) * factinv(k)) % mod res = (res * factinv(n - k)) % mod return res @lru_cache(maxsize=None) def modfact(n): if n == 0: return 1 return (n * modfact(n - 1)) % mod @lru_cache(maxsize=None) def factinv(n): if n == 0: return 1 return (pow(n, mod - 2, mod) * factinv(n - 1)) % mod ''' if __name__ == '__main__': solve() ```
678
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` mod = 1000000007 H, W, A, B = map(int, input().split()) import sys sys.setrecursionlimit(10000) factorial = [1] for n in range(1, H+W): factorial.append(factorial[n-1]*n % mod) def power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return (power(x, y//2)**2) % mod else: return (power(x, y//2)**2 * x) % mod inverseFactorial = [0 for i in range(H+W)] inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2) for n in range(H+W-2, -1, -1): inverseFactorial[n] = (inverseFactorial[n+1] * (n+1) )% mod def combi(n, m): return (factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] )% mod sum = 0 for i in range(B+1, W+1): sum = (sum + combi(H-A-1+i-1, i-1) * combi(A-1+W-i, W-i)) % mod print(sum) ``` Yes
679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` # ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D) def get_fact(lim): # compute a toble of factorials (1-idx) fact = [1] * (lim + 1) x = 1 for i in range(1, lim + 1): x = (x * i) % MOD fact[i] = x return fact def get_inv(lim): # compute a toble of inverse factorials (1-idx) inv = [1] * (lim + 1) inv[lim] = pow(fact[lim], MOD - 2, MOD) x = inv[lim] for i in range(lim - 1, 0, -1): x = (x * (i + 1)) % MOD inv[i] = x return inv def comb(n: int, r: int) -> int: # compute nCr (n! / r!(n - r)!) return fact[n] * inv[n - r] * inv[r] def main(): global MOD, fact, inv H, W, A, B = tuple(map(int, input().split())) MOD = 10 ** 9 + 7 fact = get_fact(H + W) inv = get_inv(H + W) ans = 0 x, y = H - A - 1, W + A - 2 for i in range(B, W): ans += comb(x + i, i) * comb(y - i, A - 1) ans %= MOD print(ans) if __name__ == "__main__": main() ``` Yes
680
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` P=10**9+7 def egcd(a, b): (x, lastx) = (0, 1) (y, lasty) = (1, 0) while b != 0: q = a // b (a, b) = (b, a % b) (x, lastx) = (lastx - q * x, x) (y, lasty) = (lasty - q * y, y) return (lastx, lasty, a) def inv(x): return egcd(x,P)[0] H,W,A,B=map(int,input().split()) N=H+W fact=[0 for i in range(N+1)] finv=[0 for i in range(N+1)] fact[0]=1 finv[0]=1 for i in range(1,N+1): fact[i]=(fact[i-1]*i)%P finv[i]=(inv(fact[i]))%P def C(a,b): return (fact[a+b]*(finv[a]*finv[b])%P)%P D=0 for i in range(B,W): K=(C(H-A-1,i)*C(A-1,W-1-i))%P D=(D+K)%P print(D) ''' HWAB 6734 4 C(2,4)*C(2,2) 15*6=90 5 C(2,5)*C(2,1) 21*3=63 6 C(2,6)*C(2,0) 28*1=28 ''' ``` Yes
681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` SIZE=2*10**5; MOD=10**9+7 #998244353 #ここを変更する SIZE += 1 inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD inv[i] = finv[i]*fac[i-1]%MOD def choose(n,r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD else: return 0 # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline h,w,a,b = map(int,read().split()) ans = 0 for r in range(0,h-a): ans += choose(b-1+r,b-1)*choose(w-b-1+h-r-1,w-b-1) print(ans%MOD) ``` Yes
682
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` import math def comb(n, r): return f[n] // (f[n-r] * f[r]) H,W,A,B=map(int,input().split()) f=[1] for i in range(1,100001): f.append(f[i-1]*i) M=10**9+7 ans=0 for i in range(B,W): a=comb(H-A-1+i,i)%M b=comb(A+W-2-i,W-1-i)%M c=(a*b)%M ans+=c ans%=M print(ans) ``` No
683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` ai = lambda: list(map(int,input().split())) mod = 10**9+7 def nCb(n, b): if b > n - b: b = n - b r = 1 for k in range(n, n-b, -1): r = r * k % mod d = 1 for k in range(1, b+1): d = d * k % mod return r * inv(d) % mod def inv(x): return pow(x, mod - 2, mod) h,w,a,b = ai() ans = 0 c1 = nCb(b-1,0) c2 = nCb(w-b+h-2, h-1) for i in range(h-a): ans += c1 * c2 ans %= mod c1 = c1 * (b+i) // (i+1) c2 = c2 * (h-i-1) // (w-b+h-i-2) print(ans) ``` No
684
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` import math def comb(n, r): return f[n] // (f[n-r] * f[r]) H,W,A,B=map(int,input().split()) f=[1] M=10**9+7 for i in range(1,H+W): f.append(f[i-1]*i%M) ans=0 for i in range(B,W): aa=(f[H-A-1+i]//(f[H-A-1] * f[i]))%M bb=(f[A+W-2-i]//(f[A-1]*f[W-1-i]))%M cc=(aa*bb)%M ans+=cc ans%=M print(ans) ``` No
685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020 Submitted Solution: ``` import math def comb(n, r): return f[n] // (f[n-r] * f[r]) H,W,A,B=map(int,input().split()) f=[1] for i in range(1,100001): f.append(f[i-1]*i%M) M=10**9+7 ans=0 for i in range(B,W): a=comb(H-A-1+i,i)%M b=comb(A+W-2-i,W-1-i)%M c=(a*b)%M ans+=c ans%=M print(ans) ``` No
686
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` results = {"01234567": 0} def main(): while True: try: tmp = input().replace(' ', '') print(results[tmp]) except EOFError: break def swap(field, a, b): tmp = list(field) tmp[b], tmp[a] = tmp[a], tmp[b] return "".join(tmp) def convert_matrix_index(index): return index % 4, int(index / 4) def convert_array_index(x, y): return x + y * 4 def bfs(results): q = [["01234567", 0]] while len(q) is not 0: field, res = q.pop(0) x, y = convert_matrix_index(field.find('0')) for dx, dy in zip([0, 0, -1, 1], [1, -1, 0, 0]): nx = x + dx ny = y + dy if nx < 0 or ny < 0 or nx >= 4 or ny >= 2: continue next_field = swap(field, convert_array_index(x, y), convert_array_index(nx, ny)) if next_field not in results: results[next_field] = res + 1 q.append([next_field, res + 1]) return results if __name__ == '__main__': results = bfs(results) main() ```
687
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` # AOJ 0121 from collections import deque score = {} score[tuple(range(8))] = 0 queue = deque() queue.append(tuple(range(8))) move = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5), (1, 4, 6), (2, 5, 7), (3, 6)) while queue: puz = queue.popleft() pos = puz.index(0) for npos in move[pos]: npuz = list(puz) npuz[pos], npuz[npos] = npuz[npos], 0 npuz = tuple(npuz) if npuz not in score: queue.append(npuz) score[npuz] = score[puz] + 1 while True: try: puzzle = tuple(map(int, input().split())) print(score[puzzle]) except EOFError: break ```
688
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` from collections import deque from itertools import permutations from itertools import combinations puz = [0,1,2,3,4,5,6,7] puzper = list(permutations(puz)) dic = {} for i in range(40320): dic[puzper[i]] = -1 queue = deque([(0,1,2,3,4,5,6,7)]) dic[(0,1,2,3,4,5,6,7)] = 0 while queue: a = queue.popleft() poszero = a.index(0) yy = (poszero) // 4 xx = (poszero) % 4 dydx = [[1,0],[-1,0],[0,1],[0,-1]] for j,k in dydx: newy,newx = yy+j,xx+k if (0 <= newy <2) and (0 <= newx < 4): newp = newy*4 + newx lisa = list(a) lisa[poszero],lisa[newp] = lisa[newp],lisa[poszero] newper = tuple(lisa) if (dic[newper] == -1): dic[newper] = dic[a] + 1 queue.append(newper) while True: try: inp = list(map(int, input().split())) print(dic[tuple(inp)]) except: break ```
689
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` from collections import deque dic = {} dic[(0,1,2,3,4,5,6,7)] = 0 swap_dic = {0:(1, 4), 1:(0, 2, 5), 2:(1, 3, 6), 3:(2, 7), 4:(0, 5), 5:(1, 4, 6), 6:(2, 5, 7), 7:(3, 6)} def swap(puz, i, j): new = [k for k in puz] new[i], new[j] = new[j], new[i] return tuple(new) que = deque() que.append((0, (0,1,2,3,4,5,6,7))) while que: score, puz = que.popleft() score += 1 z_ind = puz.index(0) for swap_ind in swap_dic[z_ind]: new_puz = swap(puz, z_ind, swap_ind) if not new_puz in dic: dic[new_puz] = score que.append((score, new_puz)) while True: try: print(dic[tuple(map(int, input().split()))]) except EOFError: break ```
690
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` import itertools import collections INF = 10 ** 9 def Z(): return int(input()) def ZZ(): return [int(_) for _ in input().split()] def main(): p = collections.defaultdict(int) q = collections.defaultdict(list) for i, v in enumerate(itertools.permutations(range(8))): p[v] = i q[i] = list(v) dist = [INF] * (40325) dist[0] = 0 que = collections.deque() que.append(0) def change(i, j, l): d = dist[p[tuple(l)]] l[i], l[j] = l[j], l[i] if dist[p[tuple(l)]] == INF: dist[p[tuple(l)]] = d + 1 que.append(p[tuple(l)]) l[i], l[j] = l[j], l[i] return while que: v = que.popleft() ll = q[v] i = ll.index(0) if i in {0, 4}: change(i, i+1, ll) elif i in {3, 7}: change(i-1, i, ll) else: change(i, i+1, ll) change(i-1, i, ll) change(i, (i+4)%8, ll) while True: try: A = ZZ() print(dist[p[tuple(A)]]) except: break return if __name__ == '__main__': main() ```
691
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` from __future__ import division import sys if sys.version_info[0]>=3: raw_input=input X=4 Y=2 i=0 m={} prev={} v=[] for i in range(X*Y): v.append(str(i)) m[''.join(v)]=[0,0] prev[''.join(v)]=[''.join(v),None] q=[v] while len(q)>0: v=q.pop(0) coor=m[''.join(v)][0] x=coor%X y=coor//X depth=m[''.join(v)][1] nextstr=''.join(v) if 0<x: v[coor],v[coor-1]=v[coor-1],v[coor] if ''.join(v) not in m: m[''.join(v)]=[coor-1,depth+1] q.append(v[:]) prev[''.join(v)]=[nextstr,'R'] v[coor],v[coor-1]=v[coor-1],v[coor] if x<X-1: v[coor],v[coor+1]=v[coor+1],v[coor] if ''.join(v) not in m: m[''.join(v)]=[coor+1,depth+1] q.append(v[:]) prev[''.join(v)]=[nextstr,'L'] v[coor],v[coor+1]=v[coor+1],v[coor] if 0<y: v[coor],v[coor-X]=v[coor-X],v[coor] if ''.join(v) not in m: m[''.join(v)]=[coor-X,depth+1] q.append(v[:]) prev[''.join(v)]=[nextstr,'D'] v[coor],v[coor-X]=v[coor-X],v[coor] if y<Y-1: v[coor],v[coor+X]=v[coor+X],v[coor] if ''.join(v) not in m: m[''.join(v)]=[coor+X,depth+1] q.append(v[:]) prev[''.join(v)]=[nextstr,'U'] v[coor],v[coor+X]=v[coor+X],v[coor] try: while True: v=raw_input().split() print(m[''.join(v)][1]) except EOFError: pass ```
692
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` from collections import deque swap = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7], [0, 5], [1, 4, 6], [2, 5, 7], [3, 6]] def bfs(): ia = list(range(8)) count = { str(ia): 0 } q = deque() q.append([ia, 0]) while q: a, c = q.popleft() i = a.index(0) for j in swap[i]: na = a.copy() na[i], na[j] = na[j], na[i] if str(na) not in count: count[str(na)] = c + 1 q.append([na, c+1]) return count if __name__ == '__main__': count = bfs() while True: try: a = list(map(int, input().split())) print(count[str(a)]) except: break ```
693
Provide a correct Python 3 solution for this coding contest problem. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 "Correct Solution: ``` from collections import deque import copy swap = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7], [0, 5], [1, 4, 6], [2, 5, 7], [3, 6]] def bfs(): ia = list(range(8)) count = {str(ia): 0} que = deque() que.append((ia, 0)) while len(que) != 0: state, cnt = que.popleft() # pos:0????????? pos = state.index(0) swap_target = swap[pos] for i in swap_target: tmp_state = copy.copy(state) tmp_state[i], tmp_state[pos] = tmp_state[pos], tmp_state[i] if str(tmp_state) not in count: count[str(tmp_state)] = cnt + 1 que.append((tmp_state, cnt + 1)) return count if __name__ == '__main__': count = bfs() while True: try: prob = list(map(int, input().split())) print(count[str(prob)]) except: break ```
694
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 Submitted Solution: ``` # AOJ 0121 Seven Puzzle # Python 2017.6.23 bal4u def swap(state, x, y): s = list(state) s[x], s[y] = s[y], s[x] return tuple(s) from collections import deque MAGIC = 37 move = ((1,4), (0,2,5), (1,3,6), (2,7), (0,5), (1,4,6), (2,5,7), (3,6)) Q = deque() Q.append(((0,1,2,3,4,5,6,7), 0)) hash = {} hash[(0,1,2,3,4,5,6,7)] = 0 while Q: state, x = Q.popleft() step = hash[state]+1 if step > MAGIC: continue for y in move[x]: nstate = swap(state, x, y) if nstate not in hash: nstep = 100 else: nstep = hash[nstate] if step < nstep: Q.append((nstate, y)) hash[nstate] = step while 1: try: state = tuple(map(int, input().split())) except: break print(hash[state]) ``` Yes
695
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 Submitted Solution: ``` # -*- coding: utf-8 -*- def main(): line = input().strip() while line!='': print(0) line = input().strip() if __name__=='__main__': main() ``` No
696
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 Submitted Solution: ``` # -*- coding: utf-8 -*- line = input().strip() while line!='': print(0) line = input().strip() ``` No
697
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 Submitted Solution: ``` # -*- coding: utf-8 -*- import copy,sys def solve(pieace): history,frontier = set(),set() frontier.add(tuple(pieace)) target_list = list(range(8)) step = 0 while True: next_frontier = set() for pieace in frontier: if all(x==y for x,y in zip(pieace,target_list)): # print([(x,y) for x,y in zip(pieace,target_list)]) return step zero_position = pieace.index(0) relative = zero_position%4 new_peiace = list(copy.deepcopy(pieace)) new_peiace[relative],new_peiace[relative+4] = new_peiace[relative+4],new_peiace[relative] new_peiace = tuple(new_peiace) if new_peiace not in history: next_frontier.add(new_peiace) if relative in [0,1,2]: new_peiace = list(copy.deepcopy(pieace)) new_peiace[zero_position],new_peiace[zero_position+1] = new_peiace[zero_position+1],new_peiace[zero_position] new_peiace = tuple(new_peiace) if new_peiace not in history: next_frontier.add(new_peiace) if relative in [1,2,3]: new_peiace = list(copy.deepcopy(pieace)) new_peiace[zero_position],new_peiace[zero_position-1] = new_peiace[zero_position-1],new_peiace[zero_position] new_peiace = tuple(new_peiace) if new_peiace not in history: next_frontier.add(new_peiace) history |= frontier frontier = next_frontier step += 1 def main(): line = input().strip() while line!='': pieace = list(map(int,line.split(' '))) print(solve(pieace)) line = input().strip() if __name__=='__main__': main() ``` No
698
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the frame can be swapped with adjacent cards on the top, bottom, left, and right. For example, when the frame state is shown in Figure (a), if you exchange the position with the 7 card adjacent to the right of the 0 card, you will get the state shown in Figure (b). Alternatively, the state shown in Fig. (A) can be changed to the state shown in Fig. (C) by exchanging the position with the adjacent 2 card under the 0 card. In the state shown in Fig. (A), the cards with 0 and the cards adjacent to the top, bottom, left, and right are only the cards 7 and 2, so other positions cannot be swapped. The purpose of the game is to arrange the cards neatly so that they are in the state shown in Figure (d). Create a program that takes the initial state as input and outputs the minimum number of steps required to align the cards neatly. However, it is possible to move from the state of the entered card to the state shown in Fig. (D). The input data is given eight numbers per line, separated by blanks. These represent the initial sequence of cards. For example, the number representation in Figure (a) is 0 7 3 4 2 5 1 6 and Figure (c) is 2 7 3 4 0 5 1 6. <image> | <image> --- | --- Figure (a) 0 7 3 4 2 5 1 6 | Figure (b) 7 0 3 4 2 5 1 6 <image> | <image> --- | --- Figure (c) 2 7 3 4 0 5 1 6 | Figure (d) 0 1 2 3 4 5 6 7 (final state) Input Multiple puzzles are given in the above format. Please process until the end of the input. No more than 1,000 puzzles will be given. Output For each puzzle, output the minimum number of steps to move to the final state on one line. Example Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output 0 1 28 Submitted Solution: ``` while True: line = input().strip() if len(line)==0:break print(0) """ /* 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 0 1 28 */ """ ``` No
699