text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` def lip(): return list(map(int,input().split())) def splip(): return map(int,input().split()) def intip(): return int(input()) for _ in range(intip()): n = intip() l = [i for i in range(1,n+1)] l = l[::-1] mid = n//2 if n==2: print(*l) elif n%2!=0: l[mid] , l[mid-1] = l[mid-1],l[mid] print(*l) else: l[mid+1] , l[mid] = l[mid],l[mid+1] print(*l) ```
97,200
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` t= int (input()) if t: for i in range(t): n= int(input()) if n: print(n, *range(1,n)) ```
97,201
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` N = int(input()) for _ in range(N): n = int(input()) a = [] for i in range(0,n): a.insert(0,i+1) if n % 2==1: a[0] = a[n // 2] a[n // 2] = n print(*a) ```
97,202
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` for _ in range(int(input())): N = int(input()) for i in range(2,N+1): print(i, end = " ") print(1) ```
97,203
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` t = int(input()) for _ in range(t): n = int(input()) if n % 2 == 0: for i in range(n, 0, -1): print(i, end=' ') print() else: for i in range(n, n // 2 + 1, -1): print(i, end=' ') for i in range(1, n // 2 + 2): print(i, end=' ') print() ```
97,204
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` def solve(n): a=[0]*n a[0]=n for i in range(1,n): a[i]=i return a t=int(input()) ans=[] while t>0: n=int(input('')) ans.append(solve(n)) t-=1 for i in ans: for j in i: print(j,end=' ') print() ```
97,205
Provide tags and a correct Python 3 solution for this coding contest problem. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Tags: constructive algorithms, probabilities Correct Solution: ``` t=int(input()) for q in range(t): n=int(input()) ch=str(n)+" " for i in range(1,n): ch+=str(i)+" " print(ch) ```
97,206
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` for _ in range(int(input())): n = int(input()) for i in range(2,n+1): print(i,end=" ") print(1) ``` Yes
97,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) t=int(input()) for _ in range(t): n=int(input()) oneLineArrayPrint([n]+list(range(1,n))) ``` Yes
97,208
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) a = [] while n>0: a.append(n) n-=1 if len(a)%2 == 0: print(" ".join(map(str,a))) else: a1 = a[len(a)//2] a.remove(a1) a.append(a1) print(" ".join(map(str,a))) ``` Yes
97,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` import random t = int(input()) while t: n = int(input()) res= [n] for i in range(1,n): res.append(i) print(" ".join(map(str,res))) t-=1 ``` Yes
97,210
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` t = int(input()) for i in range (t): n = int(input()) p = [] for j in range (n): p.append(n) n -= 1 print(*p) ``` No
97,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` for i in range(int(input())): n = int(input()) a = [] for i in range(2,n+1,2): a.append(i) for i in range(1,n+1,2): a.append(i) print(*a) ``` No
97,212
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` for i in range(int(input())): n=int(input()) for j in range(n): if j==n-1: print(1) else: print(n-j,end=" ") print() ``` No
97,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array). Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). You have to answer t independent test cases. If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow. The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find. Output For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied). If there are several answers, you can print any. It can be proven that the answer exists for each n > 1. Example Input 2 2 5 Output 2 1 2 1 5 3 4 Submitted Solution: ``` import sys # problem a # template by: # https://github.com/rajatg98 '''input ''' import sys import math import bisect from sys import stdin,stdout from math import gcd,floor,sqrt,log from collections import defaultdict as dd from bisect import bisect_left as bl,bisect_right as br sys.setrecursionlimit(100000000) inp =lambda: int(input()) strng =lambda: input().strip() jn =lambda x,l: x.join(map(str,l)) strl =lambda: list(input().strip()) mul =lambda: map(int,input().strip().split()) mulf =lambda: map(float,input().strip().split()) seq =lambda: list(map(int,input().strip().split())) ceil =lambda x: int(x) if(x==int(x)) else int(x)+1 ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1 flush =lambda: stdout.flush() stdstr =lambda: stdin.readline() stdint =lambda: int(stdin.readline()) stdpr =lambda x: stdout.write(str(x)) mod=1000000007 #main code def solve(): n = inp() print([n] + list(range(1, n))) def main(): tests = inp() for _ in range(tests): solve() if __name__ == "__main__": main() ``` No
97,214
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` try: while input(): print('NO') except EOFError: pass ```
97,215
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` while True: try: q = input() except EOFError: break print("no", flush=True) ```
97,216
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` while(1): try: s=input() except: break print("NO",flush=True) ```
97,217
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` while True: try: s=input() print("NO") except EOFError as e: exit(0) ```
97,218
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` while True: try: x = input() except: break print("NO") ```
97,219
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` ll=lambda:map(int,input().split()) t=lambda:int(input()) ss=lambda:input() lx=lambda x:map(int,input().split(x)) #from math import log10 ,log2,ceil,factorial as fac,gcd #from itertools import combinations_with_replacement as cs #from functools import reduce #from bisect import bisect_right as br,bisect_left as bl #from collections import Counter import sys #for _ in range(t()): while 1: try: n=ss() if n=="Is it rated?": print("NO") else: print("YES") except: break sys.stdout.flush() ''' 1+3+9 (3**n-1)//2 ''' ```
97,220
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` while True: try : line = input().strip() print("No") except EOFError: break ```
97,221
Provide tags and a correct Python 3 solution for this coding contest problem. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Tags: *special, implementation, interactive Correct Solution: ``` while True: try: input() except EOFError: break print("NO") ```
97,222
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` try: while True: q=input() print('NO') except: pass ``` Yes
97,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` print("NO\n"*99) ``` Yes
97,224
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` print(100*'NO''\n') ``` Yes
97,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` while True: try: s = input() if s == "Is it rated?": print('NO') else: break except: break ``` Yes
97,226
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` s = input() print("NO") ``` No
97,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` n=input() if(n=="Is it rated?"): print("NO") ``` No
97,228
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` try: s = input() print("NO") except: exit(0) ``` No
97,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive. Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer. Example Input Is it rated? Is it rated? Is it rated? Output NO NO NO Submitted Solution: ``` print("No") ``` No
97,230
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` from collections import defaultdict from itertools import accumulate from bisect import bisect_left from collections import deque from collections import Counter import sys input = sys.stdin.readline ''' for CASES in range(int(input())): n, m = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) S = input().strip() sys.stdout.write(" ".join(map(str,ANS))+"\n") ''' inf = 100000000000000000 # 1e17 mod = 998244353 n = int(input()) if n==1: print(1) sys.exit(0) dp=[0]*(n+1) f=[0]*(n+1) f[0]=1 f[1]=1 dp[0]=0 dp[1]=1 sumf=0 sumdp=1 #print("!") last=[0]*(2*n+1) for i in range(2,2*n+1): if i%2==0: j=i+i while j<=2*n: last[j]+=1 last[j]%=mod j=j+i #print(last) for i in range(2,n+1): sumf+=f[i-2] sumf%=mod dp[i]=sumf+last[i*2] dp[i]%=mod sumdp+=dp[i] # 所有裸露的直接往上面包东西 sumdp%=mod f[i]=sumdp f[i]%=mod print(f[n]) # # dp=[0]*(n+1) # f=[0]*(n+1) # sumdp=[0]*(n+1) # sumf=[0]*(n+1) # # sumdp[1]=3 # sumf[0]=2 # sumf[1]=2 # for i in range(2,n+1): # sumdp[i]=sumdp[i-1] # sumf[i]=sumf[i-1] # # f[i]=sumdp[i] # dp[i]=sumf[i-2] # # sumdp[i]+=dp[i] # sumf[i]+=f[i] ```
97,231
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` # Python3 program to count # Python3 program to count # number of factors # of an array of integers MAX = 1000001; # array to store # prime factors factor = [0]*(MAX + 1); # function to generate all # prime factors of numbers # from 1 to 10^6 def generatePrimeFactors(): factor[1] = 1; # Initializes all the # positions with their value. for i in range(2,MAX): factor[i] = i; # Initializes all # multiples of 2 with 2 for i in range(4,MAX,2): factor[i] = 2; # A modified version of # Sieve of Eratosthenes # to store the smallest # prime factor that divides # every number. i = 3; while(i * i < MAX): # check if it has # no prime factor. if (factor[i] == i): # Initializes of j # starting from i*i j = i * i; while(j < MAX): # if it has no prime factor # before, then stores the # smallest prime divisor if (factor[j] == j): factor[j] = i; j += i; i+=1; # function to calculate # number of factors def calculateNoOFactors(n): if (n == 1): return 1; ans = 1; # stores the smallest # prime number that # divides n dup = factor[n]; # stores the count of # number of times a # prime number divides n. c = 1; # reduces to the next # number after prime # factorization of n j = int(n / factor[n]); # false when prime # factorization is done while (j > 1): # if the same prime # number is dividing # n, then we increase # the count if (factor[j] == dup): c += 1; # if its a new prime factor # that is factorizing n, # then we again set c=1 and # change dup to the new prime # factor, and apply the formula # explained above. else: dup = factor[j]; ans = ans * (c + 1); c = 1; # prime factorizes # a number j = int(j / factor[j]); # for the last # prime factor ans = ans * (c + 1); return ans; # Driver Code if __name__ == "__main__": # generate prime factors # of number upto 10^6 generatePrimeFactors() a = [10, 30, 100, 450, 987] q = len(a) for i in range (0,q): pass # This code is contributed # by mits. n=int(input()) l=[0,1,3,6] alp=calculateNoOFactors(3) if n>3: for i in range(4,n+1): k=calculateNoOFactors(i) l.append(((2*l[i-1])+k-alp)%998244353) alp=k print(l[-1]) else:print(l[n]) ```
97,232
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` n=int(input()) dp=[1]*(10**6+5) for i in range(2,n+1): for j in range(i,n+1,i): dp[j]+=1 x=1 ans=1 m=998244353 for i in range(1,n): ans=(dp[i+1]+x)%m x+=(dp[i+1]+x)%m print(ans) ```
97,233
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` p = 998244353 n = int(input()) if n == 1: print(1) else: divs = [0]*n for i in range(1,n+1): j = i while j <= n: divs[j-1] += 1 j += i total = 1 for i in range(1,n-1): total = (total*2+divs[i])%p print((total+divs[n-1])%p) ```
97,234
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #from bisect import bisect_left as bl, bisect_right as br, insort #from heapq import heapify, heappush, heappop #from collections import defaultdict as dd, deque, Counter #from itertools import permutations,combinations def data(): return sys.stdin.buffer.readline().strip() def mdata(): return list(map(int, data().split())) def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n') def out(var) : sys.stdout.write(str(var)+'\n') #from decimal import Decimal #from fractions import Fraction #sys.setrecursionlimit(100000) #INF = float('inf') mod = 998244353 n = int(data()) l=[1]*(n+1) for i in range(1,n+1): for j in range(i*2,n+1,i): l[j]+=1 dp = [1] s = 1 for i in range(1,n+1): a = s a+=l[i]-1 dp.append(a%mod) s+=dp[i] print(dp[-1]) ```
97,235
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` MOD = 998244353 n = int(input()) dp = [None] * (n+1) pref = [None] * (n+1) div = [2] * (n+1) dp[1] = 1 pref[1] = 1 for i in range(2,n+1): dp[i] = (div[i] + pref[i-1]) % MOD pref[i] = (pref[i-1] + dp[i]) % MOD for j in range(i<<1, n+1, i): div[j] += 1 print(dp[n]) ```
97,236
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` '''from bisect import bisect,bisect_left from collections import * from heapq import * from math import gcd,ceil,sqrt,floor,inf from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import *''' #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().split()) def RLL(): return list(map(int, sys.stdin.readline().split())) def N(): return int(input()) def A(n):return [0]*n def AI(n,x): return [x]*n def A2(n,m): return [[0]*m for i in range(n)] def G(n): return [[] for i in range(n)] def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc mod=10**9+7 farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa fact(x,mod) ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa.reverse() def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def floorsum(a,b,c,n):#sum((a*i+b)//c for i in range(n+1)) if a==0:return b//c*(n+1) if a>=c or b>=c: return floorsum(a%c,b%c,c,n)+b//c*(n+1)+a//c*n*(n+1)//2 m=(a*n+b)//c return n*m-floorsum(c,c-b-1,a,m-1) def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m def lowbit(n): return n&-n class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans class ST: def __init__(self,arr):#n!=0 n=len(arr) mx=n.bit_length()#取不到 self.st=[[0]*mx for i in range(n)] for i in range(n): self.st[i][0]=arr[i] for j in range(1,mx): for i in range(n-(1<<j)+1): self.st[i][j]=max(self.st[i][j-1],self.st[i+(1<<j-1)][j-1]) def query(self,l,r): if l>r:return -inf s=(r+1-l).bit_length()-1 return max(self.st[l][s],self.st[r-(1<<s)+1][s]) class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]>self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)] class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv class UF:#秩+路径+容量,边数 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n self.size=AI(n,1) self.edge=A(n) def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: self.edge[pu]+=1 return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu self.edge[pu]+=self.edge[pv]+1 self.size[pu]+=self.size[pv] if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv self.edge[pv]+=self.edge[pu]+1 self.size[pv]+=self.size[pu] def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break return flag def dij(s,graph): d=AI(n,inf) d[s]=0 heap=[(0,s)] vis=A(n) while heap: dis,u=heappop(heap) if vis[u]: continue vis[u]=1 for v,w in graph[u]: if d[v]>d[u]+w: d[v]=d[u]+w heappush(heap,(d[v],v)) return d def bell(s,g):#bellman-Ford dis=AI(n,inf) dis[s]=0 for i in range(n-1): for u,v,w in edge: if dis[v]>dis[u]+w: dis[v]=dis[u]+w change=A(n) for i in range(n): for u,v,w in edge: if dis[v]>dis[u]+w: dis[v]=dis[u]+w change[v]=1 return dis def lcm(a,b): return a*b//gcd(a,b) def lis(nums): res=[] for k in nums: i=bisect.bisect_left(res,k) if i==len(res): res.append(k) else: res[i]=k return len(res) def RP(nums):#逆序对 n = len(nums) s=set(nums) d={} for i,k in enumerate(sorted(s),1): d[k]=i bi=BIT([0]*(len(s)+1)) ans=0 for i in range(n-1,-1,-1): ans+=bi.query(d[nums[i]]-1) bi.update(d[nums[i]],1) return ans def michange(a,b): d=defaultdict(deque) for i,x in enumerate(b): d[x].append(i) order=A(len(a)) for i,x in enumerate(a): if not d: return -1 order[i]=d[x].popleft() return RP(order) class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j,n,m): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj def topo(n): q=deque() res=[] for i in range(1,n+1): if ind[i]==0: q.append(i) res.append(i) while q: u=q.popleft() for v in g[u]: ind[v]-=1 if ind[v]==0: q.append(v) res.append(v) return res @bootstrap def gdfs(r,p): for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None ''' from random import randint def ra(n,a,b): return [randint(a,b) for i in range(n)] ''' @bootstrap def dfs(x): global T tin[x]=T T+=1 for ch in gb[x]: yield dfs(ch) tout[x]=T T+=1 yield None mod=998244353 t=1 for i in range(t): n=N() dp=AI(n+1,1) pre=2 for i in range(2,n//2+1): for j in range(2*i,n+1,i): dp[j]+=1 for i in range(2,n+1): dp[i]=(pre+dp[i])%mod pre=(pre+dp[i])%mod ans=dp[-1] print(ans) ''' sys.setrecursionlimit(200000) import threading threading.sta1ck_size(10**8) t=threading.Thr ead(target=main) t.start() t.join() ''' ```
97,237
Provide tags and a correct Python 3 solution for this coding contest problem. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Tags: combinatorics, dp, math Correct Solution: ``` # Problem: B. Kavi on Pairing Duty # Contest: Codeforces - Codeforces Round #722 (Div. 1) # URL: https://codeforces.com/contest/1528/problem/B # Memory Limit: 256 MB # Time Limit: 1000 ms # # Powered by CP Editor (https://cpeditor.org) from collections import defaultdict from functools import reduce from bisect import bisect_right from bisect import bisect_left #import sympy #Prime number library import copy import heapq mod=998244353 def main(): n=int(input()) dp=[0]*(2*n+1) prev=[0]*(2*n+1) dp[0]=1;prev[0]=1; NumOfDivisors(n) for i in range(2,2*n+1,2): dp[i]=(prev[i-2]+div[i//2]-1)%mod prev[i]=(prev[i-2]+dp[i])%mod print(dp[2*n]) div=[0]*(1000001) def NumOfDivisors(n): #O(nlog(n)) for i in range(1,n+1): for j in range(i,n+1,i): div[j]+=1 def primes1(n): #return a list having prime numbers from 2 to n """ Returns a list of primes < n """ sieve = [True] * (n//2) for i in range(3,int(n**0.5)+1,2): if sieve[i//2]: sieve[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1) return [2] + [2*i+1 for i in range(1,n//2) if sieve[i]] def GCD(a,b): if(b==0): return a else: return GCD(b,a%b) if __name__ == '__main__': main() ```
97,238
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` # cook your dish here n=int(input()) if n==1: print(1) else: summ=1 mod=998244353 divisor=[0]*n for i in range(1,n+1): for j in range(i,n+1,i): divisor[j-1]+=1 for i in range(2,n+1): divisor[i-1]+=summ if divisor[i-1]>mod: divisor[i-1]-=mod summ+=divisor[i-1] if summ>mod: summ-=mod print(divisor[n-1]) ``` Yes
97,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` # by the authority of GOD author: manhar singh sachdev # def some_random_function(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function5(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) import os,sys from io import BytesIO,IOBase from array import array # 2D list [[0]*large_index for _ in range(small_index)] # switch from integers to floats if all integers are ≤ 2^52 and > 32 bit int # fast mod https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/mod.py def main(): mod = 998244353 n = int(input()) dp = array('i',[1]+[0]*n) fac = [0 for _ in range(n+1)] for i in range(1,n//2+1): for j in range(i+i,n+1,i): fac[j] += 1 su = 1 for i in range(1,n+1): dp[i] = (su+fac[i])%mod su = (su+dp[i])%mod print(dp[n]) #Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def some_random_function1(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function2(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function3(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function4(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function6(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function7(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function8(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am making random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) if __name__ == '__main__': main() ``` Yes
97,240
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` N=int(input()) mod=998244353 D=[0]*(N+1) for i in range(1,N+1): for j in range(i,N+1,i): D[j]+=1 X=[] for i in range(N): X.append(D[i+1]-D[i]) x=1 DP=[0]*(N+1) for i in range(N): DP[i+1]=(DP[i]*2+X[i])%mod print(DP[N]) ``` Yes
97,241
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` n,a,b,i=int(input())+1,0,0,1;d=[0]*n while i<n: for j in range(i,n,i):d[j]+=1 a=b%998244353+d[i];b+=a;i+=1 print(a) ``` Yes
97,242
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` p = 998244353 n = int(input()) divs = [0]*n for i in range(1,n+1): j = i while j <= n: divs[j-1] += 1 j += i total = 1 for i in range(1,n-1): total = (total*2+divs[i])%p print((total+divs[n-1])%p) ``` No
97,243
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` import sys input = sys.stdin.readline n=int(input()) mod=998244353 DP=[0,1,3,6] SUM=[0,1,4,10] PLUS=[1]*(10**6+5) for i in range(2,10**6): for j in range(i,10**6+5,i): PLUS[j]+=1 #print(PLUS[:10]) for i in range(10**6): DP.append((SUM[-1]+PLUS[i+4])%mod) SUM.append((SUM[-1]+DP[-1])%mod) print(DP[n]) ``` No
97,244
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` #!/usr/bin/env python3 import sys import getpass # not available on codechef import math, random import functools, itertools, collections, heapq, bisect from collections import Counter, defaultdict, deque input = sys.stdin.readline # to read input quickly # available on Google, AtCoder Python3, not available on Codeforces # import numpy as np # import scipy M9 = 998244353 yes, no = "YES", "NO" # d4 = [(1,0),(0,1),(-1,0),(0,-1)] # d8 = [(1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)] # d6 = [(2,0),(1,1),(-1,1),(-2,0),(-1,-1),(1,-1)] # hexagonal layout MAXINT = sys.maxsize # if testing locally, print to terminal with a different color OFFLINE_TEST = getpass.getuser() == "hkmac" # OFFLINE_TEST = False # codechef does not allow getpass def log(*args): if OFFLINE_TEST: print('\033[36m', *args, '\033[0m', file=sys.stderr) def solve(*args): # screen input if OFFLINE_TEST: log("----- solving ------") log(*args) log("----- ------- ------") return solve_(*args) def read_matrix(rows): return [list(map(int,input().split())) for _ in range(rows)] def read_strings(rows): return [input().strip() for _ in range(rows)] def minus_one(arr): return [x-1 for x in arr] def minus_one_matrix(mrr): return [[x-1 for x in row] for row in mrr] # ---------------------------- template ends here ---------------------------- def solve_(k): # your solution here if k == 1: return 1 if not OFFLINE_TEST: if k == 100: return 688750769 res = 1 # series for x in range(1,k-1): log(x) res += pow(2,x-1,M9) res += pow(2,k-1,M9) return res%M9 for case_num in [0]: # no loop over test case # for case_num in range(100): # if the number of test cases is specified # for case_num in range(int(input())): # read line as an integer k = int(input()) # read line as a string # srr = input().strip() # read one line and parse each word as a string # lst = input().split() # read one line and parse each word as an integer # a,b,c = list(map(int,input().split())) # lst = list(map(int,input().split())) # lst = minus_one(lst) # read multiple rows # arr = read_strings(k) # and return as a list of str # mrr = read_matrix(k) # and return as a list of list of int # mrr = minus_one_matrix(mrr) res = solve(k) # include input here # print length if applicable # print(len(res)) # parse result # res = " ".join(str(x) for x in res) # res = "\n".join(str(x) for x in res) # res = "\n".join(" ".join(str(x) for x in row) for row in res) # print result # print("Case #{}: {}".format(case_num+1, res)) # Google and Facebook - case number required print(res) ``` No
97,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds: * One of the segments A and B lies completely inside the other. * A and B have the same length. Consider the following example: <image> A is a good pairing since the red segment lies completely inside the blue segment. B is a good pairing since the red and the blue segment have the same length. C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size. Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353. Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another. Input The single line of the input contains a single integer n (1≤ n ≤ 10^6). Output Print the number of good pairings modulo 998244353. Examples Input 1 Output 1 Input 2 Output 3 Input 3 Output 6 Input 100 Output 688750769 Note The good pairings for the second example are: <image> In the third example, the good pairings are: <image> Submitted Solution: ``` import math import sys sys.setrecursionlimit(10**6+100) def div(n) : cnt = 0 for i in range(1, (int)(math.sqrt(n)) + 1) : if (n % i == 0) : if (n / i == i) : cnt = cnt + 1 else : # Otherwise count both cnt = cnt + 2 return cnt def ans(n,pre,pr_ans): if(n==1): return 1 elif(n==2): return 3 elif(n==3): return 6 else: return (2*pr_ans+div(n)-div(n-1)) #return(2*ans(n-1)+div(n)-div(n-1)) n=int(input()) if n==1: print(1) elif(n==2): print(3) elif(n==3): print(6) elif(n==333625): print(668510586) elif(n==1000000): print(123) elif(n>500000): res=7993472373202089015346647259458696082532062862039876127112380610002294466097669420037495436014591213822038512726371749787635107773503232815107353201490561733068556198634847487052336375482771716440411860106504919923562698197474940717127996272801574351759103670244013302239415293457942065023154673574287881689064254399390214425177532534724504542132860236020385100915569282371191306329419371012535306844448580425305073331002510251604376156745018741535036236158474033088461882232816490362398455282999089900777611178701070578263349930751866527191899521750327259931635264949627609097326867245406307548062359611360456200585578685198529107240759809674346888474129081507302179820852158871688492052143428447146408884629001561715613126946492846050043700708012396025694566940049025702264541133543552570009198512135914634616270793670649086755437746294562338681811659055571053773936719489490866376590116022752817096127301926735453981640946449738923700816159879300620418544068515572461086348779252484673906370928303878981364152931180836741601754303560146135040878557646910891702601595496323831093367385164741130605712453031642619262741374572551937392865276572092910751970467030924869960564754562214745267467123766122647523188367482572659366827119395979133050779070475415999478381726825752723458727062962175679544429793309486904955151123773276088959584186136260914906675356533754416423735003677657919597753135215479694394753387739976719844624811251825155613699140719712918587009184939256583869807607323431930999369356297145440636860748846648445060967392387477396002937177384754299464397599037639346915864896263655987235856260830567654433576858661698515077511243395990156628569371514509954328735162481834133799531420136265978578446272807576640213659342565699272273526388328432811597525002655935303554530003297243494487097505292057245356072184267495073133337945179019479106174699236530290672500893567368740860311832438547491457093840620682536965693517918553951227851384080598619289647140632641704666936961373383992940988910964492195841938067636392239511609837490266391908917135845124496992739570560966972180993782994341156239912474384407570826593983299825469050423480513103660584465632895472212985958560872992900927611751999880044377825418309021208714668982676874567216877970432132683652204490869259219957866144482537278405557967358291453406204237366272824769915868958720954954613861229920937958377646247376027568161666055122108149714620455086237489051472689473393357194163439393384902337791096896632353937721797853193110903255812607246444735216588758824285124880490687753611915080221903797559718568987976261983815913349660959513865810142828803990013587967731454871947234705943992890490310113363176235353986986819033078048800956715012138425304808901519312676376473152826451140689306132299722068223053751675945032000436609761224533196350568047555606572142133442653106328920949002605391877706507944401227965945453630524937569321994974550298793156905811442968542251997563714174297026752463498238554414158954951361339256233871076078757493224859058252728342588828483616060213933655669468598307162549310377996342385506669668328880256808848725172682082877978103234928014111254999230341982482073170398593920749422254753345504268868482753286911209138894278309548379295578525315452486681009657910894349084859073919932580150393192398207823754893574629283233583762524934937851288111180809434169689666348952088771821484195118173093695409984889851627958800810557679276183773444910752006119236451394764143246375869216540645327643716115268499829917375105154435295823409751918845629831962531454068626527275301203287987546766408465750211115476874361476540936981205892211201332286353497373812655145473919586734592394709477616541469942984247244178178906270780992188986174724024053594972686081576130571449368167769501520360079004105755826222094909089023772215710031604299643123238191622864858519497870148714500586415613777608563570183227699982156757947181846691484140781885134063654177794797201549831440409383444758130150483821442159283518933200459590316058989345047420738318598972395290804055040909992880914795311459451914738805010306325112508381353530051185304657336911321100584439143461596870138347178592045784220956941750070870787416669599780102365066484846934808938454976184160984969759655925522581007488644414005290962609183698163469877509420621331023369365280750530022367930413229229437636542719743554387933460582966677012990860579453223805003291924381659535482203431424036026857225969378872246755851402629466052534105682953709824361008049830316902843262497096560518865638768144130452689321861636499748393608095738140051509735006832318894160596880164932799408761843201084957098717173329568250490499782667386974362133887079926521459010748493214312180965012141618378372257551571657408500710372091275321454698216478597012523643374876963391801558695383666361159000252175715156339688890083550690606608639075469373892633649885780659352268562011426208638470673720848872467661750641544494815320794338527814671929431902306885392313648522371690119248444373757306217652708451057571208298538480006227266817301780959689616480820255528933418307373932304808638536667448855704230521702061183879759256800911455806707045481165120836981663084806159718564536209198480334365828238050410934498634076655679158063207252187940105841917097752049338637875735694917471533430265919043137827986213925121547970402026374302911839293287510592213835990343536193998259122523801881987137572273247163443185582329937081174190486688749215484448234947416078991960235611190323878578275996888233385463800925425339434386324686521438726587103573345212033360479687695317279052926872466755285783717665943853405655744646768944515984612168218159771827681881884374519570794728927372782821391349048064725288011809103419759716123710189933533646964674675239646387505894266175128680509944177187747686555801597446844990946287078286479212959915474448636398804445196881992927916241371700402997983231753273835842126222481437822740325304040293285096049678976503458372626771144815882542074982717455411937902122251671682579404234898720717822787425285266974279202914015180456245719128583410335657235158029495481550932876363597831728587709081487727913762829850007807642560273977216874668720069808523057572777583985825130829642724321004886693737154871122578280309613683824107657919428404979031873939428723871364655771175794812037013832997509459077323333105725926015305559662301154374343501054069320944872931439825919342540975026803804161775864079017007654011285838915099478794667858617932572362941180713315214215792723977451642619487480432969685764140491085403339538604311079889348246958447970318179814845507751095461558928103239886604428409429147508579884645110072411760405667152264605977471917734128352440544304295716510620987099162919728023582427113786066815921638449380093132691747719429724048414793949286017833548033901324969519776787933718730264712783309750787389491329049096282782178863966985880861095008455163257371875772965076428837811697664413763058250408181636396294387478128726008827351313712389100049488965432602707791269047370837102575331730582551172731234001161875357354396443408074485270811798380280897645295048067942238046405964875614295299080153434448977410859999689093592501378460932467335733327793211124199357157554177408075193131702585825512006194935034923075875650597030572306995420300577771567098047421335294852013845005565267112849372626081897819042791969276296931882025610152454662994495108145172968081550975664927627313573554424361782469066089380839892447087215184824351924213982225071633071573902019790614460799299354834271625046478126639231549225754275595882463915278563646072373758836118183925108641730253701343664763608306425748394134595580779205123735693671718317514717178117087982239395417244619570164263616675475461594122074841074047388282527090151981226146377554773706982563848701766888632660045636849604070705754298355719638807997524170815868571925018365555898301089364372751767605349745881582957935661722518570218500091681582865095619795457060300195560122306456005388606304574173497771532742531686311661628808934478144521274373515464848402118179224837767024145128790657734052605652977935776394751452628734841281411790733255285069105408171509337873817243350830197373571142535126415148107268580693728656826344595451102807242000914505348212696643558452280710872006463136389692441202415821110316776771224170359398041368644186743641066212794135227309948003682870295505634458591470598291215556354877869384056069470841495138204162393219256954463207498829913770437765678322293662239593654606194092570217177731021155049298054899675375818899125558938676030359915958065148199968681862608919294371185276075284267843161489117007657678543517344127566356803997272958188331720064069752153893598660574117854992485764176214222487380195272405684330522659431930257015182189731469305425940851447477776396238763495199637729321100841406165627500875654873319206451783083341519146837460512334850341682326700600576857633757561751143934881260359841737175391094415912827491135073151644843893569741902605597359064209627765187582482781707156857559412143366699513225492254331682830253785426910382601220662574549673255805243278245653806046114333135685217049452879360072543610512743608990551266011696813741204364957166952649738684848494446135738311240486930911625923310517484571222885964508989408343036626585868891376434036474845416228850353325876799744439415055812432656547612929109666833977803709581801829262625715290391134636453949421173283532428057409173588534402148878442324317032465009786827469058231957061364260719593889430323184834060125080056487863271944917733710447163279666172662793046919768778224371218026412177115555958377175778025665282567006452028152490794793661576162397228682459891825131679148709529555880730137233394601604817145660067710782886511369145348732921183314626022058652804198240864706734173199026353258718878032030934167297123014545632702546448853418300830119018260932630179438830965642028804536255615061825732052284192374553661616584201302020334257677394672684333941794955831793759234229363083090084179895205007149146230831848046760805976400745541220880070481934458222169516716027599256657325985286728975715091189987428115112994120702722258419661476010283495322420194948533043000250578622433718214164915 for m in range(500001,n+1): res=ans(m,m-1,res) print(res%998244353) elif(n>400000): res=8001457083120437458753816741146583024273796972656886861406341277697147332169727739984583243708670181166646895440620312588421517440527754710898942201543441778588894546483519857276111568042433258766354072799055355906783803080039425650358300937309119867754933317619566395584469220318740953828336650192442211292492672453268682426698901306251410732966459023475853800910392301413829588925093057170521779822703271586680117299048890731754835211168807805288440130319490011732933559838092096900345305721102795182447254579982163137307957410924240383494256181715502594403239898134521985732805251295359790377012837697766867351725964335656116945931644288523731788358633971489643588074619443437427547024422066874463967868146275469462192312292396211807526797172788880611796054300969411841752781245887340183107403001601080072145514795664306927659835851800913303433008938725275822810793128791392527558749912615317013135880860326457378072781883610906352110212053107453668632920581514699476359998495250020871760096211283225465018560570984439643743420417950983350887259917686690493105104304625396773170431263159743400990298742404683768509564610734868655559726902015503303218515160802429401424015649139391562639926499644343959274804666635968259632412561835977958883508612822790678806043579701283803878588173138420188188732732547570461964647958434120477814316042694779966549239503538198878783697311983934787878751821604111743953858500068519965798602107692950137752508623270100232952221725829929079402604400938995983086178082779390052290115363534088822724997625314702946144329592223005303955336791369599448060639837357241062481121737344750658933845450930742658169624692129926689433258193231467532361293462848264320108555391647946299439365879490170496902473082786117558115744411484363047759470263087127288900530840436243790049937912606955570323572577885572093759260448805621285972002612113000440754154648959199864480848317149949733563960269519016118355435657946148496937224825155536436303817557410663885078257661385520497162530740171407523189060859147736308117128883474576283259847821719868959283163536010994435057224558115953738514867850822956825622903242878757475275987474747645123687185979072813433465216340431989634818781389456345939475739709257075242915016693799618100462936155981685536085509493612124096859496516338767642448120416957335079112545111756647712400192335777334468809225215450649553036910107451816306444474770579007222973718941429886147162465670582994383460628094260809271356597769821256910661256870231981524968582735020037132604712848587452194977538501005001259015812285537411441459573486602513642379704366928166629241854644982117585005314239270259052031992130310137659782368402892661797087968966163256044854180750618691017852565802965528559577686751323434286623451953407223107267085365292452109819535288015892105808195960168771537860545740972567845246566158332910373294349375195335763185441228146967471077921554208870531507784641551782650110578574277146330467283015610071187126096924157673233187304774233713039476241886985255757796724229998901873773585136398374299400651367076963225624792039913550946668685109382100844589250022368124333935637763582322095382016420145412782242286924131580285148125427595931815056000484012940535287867496154800877211695949610887753821158740076291873356780119156190234925452115145408119009583025779103838994915199690882899933438456640696923089559891925250427346286186555637281294067616490770102949784741629947546423511792527088030299686434541916256529458060582120820263054951436084289157221807911309067480941213581049302717966211705255053046290281846059653768642315593625398209436046382813088455414214693272946686942067380192952184984914645947574330050979040001447187639837314752197558099595708555077226890954846218125788227577036222491582779397116700310329090355382036451222213020656407881100889748154829439540356787962432883682440919619634042418838992495777653291964264422189908802817908293157827841249158936574410588859670995581777118407112844234484779424207197643609137278009629293179226760542536721430685529208825692532083179441183460277737326062510916873055175893651151895266495347448410950425610561107342780071290994559360998135656338626864469027483155982558046978992949863352965646275757949294951851832842919298987579758095959656439985880380522841485428828059698878644550214875001378335833572959593280577469606590365825494611767482085589060739225018207390002510472970919411184749965434611203618786483274629773833702042545866160110427505547092147873506794823675196310007728408164422741909244972417125774062145508429917723526510877819739294194418322785299667849485257916557378764777264003269647826529808710432360711543336635614558841953214619366504633153749725456291557657211047828697581678481487904909485439659737722827170811470076399359809736028384034565366663282683447889467673128884021931567447469146832472560539883547900836418097872287745480598119435186443562043171980475457186105345253863175502717722466423759795149009085362122190652144103238784156917045245075039494657867197357099510123081690193128934855439720912373141732431010671843884488333965763173192982590747459073452943889509973493457533539386340883262267699691989044602755407589941548713919529936520353701902791716450443215000649383629318334044958999191906330270666941999085161383038369926616369327396448278436875598969309294186646965637403463424758116949589085764804523333860540089289501211433476142017169555521672762136030977096547322706162766686700809802770998555399547823044080207998529128242646085974354941777668056086810852194293699531986038767463861627292818254475181752527879053255991030707778981639731470791248537975967081594782579105478650321459598181344978227299686099403039084449461518607112866168643836758957295494774414522942433874396091635036516389744305994117215326890168659475493766439725799013950849442475495215633992168820415930085650665394461942038449757870256568121273748485770617085139512799483534222825967778025902049122890581114625650900942444183985546042653471953892949498604995897641723970684719198088531160234471868397455550313992152257934417297312886155673536088845542551406522184644443146564315647398967824559975059754032568980740871306216351016911697758542968106261476904391804398617842498605776848534879882966495853404973319564051517606267906659747856001411557798757446598948862434465056768005767719611558522973167196310731104808320233271295010867784185564475088492679804407421631856387110553975433331344182030776212042989770004051081657359099687981715124487402917543037484145699879601284282091556889280217223754107481620001268897467985090635221634052067678189421803756453332554825832970299881045197289386992627100969559979288772658715044615814120415916714633427148100121907404447067172166287611003177926330873538652981495560784810494577704004440326531053204834791070742348676095331892282607182319736736122660437535068721991066123129247837406276805682549602209725430462589762516386659503457675753609378476841531712822881690690955408278079234450321895611286667792662373062950254097233951768820849775160194439257738421440661027178712080911233800460590093903893645755898830049209423936156386827253705922411492576597315993348768029865902313917613125138572747725887278878858473856966960146776878170796621247124320079537945257647639048144391932617776494615922679061111396801223452623230790845535293822371213846454479015663313639220424171905806605772305901461592502622731311159411982526526951542559660802671373181159413313446453264598629008245039543927053590535474865101541855686088018543149026158893423740196289190055237132339409273623137445040460034544548235173122948884477594843989414145971736991194889183037299522260953354553029929250393585939549036377675026017828875972450250693211978688741696656459412094568819033756018102994930695517661494973027841345120956748296873114008488327787162232871019530445562144423370785663658793737129567214305880284590211756920717829725730638354891356996827019326215758897702407722049295720662061011506834218108504609600867638403171258222068923242499343759341641941672831798826095247071564642234050575085557288839717181159113154880686337258873648807706545909361490882646056554538355402280403020227397909067709154134138284110977366337675312461024989335910262944311720021825726335342905261894665434866636227199510553702177193154970445819778085564064964374137777415108242424883704628544617470391851699244693208282247948761396791001852782435500388121485745537693302119301593124554442743338599332387622728005123251692529215258665220202604531254216493155240698924443978880256921565076004297892412385544317707751695333545860054402083309868054239982651637930876471479274828109003764042684883194249056018653056407933143729247052512487950818878380884675579648709402071927240114624582618813674646266396261348354420965668052659729681711057985259417250267160635299963715576691398449869181893271919405093736979341127800712852087829789921508329545844734367452930938800446055932438844622312526665249995052951669440875157471925887034135193951752681550261452363529690030963758485191449947122209248889972788569039860294229372600234733992617900554616418529416101279868116833791057303723037307025512321342152725679177347437469331810346871301508344487501662865765528556172238094541458423944747452216296613602464680959498935800243282739121266586578263085338468304397190045165422693779924289534592876688086082276512921190506407945740716768147141485867663867491092838145130386093015318343833761129652509104497487260145995546050580513145772242279424118851255612876573837960014069771514311781009484109101575033304027684457206295023972014350260534755415045757344812430780778561578238922217090718443805597698415400638107441937044128817966821841654448692635986319766072847749635164360891925794905436686970157675548127180285036379222585545083112460586285703191018304888711924294561323055745947325531337962193605285692843439043825183754056975702341163477087688763158980360627222962407621737885711357357810768386900495113701973856923604404619801561223602320223817305671284230949231412950944375884586766439697567867223981881699216048306479761534957038672413287041434726295010804758339379959887481340504254910177148750175076592000832000983877550640707747607101088318274044835379293563134588614232081520237236920593747967 for m in range(400001,n+1): res=ans(m,m-1,res) print(res%998244353) elif(n>300000): res=8009449768995854811411655849707156308854078268005173975012032013846509806603736441663361906458873267429544610288897915707850299207449140672451059356628278326072583844915060937394167486088087284632792951873526975509261947761133873711500928594520565654392638068701460868976992791175135208774946725041104924509715175757133841863441452210769126061168119938454561427431364095143085915604705538470950444723513074701496601410677742435184271246873396766493630909186924930010495107220949828332892452528090752604447304470885659739018925696066297325159035503830822784532506951495131197806353629203709475173235006516630574997675821558416070083084521467175276654083027879510483051034851485683184078383567723072792108928462853519189970140603132937336199496828158069971341607170448361594544809389678088969937074720085589700784318737955370613385761740883970451696552328711248155866564164917214402968343220174655409056845113127363557324916300890039721622802596560737437884382659658513016649026633655160920956145889183236946069576447533300545324102210404933138099052421741464355084633037800169274181600612736940484097214947231511671974319592759264171846996301689708891657674114343490635548875299137844191019088977863377777709763645019799826602335030497643443256054459328628688815433769086696572328352849925318106577544133789448230189966360416828693501415354454632868365135770286162764989978539019384262453255437586310709202990093114323500997660436894784996639486821321816872877437656208577266111083648251145544150940843420015843998429748968919222719803793960265106858209270868977774707178709033782835859973098230435673628705333724109508330540936980496462274269353171965565584936274595633345453294042307055180360177721104090088004267521478354672929229108625322223441700154125544106233534733257906629158225269659788648667851231917425360138795613167704538674753149689229034203584744348817311673965581667390409948537499630207287146569690107415261163936402682695458346967129483264490533277008469672763958652036882796803809695385039712410082200712894001461205810753456611370503552231881461782546727087993513710129201110156393314548425353265410401731414615793770835486967416799089915209279646977250526604971847025990596026894537021863337824196234506783903522223709126407792207710233205007565027373871546216256853349081173090586718754290060924696519849090640456643040687463798311022849880166593739977170187370397347834273925621188474060260437925390953545404147931798391088116822997964279198229074984883972875641547043825342150375108280947659639470298831217564485631260047034041880544924187926641687084749909908498799497679065678518574978920726114375320580766913183294580727713622276576376780323250631415408828547047294606207343038394414868789783917053379964887888732542163791555904314607582902036336859427005066231107110894929741267205038036485279595957685849512534327565301879096441341133044227817437873809323296295041045166529668326206553320579573922041681398762456425198601897470193746794348314787180680654480215090917987767715235816785198618355810057563879724409213047749481959154187428238287920614219754275641096085934252368676372385794900677437152534669625694697393622241228185985650889980324375384702947843795226832895796402156310005252445834828506387139074289493155533571790231696139117569590064182100974272559767362666334832973738183953037285194253946058527985816605116536625045219735495720577015185434079403547968369386629501104708969613510235517035952733369737589856836092723270902308803084005481705408768228319047781724160121894832036047305077199210360385784976644928283027443259579011262193066489263671518381336404077679185915918279706531858549870971491681972036296391178343611035122701937674282712481396812931214798793632027360857225153047999845680049428353754214758552849785641025482164983376642407145261851890642501121327430841461643237367656528137153167583981795647068490772331920205375706639763152261001075692714210882919108935484842403116706508177684308289972969599416291339842563059564271512875839333722188785441287248446117045821404137605619621806849363858546612125823371272995566905100904351540446239018141615592096185869645596362577521789183893613677601007577422829649774998677115896430748465573220225120443914068768098983766142058697597953800580677662162924304756290488081558797351130101863915928615002181385804561107591426916152868926234161809576553779562881942495263729612959057577210682959015521441937526009463190069065847037878683654626392146641671208138749169432458109178809436688238333907131785711486677751698504535436101115054516022549413919256771910988934789421510707087280231030223888438586069533930820134633719401954924773858072079420875954861114304127544669910477133555471221991849112104826958701223808688008142836079602035164918196217294506314353698617043608232694354280236022054684426043582022561194315343833891464489053253861244374206299764732759355834796604210295015378758903656394921039707207997431114618117348767861650627428507375736230309683239538491964235089931658364970554601674178738934102458390551133949633602330186402184177393111377079087281652505969922954307819835280212324526018701473088126778199605996300952343980849530498876402981125040826432724524307444528975451233785274093242150161695608402331250527037493674924002354045655906035805885035324117620106384282927877040288227149072438689355449380581473044417297375995081479054133386615442628637011314724288548580219164897234959461426405089700209038341280627342197717659286215116692135149008581412386087126223637914809521252370367640037905643834808694083135462767589032678193728894111253291510231802114920009042852139297600537929185634475315383935365248539073470288234842312478041970214390624865935754459618668453491570612427752116458501857361555234943797338657757125397826216249310927970249903627427669361254178882508523994231134594735313963389064408845332123181421157671941404597938977749876936866532519436997009448658376407547772533241242322699385262924738307106828358677862857414467852086194401278013025085725798804045651148207232993878804897742829655111447133262824032472990319421335991416121876627283034412493759035418580266970504821683384120448953776824130726604450537049539733050306235644870077621760850332103528109709575255940234084353247867223980770002017031090646732725359431473589384370772917759107677878358904111337488943965072623324969260984069572547312190178130464210562138022592130871434855852344689972342820321066504737121293804797535468461984818427632981837115289069042146975289439638890661509438846354638897967877497699099678187802219048732391729803095075060072891647765902932805267396366837680994415281650759417673213479659856240437516283654795954111555106793146811207167290702371276699405778690034101522588472724988248011331884701213019605286064911030159905848605902252993921818488090049411925630669081806884437793976501136772369299116568351429956979798445999485415962230262981577144525090815387273476298619534955795444704221507106245250256771211124114273042081139770480825633981371318794924954289809922400980807194050313728410629368972697584120446942022021336483608585393153543750031803135090917861181195368521114168542927530368580834778603089395395175630340009421981391237295616573745876350839796899841699997651605771046173825487484279594583587798515247988067089485723289148246254854812551252434918560003383464172309596964149669495034426872267910586945874450159106594409345932525700507710900568734772760664873200563785853691049831332252385781364632197978194163434490675973336984271713403048019134178776473424842493174328844329091696956372904460795208153486318644086438898241943642191192173657618752941869386081751661311864680508367738285448909891154288270001499444815033098489591254888340532173405317263056837147194142227802227270559767163192158407124207785260845424557080297523836778022860075267767393356976783497469455080778939882789800039977639774911644382332352122803400052369557310689484087573096000564122051464587657142552367772804125657640951633865000733917242638427969228515153218549439155329040330261316163519718166219264447023717624071135031682068185389429584994316543897771919965654075104065345135358834199510627259973946403677514508658002642995207119922180370046907584056995382036748785529734542656641589466381134897773314185247501543493070833450940059961591772076280976530313959876630742919601757967835400413003832068083137100848300682248035035592767980255101737601837037834214412170853683020257378335976178292667429213438041779646552205816663111454752021798837829021580725995953430818880193018910037948746585678393038367984189238486439222159167260905649373996940657672361119750462455166503945436756701551872987465429907026925878809473853352066925720260911290023090123430265077676233807728098607000307866906435331246300732417157249588740908645709866761213632640766388061872915761886333091495391937494483931140542567263349413761537247328823920369883701405524832120403458467699784585420810400092814984731958758583790874789508875736089040108423942695902066809848089982444912497965903765202520923188170406434176053612077599140886117304937437410965435011915198481704156122016579588020365205311979241439462931561285121431994899759976183266911427157198326676701309093399168566923778711045564403729780791707139774827752880264923913705167704697849165465067230872728594403236994134477986450891203238667071691726461227327788944284015999417099200068962885296074874497104269883497091603275671000777698985052203071547701346845130137150286335215360025004116218027488507257071800498742509696205699155349786566482427353096318371724084140610639909642864631556758520062184151434143972876705140433021343436253486951678310437327740361677501180130953267485252102755543740241498424336952149427820261726751902720804988779470291469582269057693833175114501347214421868577757642398161163803373280837923189112824607070550398981996839581667714578209162655966410293400662995030551339968370887080270967186767914234356366837701363568223289827213527288550027142414364858064229579275095515463985517081508696467182011969548577456907224103695134196437680649075185472067090216931018214055037659097605054523593972858696210194897657538932443418242067264696193174404329877869967792996161438353727000619872893532864377343110528578807939883678523264950179076588121107815506 for m in range(300001,n+1): res=ans(m,m-1,res) print(res%998244353) elif(n>200000): res=8017450438795554887675207521553510501188498678892269166400761455404971455643009722039082368787972975718346114711857804924096304157284280181103201392717477822850648800553442718703698648893965360073768596726570674857214778409088461558346729643111377019454123694625142197008371688554148810174889625458234724090633831231375746915164145396752372878736507493518350222085660344164320985707811847309764837453317790946513837583885717135608928772367893279345558464995625964301024554170064366345606221348870108744136424702745874458347620699099163717947931910681962956277162535967337682829551028667591493197931880173534721891383661470137491732441498350672149611360321490353164372129895633575034880967066756015810467831054608631085316588583225492852234722642443325245819070484277176946554817396448841700335998514147214807365457907176887150660493519485490489941591252583549669480591926886849738382553552273827147927696518879811414744222476816936050732128272545170430901557867948639434947286662601241340653610997619579247784967402446587975558693165377431217545184045238472756107415164045735808665770633779588319844372068948710752136892500488088265605509689311040565986942262205435070486001142495480804085487080333319013418983320841204295160353038010185445460006839038621797033055750424672818552735751345252328028760793162157538264779505927649636257111050560551202786395322957418616200731544071589617450454938573316150492148364623000477786037382254885760901240008827983995641794687986200777437852839042549198429379853521078964299889132664054823807699510820857941344414462454838337332212689924333718645948666758559629510250447266874104806366211243667070219145883486282935134548642909934883981449994973941151287932853575371702347305026322355127819791425692480282918890419547172323280996077072826020214642673839189676357590653751781806717703758893450320510712229304233654693177025430957343871850458836411231433018046271683847596939732283009625599118607766279704332827277611974477879514397633729923817878784618573078859938774466961456739254926937866591685581175114439649314390874908488806062637404346335659557959175869786363975692443374128663355871506457711203215762066074918058471285902268588783753414209033503712733279447291379975377217806408097036253444816911221103900512363392538692482921627645487843457413369160642698445562195397695215597778630952686623486988107142830285357615357988189802496913421753715952443741726991573366438253092047848637904296986442151454711223706410202282601618964013397462899476975330962193581949919980618666512208266281854818302961481114767743957391321887162000259657012369027637341086033959086448870772459811533870722698422517707107168020113440902628279388926880476381443253711961327161657608861004892617747707554707448683165134331364249357668779758063574722513185024141233349289959082974593618830451079291819046593314526374078332990007402895762600874126511741430087084681822130613352072436576572936585061340667562408238276325302179855972173325781548982134708128858036752954669233102384927086933372819510609121785415668156478850892524044325221867355546164576073161780122848961384670419454147216721514942749105857795766330904006767161385504995459613897773770049367326937624267878703289314893197283740924728479594761907079756291406651604797630717658918629489333227655743346987210620266774669229840160276433831894203635764811341296363205149353252180494977442869578285638635620076582880533619200277612350638374951776287931881226464062783294163175038311658524978352115383756794998640793777783311646469077975626442250606165073471329799677856060695647528606991189515518547523134126482539957183377392277721555775310379157215786139759155088762464800693219590086473576427041925324866603653533090751254153006945793497728646900103546798271023879404826904223841705606857906318314105454708304136667749562875129753525851370417932332443838153634518308909406167773569505823225493962858251224392113866672598417783244509423138232689571525803308864430269141202487684313979924404368575950057862959269819329603494853407308613831775362965444674274227474920864725514172047818376656547965795727147133016281658134991318667661013749745725226665569367236393106313661763717798125422469055322031245207927471349611049669585500080209131144519623060867150104358254170344201844692053719420875739359286236821891348886283830073006552355275276927792810024611781063530114307042561535191336026120768919159129029579879982100190662239464131810925466762134159985916843773906883531461855743655178706492825346016493855682503779251104522915147326683585076626900200726606674047788234796443664423738146541345691257772235864488536106868837528756243751673635010302139836424861885057738046988196462757471913944010044240758976974064265926641322899907597006631290291336685962116230168402535420505658094640581720445802457600422111806218842806921412637509066532309584636542268959254554501942590034595128881303893635625137705739345405791763228361605133970215006106158774671407561295800908160521231627103228094770390614963832459677111126649213263498057405687816034852229166395729238723118163546495651923573737885919315393252602514719162615452140884932992015795458201681702815170905677736077047686244295783303476878181026049029764287172716074552777356425510167887525875804322094481714506696657268921644097020026438737372919585186587230816629101967145095533794817253917043482376072129391295846951070670023105469528650817784665130002390255904820672282297946140422909833748414580380867338899342832982162446626240333555095703047977919659859421797276938056621299579040426787169317052479210420457170464562555215764075817117731616261161298436419984097872860920706685306763055593507856287715702489984630662283345609176910967297046798405759953065041670595961586640625598611115528404850208680480812057442973171019491780134289087517888509165184877037659580676528378260661083266978931353759329032700000685707347803895796832359354487643434957429697351005327618776365330337885136739356515130811417520162332509106112571535898578702926497576473982517147201539948965949100951015021624425788122934551047047529256925631012407339977535457927169436439250824605547135950708071081781592306136262199869170945105025370474639041679950134965069716494096949712432457768919121409364841520588482741002306188982242126104387920111119651487236342741843897261664476638233910275668584493381516819409878992041686266293856967151838063209633417004685953527863414647118566580754007372072338689846375019554434989627553799787569732074108406467650708983466165835056193300463293282904876506049598994048234942184852891009449948847935348981144712596259188315660318145690050150408618809011871849996799365520827374627985379556737012327298543599078075147101638791964979040876712128162278142906893425353965050633296747578706176747290697783535251850988233392627032317528884165685115888409815319042372811521851603602562949439072726901846308522307256136253623750270731721352728710154377342357939849715500319474389341913162001990104534304939191457825227399910822786852345317153289062182605159172635375263087964714474649435605948425786291038106609684089491511968046223407427917922702941795809422188255065444358556338366765003480506910582119069422147244165081524568969654952751517142640964972881840167548432239441689209262069250233670706046200330005943442889786401205328109605598010616721355191305652734003200132615980484895975896926354396049456558891631150298915458734487727606392931120546206171208212874937454295681119267387367711584770665318997691245470364685000707858302364956697651029374824145887038030665671087154785131590386475730554009564001538539019397734263457404104756247559207111242508938712135751455194837864676072267138654906486125377697350846770786222875467211084915851852636308970452165846876708645086927074816765378957396843807744418251564729466868749172123544858757405478238749472806015746984822100540738228121093941842860790213958666320813255942339583708139389616537043582527205247279821171765470596311437786907037923722732896686199188054266185080172985137091859255640535398955379827287864996065712747168271539490461557244868162898367519234115725676447720732521799780284251214571246885925126621766943716912893380206907504900086904340266662932425812186334124087212874142687760609691465428875546769271153832658597008505425783195261176421182774267935589422373170886634085458836178857593843402139516996101408716159950558851304776395445954843183445810034096496811576788490421735291587472943826855890198152371193826986683066333205796627038801102828366948462976948926921084622875636026369556612811332734981832410159134115045369934489622939641859453113457241793643622148200866879433232906428324823181953074964274549713362108949676981983417827554461771783211846271186143479320653218613679860786915548984629767414749928546995234546023844846878860320859075459522064521396840888290851810116331365423233506995875904401246920916298648305386639644628427356170888941431347944040257881162410830002959942363361455734466639961871346111809589050992206960872881064676858154445014977090747081023408216537501402772649527349583568524360384733257335585413478567425819492251685262863116496428105802254799267949513160265269688780012038344029210028763717905471595895192395031519723290892955322988381863528549742602835374506529154324071893916149762297138409010938882563079791590514743412905723437809998559843688865285705828022700340219851684519112272152880783720603828478005301157924171601135349965750423523234480470674551833779604101368041826188433757412418705287092576861133006078996366897915826389989075034850532725205801508582279188498482592350170639828287807841483132950168280667487251273989540757859112452150362428084154768142807864617822219523736709175527791696190639979946822997907126047106173772441200437942437095437049646296816296230157311037532927651097835386444108208571148899515534889174379871197503821380684586035304408558716352355165119292421263304370036288731025355447600631424112610520870732738258604009934937930638404144740181011437162408180467499131980896670050096686797703814794085803470588858164047792308119552879695993739954534914328655045618338762274553467980157889733570150371035180107586462628484379278952290787520937306151643463631363609970541651298012896126198877992583785667985261315470401676452234854844045697733763164995 for m in range(200001,n+1): res=ans(m,m-1,res) print(res%998244353) else: res=3 for m in range(3,n+1): res=ans(m,m-1,res) print(res%998244353) ``` No
97,246
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` n, t = [int(item) for item in input().split(' ')] cont = [] for i in range(n): center, house_len = [int(item) for item in input().split(' ')] cont.append([center-house_len / 2, center + house_len / 2]) cont.sort(key=lambda item: item[0]) ans = 2 for i in range(n - 1): gap = cont[i + 1][0] - cont[i][1] if gap > t: ans += 2 elif gap == t: ans += 1 print(ans) ```
97,247
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` n,t = map(int, input().split()) lista_punktow = list() lista_odleglosci = list() suma= 0 for i in range(n): x,a = map(int, input().split()) lista_punktow.append(float(x-a/2)) lista_punktow.append(float(x+a/2)) lista_punktow.sort() #print (lista_punktow) for i in range(0,len(lista_punktow)-2,2): w = lista_punktow[i+2] - lista_punktow[i+1] lista_odleglosci.append(w) #print(lista_odleglosci) for i in range(len(lista_odleglosci)): if (lista_odleglosci[i] - t) > 0: d = (lista_odleglosci[i] - t) suma += 2 elif (lista_odleglosci[i] - t) == 0: suma +=1 print (suma+2) ```
97,248
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` temp = input().split() n, t, ans = int(temp[0]), int(temp[1]), 2 cont = [] for i in range(n): # string_arr = input().split() # temp = input().split(' ') # center, house_len = float(temp[0]), float(temp[1]), # temp = [float(item) for item in input().split(' ')] # house_center, house_len = temp[0], temp[1] temp = list(map(float, input().split())) house_center, house_len = temp[0], temp[1] cont.append([house_center - house_len / 2, house_center + house_len / 2]) cont.sort(key=lambda item: item[0]) for i in range(n - 1): helper = cont[i + 1][0] - cont[i][1] if helper > t: ans += 2 elif helper == t: ans += 1 print(ans) # print(cont) ```
97,249
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` n,t = list(map(int,input().split())) cottages = [] for i in range(n): c,d = list(map(int,input().split())) cottages.append([c-d/2,c+d/2]) cottages.sort() possibilities = 0 for i in range(1,len(cottages)): interval = cottages[i][0]-cottages[i-1][1] if interval > t: possibilities += 2 elif interval == t: possibilities += 1 else: pass possibilities += 2 print(possibilities) ```
97,250
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` n, t = map(int, input().split()) x, var = sorted(list(map(int, input().split())) for i in range(n)), 2 for i in range(n - 1): distance = 2 * x[i + 1][0] - x[i + 1][1] - 2 * x[i][0] - x[i][1] #calculate diatance btw existing houses if distance > 2 * t: #case when we have enough distance for 2 positions var += 2 elif distance == 2 * t: #case when we have only one position available var += 1 print(var) #print answer ```
97,251
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` L = input() L = L.split() n = int(L[0]) t = int(L[1]) A = [] for k in range (n): h = input() h = h.split() center = int(h[0]) side = int(h[1]) A.append(center-(side/2)) A.append(center+(side/2)) moves = 2 A.sort() for k in range (1,len(A)-1,2): if A[k+1]-A[k]>t: moves += 2 elif A[k+1]-A[k]==t: moves +=1 print(moves) ```
97,252
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` def overlap_check(arr,c,t): #print("ASd") for i in arr: c1 = i[0] d1 = i[1] dc = abs(c1-c) #print(dc,t,d1) if(t+d1>dc): return False #print(c,t) return True n,t = map(int,input().split()) arr = [] for i in range(n): c,d = map(int,input().split()) d = d/2 arr.append((c,d)) ans = set() t/=2 for i in arr: #left c = i[0]-i[1] - t if overlap_check(arr,c,t): ans.add(c) #right c = i[0]+i[1]+t if overlap_check(arr,c,t): ans.add(c) print(len(ans)) ```
97,253
Provide tags and a correct Python 3 solution for this coding contest problem. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Tags: implementation, sortings Correct Solution: ``` import sys import math import bisect def solve(A, m): n = len(A) A.sort() #ke print('A: %s' % (str(A))) ans = 2 for i in range(1, n): delta = A[i][0] - A[i-1][1] if delta == m: ans += 1 elif delta > m: ans += 2 return ans def main(): n, m = map(int, input().split()) m <<= 1 A = [] for i in range(n): a, b = map(int, input().split()) A.append((2 * a - b, 2 * a + b)) ans = solve(A, m) print(ans) if __name__ == "__main__": main() ```
97,254
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` n,t = map(int,input().split()) xa = [] for i in range(n): xi,ai = map(int,input().split()) xa.append([xi,ai]) xa.sort() for i in range(n): xa[i] = [xa[i][0]-xa[i][1]/2,xa[i][0]+xa[i][1]/2] count = 2 for i in range(n-1): k = xa[i+1][0] - xa[i][1] if k < t: continue if k == t: count += 1 else: count += 2 print(count) ``` Yes
97,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` from math import floor n, t = [int(x) for x in input().split()] centers = [] houses = {} answer = 2 place = 0 for i in range(n): x, a = [float(x) for x in input().split()] centers.append(x) houses[str(x)] = (a / 2) centers.sort() for i in range(1, n): place = (centers[i] - centers[i - 1] - houses[str(centers[i])] - houses[str(centers[i - 1])]) if place == t: answer += 1 if place > t: answer += 2 #print(centers) #print(houses) print(answer) ``` Yes
97,256
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` N, T = map(int, input().split()) def read_houses(): for _ in range(N): yield tuple(map(int, input().split())) houses = list(read_houses()) houses.sort() count = 2 # borders left and right for (a, x), (b, y) in zip(houses, houses[1:]): if b-a - (x/2+y/2) > T: count += 2 if b-a - (x/2+y/2) == T: count += 1 print(count) ``` Yes
97,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` n,t = list(map(int,input().split())) cottages = [] for i in range(n): c,d = list(map(int,input().split())) cottages.append([c-d/2,c+d/2]) cottages.sort() psbLocs = 0 for i in range(1,len(cottages)): interval = cottages[i][0]-cottages[i-1][1] if interval > t: psbLocs += 2 elif interval == t: psbLocs += 1 else: pass psbLocs += 2 print(psbLocs) ``` Yes
97,258
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` n,t=list(map(int,input().split())) amount=2 for i in range(n): c,l=list(map(int,input().split())) l=l//2 start,end=c-l,c+l if i: if start-prev_end>t: amount+=2 elif start-prev_end==t: amount+=1 prev_end=end print(amount) ``` No
97,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` n, t = map(int, input().split()) houses = [list(map(int, input().split())) for i in range(n)] ans = 2 for i in range(n - 1): x = houses[i][0] + houses[i][1] / 2 y = houses[i + 1][0] - houses[i + 1][1] / 2 if y - x == t: ans += 1 elif y - x > t: ans += 2 print(ans) ``` No
97,260
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` #15A - Cottage Village # n - how many square houses we have on the x-axis # t - the side of the main house n, t = map(int, input().split()) #Variable that sorts square houses by x-axis coordinates in ascending order #Input: house's center on the x-axis and the house's side length houses = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0]) print(houses) #Because there's at least 1 other house in the village, we have 2 possibilities #by default, cause the main house can touch one of the 2 exposed sides of the other house ans = 2 #The next loop computes the number of houses that fit between 2 adjacent houses for i in range(n - 1): x = houses[i][0] + houses[i][1] / 2 y = houses[i + 1][0] - houses[i + 1][1] / 2 #If the space between the 2 houses is equal to the main house's side, #the only way we can place our house is to touch both houses at the same time if y - x == t: ans += 1 #If the space between the houses is bigger than the main house's side, #then we consider the 2 houses as 2 separate cases, each with 2 possibilities #of their own elif y - x > t: ans += 2 print(ans) ``` No
97,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000). Output Output the amount of possible positions of the new house. Examples Input 2 2 0 4 6 2 Output 4 Input 2 2 0 4 5 2 Output 3 Input 2 3 0 4 5 2 Output 2 Note It is possible for the x-coordinate of the new house to have non-integer value. Submitted Solution: ``` n, t = map(int, input().split()) li = [] for _ in range(n): tx = tuple(map(int, input().split())) li.append(tx) p = 2 li.sort(key = lambda x: x[0]) for i in range(len(li)-1): k = (li[i][1]+li[i+1][1]) if k%2 != 0: d = abs(li[i][0]-li[i+1][0])-int(k/2+.5) else: d = abs(li[i][0]-li[i+1][0])-(k/2) if d > t: p += 2 elif d == t: p += 1 print(p) ``` No
97,262
Provide tags and a correct Python 3 solution for this coding contest problem. A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept. You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs. You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words. The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer. The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence. Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise. Input The first line contains a single integer n (1 ≤ n ≤ 15) — the number of words in Lesha's problem. The second line contains n space-separated words — the short description of the problem. The third line contains a single integer m (1 ≤ m ≤ 10) — the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 ≤ k ≤ 500000) is the number of words in the problem and si is a word of the problem description. All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015. Output If Lesha's problem is brand new, print string "Brand new problem!" (without quotes). Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input. Examples Input 4 find the next palindrome 1 10 find the previous palindrome or print better luck next time Output 1 [:||||||:] Input 3 add two numbers 3 1 add 2 two two 3 numbers numbers numbers Output Brand new problem! Input 4 these papers are formulas 3 6 what are these formulas and papers 5 papers are driving me crazy 4 crazy into the night Output 1 [:||||:] Input 3 add two decimals 5 4 please two decimals add 5 decimals want to be added 4 two add decimals add 4 add one two three 7 one plus two plus three equals six Output 3 [:|||:] Note Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions — pairs of words "numbers" and "add", "numbers" and "two". Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 ≤ i1 < i2 < ... < ik ≤ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements). In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next"). In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence. Tags: bitmasks, brute force, dp Correct Solution: ``` import itertools def count_inversions(enumerate_seq): tmp = list(enumerate_seq[:]) result = 0 for i in range(len(tmp)): for j in range(len(tmp) - 1): if tmp[j][0] > tmp[j + 1][0]: result += 1 tmp[j], tmp[j + 1] = tmp[j + 1], tmp[j] return result def sub_seq(a, b): i, j = 0, 0 while i < len(a) and j < len(b): if a[i] == b[j]: i += 1 j += 1 return i == len(a) n = int(input()) A = input().split() B = [] m = int(input()) for _ in range(m): B += [input().split()[1:]] brand_new = True best_perms = 0 best_seq = [] best_ind = -1 for i, b in enumerate(B): for tmp in itertools.permutations(enumerate(A)): if sub_seq([x for y, x in tmp], b): brand_new = False inversions = count_inversions(tmp) similarity = n * (n - 1) // 2 - inversions + 1 if best_perms < similarity: best_perms = similarity best_seq = [x for y, x in tmp] best_ind = i if not brand_new: print(best_ind + 1) print('[:' + '|' * best_perms + ':]') else: print("Brand new problem!") ```
97,263
Provide tags and a correct Python 3 solution for this coding contest problem. A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept. You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs. You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words. The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer. The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence. Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise. Input The first line contains a single integer n (1 ≤ n ≤ 15) — the number of words in Lesha's problem. The second line contains n space-separated words — the short description of the problem. The third line contains a single integer m (1 ≤ m ≤ 10) — the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 ≤ k ≤ 500000) is the number of words in the problem and si is a word of the problem description. All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015. Output If Lesha's problem is brand new, print string "Brand new problem!" (without quotes). Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input. Examples Input 4 find the next palindrome 1 10 find the previous palindrome or print better luck next time Output 1 [:||||||:] Input 3 add two numbers 3 1 add 2 two two 3 numbers numbers numbers Output Brand new problem! Input 4 these papers are formulas 3 6 what are these formulas and papers 5 papers are driving me crazy 4 crazy into the night Output 1 [:||||:] Input 3 add two decimals 5 4 please two decimals add 5 decimals want to be added 4 two add decimals add 4 add one two three 7 one plus two plus three equals six Output 3 [:|||:] Note Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions — pairs of words "numbers" and "add", "numbers" and "two". Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 ≤ i1 < i2 < ... < ik ≤ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements). In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next"). In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence. Tags: bitmasks, brute force, dp Correct Solution: ``` import itertools def check(curr_words, line): if curr_words == []: return True for i in range(len(line)): if line[i] == curr_words[0]: return check(curr_words[1:], line[i+1:]) return False n = int(input()) words = input().split() m = int(input()) res, idx = 0, 0 for i in range(m): line = input().split()[1:] for p in itertools.permutations(range(n)): curr_words = [words[j] for j in p] cnt = 0 for j in range(n): cnt += len([k for k in range(j+1, n) if p[k] < p[j]]) v = n * (n-1) // 2 - cnt + 1 if check(curr_words, line[:]) and v > res: res, idx = v, i+1 if res > 0: print(idx) print('[:'+str('|'*res)+':]') else: print('Brand new problem!') ```
97,264
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept. You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs. You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words. The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer. The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence. Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise. Input The first line contains a single integer n (1 ≤ n ≤ 15) — the number of words in Lesha's problem. The second line contains n space-separated words — the short description of the problem. The third line contains a single integer m (1 ≤ m ≤ 10) — the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 ≤ k ≤ 500000) is the number of words in the problem and si is a word of the problem description. All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015. Output If Lesha's problem is brand new, print string "Brand new problem!" (without quotes). Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input. Examples Input 4 find the next palindrome 1 10 find the previous palindrome or print better luck next time Output 1 [:||||||:] Input 3 add two numbers 3 1 add 2 two two 3 numbers numbers numbers Output Brand new problem! Input 4 these papers are formulas 3 6 what are these formulas and papers 5 papers are driving me crazy 4 crazy into the night Output 1 [:||||:] Input 3 add two decimals 5 4 please two decimals add 5 decimals want to be added 4 two add decimals add 4 add one two three 7 one plus two plus three equals six Output 3 [:|||:] Note Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions — pairs of words "numbers" and "add", "numbers" and "two". Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 ≤ i1 < i2 < ... < ik ≤ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements). In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next"). In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence. Submitted Solution: ``` data = [] i = int(input()) words = list(map(str, input().split(' '))) j = int(input()) for t in range(j): ok = list(map(str, input().split(' '))) data.append([int(ok[0]), ok[1:]]) if i == 1: inv = [] for x in range(len(data)): if words[0] in data[x][1]: print(x) print('[:|:]') quit() print("Brand new problem!") elif i == 2: inv = [] a = words[0] b = words[1] for x in range(len(data)): invx = 0 for i in range(data[x][0]): for j in range(data[x][0]): if i != j: if data[x][1][i] == a and data[x][1][j] == b: if i > j: invx+=1 inv.append([x, invx]) inv.sort(key = lambda x : x[1]) if inv == []: print("Brand new problem!") else: print(inv[0][0]+1) print('[:' + (1+1-inv[0][1]) * '|' + ':]') elif i == 3: inv = [] a = words[0] b = words[1] c = words[2] for x in range(len(data)): invx = 0 for i in range(data[x][0]): for j in range(data[x][0]): for k in range(data[x][0]): if i != j and j != k and i != k: if data[x][1][i] == a and data[x][1][j] == b and data[x][1][k] == c: if i > j: invx+=1 if i > k: invx += 1 if j > k: invx += 1 inv.append([x, invx]) inv.sort(key = lambda x : x[1]) if inv == []: print("Brand new problem!") else: print(inv[0][0]+1) print('[:' + (3+1-inv[0][1]) * '|' + ':]') elif i == 4: inv = [] a = words[0] b = words[1] c = words[2] d = words[3] for x in range(len(data)): invx = 0 for i in range(data[x][0]): for j in range(data[x][0]): for k in range(data[x][0]): for l in range(data[x][0]): if i != j and j != k and i != k and i != l and j != l and k != l: if data[x][1][i] == a and data[x][1][j] == b and data[x][1][k] == c and data[x][1][l] == d: if i > j: invx+=1 if i > k: invx += 1 if j > k: invx += 1 if j > l: invx += 1 if i > l: invx += 1 if k > l: invx += 1 inv.append([x, invx]) inv.sort(key = lambda x : x[1]) if inv == []: print("Brand new problem!") else: print(inv[0][0]+1) print('[:' + (6+1-inv[0][1]) * '|' + ':]') ``` No
97,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept. You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs. You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words. The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer. The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence. Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise. Input The first line contains a single integer n (1 ≤ n ≤ 15) — the number of words in Lesha's problem. The second line contains n space-separated words — the short description of the problem. The third line contains a single integer m (1 ≤ m ≤ 10) — the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 ≤ k ≤ 500000) is the number of words in the problem and si is a word of the problem description. All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015. Output If Lesha's problem is brand new, print string "Brand new problem!" (without quotes). Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input. Examples Input 4 find the next palindrome 1 10 find the previous palindrome or print better luck next time Output 1 [:||||||:] Input 3 add two numbers 3 1 add 2 two two 3 numbers numbers numbers Output Brand new problem! Input 4 these papers are formulas 3 6 what are these formulas and papers 5 papers are driving me crazy 4 crazy into the night Output 1 [:||||:] Input 3 add two decimals 5 4 please two decimals add 5 decimals want to be added 4 two add decimals add 4 add one two three 7 one plus two plus three equals six Output 3 [:|||:] Note Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions — pairs of words "numbers" and "add", "numbers" and "two". Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 ≤ i1 < i2 < ... < ik ≤ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements). In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next"). In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence. Submitted Solution: ``` import itertools def check(curr_words, line): if curr_words == []: return True for i in range(len(line)): if line[i] == curr_words[0]: return check(curr_words[1:], line[i+1:]) return False n = int(input()) words = input().split() m = int(input()) res, idx = 0, 0 for i in range(m): line = input().split()[1:] for p in itertools.permutations(range(n)): curr_words = [words[j] for j in p] cnt = 0 for j in range(n): cnt += len([k for k in range(j+1, n) if p[k] < p[j]]) v = n * (n-1) // 2 - cnt + 1 if check(curr_words, line[:]) and v > res: res, idx = v, i+1 if res > 0: print(idx) print('[:'+str('|'*res)+':]') else: print('Brand new wordslem!') ``` No
97,266
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) c,x=0,0 d=[] for i in range(n): if(l[i]<0): c=c+1 x=x+1 if(x==2): d.append(c) x=0 c=0 else: c=c+1 if(d==[]): d.append(c) c=0 if(c>0 and x==0): d[-1]+=c elif(c>0 and x!=0): d.append(c) print(len(d)) print(*d) ```
97,267
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` n = input() s = input().split(" ") rugi, jumlah, berkas = 0, 0, [] for j, i in enumerate(s): if int(i) < 0: rugi += 1 if rugi == 3: rugi = 1 berkas.append(str(jumlah)) jumlah = 1 else: jumlah += 1 else: jumlah += 1 if j == len(s)-1: berkas.append(str(jumlah)) print(len(berkas), " ".join(berkas), sep='\n') ```
97,268
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` n = int(input()) dig = list( map(int, input().split() )) flag = 0 index = 0 folder = [] for i in range(n): folder.append( 0 ) for i in dig: if i<0: flag+=1 if flag == 3: flag = 1 index +=1 folder[index]+=1 print( index+1 ) for i in range(index+1): print(folder[i], end = " ") ```
97,269
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` n=eval(input()) import math l=list(map(int,input().split())) i=0 c=0 while(i<n): if(l[i]<0): c+=1 i+=1 d=math.ceil(c/2) if(c==0 or c==1): print(1) else: print(d) c=0 i=0 s=0 while(i<n): if(l[i]<0): c+=1 else: s+=1 if(c==3): print(s+c-1,end=" ") c=1 s=0 i+=1 if(s+c!=0): print(s+c,end=" ") ```
97,270
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` N = int( input() ) A = list( map( int, input().split() ) ) ans = [] ptr = 0 while ptr < N: s = 0 nxt = ptr while nxt < N and s + ( A[ nxt ] < 0 ) <= 2: s += ( A[ nxt ] < 0 ) nxt += 1 ans.append( nxt - ptr ) ptr = nxt print( len( ans ) ) print( * ans ) ```
97,271
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` import sys import math n = int(sys.stdin.readline()) an = [int(x) for x in (sys.stdin.readline()).split()] res = 0 v = [] p = 0 k = 0 for i in an: if(i < 0): if(p < 2): p += 1 else: p = 1 v.append(str(k)) res += 1 k = 0 k += 1 if(k != 0): res += 1 v.append(str(k)) print(res) print(" ".join(v)) ```
97,272
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` import re import itertools from collections import Counter class Task: a = [] answer = [] def getData(self): input() self.a = [int(x) for x in input().split(" ")] def solve(self): currentFolderCounter = 0 badDaysCounter = 0 for x in self.a: if x >= 0: currentFolderCounter += 1 elif badDaysCounter <= 1: currentFolderCounter += 1 badDaysCounter += 1 else: self.answer += [currentFolderCounter] currentFolderCounter = 1 badDaysCounter = 1 if currentFolderCounter > 0: self.answer += [currentFolderCounter] def printAnswer(self): print(len(self.answer)) print(re.sub('[\[\],]', '', str(self.answer))) task = Task(); task.getData(); task.solve(); task.printAnswer(); ```
97,273
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Tags: greedy Correct Solution: ``` def fun(ls,n): count=0 ans=[] number_of_elements=0 for ind,i in enumerate(ls): number_of_elements+=1 if(i<0): count+=1 if(count>2): ans.append(number_of_elements-1) count=1 number_of_elements=1 if(ind==n-1): ans.append(number_of_elements) count=0 print(len(ans)) print(*ans) # T = int(input()) # for i in range(T): n = int(input()) ls=list(map(int,input().split())) fun(ls,n) ```
97,274
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) count,days,total,b = 0,0,0,[] for i in range(n): days += 1 if a[i]<0: count+=1 if count==3: total+=1 b.append(days-1) days=1 count=1 else: print(total+1) b.append(days) print(*b) ``` Yes
97,275
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` Answer = [] N = int(input()) Negative, Count = 0, 0 X = list(map(int, input().split())) for i in range(N): if X[i] < 0: if Negative == 2: Answer.append(Count) Negative = 1 Count = 0 else: Negative += 1 Count += 1 Answer.append(Count) print(len(Answer)) print(*Answer) # UB_CodeForces # Advice: Falling down is an accident, staying down is a choice # Location: Mashhad for few days # Caption: Finally happened what should be happened # CodeNumber: 697 ``` Yes
97,276
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` input() B = [] b = neg = 0 for a in map(int, input().split()): if a < 0: if neg > 1: B.append(b) b = neg = 0 neg += 1 b += 1 print(len(B)+1) print(*B, b) ``` Yes
97,277
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` n = int(input()) reports = list(map(int , input().split())) count = 0 i=0 folders = 1 arr=[] pos = 0 while i<len(reports): if reports[i]<0: count = count+1 pos = pos + 1 if count==3: count= 1 folders = folders + 1 arr.append(pos-1) pos = 1 i = i + 1 if sum(arr)!=len(reports): arr.append(len(reports)- sum(arr)) print(folders) print(*arr) ``` Yes
97,278
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` from math import * import time n=int(input()) l=input().split(" ") ll=[] c=0 s=0 for i in range(0,len(l)): if(s==3): ll.append(c-1) c=2 s=1 else: if(int(l[i])<0): s=s+1 c=c+1 else: c=c+1 if(s==3): ll.append(c-1) ll.append(1) else: ll.append(c) print(len(ll)) print(*ll) # print(time.time()-t1) ``` No
97,279
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` n=int(int(input())) l=list(map(int,input().split())) neg=pos=0 z=[] for x in range(n): if l[x]>=0: pos+=1 else: if neg<2: neg+=1 else: z.append(neg+pos) neg=1 pos=0 if neg!=0 or pos!=0: z.append(neg+pos) print(len(z)) ``` No
97,280
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` p, x, y, n, t = [], 0, 0, int(input()), list(map(int, input().split())) for i in range(1, n): if t[i] < 0: x += 1 if x == 3: p.append(i - y) x = 1 y = i p.append(n - y) print(len(p)) print(' '.join(str(i) for i in p)) ``` No
97,281
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) c=0 f=0 for i in range(0,n): if a[i]>=0: c=c+1 elif a[i]<0: f=f+1 if f>2: f=f-2 print(c+2,end=" ") c=0 print(c+f) ``` No
97,282
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` #author: riyan def solve(n, m): grid = [] for i in range(n): grid.append(input().strip()) cnt = 0 for j in range(1, m): if grid[i][j] != grid[i][j - 1]: cnt += 1 if (cnt > 2) or (cnt == 2 and grid[i][0] == 'B'): #print('row2 check, cnt = ', cnt) return False for j in range(m): cnt = 0 for i in range(1, n): #print(i, j, grid[i][j]) if grid[i][j] != grid[i - 1][j]: cnt += 1 if (cnt > 2) or (cnt == 2 and grid[0][j] == 'B'): #print('col2 check, cnt = ', cnt) return False bps = [] for i in range(n): for j in range(m): if grid[i][j] == 'B': bp1 = (i, j) for k in range(len(bps)): bp2 = bps[k] if not ( (grid[bp1[0]][bp2[1]] == 'B') or (grid[bp2[0]][bp1[1]] == 'B') ): #print(bp1, bp2) return False bps.append((i, j)) return True if __name__ == '__main__': n, m = map(int, input().strip().split()) ans = solve(n, m) if ans: print('YES') else: print('NO') ```
97,283
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` import sys def exi(): print("NO") sys.exit() I=lambda:list(map(int,input().split())) g=[] n,m=I() for i in range(n): g.append(list(input())) for i in range(n): temp=0 for j in range(1,m): if g[i][j-1]!=g[i][j]: temp+=1 #print(temp) if temp>2 or temp==2 and g[i][0]=='B':exi() for j in range(m): temp=0 for i in range(1,n): if g[i-1][j]!=g[i][j]: temp+=1 if temp>2 or temp==2 and g[0][j]=='B':exi() for i1 in range(n): for j1 in range(m): if g[i1][j1]=='B': for i2 in range(n): for j2 in range(m): if g[i2][j2]=='B': if g[i1][j2]=='W' and g[i2][j1]=='W':exi() print("YES") ```
97,284
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import Counter BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) def main(): n, m = map(int, input().split()) a = [] for i in range(n): t = input() k = [] for j in t: if j == 'W': k.append(0) if j == 'B': k.append(1) a.append(k) reach1 = [[] for i in range(2600)] blacks=[] for i in range(n): for j in range(m): if a[i][j]: blacks.append(i*m+j) t = i while t >= 0 and a[t][j]: reach1[i*m+j].append(t*m+j) t -= 1 t=i+1 while t<n and a[t][j]: reach1[i * m + j].append(t * m + j) t +=1 t=j-1 while t >= 0 and a[i][t]: reach1[i*m+j].append(i*m+t) t -= 1 t=j+1 while t<m and a[i][t]: reach1[i * m + j].append(i* m + t) t+=1 f=1 #print(blacks) # print(reach1) for i in blacks: k=set(reach1[i]) #print(reach1[i]) k.add(i) for j in reach1[i]: if j!=i: for m in reach1[j]: k.add(m) for m in blacks: if m not in k: f=0 break if f==0: break if f: print('YES') else: print('NO') return if __name__ == "__main__": main() ```
97,285
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` def f(): n, m = map(int, input().split()) t = [input() for j in range(n)] p = [''.join(i) for i in zip(*t)] if h(p): return 1 i = 0 while i < n and not 'B' in t[i]: i += 1 while i < n: a = t[i].find('B') if a < 0: i += 1 break b = t[i].rfind('B') if 'W' in t[i][a: b + 1]: return 1 for j in range(i + 1, n): if a > 0 and t[j][a - 1] == 'B' and t[j][b] == 'W': return 1 if b < m - 1 and t[j][b + 1] == 'B' and t[j][a] == 'W': return 1 i += 1 while i < n: if 'B' in t[i]: return 1 i += 1 return 0 def h(t): i, n = 0, len(t) while i < n and not 'B' in t[i]: i += 1 while i < n: a = t[i].find('B') if a < 0: i += 1 break b = t[i].rfind('B') if 'W' in t[i][a: b + 1]: return 1 i += 1 while i < n: if 'B' in t[i]: return 1 i += 1 return 0 print('YNEOS'[f():: 2]) ```
97,286
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` def f(): n, m = map(int, input().split()) t = [input() for j in range(n)] p = [''.join(i) for i in zip(*t)] if h(p): return 1 i = 0 while i < n and not 'B' in t[i]: i += 1 while i < n: a = t[i].find('B') if a < 0: i += 1 break b = t[i].rfind('B') if 'W' in t[i][a: b + 1]: return 1 for j in range(i + 1, n): if a > 0 and t[j][a - 1] == 'B' and t[j][b] == 'W': return 1 if b < m - 1 and t[j][b + 1] == 'B' and t[j][a] == 'W': return 1 i += 1 while i < n: if 'B' in t[i]: return 1 i += 1 return 0 def h(t): i, n = 0, len(t) while i < n and not 'B' in t[i]: i += 1 while i < n: a = t[i].find('B') if a < 0: i += 1 break b = t[i].rfind('B') if 'W' in t[i][a: b + 1]: return 1 i += 1 while i < n: if 'B' in t[i]: return 1 i += 1 return 0 print('YNEOS'[f():: 2]) # Made By Mostafa_Khaled ```
97,287
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` n, m = map(int, input().split()) z = [[] for i in range(n+1)] for i in range(n): a = input() for j in a: z[i].append(j) def solve(n, m): for i in range(n): cnt = 0 for j in range(1, m): if z[i][j] != z[i][j - 1]: cnt += 1 if cnt > 2: return 1 if cnt == 2 and z[i][0] == 'B': return 1 for j in range(m): cnt = 0 for i in range(1, n): if z[i][j] != z[i-1][j]: cnt += 1 if cnt > 2: return 1 if cnt == 2 and z[0][j] == 'B': return 1 for i in range(n): for j in range(m): if z[i][j] == 'B': for x in range(i, n): for y in range(m): if z[x][y] == 'B': if z[i][y]=='W' and z[x][j]=='W': return 1 return 0 print(['YES','NO'][solve(n, m)]) ```
97,288
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` n,m = map(int, input().split()) row, col_sum, row_sum, black = [], [], [], [] for i in range(n): row.append(input()) t = [0] for j in range(m): t += [t[j] + (row[i][j] == 'B')] row_sum += [t] d = [[0,1], [1,0], [-1,0], [0,-1]] for i in range(n): for j in range(m): if row[i][j] is 'W': continue w = 0 for di in d: x = i + di[0] y = j + di[1] if x < 0 or y < 0 or x >= n or y >= m: w += 1 ; continue if row[x][y] is 'W': w += 1 if w > 0: black.append((i,j)) for i in range(m): t = [0] for j in range(n): t += [t[j] + (row[j][i] == 'B')] col_sum += [t] def row_check(r, s, e): if s > e: e, s = s, e return row_sum[r][e + 1] - row_sum[r][s] == e - s + 1 def col_check(c, s, e): if s > e: e,s = s,e return col_sum[c][e + 1] - col_sum[c][s] == e - s + 1 res = True for i in black: for j in black: if i <= j: continue a = row_check(i[0], i[1], j[1]) and col_check(j[1], i[0], j[0]) b = row_check(j[0], i[1], j[1]) and col_check(i[1], i[0], j[0]) res = res and (a or b) print('YES' if res else 'NO') ```
97,289
Provide tags and a correct Python 3 solution for this coding contest problem. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Tags: constructive algorithms, implementation Correct Solution: ``` n, m = map(int, input().split()) grid = [] ans = True for i in range(n): grid.append(input()) black = False change = False for j in range(m): if grid[i][j] == "W" and black: change = True elif grid[i][j] == "B": if change and black: ans = False black = True if not ans: print("NO") exit() for j in range(m): black = False change = False for i in range(n): if grid[i][j] == "W" and black: change = True elif grid[i][j] == "B": if change and black: print("NO") exit() black = True for i in range(n): for j in range(m): if grid[i][j] == "B": for i_2 in range(n): for j_2 in range(m): if grid[i_2][j_2] == "B" and grid[i][j_2] == "W" and grid[i_2][j] == "W": print("NO") exit() print("YES") ```
97,290
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` n, m = map(int, input().split()) c = [input() for _ in ' ' * n] def sol(n, m): for i in range(n): count = 0 for j in range(1, m): if c[i][j] != c[i][j - 1]: count += 1 if count > 2: return False if count == 2 and c[i][0]=='B': return False for j in range(m): count = 0 for i in range(1, n): if c[i][j] != c[i - 1][j]: count += 1 if count > 2: return False if count == 2 and c[0][j]=='B': return False for i in range(n): for j in range(m): if c[i][j] == 'B': for x in range(i, n): for y in range(m): if c[x][y] == 'B': if c[i][y] == 'W' and c[x][j] == 'W': return False return True print('NYOE S'[sol(n, m)::2]) ``` Yes
97,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` import sys input = sys.stdin.readline def check(x, y): for i in range(min(x[0], y[0]), max(x[0], y[0]) + 1): if not plan[i][x[1]] == "B": return False for i in range(min(x[1], y[1]), max(x[1], y[1]) + 1): if not plan[y[0]][i] == "B": return False return True n, m = map(int, input().split()) plan = tuple(tuple(i for i in input().strip()) for j in range(n)) start = [(i, j) for i in range(n) for j in range(m) if plan[i][j] == "B"] for i in range(len(start)): for j in range(i + 1, len(start)): if not check(start[i], start[j]) and not check(start[j], start[i]): print("NO") sys.exit() print("YES") ``` Yes
97,292
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` import sys input=sys.stdin.readline def exi(): print("NO") sys.exit() I=lambda:list(map(int,input().split())) g=[] n,m=I() for i in range(n): g.append(list(input())) for i in range(n): temp=0 for j in range(1,m): if g[i][j-1]!=g[i][j]: temp+=1 #print(temp) if temp>2 or temp==2 and g[i][0]=='B':exi() for j in range(m): temp=0 for i in range(1,n): if g[i-1][j]!=g[i][j]: temp+=1 if temp>2 or temp==2 and g[0][j]=='B':exi() for i1 in range(n): for j1 in range(m): if g[i1][j1]=='B': for i2 in range(n): for j2 in range(m): if g[i2][j2]=='B': if g[i1][j2]=='W' and g[i2][j1]=='W':exi() print("YES") ``` Yes
97,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` #author: riyan def cprf(p1, p2, grid): path = True for r in range(min([p1[0], p2[0]]), max([p1[0], p2[0]]) + 1): c = p1[1] if grid[r][c] == 'W': path = False break if path: for c in range(min([p1[1], p2[1]]), max([p1[1], p2[1]]) + 1): r = p1[0] if grid[r][c] == 'W': path = False break return path def cpcf(p1, p2, grid): path = True for c in range(min([p1[1], p2[1]]), max([p1[1], p2[1]]) + 1): r = p1[0] if grid[r][c] == 'W': path = False break if path: for r in range(min([p1[0], p2[0]]), max([p1[0], p2[0]]) + 1): c = p1[1] if grid[r][c] == 'W': path = False break return path if __name__ == '__main__': grid = [] n, m = map(int, input().strip().split()) for i in range(n): grid.append(list(input().strip())) bps = [] for i in range(n): for j in range(m): if grid[i][j] == 'B': bps.append((i, j)) ans = True for bp1 in bps: for bp2 in bps: way1 = cprf(bp1, bp2, grid) way2 = cpcf(bp1, bp2, grid) if not (way1 and way2): ans = False break if not ans: break if ans: print('YES') else: print('NO') ``` No
97,294
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` # Author : raj1307 - Raj Singh # Date : 02.01.2020 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def msi(): return map(str,input().strip().split(" ")) def li(): return list(mi()) def dmain(): sys.setrecursionlimit(100000000) threading.stack_size(40960000) thread = threading.Thread(target=main) thread.start() #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace #from math import ceil,floor,log,sqrt,factorial #from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right #from decimal import *,threading #from itertools import permutations abc='abcdefghijklmnopqrstuvwxyz' abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def getKey(item): return item[1] def sort2(l):return sorted(l, key=getKey) def d2(n,m,num):return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo (x): return (x and (not(x & (x - 1))) ) def decimalToBinary(n): return bin(n).replace("0b","") def ntl(n):return [int(i) for i in str(n)] def powerMod(x,y,p): res = 1 x %= p while y > 0: if y&1: res = (res*x)%p y = y>>1 x = (x*x)%p return res def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def main(): #for _ in range(ii()): n,c=mi() f=1 l=[] mark=[] for i in range(n): l.append(si()) x=[] for j in l[i]: if j=='B': x.append(0) else: x.append(1) mark.append(x) m=mark[:] if n==1 and c==1: print('YES') exit() for i in range(n): for j in range(c): if l[i][j]=='B': #m[i][j]=1 for k in range(j+1,c): #Right if l[i][k]=='W': break m[i][k]=1 for x in range(i-1,-1,-1): if l[x][k]=='W': break m[i][k]=1 for x in range(i+1,n): if l[x][k]=='W': break m[i][k]=1 for k in range(j-1,-1,-1): #Left if l[i][k]=='W': break m[i][k]=1 for x in range(i-1,-1,-1): if l[x][k]=='W': break m[x][k]=1 for x in range(i+1,n): if l[x][k]=='W': break m[x][k]=1 for k in range(i-1,-1,-1): #Up if l[k][j]=='W': break m[k][j]=1 for x in range(j-1,-1,-1): if l[k][x]=='W': break m[k][x]=1 for x in range(j+1,c): if l[k][x]=='W': break m[k][x]=1 for k in range(i+1,n): #Down if l[k][j]=='W': break m[k][j]=1 for x in range(j-1,-1,-1): if l[k][x]=='W': break m[k][x]=1 for x in range(j+1,c): if l[k][x]=='W': break m[k][x]=1 if m==[[1]*c]*n: print('YES') else: print('NO') # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main() #dmain() # Comment Read() ``` No
97,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` import os import sys from io import BytesIO, IOBase from collections import Counter BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) def main(): n, m = map(int, input().split()) a = [] for i in range(n): t = input() k = [] for j in t: if j == 'W': k.append(0) if j == 'B': k.append(1) a.append(k) reach1 = [[] for i in range(2600)] blacks=[] for i in range(n): for j in range(m): if a[i][j]: blacks.append(i*m+j) t = i while t >= 0: reach1[i*m+j].append(t*n+j) t -= 1 t=i+1 while t<n: reach1[i * m + j].append(t * m + j) t +=1 t=j-1 while t >= 0: reach1[i*m+j].append(i*n+t) t -= 1 t=j+1 while t<m: reach1[i * m + j].append(i* m + t) t+=1 f=1 # print(blacks) # print(reach1) for i in blacks: k=set(reach1[i]) k.add(i) for j in blacks: if j!=i: for m in reach1[j]: k.add(m) for m in blacks: if m not in k: f=0 if f: print('YES') else: print('NO') return if __name__ == "__main__": main() ``` No
97,296
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. <image> You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES Submitted Solution: ``` #author: riyan def solve(n, m): grid = [] for i in range(n): grid.append(input().strip()) cnt = 0 for j in range(1, m): if grid[i][j] != grid[i][j - 1]: cnt += 1 if (cnt > 2) or (cnt == 2 and grid[i][0] == 'B'): return False for j in range(m): cnt = 0 for i in range(n): if grid[i][j] != grid[i - 1][j]: cnt += 1 if (cnt > 2) or (cnt == 2 and grid[0][j] == 'B'): return False bps = [] for i in range(n): for j in range(m): if grid[i][j] == 'B': bp1 = (i, j) for k in range(len(bps)): bp2 = bps[k] if not ( (grid[bp1[0]][bp2[1]] == 'B') or (grid[bp2[0]][bp1[1]] == 'B') ): return False bps.append((i, j)) return True if __name__ == '__main__': n, m = map(int, input().strip().split()) ans = solve(n, m) if ans: print('YES') else: print('NO') ``` No
97,297
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` def find(a, n, sz): lo = 0 hi = sz-1 while lo <= hi: mid = int ((lo + hi) / 2) if a[mid] == n : return mid if a[mid] < n : lo = mid + 1 if a[mid] > n : hi = mid - 1 # print(n, end=" ") # print(a[mid]) return -1 n, m, k = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) countA = [0] * (m+n + 5) countB = [0] * (n+m + 5) A = [] for i in range(n): A.append(x[i]) for i in range(m): A.append(y[i]) A.sort() for i in range(n): id = find(A, x[i], m+n) countA[id] += 1 for i in range(m): id = find(A, y[i], m+n) countB[id] += 1 flag = 0 i = m + n + 1 cA = 0 cB = 0 while i>=0 : cA += countA[i] cB += countB[i] if cA > cB: flag = 1 i -= 1 if flag: print("YES") else: print("NO") ```
97,298
Provide tags and a correct Python 3 solution for this coding contest problem. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight? Input The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species. Output Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. Examples Input 3 3 3 2 2 2 1 1 3 Output YES Input 4 7 9 5 2 7 3 3 5 2 7 3 8 7 Output NO Note In the first sample, if w1 = 1, w2 = 2, w3 = 2.5, then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5. In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish. Tags: constructive algorithms, greedy Correct Solution: ``` from collections import Counter a,b,c = map(int, input().split()) l = list(map(int, input().split())) l2 = list(map(int, input().split())) m = max(max(l), max(l2)) s1 = Counter(l) s2 = Counter(l2) c1 = 0 c2 = 0 vis = set() l3 = [] for i in l+l2: if i not in vis: l3.append(i) vis.add(i) l3 = sorted(l3) for i in reversed(l3): c1 += s1[i] c2 += s2[i] if c1 > c2: print("YES") exit() print("NO") ```
97,299