message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Your task is to calculate the number of arrays such that: * each array contains n elements; * each element is an integer from 1 to m; * for each array, there is exactly one pair of equal elements; * for each array a, there exists an index i such that the array is strictly ascending before the i-th element and strictly descending after it (formally, it means that a_j < a_{j + 1}, if j < i, and a_j > a_{j + 1}, if j β‰₯ i). Input The first line contains two integers n and m (2 ≀ n ≀ m ≀ 2 β‹… 10^5). Output Print one integer β€” the number of arrays that meet all of the aforementioned conditions, taken modulo 998244353. Examples Input 3 4 Output 6 Input 3 5 Output 10 Input 42 1337 Output 806066790 Input 100000 200000 Output 707899035 Note The arrays in the first example are: * [1, 2, 1]; * [1, 3, 1]; * [1, 4, 1]; * [2, 3, 2]; * [2, 4, 2]; * [3, 4, 3]. Submitted Solution: ``` #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 import math def modinv(n,p): return pow(n,p-2,p) import operator as op from functools import reduce def ncr(n, r, mod): a = min(r, n-r) b = max(r, n-r) num = 1 den = 1 for i in range(b+1, n+1): num = (num * i)%mod for i in range(1, a+1): den = (den * i)%mod return ((num % mod)*modinv(den, mod))%mod def main(): #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt', 'w') n, m = [int(x) for x in input().split()] if m == 2: print(0) return mod = 998244353 k = ncr(m, n-1, mod) % mod # print(k) if n > 2: k = (k * (n-2))%mod for i in range(n-3): k = (k * 2) % mod else: pass print(k) #------------------ Python 2 and 3 footer by Pajenegod and c1729----------------------------------------- py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: 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') if __name__ == '__main__': main() ```
instruction
0
20,403
12
40,806
No
output
1
20,403
12
40,807
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,516
12
41,032
Tags: math, number theory Correct Solution: ``` import math def get_int(): return int(input()) def get_list_ints(): return list(map(int, input().split())) def get_char_list(): s = input() return list(s[:len(s) - 1]) def get_tuple_ints(): return tuple(map(int, input().split())) def print_iterable(p): print(" ".join(map(str, p))) def main(): t= get_int() for i in range(t): f=0 n= get_int() a= get_list_ints() for j in range(n): p= math.sqrt(a[j]) if(p!= int(p)): f=1 break else: f=0 if(f==1): print("YES") else: print("NO") if __name__== "__main__": main() ```
output
1
20,516
12
41,033
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,517
12
41,034
Tags: math, number theory Correct Solution: ``` import math t = int(input()) for i in range(t): n = int(input()) a = list(map(int,input().split())) cnt=0 for j in range(n): res = math.sqrt(a[j]) if(res-int(res)!=0): cnt=1 break if(cnt): print("YES") else: print("NO") ```
output
1
20,517
12
41,035
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,518
12
41,036
Tags: math, number theory Correct Solution: ``` from math import sqrt for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) f=0 for i in a: if(sqrt(i)%1!=0): f=1 break; if(f==1): print("YES"); else: print("NO") ```
output
1
20,518
12
41,037
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,519
12
41,038
Tags: math, number theory Correct Solution: ``` 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()) from math import * for _ in range(ii()): n = ii() l = li() f = 1 for i in l: if(sqrt(i)!=int(sqrt(i))): print("YES") f = 0 break if(f): print("NO") ```
output
1
20,519
12
41,039
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,520
12
41,040
Tags: math, number theory Correct Solution: ``` from math import sqrt def check(n,l): for i in range(n): t = sqrt(l[i]) if(t!=int(t)): return True return False t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) if(check(n,l)): print("YES") else: print("NO") ```
output
1
20,520
12
41,041
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,521
12
41,042
Tags: math, number theory Correct Solution: ``` import math def is_square(integer): root = math.sqrt(integer) return integer == int(root + 0.5) ** 2 cases = int(input()) for case in range(0, cases): n = int(input()) array = [int(x) for x in input().split(" ")] x = 0 for num in array: if not is_square(num): print("Yes") x = 1 break if x == 0: print("No") ```
output
1
20,521
12
41,043
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,522
12
41,044
Tags: math, number theory Correct Solution: ``` from math import ceil num = int(input()) for _ in range(num): n = int(input()) ans = False for i in map(int, input().split()): if int(i ** .5) != ceil(i ** .5): ans = True break print("YES" if ans else "NO") ```
output
1
20,522
12
41,045
Provide tags and a correct Python 3 solution for this coding contest problem. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
instruction
0
20,523
12
41,046
Tags: math, number theory Correct Solution: ``` from math import sqrt, ceil for i in range(int(input())): n = int(input()) l = list(set(map(int, input().split()))) c = 0 for j in l: if int(ceil(sqrt(j))**2) != int(j): print("YES") c = -1 break if c == 0: print("NO") ```
output
1
20,523
12
41,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) m = list(map(int,input().split())) out = False for i in range(n): if m[i]**0.5*10!=int(m[i]**0.5)*10: out = True print("YES" if out else "NO") ```
instruction
0
20,524
12
41,048
Yes
output
1
20,524
12
41,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` import sys input=sys.stdin.readline from collections import defaultdict as dc from collections import Counter from bisect import bisect_right, bisect_left import math from operator import itemgetter from heapq import heapify, heappop, heappush from queue import PriorityQueue as pq for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) f=0 for i in l: p=math.sqrt(i) if p!=int(p): f=1 break if f: print("YES") else: print("NO") ```
instruction
0
20,525
12
41,050
Yes
output
1
20,525
12
41,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` # aadiupadhyay import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): return int(sys.stdin.readline()) def pr(n): return sys.stdout.write(str(n)+"\n") def prl(n): return sys.stdout.write(str(n)+" ") if os.path.exists('input.txt'): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def solve(): n = inp() l = li() for i in l: a = i**0.5 if ceil(a) != floor(a): pr('YES') return pr('NO') for _ in range(inp()): solve() ```
instruction
0
20,526
12
41,052
Yes
output
1
20,526
12
41,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` for __ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) ans = 'NO' for elem in ar: i = 2 while i * i <= elem: while elem % i == 0 and elem % (i * i) == 0: elem //= i elem //= i i += 1 if elem != 1: ans = 'YES' break print(ans) ```
instruction
0
20,527
12
41,054
Yes
output
1
20,527
12
41,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` import math def isPerfectSquare(x): #if x >= 0, if(x >= 0): sr = int(math.sqrt(x)) #return boolean T/F return ((sr*sr) == x) return false t=int(input()) while t>0: t-=1 n=int(input()) ans=False a=list(map(int,input().split())) for i in range(n): if not isPerfectSquare(i): ans=True break if ans: print("YES") else: print("NO") ```
instruction
0
20,528
12
41,056
No
output
1
20,528
12
41,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` import math a = int(input()) for i in range(a): m = int(input()) k = list(map(int,input().split())) product = 1 for ele in k: product*=ele number = int(math.sqrt(product)) if (number*number == product): print("YES") else: print("NO") ```
instruction
0
20,529
12
41,058
No
output
1
20,529
12
41,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` import math t=int(input()) ans=[] for i in range(t): n=int(input()) a=[int(x) for x in input().split()] flag=0 for num in a: numroot=int(math.sqrt(num)) if numroot*numroot!=num: print(numroot) flag+=1 ans.append(1) break if flag==0: ans.append(0) for i in ans: if i==1: print("YES") else: print("NO") ```
instruction
0
20,530
12
41,060
No
output
1
20,530
12
41,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements. Input The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1 ≀ n ≀ 100) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, …, a_{n} (1 ≀ a_i ≀ 10^4) β€” the elements of the array a. Output If there's a subsequence of a whose product isn't a perfect square, print "YES". Otherwise, print "NO". Example Input 2 3 1 5 4 2 100 10000 Output YES NO Note In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product. Submitted Solution: ``` for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) answer="NO" for i in range(n): if int(a[i]**0.5)**2!=a[i]: answer="YES" else: break print(answer) ```
instruction
0
20,531
12
41,062
No
output
1
20,531
12
41,063
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,548
12
41,096
Tags: greedy Correct Solution: ``` import sys input = sys.stdin.readline from math import * import bisect as bs n=int(input()) a=[int(x) for x in input().split()] b= [int(x) for x in input().split()] d={} for i in range(n): d[b[i]]=i c=0 ans=0 u=[0 for i in range(n)] for i in range(n): u[i]=d[a[i]] #print(u) for i in range(1,n): if u[i]<u[i-1]: ans=n-i break print(ans) ```
output
1
20,548
12
41,097
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,549
12
41,098
Tags: greedy Correct Solution: ``` x=int(input()) a=input() list1=[int(n) for n in a.split()] a=input() list2=[int(n) for n in a.split()] dic={} pos={} llist=[] ans=0 for i in range(x): dic[list2[i]]=i for i in list1: llist.append(dic[i]) for i in range(x): pos[llist[i]]=i cnt=0 num=0 while cnt!=x-1: if llist[num]!=cnt: if cnt in pos: for i in range(pos[cnt],x-ans): if llist[i] in pos: ans+=1 pos.pop(llist[i]) cnt+=1 else: cnt+=1 num+=1 print(ans) ```
output
1
20,549
12
41,099
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,550
12
41,100
Tags: greedy Correct Solution: ``` n = int(input()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) vis, j = set(), n-1 res = j for i in range(n-1, -1, -1): if a2[i] in vis: continue if a2[i] == a1[j]: j -= 1 continue while a2[i] != a1[j]: vis.add(a1[j]) j -= 1 j -= 1 res = j+1 print(n-res-1) ```
output
1
20,550
12
41,101
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,551
12
41,102
Tags: greedy Correct Solution: ``` u,d,x,n=0,0,0,int(input()) # n = [0 for i in range(n+10)] f=list(map(int,input().split())) s=list(map(int,input().split())) while d<n: if s[d]!=f[u]: x+=1 d+=1 else: d+=1 u+=1 print(x) # Made By Mostafa_Khaled ```
output
1
20,551
12
41,103
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,552
12
41,104
Tags: greedy Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 p = 1 Mark = [0 for i in range(n + 1)] while len(a): while Mark[b[-1]]: del b[-1] if (a[-1] != b[-1]): ans = p p += 1 Mark[a[-1]] = 1 del a[-1] print(ans) ```
output
1
20,552
12
41,105
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,553
12
41,106
Tags: greedy Correct Solution: ``` n = int(input()) a, b = list(map(int, input().split())), list(map(int, input().split())) i = j = 0 while i < n and j < n: if b[j] == a[i]: i += 1 j += 1 print(n - i) ```
output
1
20,553
12
41,107
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,554
12
41,108
Tags: greedy Correct Solution: ``` from operator import itemgetter def to_remove(seq): i = 0 #print(seq) prev = 0 for x in range(1, len(seq)): if not seq[x] > seq[x-1]: i = x break if not i: i = len(seq) #print(len(seq), i) return len(seq) - i class CodeforcesTask187ASolution: def __init__(self): self.result = '' self.sequence1 = [] self.sequence2 = [] def read_input(self): input() self.sequence1 = [int(x) for x in input().split(" ")] self.sequence2 = [int(x) for x in input().split(" ")] def process_task(self): seq_2 = [(i, x) for i, x in enumerate(self.sequence2)] seq_2 = sorted(seq_2, key=itemgetter(1)) positions = [seq_2[self.sequence1[x] - 1][0] + 1 for x in range(len(self.sequence1))] #positions = [self.sequence2.index(self.sequence1[x]) + 1 for x in range(len(self.sequence1))] #print(positions == positions1) #print(positions1, positions) i = to_remove(positions) self.result = str(i) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask187ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
20,554
12
41,109
Provide tags and a correct Python 3 solution for this coding contest problem. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves.
instruction
0
20,555
12
41,110
Tags: greedy Correct Solution: ``` import sys N = int(input()) current = input().split(" ") real = input().split(" ") positions = [-1 for i in range(int(2e5))] for i, val in enumerate(real): positions[int(val)-1] = i # print(positions[:N]) last_pos = -1 for i, val in enumerate(current[1:], 1): # print(val, positions[int(val) - 1] - i) if positions[int(current[i - 1]) - 1] > positions[int(val) - 1]: print(N - i) sys.exit() # if positions[int(val)-1] - i < 0: # print(N - i) # sys.exit() # elif positions[int(val) - 1] - i > 0: # if last_pos == -1: # last_pos = i # else: # if last_pos != -1: # print(N - i) # sys.exit() print(0) ```
output
1
20,555
12
41,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` n = int(input()) l1 = [int(x) for x in input().split()] l2 = [int(x) for x in input().split()] used = set() j = len(l1)-1 worst = j for i in range(len(l2)-1, -1, -1): if l2[i] in used: continue if l2[i] == l1[j]: j-=1 else: while l2[i] != l1[j]: used.add(l1[j]) j-=1 j -= 1 worst = j+1 #print(worst) print(len(l1) - worst - 1) ```
instruction
0
20,556
12
41,112
Yes
output
1
20,556
12
41,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) id = [0] * 3 * 10**6 res = 0 for i in range(n): id[b[i]] = i for i in range(n): a[i] = id[a[i]] for i in range(1,n): if a[i] <a[i-1]: res = n - i break print(res) ```
instruction
0
20,557
12
41,114
Yes
output
1
20,557
12
41,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` def mp():return map(int,input().split()) def it():return int(input()) n=it() a=list(mp()) b=list(mp()) ans=0 for i in range(n): if b[i]==a[ans]: # print(b[i],a[ans],ans) ans+=1 print(n-ans) ```
instruction
0
20,558
12
41,116
Yes
output
1
20,558
12
41,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` u,d,x,n=0,0,0,int(input()) # n = [0 for i in range(n+10)] f=list(map(int,input().split())) s=list(map(int,input().split())) while d<n: if s[d]!=f[u]: x+=1 d+=1 else: d+=1 u+=1 print(x) ```
instruction
0
20,559
12
41,118
Yes
output
1
20,559
12
41,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` n = int(input()) l1 = [int(x) for x in input().split()] l2 = [int(x) for x in input().split()] used = set() j = len(l1)-1 answ = 0 for i in range(len(l2)-1, -1, -1): if l2[i] in used: continue while j >= 0 and l1[j] != l2[i]: used.add(l1[j]) j-=1 answ += 1 if j >= 0 and l1[j] == l2[i]: j-=1 print(answ) ```
instruction
0
20,560
12
41,120
No
output
1
20,560
12
41,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` d=input() a=[int(i) for i in input().split()[0]] b=[int(i) for i in input().split()[0]] l=0 g={i:0 for i in range(0,10)} pa, pb= 0, 0 while len(a) - pa: if a[pa]==b[pb]: pa += 1 pb += 1 elif g[b[pb]]: g[b[pb]]-=1 pb+=1 else: g[a.pop()]+=1 l+=1 print(int(l)) ```
instruction
0
20,561
12
41,122
No
output
1
20,561
12
41,123
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` if __name__ == '__main__': n = int(input()) str1 = input().split() str2 = input().split() eq_position = 0 #From left # print(str1[eq_position], str2[eq_position]) while eq_position <n: if str1[eq_position] == str2[eq_position]: eq_position += 1 else: break # print(str1[eq_position]) #from this point we have different characte moves = 0 # while str1 != str2: for i in range (n-1): # while str1 != str2: x = str1[n-1] ind = str2.index(x) if ind < n-1: ind += 1 who_next = str2[ind] who_2 = str1.index(who_next) if ind>1 and str1[who_2] == x: continue if ind <= 1 and str1[0] == x: continue str1.remove(x) if ind >1: str1.insert(who_2,x) moves += 1 else: str1.insert(0,x) moves += 1 print(moves) ```
instruction
0
20,562
12
41,124
No
output
1
20,562
12
41,125
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second. Input The first line contains a single integer n (1 ≀ n ≀ 2Β·105) β€” the quantity of the numbers in the both given permutations. Next line contains n space-separated integers β€” the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format. Output Print a single integer denoting the minimum number of moves required to convert the first permutation to the second. Examples Input 3 3 2 1 1 2 3 Output 2 Input 5 1 2 3 4 5 1 5 2 3 4 Output 1 Input 5 1 5 2 3 4 1 2 3 4 5 Output 3 Note In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: * 1 5 2 3 4 * 1 4 5 2 3 * 1 3 4 5 2 * 1 2 3 4 5 So he needs three moves. Submitted Solution: ``` import sys input = sys.stdin.readline from math import * import bisect as bs n=int(input()) a=[int(x) for x in input().split()] b= [int(x) for x in input().split()] d={} for i in range(n): d[b[i]]=i c=0 ans=0 u=[0 for i in range(n)] for i in range(n): u[i]=d[a[i]] for i in range(n): if u[i]>i: ans=n-i-1 break print(ans) ```
instruction
0
20,563
12
41,126
No
output
1
20,563
12
41,127
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,596
12
41,192
Tags: greedy, implementation Correct Solution: ``` n, k = [int(x) for x in input().split()] if n//2 >=k: arr = list(range(1,n+1)) c = 0 for i in range(0,n-1,2): if c == k: break arr[i] , arr[i+1] = arr[i+1] , arr[i] c += 1 else: arr = list(reversed(range(1, n + 1))) c = n-1 for i in range(0,n-1,2): if c == k: break arr[i] , arr[i+1] = arr[i+1] , arr[i] c -= 1 for x in arr: print(x, end=' ') ```
output
1
20,596
12
41,193
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,597
12
41,194
Tags: greedy, implementation Correct Solution: ``` n, k = map(int, input().split()) i = 0 while(i < k): print(n - i, end = " ") i += 1 i = 1 while(i <= n - k): print(i, end = " ") i += 1 ```
output
1
20,597
12
41,195
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,598
12
41,196
Tags: greedy, implementation Correct Solution: ``` n,k = map(int,input().split()) # ar = [i for i in range(1,n+1)] if k != 0 : # tmp = ar[k] # ar[k] = ar[k+1] # ar[k+1] = tmp for i in range(n,n-k,-1) : print(i,end=" ") for i in range(1,n-k+1) : print(i,end=" ") else : for i in range(1,n+1) : print(i,end=" ") ```
output
1
20,598
12
41,197
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,599
12
41,198
Tags: greedy, implementation Correct Solution: ``` n,k=map(int, input().split()) print(*([i for i in range(n, n-k, -1)]+[i for i in range(1, n-k+1)])) ```
output
1
20,599
12
41,199
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,600
12
41,200
Tags: greedy, implementation Correct Solution: ``` n, k = map(int, input().split()) i = -1 for i in range(k): print(n-i,end = ' ') for i in range(i+1,n): print(i-k+1, end = ' ') ```
output
1
20,600
12
41,201
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,601
12
41,202
Tags: greedy, implementation Correct Solution: ``` n, k= input().split() n=int(n) k=int(k) nn =n arr = [] for i in range(k): arr.append(n) n-=1; for i in range(nn-k): arr.append(i+1) for i in range(nn): print(arr[i],end=" ") ```
output
1
20,601
12
41,203
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,602
12
41,204
Tags: greedy, implementation Correct Solution: ``` n,k=map(int,input().strip().split()) r=[a for a in range(n, 0, -1)] b=[k for k in r[:n-k]] b.sort() r=b+r[n-k: ] print(*r) ```
output
1
20,602
12
41,205
Provide tags and a correct Python 3 solution for this coding contest problem. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1
instruction
0
20,603
12
41,206
Tags: greedy, implementation Correct Solution: ``` def main(): n, k = map(int, input().strip().split()) return list(range(n, n - k, -1)) + list(range(1, n - k + 1)) print(*main()) ```
output
1
20,603
12
41,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` n,k=map(int,input().split()) for i in range(k):print(n-i,end=' ') for i in range(n-k):print(i+1,end=' ') ```
instruction
0
20,604
12
41,208
Yes
output
1
20,604
12
41,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` n,k=map(int,input().split()) l,r=list,range a=l(r(n,n-k,-1))+l(r(1,n-k+1)) print(' '.join(map(str,a))) ```
instruction
0
20,605
12
41,210
Yes
output
1
20,605
12
41,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` n,k = map(int,input().split()) if k==0: print(*[i for i in range(1,n+1)]) else: arr = [n] t = 0 for i in range(n-1,0,-1): if t==k-1: break arr.append(i) t+=1 for i in range(1,arr[-1]): arr.append(i) print(*arr) ```
instruction
0
20,606
12
41,212
Yes
output
1
20,606
12
41,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` # Description of the problem can be found at http://codeforces.com/problemset/problem/285/A n, k = map(int, input().split()) l_n = [str(x) for x in range(1, n + 1)] l_n = l_n[n : n - k - 1 : -1] + l_n[0 : n - k] print(" ".join(l_n)) ```
instruction
0
20,607
12
41,214
Yes
output
1
20,607
12
41,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` n ,k = [int(x) for x in input().strip().split()] l = list(range(1,n+1)) if k==n-1: print(" ".join([str(x) for x in l[::-1]])) elif k == 0: print(" ".join([str(x) for x in l])) else: for i in range(0,n-1,n//k): k=l[i] l[i]=l[i+1] l[i+1]=k print(" ".join([str(x) for x in l])) ```
instruction
0
20,608
12
41,216
No
output
1
20,608
12
41,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` import collections import math from sys import stdin def get(t=int): lis = stdin.readline().strip().split() return list(map(t, lis)) def single_str(): return get(str)[0] n, k = get() a = [i for i in range(1, n + 1)] print(list(reversed(a[:k + 1])) + a[k + 1:]) ```
instruction
0
20,609
12
41,218
No
output
1
20,609
12
41,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` def go(): n, k = [int(i) for i in input().split(' ')] x = 0 o = [] for i in range(n, n - k, -1): o.append(i) o += list(range(1, n - k + 1)) return o print(go()) ```
instruction
0
20,610
12
41,220
No
output
1
20,610
12
41,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≀ i < n), that pi > pi + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. Input The single line contains two space-separated integers: n, k (1 ≀ n ≀ 105, 0 ≀ k < n) β€” the permutation length and the decreasing coefficient. Output In a single line print n space-separated integers: p1, p2, ..., pn β€” the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Examples Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 1 Submitted Solution: ``` n, k = map(int, input().split()) arr = [i for i in range(1, n + 1)] arr.sort() if k == n - 1: arr.sort(reverse = True) print(*arr) else: flag = False for i in range(0, len(arr) - 1, 2): if k == 0: print(*arr) flag = True break else: k -= 1 arr[i], arr[i + 1] = arr[i + 1], arr[i] if not flag: print(*arr) ```
instruction
0
20,611
12
41,222
No
output
1
20,611
12
41,223
Provide tags and a correct Python 3 solution for this coding contest problem. As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: <image> A swap operation is the following sequence of actions: * choose two indexes i, j (i β‰  j); * perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp. What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations? Input The first line contains two integers n and k (1 ≀ n ≀ 200; 1 ≀ k ≀ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 ≀ a[i] ≀ 1000). Output In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations. Examples Input 10 2 10 -1 2 2 2 2 2 2 -1 10 Output 32 Input 5 10 -1 -1 -1 -1 -1 Output -1
instruction
0
20,644
12
41,288
Tags: brute force, sortings Correct Solution: ``` def readln(): return tuple(map(int, input().split())) n, k = readln() a = list(readln()) ans = -10**9 for i in range(n): for j in range(i, n): x = a[:i] + a[j + 1:] y = a[i:j + 1] x.sort() y.sort() x.reverse() for p in range(min(k, min(len(x), len(y)))): if x[p] > y[p]: x[p], y[p] = y[p], x[p] ans = max(ans, sum(y)) print(ans) ```
output
1
20,644
12
41,289