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. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n=int(input()) x = list(map(int, input().split(" "))) if n==1 or x.count(min(x))==2==len(x): print(-1) else: print(1,x.index(min(x))+1,sep="\n") ``` Yes
13,100
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) if n == 1: print (-1) elif n == 2 and a[0] == a[1]: print (-1) else: m = min(a) id = a.index(m) + 1 print (1) print (id) ``` Yes
13,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n=int(input()) arr=list(map(int,input().strip().split(' '))) m=min(arr) ind=arr.index(m) if(n==1): print(-1) elif(n==2 and arr[0]==arr[1]): print(-1) else: print(1) print(ind+1) ``` Yes
13,102
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) if n==1 or n==2 and a[0]==a[1]: print(-1) else: print(1) print(a.index(min(a))+1) ``` Yes
13,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) a.sort() if (a[0] == sum(a[:1]) or len(a) <= 1): print(-1) else: print(a[0]) print(*a[1:]) ``` No
13,104
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` a=int(input());b=sorted(map(int,input().split()));print(*[[-1],["1\n1"]][a>1 and b[0]!=sum(b)-b[0]]) ``` No
13,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n = int(input()) A = list(map(int, input().split())) if n == 1: print(-1) elif len(A) == 2: if A[0] != A[1]: print(1) print(A[0]) else: print(-1) else: if sum(A) - A[n - 1] != A[:n-1]: print(1) print(A[n - 1]) else: print(2) print(A[n-1], A[n-2]) ``` No
13,106
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. They want to divide the balloons among themselves. In addition, there are several conditions to hold: * Do not rip the packets (both Grigory and Andrew should get unbroken packets); * Distribute all packets (every packet should be given to someone); * Give both Grigory and Andrew at least one packet; * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions. Input The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons. The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet. Output If it's impossible to divide the balloons satisfying the conditions above, print -1. Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them. Examples Input 3 1 2 1 Output 2 1 2 Input 2 5 5 Output -1 Input 1 10 Output -1 Note In the first test Grigory gets 3 balloons in total while Andrey gets 1. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all. Submitted Solution: ``` n = int(input()) ar = input().split() mi = ar.index(min(ar)) print("-1" if n == 2 and ar[0] == ar[1] else "1 " + str(mi)) ``` No
13,107
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` input() a=[int(i) for i in input().split()] ans=1 if 0 in a: print(0) exit() for i in a: ans*=i if ans>10**18: print(-1) exit() print(ans) ```
13,108
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` N=int(input()) ans=1 A=list(map(int, input().split())) for i in range(N): ans=ans*A[i] if ans>10**18 or ans<0: ans=-1 print(ans) ```
13,109
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) a.sort() t=1 for i in a: t*=i if t>10**18: t=-1 break print(t) ```
13,110
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` n,*a=map(int,open(0).read().split()) a.sort() ans=1 for ai in a: ans*=ai if ans>10**18: print(-1) exit() print(ans) ```
13,111
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` a,b=open(0);c=1; for i in sorted(b.split()): c*=int(i) if c>10**18:c=-1;break print(c) ```
13,112
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` n = int(input()) a = map(int, input().split()) a = sorted(a) s = 1 for x in a: s *= x; if s > 1e18: print(-1) exit() print(s) ```
13,113
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` N=int(input()) A=[*map(int,input().split())] a=1 if 0 in A: a=0 else: while A: a*=A.pop() if a>10**18: a=-1 break print(a) ```
13,114
Provide a correct Python 3 solution for this coding contest problem. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 "Correct Solution: ``` n,*a=map(int,open(0).read().split()) a.sort() ans=1 for i in a: ans*=i if ans>1e18: print(-1) exit() print(ans) ```
13,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` n=int(input()) A=list(map(int,input().split())) A.sort() ans = 1 for i in A: ans *= i if ans>10**18: print(-1) exit() print(ans) ``` Yes
13,116
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` N = int(input()) ans = 1 for a in sorted(input().split()): ans *= int(a) if ans > 10**18: print(-1) exit() print(ans) ``` Yes
13,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` x=int(input()) s=list(map(int,input().split())) s.sort() res=1 for n in s: res*=n if res>1e18: res=-1 print(-1) exit(0) print(res) ``` Yes
13,118
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` n=int(input()) A=list(map(int,input().split())) s=1 if 0 in A: s=0 else: for a in A: s*=a if s>10**18: s=-1 break print(s) ``` Yes
13,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` N = int(input()) As = list(map(lambda x: int(x), input().split(" "))) LIMIT = 10**18 result = 1 for a in As: result *= a if result > LIMIT: result = -1 break print(result) ``` No
13,120
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` N=int(input()) L=list(map(int,input().split())) A=1 if 0 in L: print(0) for i in range(N): A=A*L[i] if 10**18<A: print(-1) exit() print(A) ``` No
13,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` n=int(input()) A=list(map(int,input().split())) if 0 in a: print(0) else: a=1 for i in A: a=a*i if a>1000000000000000000: print(-1) else: print(a) ``` No
13,122
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print `-1` instead. Constraints * 2 \leq N \leq 10^5 * 0 \leq A_i \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output Print the value A_1 \times ... \times A_N as an integer, or `-1` if the value exceeds 10^{18}. Examples Input 2 1000000000 1000000000 Output 1000000000000000000 Input 3 101 9901 999999000001 Output -1 Input 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Output 0 Submitted Solution: ``` N=int(input()) A=input().split() answer=1 for i in range(N): answer=answer*int(A[i]) if answer>1*10**18: print(-1) else: print(answer) ``` No
13,123
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` H, N, *AB = map(int, open(0).read().split()) dp = [0] * (H + max(AB[::2])) for i in range(1, len(dp)): dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(AB)] * 2)) print(min(dp[H:])) ```
13,124
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` H,N = map(int,input().split()) AB = [list(map(int,input().split())) for _ in range(N)] maxA = max(a for a,b in AB) dp = [0]*(H+maxA) for i in range(1,H + maxA): dp[i] = min(dp[i-a]+b for a,b in AB) print(dp[H]) ```
13,125
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` h, n = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(n)] dp = [1 << 31] * (h + 10**4) dp[0] = 0 for i in range(h): for a, b in AB: dp[i + a] = min(dp[i + a], dp[i] + b) print(min(dp[h:])) ```
13,126
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` h,n=map(int,input().split()) dp=[10**10 for i in range(h+1)] dp[0]=0 for i in range(n): x,y=map(int,input().split()) for j in range(h+1): nj=min(h,j+x) dp[nj]=min(dp[nj],dp[j]+y) print(dp[h]) ```
13,127
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` H,N = map(int,input().split()) MAXH = H+10000 DP = [float("inf")]*MAXH DP[0] = 0 for i in range(N): a,b = map(int,input().split()) for j in range(MAXH-a): if j>H+a:break DP[j+a] = min(DP[j+a],DP[j]+b) print(min(DP[H:])) ```
13,128
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` h,n = map(int, input().split()) magics = [tuple(map(int, input().split())) for _ in range(n)] max_a = sorted(magics, key=lambda x: x[0], reverse=True)[0][0] dp = [0]*(h+max_a) for i in range(1, h+max_a): dp[i] = min(dp[i-a]+b for a,b in magics) print(min(dp[h:])) ```
13,129
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` h, n = map(int, input().split()) ab = [list(map(int, input().split())) for i in range(n)] table = [float("inf")] * (h + 10000) table[0] = 0 for a, b in ab: for i in range(h): table[i+a] = min(table[i+a], table[i] + b) print(min(table[h:])) ```
13,130
Provide a correct Python 3 solution for this coding contest problem. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 "Correct Solution: ``` h, n = map(int, input().split()) magics = [list(map(int, input().split())) for _ in range(n)] max_damage = max(a for a, b in magics) dp = [0] * (h + max_damage) for i in range(1, h + max_damage): dp[i] = min(dp[i - a] + b for a, b in magics) print(dp[h]) ```
13,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` h, n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] dp = [0] * (h+max(a for a,b in ab)) for i in range(1, len(dp)): dp[i] = min(dp[i-a]+b for a, b in ab) print(min(dp[h:])) ``` Yes
13,132
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` h,n=map(int,input().split()) l=[list(map(int,input().split())) for _ in range(n)] dp=[10**9]*(h+max(l)[0]) dp[0]=0 for i in range(1,len(dp)): for a,b in l: if i-a>=0: dp[i]=min(dp[i],dp[i-a]+b) print(min(dp[h:])) ``` Yes
13,133
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` h,n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] dp = [10**10]*(h+1) dp[h] = 0 for i in range(h,0,-1): for j in ab: tmp = max(0,i-j[0]) dp[tmp] = min(dp[tmp], dp[i]+j[1]) print(dp[0]) ``` Yes
13,134
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` from operator import itemgetter h,n=map(int,input().split()) ab=[list(map(int,input().split())) for i in range(n)] infi=10**9 dp=[infi]*2*10**4 dp[0]=0 for a,b in ab: for i in range(h): if dp[i]!=infi: dp[i+a]=min(dp[i+a],dp[i]+b) print(min(dp[h:])) ``` Yes
13,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` inf = 1000000000 dp = [inf] * 20000 h, n = map(int, input().split()) dp[0] = 0 for j in range(n): a, b = map(int, input().split()) for i in range(h + 1): dp[i + a] = min(dp[i + a], dp[i] + b) print(min(dp[h:])) ``` No
13,136
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` h,n=map(int,input().split()) ab=[list(map(int,input().split())) for _ in range(n)] max_a=max(a for a,_ in ab) dp = [0] * (h+max_a) for i in range(0,h+max_a): if i==0: d[i]=0 else: dp[i]=min(dp[i-a]+b for a,b in ab) print(min(dp[h:])) ``` No
13,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` h,n,*L=map(int,open(0).read().split()) dp=[float('inf')]*(h+10100) dp[0]=0 for a,b in zip(*[iter(L)]*2): for i in range(h): t=dp[i]+b if t<dp[i+a]: dp[i+a]=dp[i]+b print(min(dp[h:])) ``` No
13,138
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints * 1 \leq H \leq 10^4 * 1 \leq N \leq 10^3 * 1 \leq A_i \leq 10^4 * 1 \leq B_i \leq 10^4 * All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Examples Input 9 3 8 3 4 2 2 1 Output 4 Input 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Output 100 Input 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Output 139815 Submitted Solution: ``` H,N=map(int, input().split()) AB = [list(map(int,input().split())) for i in range(N)] dp=[10**8]*(H+1) dp[0]=0 for i in range(1,H+1): for ab in AB: dp[i]=min(dp[max(0,i-ab[0])] + ab[1], dp[i]) print(dp[-1]) ``` No
13,139
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` n=int(input()) h=list(map(int,input().split())) res=[] t=0 for i in range(1,n): if h[i]<=h[i-1]: t+=1 else: res.append(t) t=0 res.append(t) print(max(res)) ```
13,140
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) b=[] x=0 for i in range(n-1): if a[i]>=a[i+1]: x+=1 else: b.append(x) x=0 b.append(x) print(max(b)) ```
13,141
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` n=int(input()) h=list(map(int,input().split())) l=[0]*n for i in range(1,n): if h[i]<=h[i-1]: l[i]=1+l[i-1] print(max(l)) ```
13,142
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` N = int(input()) H = [int(_) for _ in input().split()] num = [0] * N for i in range(N-2, -1, -1): if H[i] >= H[i+1]: num[i] = num[i+1]+1 print(max(num)) ```
13,143
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` N = int(input()) H = list(map(int,input().split())) a =[0]*(N+1) for i in range(N-1,0,-1): if H[i]<=H[i-1]: a[i] = a[i+1]+1 print(max(a)) ```
13,144
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` n,a=input(),list(map(int,input().split())) ans,now,cnt=0,10**20,0 for i in a: if i>now: cnt=0 cnt+=1 now=i ans=max(ans,cnt) print(ans-1) ```
13,145
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` n=int(input()) a=[int(i) for i in input().split()] m=0 c=0 for i in range(n-1): if a[i]>=a[i+1]: c+=1 else: c=0 if c>m: m=c print(m) ```
13,146
Provide a correct Python 3 solution for this coding contest problem. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 "Correct Solution: ``` N=int(input()) H=list(map(int,input().split())) a=b=c=0 for i in range(N): if H[i]<=a: a=H[i] b+=1 if b>=c: c=b else: a=H[i] b=0 print(c) ```
13,147
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` N = int(input()) H= list(map(int, input().split())) res = [0] for i in range(N-1): if H[i+1]<=H[i]: res[-1]+=1 else: res.append(0) print(max(res)) ``` Yes
13,148
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n,h=open(0);a=b=c=0 for i in map(int,h.split()):c=(b>=i)*-~c;b=i;a=max(a,c) print(a) ``` Yes
13,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n=int(input()) h=[int(i) for i in input().split()] j=0 k=0 for i in range(1,len(h)): if h[i-1]>=h[i]: j+=1 else: k=max(k,j) j=0 k=max(k,j) print(k) ``` Yes
13,150
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n=int(input()) H=list(map(int,input().split())) res=0 cnt=0 for i in range(n-1): if H[i]>=H[i+1]: cnt += 1 else: cnt = 0 res=max(res,cnt) print(res) ``` Yes
13,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n = int(input()) h = list(map(int, input().split())) a = 0 move = [] for i in range(n-1): if h[i] >= h[i+1]: a += 1 else: move.append(a) a = 0 print(max(move)) ``` No
13,152
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n = int(input()) h = list(map(int,input().split())) h.append(10**10) counter = [] for i in range(n): cnt = 0 for j in range(i,n): if h[j]>=h[j+1]: cnt +=1 else: counter.append(cnt) break ans = max(counter) print(ans) ``` No
13,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` def main(): # n,k = map(int,input().split()) n = int(input()) # s = str(input()) h = list(map(int,input().split())) # l = [list(map(int, input().split())) for _ in range(n)] # s = list(s) ans = 0 dp = [0] * n if n == 1: print(0) if n == 2: if h[0] >= h[1]: print(1) else: print(0) else: if h[0] >= h[1]: dp[0] = 1 for i in range(1,n-1): if h[i] >= h[i+1]: dp[i] = dp[i-1] + 1 else: dp[i] = 0 print(max(dp)) if __name__ == '__main__': main() ``` No
13,154
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` N = int(input()) H = input().split() Move = 0 tmp = 0 for i in range(N-1): if int(H[i+1]) > int(H[i]): tmp = 0 if Move < tmp: Move = tmp else: tmp += 1 print(H[i],H[i+1]) if Move < tmp: Move = tmp print(Move) ``` No
13,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation. Constraints * 2 \leq N \leq 2000 * 1 \leq M \leq 2000 * 1 \leq a_i, b_i \leq N * a_i \neq b_i * 1 \leq c_j, d_j \leq N * c_j \neq d_j * G does not contain multiple edges. * T is a tree. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M Output Print the final number of edges in G. Examples Input 5 3 1 2 1 3 3 4 1 5 5 4 2 5 1 5 Output 6 Input 7 5 1 5 1 4 1 7 1 2 2 6 6 3 2 5 1 3 1 6 4 6 4 7 Output 11 Input 13 11 6 13 1 2 5 1 8 4 9 7 12 2 10 11 1 9 13 7 13 11 8 10 3 8 4 13 8 12 4 7 2 3 5 11 1 4 2 11 8 10 3 5 6 9 4 10 Output 27 Submitted Solution: ``` print("5") ``` No
13,156
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation. Constraints * 2 \leq N \leq 2000 * 1 \leq M \leq 2000 * 1 \leq a_i, b_i \leq N * a_i \neq b_i * 1 \leq c_j, d_j \leq N * c_j \neq d_j * G does not contain multiple edges. * T is a tree. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M Output Print the final number of edges in G. Examples Input 5 3 1 2 1 3 3 4 1 5 5 4 2 5 1 5 Output 6 Input 7 5 1 5 1 4 1 7 1 2 2 6 6 3 2 5 1 3 1 6 4 6 4 7 Output 11 Input 13 11 6 13 1 2 5 1 8 4 9 7 12 2 10 11 1 9 13 7 13 11 8 10 3 8 4 13 8 12 4 7 2 3 5 11 1 4 2 11 8 10 3 5 6 9 4 10 Output 27 Submitted Solution: ``` import queue SIZE = 2000 vec = [[] for _ in range(SIZE)] par = [[-1] * SIZE for _ in range(SIZE)] id_ = [[-1] * SIZE for _ in range(SIZE)] ans = 0 def dfs(v: int, p: int, rt: int): par[rt][v] = p for to in vec[v]: if to == p: continue dfs(to, v, rt) def dfs2(v: int, p: int, b: int): global ans if id_[b][v] == v: ans += 1 b = v for to in vec[v]: if to == p: continue dfs2(to, v, b) def add(a: int, b: int): if id_[a][b] == b or id_[b][a] == a: return if id_[a][b] != -1: add(id_[a][b], b) return if id_[b][a] != -1: add(id_[b][a], a) return id_[a][b] = b id_[b][a] = a nxt = [] que = queue.Queue() que.put(b) while not que.empty(): v = que.get() for to in vec[v]: if to == par[a][v]: continue if id_[a][to] != -1: nxt.append((to, b)) else: id_[a][to] = b que.put(to) que.put(a) while not que.empty(): v = que.get() for to in vec[v]: if to == par[b][v]: continue if id_[b][to] != -1: nxt.append((to, a)) else: id_[b][to] = a que.put(to) for u, v in nxt: add(u, v) def adding_edges(N: int, M: int, T: list, G: list)->int: global ans for a, b in T: vec[a-1].append(b-1) vec[b-1].append(a-1) for i in range(N): dfs(i, -1, i) for c, d in G: add(c-1, d-1) for i in range(N): for to in vec[i]: dfs2(to, i, i) return ans//2 if __name__ == "__main__": N = 0 M = 0 N, M = map(int, input().split()) T = [tuple(int(s) for s in input().split()) for _ in range(N-1)] G = [tuple(int(s) for s in input().split()) for _ in range(M)] ans = adding_edges(N, M, T, G) print(ans) ``` No
13,157
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation. Constraints * 2 \leq N \leq 2000 * 1 \leq M \leq 2000 * 1 \leq a_i, b_i \leq N * a_i \neq b_i * 1 \leq c_j, d_j \leq N * c_j \neq d_j * G does not contain multiple edges. * T is a tree. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M Output Print the final number of edges in G. Examples Input 5 3 1 2 1 3 3 4 1 5 5 4 2 5 1 5 Output 6 Input 7 5 1 5 1 4 1 7 1 2 2 6 6 3 2 5 1 3 1 6 4 6 4 7 Output 11 Input 13 11 6 13 1 2 5 1 8 4 9 7 12 2 10 11 1 9 13 7 13 11 8 10 3 8 4 13 8 12 4 7 2 3 5 11 1 4 2 11 8 10 3 5 6 9 4 10 Output 27 Submitted Solution: ``` from collections import deque a=[] def bfs(maze, visited, sy, sx): queue = deque([[sy, sx]]) visited[sy][sx] = 0 while queue: y, x = queue.popleft() if queue == False: return visited[y][x] for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): new_y, new_x = y+j, x+k if maze[new_y][new_x] == "." and \ visited[new_y][new_x] == -1: visited[new_y][new_x] = visited[y][x] + 1 queue.append([new_y, new_x]) if __name__ == "__main__": R, C = map(int, input().split()) for h in range(R): k=input() a.append(k) for p in k: p="#" maze = [input() for i in range(R)] visited = [[-1]*C for j in range(R)] print(bfs(maze, visited, sy, sx)) ``` No
13,158
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation. Constraints * 2 \leq N \leq 2000 * 1 \leq M \leq 2000 * 1 \leq a_i, b_i \leq N * a_i \neq b_i * 1 \leq c_j, d_j \leq N * c_j \neq d_j * G does not contain multiple edges. * T is a tree. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M Output Print the final number of edges in G. Examples Input 5 3 1 2 1 3 3 4 1 5 5 4 2 5 1 5 Output 6 Input 7 5 1 5 1 4 1 7 1 2 2 6 6 3 2 5 1 3 1 6 4 6 4 7 Output 11 Input 13 11 6 13 1 2 5 1 8 4 9 7 12 2 10 11 1 9 13 7 13 11 8 10 3 8 4 13 8 12 4 7 2 3 5 11 1 4 2 11 8 10 3 5 6 9 4 10 Output 27 Submitted Solution: ``` # no sub撤退をしないという覚悟 print('nan') ``` No
13,159
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` N = int(input()) *A, = map(int, input().split()) def check(K): st = [] for i, a in enumerate(A): #print(K, i, st, a) while st and a < st[-1][0]: st.pop() u = i > 0 and A[i-1] >= A[i] if not st: st.append([a, u]) continue l = st[-1] if l[0] == a: l[1] += 1 while st and l[1] == K: st.pop(); a -= 1 if a == 0: return 0 if not st: st.append([a, 1]) break l = st[-1] if l[0] == a: l[1] += 1 else: st.append([a, 1]) break #print(l, st) else: st.append([a, u]) #print(st) return 1 ok = 1 for i in range(N-1): if not A[i] < A[i+1]: ok = 0 if ok: print(1) exit(0) left = 1; right = N+1 while left+1 < right: mid = (left + right) // 2 if check(mid): right = mid else: left = mid print(right) ```
13,160
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "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()) def shave(stack:list, nex:int, prv:int): res = prv-nex while res > 0: if res >= stack[-1][1]: _,y = stack.pop() res -= y else: stack[-1][1] -= res res = 0 def normalize(stack: list): if stack[-1][0] == stack[-2][0]: stack[-2][1] += stack[-1][1] stack.pop() def add(stack:list): if stack[-1][1] == 1: stack[-1][0] += 1 else: stack[-1][1] -= 1 stack.append([stack[-1][0]+1, 1]) def kuriagari(stack:list): _, y = stack.pop() add(stack) normalize(stack) stack.append([1,y]) def check(a:list, upto:int): stack = [[0,0]] for i in range(n): if a[i+1] > a[i]: stack.append([1, a[i+1]-a[i]]) normalize(stack) else: shave(stack, a[i+1], a[i]) if stack[-1][0] == upto and stack[-1][1] == a[i+1]: return False elif stack[-1][0] == upto: kuriagari(stack) else: add(stack) normalize(stack) return True def binsearch(a:list): low = 0 high = 10**9+1 while high-low > 1: mid = (high+low) // 2 if check(a, mid): high = mid else: low = mid return high n = ni() a = [0] + list(li()) ans = binsearch(a) print(ans) ```
13,161
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) ok, ng = n, 0 while ok-ng > 1: x = (ok+ng)//2 #d = defaultdict(int) d = dict() last = 0 valid = True if x == 1: for i in range(n-1): if a[i] >= a[i+1]: valid = False break if valid: ok = x else: ng = x continue for i in range(n-1): dels = [] if a[i] < a[i+1]: last = a[i+1] continue j = a[i+1] for k in d.keys(): if j < k: dels.append(k) while j > 0: if j in d and d[j] == x-1: #d[j] = 0 dels.append(j) j -= 1 else: break if j in d: d[j] += 1 else: d[j] = 1 for k in dels: del d[k] if 0 in d: valid = False break last = j if valid: ok = x else: ng = x print(ok) ```
13,162
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` import sys input = sys.stdin.readline N = int(input()) A = [int(x) for x in input().split()] A.append(1) B = [A[0]] B_cnt = [1] for i,(x,y) in enumerate(zip(A[:-1],A[1:])): if x < y and y < A[i+2]: continue if x == y: B_cnt[-1] += 1 else: B.append(y) B_cnt.append(1) def test(x): digit = [0] cnt = [0] for a,a_cnt in zip(B,B_cnt): if digit[-1] < a: digit.append(a) cnt.append(a_cnt) continue if digit[-1] == a: cnt[-1] += a_cnt continue while True: # 繰り上がり処理をしながら左に戻る if digit[-1] <= a: break n = digit.pop() k = cnt.pop() if k <= x: continue if digit[-1] == n-1: cnt[-1] += (k-1)//x else: digit.append(n-1) cnt.append((k-1)//x + 1) if digit[-1] == a: cnt[-1] += a_cnt else: digit.append(a) cnt.append(1+a_cnt) return cnt[1] <= x+1 if all(x<y for x,y in zip(A[:-2],A[1:-1])): print(1) exit() left = 1 # 無理 right = 10 # 可能? while not test(right): left *= 10 right *= 10 right = min(right,N) while right > left + 1: mid = (left+right)//2 if test(mid): right = mid else: left = mid answer = right print(answer) ```
13,163
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` N = int(input()) A = [int(a) for a in input().split()] def chk(k): if k == 1: for i in range(1, N): if A[i] <= A[i-1]: return 0 return 1 X = [(0, 0)] def add(x, y): if x <= 0: return 0 if x > X[-1][0]: X.append((x, 0 if x == y else 1)) elif x == X[-1][0]: if X[-1][1] + 1 < k: X[-1] = (X[-1][0], X[-1][1] + 1) else: if add(x-1, y) == 0: return 0 else: while X[-1][0] > x: X.pop() if x > X[-1][0]: X.append((x, 1)) elif x == X[-1][0]: if X[-1][1] + 1 < k: X[-1] = (X[-1][0], X[-1][1] + 1) else: if add(x-1, y) == 0: return 0 if X[-1][0] < y: X.append((y, 0)) return 1 for a in A: if add(a, a) == 0: return 0 return 1 l, r = 0, 1 << 18 while r - l > 1: m = (l + r) // 2 if chk(m): r = m else: l = m print(r) ```
13,164
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` def is_possible(x, A): current = {} length = 0 for a in A: if a <= length: if x == 1: return False current = {k: current[k] for k in current if k < a} i = a - 1 if i not in current: current[i] = 0 current[i] += 1 while i in current and current[i] >= x: if i == 0: return False if (i-1) not in current: current[i-1] = 0 current[i-1] += 1 del current[i] i -= 1 length = a return True def main(): N = int(input()) A = list(map(int, input().split())) left = 1 right = N while left < right: center = (left + right) // 2 if is_possible(center, A): right = center else: left = center + 1 print(left) if __name__ == "__main__": main() ```
13,165
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` N = int(input()) A_raw = list(map(int, input().split())) flg = 1 prev = 0 A = [] for i in range(N): if A_raw[i] <= prev: flg = 0 prev = A_raw[i] if A_raw[i] <= 50: A.append(A_raw[i]) if flg: print(1) exit() N = len(A) if N <= 1: print(2) exit() ok = N ng = 1 mid = (ok + ng) // 2 while ok - ng > 1: ng_flg = 0 word = [1] * A[0] for i in range(1, N): if A[i] > A[i-1]: word.extend([1] * (A[i] - A[i-1])) else: word_prev = word[:A[i]] k = A[i] - 1 while True: if k == -1: ng_flg = 1 break if word_prev[k] != mid: word_prev[k] += 1 word = word_prev break else: word_prev[k] = 1 k -= 1 if ng_flg == 1: break if not ng_flg: ok = mid else: ng = mid mid = (ok + ng) // 2 print(ok) ```
13,166
Provide a correct Python 3 solution for this coding contest problem. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 "Correct Solution: ``` def solve(aaa): l = 1 r = 200000 while l < r: m = (l + r) // 2 if check(m, aaa): r = m else: l = m + 1 return r def check(d, aaa): if d == 1: return all(a1 < a2 for a1, a2 in zip(aaa, aaa[1:])) l = 0 word = [[0, 0]] for a in aaa: if l >= a: if not carry(d, word, a): return False l = a return True def carry(d, word, i): while word[-1][0] > i: word.pop() while word[-1] == [i, d]: word.pop() i -= 1 if i == 0: return False if word[-1][0] == i: word[-1][1] += 1 else: word.append([i, 2]) return True n = int(input()) aaa = list(map(int, input().split())) print(solve(aaa)) ```
13,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` def main(): import heapq n = int(input()) a = list(map(int, input().split())) for i in range(n-1): if a[i] >= a[i+1]: break else: print(1) return h = [] heapq.heapify(h) kind = 1 length = 0 d = dict() for i in a: if length >= i: while h: hh = -heapq.heappop(h) if hh > i: d.pop(hh) else: heapq.heappush(h, -hh) break for j in range(i, 0, -1): if j not in d: d[j] = 2 heapq.heappush(h, -j) kind = max(kind, 2) while h: hh = -heapq.heappop(h) if hh > j: d.pop(hh) else: heapq.heappush(h, -hh) break break else: if d[j] < kind: d[j] += 1 while h: hh = -heapq.heappop(h) if hh > j: d.pop(hh) else: heapq.heappush(h, -hh) break break else: d[i] += 1 kind += 1 length = i def value(kind): length = 0 d = dict() for i in a: if length >= i: del_list = [] for j in d: if j > i: del_list.append(j) for j in del_list: d.pop(j) for j in range(i, 0, -1): if j not in d: d[j] = 2 break else: if d[j] < kind: d[j] += 1 break else: d.pop(j) else: return False length = i return True def b_search(ok, ng, value): while abs(ok-ng) > 1: mid = (ok+ng)//2 if value(mid): ok = mid else: ng = mid return ok print(b_search(kind, max(1, kind-30), value)) main() ``` Yes
13,168
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` import random input() A = [int(_) for _ in input().split()] A = [A[0]] + [j for i, j in zip(A, A[1:]) if i >= j] N = len(A) def cut(array, index): if index < 1: return [] if index <= array[0][0]: return [(index, array[0][1])] for _ in range(len(array)-1, 0, -1): if array[_ - 1][0] < index: return array[:_] + [(index, array[_][1])] def is_possible(K): dp = [(A[0], 0)] for a in A[1:]: if a <= dp[-1][0]: dp = cut(dp, a) else: dp += [(a, 0)] is_added = False for j in range(len(dp) - 1, -1, -1): if dp[j][1] < K - 1: dp = cut(dp, dp[j][0] - 1) + [(dp[j][0], dp[j][1] + 1)] if dp[-1][0] < a: dp += [(a, 0)] is_added = True break if not is_added: return False return True def bis(x, y): if y == x + 1: return y elif is_possible((x + y) // 2): return bis(x, (x + y) // 2) else: return bis((x + y) // 2, y) print(bis(0, N)) ``` Yes
13,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) # import random # N = 10**5 # A = [random.randrange(1,10**9+1) for _ in range(N)] # import time def main(): l = 0 r = N while r-l > 1: m = (r+l)//2 ok = True if m == 1: pre = -1 for a in A: if pre >= a: ok = False break pre = a else: dp = {} needreset = 10**15 exception = set() pre = -1 for a in A: ind = a for _ in range(40): # 修正 if needreset >= ind or ind in exception: if not ind in dp: dp[ind] = 0 if pre < a else 1 else: dp[ind] = 0 if pre < a else 1 exception.add(ind) # たす if dp[ind] < m: dp[ind] += 1 break elif ind == 1: ok = False break else: # 繰り上がり dp[ind] = 1 ind -= 1 if not ok: break # 更新 if pre > a: needreset = a exception = set() pre = a if ok: r = m else: l = m print(r) if __name__ == "__main__": #dt = time.time() main() #print(time.time()-dt) ``` Yes
13,170
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` import bisect from collections import deque """ def pl(d,k): now = d ind = bisect.bisect_left(dlis,d) while ind > 0: dic[dlis[ind]] += 1 if dic[dlis[ind]] // k == 0: dic[dlis[ind]] = 0 else: break ind -= 1 def able(k): ndep = A[0] for i in range(len(dlis)): dic[dlis[i]] = 0 for i in range(N-1): i += 1 if ndep < A[i]: dic[A[i]] = 0 ndep = A[i] else: ndep = A[i] pl(ndep,k) print (dic,k) if dic[dlis[0]] < k: return True else: return False """ def updiv(a,b): if a % b == 0: return a // b else: return a // b + 1 def able(k): nq = deque([0]) num = deque([A[0]]) for i in range(N-1): i += 1 if A[i] > A[i-1]: if nq[-1] == 0: num[-1] += A[i] - A[i-1] else: nq.append(0) num.append(A[i] - A[i-1]) else: if A[i] < A[i-1]: ds = A[i-1] - A[i] while len(num) > 0 and ds >= num[-1]: nq.pop() ds -= num[-1] num.pop() if len(num) == 0: return False num[-1] -= ds now = 0 while len(nq) > 0 and nq[-1] == k-1: now += num[-1] nq.pop() num.pop() if len(nq) == 0: return False if num[-1] == 1: nq[-1] += 1 else: num[-1] -= 1 nq.append(nq[-1] + 1) num.append(1) if now > 0: nq.append(0) num.append(now) while len(nq) > 1 and nq[-1] == nq[-2]: num[-2] += num[-1] nq.pop() num.pop() #print (k,A[i]) #print (nq) #print (num) return True N = int(input()) A = list(map(int,input().split())) A.append(1) l = 0 r = N while r - l != 1 : m = (l + r) // 2 if able(m): r = m else: l = m print (r) ``` Yes
13,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` from collections import defaultdict from copy import copy n = int(input()) a = list(map(int, input().split())) ok, ng = n, 0 while ok-ng > 1: x = (ok+ng)//2 d = defaultdict(int) last = 0 valid = True if x == 1: for i in range(n-1): if a[i] >= a[i+1]: valid = False break if valid: ok = x else: ng = x continue for i in range(n-1): if a[i] > a[i+1]: if a[i+1] > last: d[a[i+1]] = 1 else: j = a[i+1] while d[j] == x-1 and j > 0: del d[j] j -= 1 d[j] += 1 last = a[i+1] elif a[i] == a[i+1]: j = a[i+1] while d[j] == x-1 and j > 0: del d[j] j -= 1 d[j] += 1 last = a[i+1] e = copy(d) for k in d.keys(): if k > last: del e[k] d = copy(e) #if x < 5: #print(x, last, d) if d[0] > 0: valid = False break if valid: ok = x else: ng = x print(ok) ``` No
13,172
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N - 1): if A[i] > A[i + 1]: ans += 1 print(ans) ``` No
13,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` def main(): n = int(input()) a = list(map(int, input().split())) for i in range(n-1): if a[i] >= a[i+1]: break else: print(1) return def value(kind): length = 0 d = [] for i in a: if length >= i: while d: j, k = d[-1] if j > i: d.pop() else: break l = len(d)-1 if d: jj, k = d[-1] else: jj, k = -1, -1 for j in range(i, 0, -1): if jj != j: d.append([j, 2]) kind = max(kind, 2) break else: if k < kind: d[l][1] += 1 for jjj in range(l+1, len(d)): d.pop() else: l -= 1 else: return False length = i return True def b_search(ok, ng, value): while abs(ok-ng) > 1: mid = (ok+ng)//2 if value(mid): ok = mid else: ng = mid return ok print(b_search(n, 1, value)) main() ``` No
13,174
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left. At least how many different characters are contained in S_1,S_2,...,S_N, if the length of S_i is known to be A_i? Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq A_i \leq 10^9 * A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of different characters contained in the strings. Examples Input 3 3 2 1 Output 2 Input 5 2 3 2 1 2 Output 2 Submitted Solution: ``` N = int(input()) A = [int(i) for i in input().split()] def f(al, X): def g(stack, X): if not any(stack): stack.append(-1) return l = stack.pop() if l >= X: g(stack, X) stack.append(1) else: stack.append(l + 1) st = [] s = 0 for t in al: d = t - s if d > 0: st.extend([1] * d) else: for _ in range(-d): st.pop() g(st, X) if st[0] < 0: return False s = t return True max_N = N min_N = len([i for i in A if i == 1]) b_max_N = 0 b_min_N = 0 while max_N != min_N: nx = (max_N + min_N) // 2 if f(A, nx): max_N = nx else: min_N = nx if b_max_N == max_N and b_min_N == min_N: break b_max_N = max_N b_min_N = min_N print(max_N) ``` No
13,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the number of the possible tuples of sequences (A_0,A_1,...,A_N) that satisfy all of the following conditions, modulo M: * For every i (0\leq i\leq N), A_i is a sequence of length i consisting of integers between 1 and K (inclusive); * For every i (1\leq i\leq N), A_{i-1} is a subsequence of A_i, that is, there exists 1\leq x_i\leq i such that the removal of the x_i-th element of A_i would result in a sequence equal to A_{i-1}; * For every i (1\leq i\leq N), A_i is lexicographically larger than A_{i-1}. Constraints * 1 \leq N,K \leq 300 * 2 \leq M \leq 10^9 * N, K and M are integers. Input Input is given from Standard Input in the following format: N K M Output Print the number of the possible tuples of sequences (A_0,A_1,...,A_N), modulo M. Examples Input 2 2 100 Output 5 Input 4 3 999999999 Output 358 Input 150 150 998244353 Output 186248260 Submitted Solution: ``` #include <bits/stdc++.h> using namespace std; vector<vector<int64_t> > get_combination(int N, int M) { vector<vector<int64_t> > mat(N + 1, vector<int64_t>(N + 1)); for (int i = 0; i <= N; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) mat[i][j] = 1; else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j]; mat[i][j] %= M; } } return (mat); } int main() { int N, K, M; cin >> N >> K >> M; auto C = get_combination(N, M); int dp[302][302] = {{}}; for (int i = 0; i <= K; i++) { dp[1][i] = 1; } for (int i = 2; i <= N + 1; i++) { int sub[302] = {}; for (int j = K - 1; j >= 0; j--) { for (int k = 0; k < i; k++) { sub[k] += dp[k][j + 1]; sub[k] %= M; } for (int k = 1; k <= i; k++) { dp[i][j] += 1LL * dp[i - k][j] * C[i - 2][k - 1] % M * sub[k] % M; dp[i][j] %= M; } } } cout << dp[N + 1][0] << endl; } ``` No
13,176
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` n, p = map(int, input().split()) e = [tuple(map(int, input().split())) for _ in range(n)] # e = [(w,b), ...] e2 = sorted(((100 - p) * w + p * b for w, b in e), reverse=True) rest = p * sum(b for _, b in e) cur = 0 while rest > 0 and cur < n: rest -= e2[cur] cur += 1 print(cur) ```
13,177
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` n, p = map(int, input().split()) w, b = [], [] for _ in range(n): ww, bb = map(int, input().split()) w.append(ww) b.append(bb) s = [] for ww, bb in zip(w, b): s.append((100 - p) * ww + p * bb) s.sort(reverse=True) score = -sum(b) * p cnt = 0 while score < 0: score += s[cnt] cnt += 1 print(cnt) # (100-p)*w-p*b>=0 ```
13,178
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` n,p=map(int,input().split()) l=[] for i in range(n): l.append(list(map(int,input().split()))) l.sort(key=lambda x:-(x[0]*(100-p)+x[1]*p)) z=0 for i in range(n): z+=-l[i][1]*p i=0 while z<0: z+=l[i][0]*(100-p)+l[i][1]*p i+=1 print(i) ```
13,179
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` N, P = map(int, input().split()) B = 0 Q = [] for i in range(N): w, b = map(int, input().split()) B += b Q.append((100 - P)*w + P*b) Q.sort() s = 0 for i in range(N): s += Q[-i-1] if B*P <= s: print(i+1) break ```
13,180
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` N,P=[int(i) for i in input().split()] wb=[[int(j) for j in input().split()] for i in range(N)] xs = [(100-P)*w+P*b for w,b in wb] xs.sort() xs.reverse() score=0 for i in range(N): score-=P*wb[i][1] for i in range(N): score+=xs[i] if score>=0: print(i+1) break ```
13,181
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` from itertools import accumulate def solve(l, r): if l > r: return l m = (l + r) // 2 w, b = whites[m], blues[m] if w * 100 // (w + b) < p: l = m + 1 else: r = m - 1 return solve(l, r) n, p = map(int, input().split()) wbs = [tuple(map(int, input().split())) for _ in range(n)] ass = [(w * (100 - p) + b * p, i) for i, (w, b) in enumerate(wbs)] ass.sort(reverse=True) whites = list(accumulate(wbs[i][0] for _, i in ass)) blues = [wbs[i][1] for _, i in ass[1:]] blues = list(reversed(list(accumulate(reversed(blues))))) + [0] # print(list(whites)) # print(list(blues)) print(solve(0, n - 1) + 1) ```
13,182
Provide a correct Python 3 solution for this coding contest problem. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 "Correct Solution: ``` N, P = map(int, input().split()) xs = [] value = 0 for _ in range(N): w, b = map(int, input().split()) xs.append((100-P)*w+P*b) value -= P*b xs.sort(reverse=True) for i, x in enumerate(xs, 1): value += x if value >= 0: print(i) break ```
13,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 Submitted Solution: ``` from itertools import accumulate def solve(l, r): if l > r: return l m = (l + r) // 2 w, b = whites[m], blues[m] if w * 100 // (w + b) < p: l = m + 1 else: r = m - 1 return solve(l, r) n, p = map(int, input().split()) wbs = [tuple(map(int, input().split())) for _ in range(n)] ass = [(sum(t), i) for i, t in enumerate(wbs)] ass.sort(reverse=True) whites = list(accumulate(wbs[i][0] for s, i in ass)) blues = [wbs[i][1] for s, i in ass[1:]] blues = list(reversed(list(accumulate(reversed(blues))))) + [0] # print(list(whites)) # print(list(blues)) print(solve(0, n - 1) + 1) ``` No
13,184
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints * 1 ≤ N ≤ 10^5 * 1 ≤ P ≤ 100 * 1 ≤ w_i ≤ 10^9 * 1 ≤ b_i ≤ 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Examples Input 4 75 1 1 1 1 1 1 1 1 Output 3 Input 4 75 1 1 1 1 1 1 100 1 Output 1 Input 5 60 6 3 5 9 3 4 7 8 4 7 Output 3 Submitted Solution: ``` from itertools import accumulate def solve(l, r): if l > r: return l m = (l + r) // 2 w, b = whites[m], blues[m] if w * 100 // (w + b) < p: l = m + 1 else: r = m - 1 return solve(l, r) n, p = map(int, input().split()) wbs = [tuple(map(int, input().split())) for _ in range(n)] ass = [(sum(t), t[0], i) for i, t in enumerate(wbs)] ass.sort(reverse=True) whites = list(accumulate(wbs[i][0] for s, t, i in ass)) blues = [wbs[i][1] for s, t, i in ass[1:]] blues = list(reversed(list(accumulate(reversed(blues))))) + [0] # print(list(whites)) # print(list(blues)) print(solve(0, n - 1) + 1) ``` No
13,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N(N+1)/2 dots arranged to form an equilateral triangle whose sides consist of N dots, as shown below. The j-th dot from the left in the i-th row from the top is denoted by (i, j) (1 \leq i \leq N, 1 \leq j \leq i). Also, we will call (i+1, j) immediately lower-left to (i, j), and (i+1, j+1) immediately lower-right to (i, j). <image> Takahashi is drawing M polygonal lines L_1, L_2, ..., L_M by connecting these dots. Each L_i starts at (1, 1), and visits the dot that is immediately lower-left or lower-right to the current dots N-1 times. More formally, there exist X_{i,1}, ..., X_{i,N} such that: * L_i connects the N points (1, X_{i,1}), (2, X_{i,2}), ..., (N, X_{i,N}), in this order. * For each j=1, 2, ..., N-1, either X_{i,j+1} = X_{i,j} or X_{i,j+1} = X_{i,j}+1 holds. Takahashi would like to draw these lines so that no part of L_{i+1} is to the left of L_{i}. That is, for each j=1, 2, ..., N, X_{1,j} \leq X_{2,j} \leq ... \leq X_{M,j} must hold. Additionally, there are K conditions on the shape of the lines that must be followed. The i-th condition is denoted by (A_i, B_i, C_i), which means: * If C_i=0, L_{A_i} must visit the immediately lower-left dot for the B_i-th move. * If C_i=1, L_{A_i} must visit the immediately lower-right dot for the B_i-th move. That is, X_{A_i, {B_i}+1} = X_{A_i, B_i} + C_i must hold. In how many ways can Takahashi draw M polygonal lines? Find the count modulo 1000000007. Constraints * 1 \leq N \leq 20 * 1 \leq M \leq 20 * 0 \leq K \leq (N-1)M * 1 \leq A_i \leq M * 1 \leq B_i \leq N-1 * C_i = 0 or 1 * No pair appears more than once as (A_i, B_i). Input Input is given from Standard Input in the following format: N M K A_1 B_1 C_1 A_2 B_2 C_2 : A_K B_K C_K Output Print the number of ways for Takahashi to draw M polygonal lines, modulo 1000000007. Examples Input 3 2 1 1 2 0 Output 6 Input 3 2 2 1 1 1 2 1 0 Output 0 Input 5 4 2 1 3 1 4 2 0 Output 172 Input 20 20 0 Output 881396682 Submitted Solution: ``` print(881396682) ``` No
13,186
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` def main(): S = input() print("%s %s" % (S[:4], S[4:])) if __name__ == "__main__": main() ```
13,187
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` s=input() a=s[:4] b=s[4:] print(a+" "+b) ```
13,188
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` s = input() a = s[:4] b = s[4:] print(a + ' ' + b) ```
13,189
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` # 2019/12/21 s=input() print(s[:4]+' '+s[4:]) ```
13,190
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` a = input() ans = a[:4] + ' ' + a[4:] print(ans) ```
13,191
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` S= input() print(S[:4]+" "+S[-8:]) ```
13,192
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` s = list(input()) for i in range(12): if i!=3: print(s[i], end="") else: print(s[i]+" ", end="") print() ```
13,193
Provide a correct Python 3 solution for this coding contest problem. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL "Correct Solution: ``` s = str(input()) print(s[0:4]+" "+s[4:]) ```
13,194
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL Submitted Solution: ``` N=input() print(N[0:4]+" "+N[4:16]) ``` Yes
13,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL Submitted Solution: ``` def main(): s=input() print(s[0:4],s[4:],sep=' ') main() ``` Yes
13,196
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL Submitted Solution: ``` s=input() for i, j in enumerate(s): if i==4: print(" ", end="") print(j, end="") print("") ``` Yes
13,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL Submitted Solution: ``` code_festival = input() code = code_festival[:4] festival = code_festival[4:] code_festival = code + " " + festival print (code_festival) ``` Yes
13,198
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s. Constraints * s contains exactly 12 letters. * All letters in s are uppercase English letters. Input The input is given from Standard Input in the following format: s Output Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end. Examples Input CODEFESTIVAL Output CODE FESTIVAL Input POSTGRADUATE Output POST GRADUATE Input ABCDEFGHIJKL Output ABCD EFGHIJKL Submitted Solution: ``` N = int(input()) usa = list(map(int, input().split())) print (usa[0]) for i, j in enumerate(usa): if(usa[j]-1 == i): count+=1 if(i >= N/2): break print (count) ``` No
13,199