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. Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decreasing order. for (int i = 1; i < n; i = i + 1) { int j = i; while (j > 0 && a[j] < a[j - 1]) { swap(a[j], a[j - 1]); // swap elements a[j] and a[j - 1] j = j - 1; } } Petya uses this algorithm only for sorting of arrays that are permutations of numbers from 0 to n - 1. He has already chosen the permutation he wants to sort but he first decided to swap some two of its elements. Petya wants to choose these elements in such a way that the number of times the sorting executes function swap, was minimum. Help Petya find out the number of ways in which he can make the swap and fulfill this requirement. It is guaranteed that it's always possible to swap two elements of the input permutation in such a way that the number of swap function calls decreases. Input The first line contains a single integer n (2 ≀ n ≀ 5000) β€” the length of the permutation. The second line contains n different integers from 0 to n - 1, inclusive β€” the actual permutation. Output Print two integers: the minimum number of times the swap function is executed and the number of such pairs (i, j) that swapping the elements of the input permutation with indexes i and j leads to the minimum number of the executions. Examples Input 5 4 0 3 1 2 Output 3 2 Input 5 1 2 3 4 0 Output 3 4 Note In the first sample the appropriate pairs are (0, 3) and (0, 4). In the second sample the appropriate pairs are (0, 4), (1, 4), (2, 4) and (3, 4). Submitted Solution: ``` def main(): n = int(input()) arr = input().split(" ") arr = [int(a) for a in arr] imp = 0 cnt = 0 tot = 0 for i in range(n): tot += abs(i - arr[i]) for i in range(n): for j in range(i+1, n): improvement = abs(arr[i] - i) + abs(arr[j] - j) - abs(arr[i] - j) - abs(arr[j] - i) if improvement > imp: imp = improvement a = i b = j cnt = 1 elif improvement == imp: cnt += 1 print(int(tot-imp)//2, int(cnt)) if __name__ == "__main__": main() ```
instruction
0
71,085
12
142,170
No
output
1
71,085
12
142,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decreasing order. for (int i = 1; i < n; i = i + 1) { int j = i; while (j > 0 && a[j] < a[j - 1]) { swap(a[j], a[j - 1]); // swap elements a[j] and a[j - 1] j = j - 1; } } Petya uses this algorithm only for sorting of arrays that are permutations of numbers from 0 to n - 1. He has already chosen the permutation he wants to sort but he first decided to swap some two of its elements. Petya wants to choose these elements in such a way that the number of times the sorting executes function swap, was minimum. Help Petya find out the number of ways in which he can make the swap and fulfill this requirement. It is guaranteed that it's always possible to swap two elements of the input permutation in such a way that the number of swap function calls decreases. Input The first line contains a single integer n (2 ≀ n ≀ 5000) β€” the length of the permutation. The second line contains n different integers from 0 to n - 1, inclusive β€” the actual permutation. Output Print two integers: the minimum number of times the swap function is executed and the number of such pairs (i, j) that swapping the elements of the input permutation with indexes i and j leads to the minimum number of the executions. Examples Input 5 4 0 3 1 2 Output 3 2 Input 5 1 2 3 4 0 Output 3 4 Note In the first sample the appropriate pairs are (0, 3) and (0, 4). In the second sample the appropriate pairs are (0, 4), (1, 4), (2, 4) and (3, 4). Submitted Solution: ``` n, a = int(input()), list(map(int, input().split())) s = t = 0 r = sum(max(i - j, 0) for i, j in enumerate(a)) for i in range(n - 1): for j in range(i + 1, n): d = max(i - a[i], 0) + max(j - a[j], 0) - max(j - a[i], 0) - max(i - a[j], 0) if s < d: s, t = d, 1 elif s == d: t += 1 print(r - s, t) ```
instruction
0
71,086
12
142,172
No
output
1
71,086
12
142,173
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,217
12
142,434
Tags: constructive algorithms Correct Solution: ``` n = int(input()) r = list(range(n)) a, b = r[2 - n % 2::2], r[1 + n % 2::2] print(' '.join(map(str, a + [n] + a[::-1] + b + b[::-1] + [n]))) ```
output
1
71,217
12
142,435
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,218
12
142,436
Tags: constructive algorithms Correct Solution: ``` import collections import math n = int(input()) arr = [0] * (2 * n) l, r = 0, 0 for i in range(1, n): if i % 2 == 1: arr[l] = arr[l + n - i] = i l += 1 else: arr[n + r] = arr[n + r + n - i] = i r += 1 for i in range(2): while arr[l]: l += 1 arr[l] = n print(' '.join(str(x) for x in arr)) ```
output
1
71,218
12
142,437
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,219
12
142,438
Tags: constructive algorithms Correct Solution: ``` # [https://codeforces.com/contest/622/submission/15939479] n = int(input()) A = [0] * (2*n) per1 = 0 per2 = n for i in range(1, n): if i % 2==1: A[per1] = i A[per1+n-i] = i per1+=1 else: A[per2] = i A[per2+n-i] = i per2+=1 A[-1] = n if n % 2 == 1: A[n//2] = n else: A[-(n//2+1)] = n print(' '.join(map(str, A))) ```
output
1
71,219
12
142,439
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,220
12
142,440
Tags: constructive algorithms Correct Solution: ``` from sys import stdin, stdout, setrecursionlimit input = stdin.readline # setrecursionlimit(int(1e6)) inf = float('inf') from functools import cmp_to_key from collections import defaultdict as dd from collections import Counter, deque from heapq import * import math from math import floor, ceil, sqrt def geti(): return map(int, input().strip().split()) def getl(): return list(map(int, input().strip().split())) def getis(): return map(str, input().strip().split()) def getls(): return list(map(str, input().strip().split())) def gets(): return input().strip() def geta(): return int(input()) def print_s(s): stdout.write(s+'\n') from itertools import permutations as perm def calc(a): cost = 0 index = dd(list) n = len(a) for i in range(n): index[a[i]].append(i) # for i in sorted(index): # print(i, index[i]) n //= 2 for i in range(1, n+1): # print(i) d = index[i][1] - index[i][0] cost += (n - i)*abs(d + i - n) return cost def solve(): n = geta() diff = n - 1 ans = [0]*(2*n) index = 0 for i in range(1, n, 2): # print(ans) ans[index] = i ans[index + diff] = i diff -= 2 while index < 2*n and ans[index]: index += 1 if index == 2*n: break # print(ans) index = n diff = n - 2 for i in range(2, n, 2): ans[index] = i ans[index + diff] = i diff -= 2 while index < 2*n and ans[index]: index += 1 for i in range(2*n): if not ans[i]: ans[i] = n # for _ in range(20): # temp = getl() # print(*temp) print(*ans) # print(calc(ans)) if __name__=='__main__': solve() ```
output
1
71,220
12
142,441
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,221
12
142,442
Tags: constructive algorithms Correct Solution: ``` n = int(input()) a = [] for i in range(1 + n % 2, n, 2): a.append(i) for i in range(n // 2): a.append(a[-(2 * i + 1)]) for i in range(1 + (n % 2 ^ 1), n, 2): a.append(i) a.append(n) for i in range((n - 1) // 2): a.append(a[-(2 * i + 2)]) a.append(n) print(*a) ```
output
1
71,221
12
142,443
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,222
12
142,444
Tags: constructive algorithms Correct Solution: ``` #!/usr/bin/env python3 def make_seq(n): os = list(range(1, n, 2)) es = list(range(2, n, 2)) ls = os[:] if n % 2 != 0: ls += [n] ls += os[::-1] ls += [n] ls += es if n % 2 == 0: ls += [n] ls += es[::-1] return ls def main(): print(' '.join(str(n) for n in make_seq(int(input())))) if __name__ == '__main__': main() ```
output
1
71,222
12
142,445
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,223
12
142,446
Tags: constructive algorithms Correct Solution: ``` n=int(input()) if n%2==0: a=[] for i in range(1,n,2): a.append(i) a=a+a[::-1] b=[] for i in range(2,n,2): b.append(i) a=a+[n]+b+[n]+b[::-1] print(*a) else: a=[] for i in range(1,n,2): a.append(i) a=a+[n]+a[::-1]+[n] b=[] for i in range(2,n,2): b.append(i) a=a+b+b[::-1] print(*a) ```
output
1
71,223
12
142,447
Provide tags and a correct Python 3 solution for this coding contest problem. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1
instruction
0
71,224
12
142,448
Tags: constructive algorithms Correct Solution: ``` import sys n = int(input()) a = [n]*(n*2) def solve(i, x): if x == 0: return i if (n - x) & 1: for num in range((1 if x & 1 else 2), x+1, 2): a[i] = num i += 1 for num in range(x, 0, -2): a[i] = num i += 1 else: for num in range((1 if x & 1 else 2), x+1, 2): a[i] = num i += 1 i += 1 for num in range(x, 0, -2): a[i] = num i += 1 return i i = solve(0, n-1) solve(i, n-2) sys.stdout.buffer.write((' '.join(map(str, a))).encode('utf-8')) ```
output
1
71,224
12
142,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` import sys input=sys.stdin.readline n=int(input()) if n%2==0: a=[] for i in range(1,n,2): a.append(i) a=a+a[::-1] b=[] for i in range(2,n,2): b.append(i) a=a+[n]+b+[n]+b[::-1] print(*a) else: a=[] for i in range(1,n,2): a.append(i) a=a+[n]+a[::-1]+[n] b=[] for i in range(2,n,2): b.append(i) a=a+b+b[::-1] print(*a) ```
instruction
0
71,225
12
142,450
Yes
output
1
71,225
12
142,451
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` n = int(input()) A = [i for i in range(1, n+1, 2)] B = [i for i in range(n-2 if n%2 else n-1, 0, -2)] C = [i for i in range(2, n+1, 2)] D = [i for i in range(n-1 if n%2 else n-2, 0, -2)] ans = ' '.join(map(str, A+B+C+D+[n])) print(ans) ```
instruction
0
71,226
12
142,452
Yes
output
1
71,226
12
142,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` n = int(input()) a = list(range(n % 2 + 1, n, 2)) a.extend(list(range(n - 1, 0, -2))) a.append(n) a.extend(list(range(2 - n % 2, n + 1, 2))) a.extend(list(range(n - 2, 0, -2))) print(*a) ```
instruction
0
71,227
12
142,454
Yes
output
1
71,227
12
142,455
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` N = int( input() ) ans = [ N for i in range( 2 * N ) ] for i in range( 1, N + 1 ): x = i // 2 if i & 1 else N - 1 + i // 2 y = x + N - i ans[ x ], ans[ y ] = i, i print( *ans ) ```
instruction
0
71,228
12
142,456
Yes
output
1
71,228
12
142,457
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` # | # _` | __ \ _` | __| _ \ __ \ _` | _` | # ( | | | ( | ( ( | | | ( | ( | # \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_| import sys import math def read_line(): return sys.stdin.readline()[:-1] def read_int(): return int(sys.stdin.readline()) def read_int_line(): return [int(v) for v in sys.stdin.readline().split()] def read_float_line(): return [float(v) for v in sys.stdin.readline().split()] n = read_int() a = [i+1 for i in range(n)] ans = a + a[::-1] print(*ans) ```
instruction
0
71,229
12
142,458
No
output
1
71,229
12
142,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` n = int(input()) odd = n - 2 if n % 2 == 1 else n - 1 even = n-1 if n % 2 == 1 else n - 2 for i in range(2,n, 2): print(i,end = ' ') for i in range(even,0, -2): print(i,end = ' ') for i in range(1,n,2): print(i,end=' ') print(n,end=' ') for i in range(odd, 0, -2): print(i,end = ' ') print(n,end=' ') ```
instruction
0
71,230
12
142,460
No
output
1
71,230
12
142,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` # | # _` | __ \ _` | __| _ \ __ \ _` | _` | # ( | | | ( | ( ( | | | ( | ( | # \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_| import sys import math def read_line(): return sys.stdin.readline()[:-1] def read_int(): return int(sys.stdin.readline()) def read_int_line(): return [int(v) for v in sys.stdin.readline().split()] def read_float_line(): return [float(v) for v in sys.stdin.readline().split()] n = read_int() a = [i+1 for i in range(n)] ans = a + a print(*ans) ```
instruction
0
71,231
12
142,462
No
output
1
71,231
12
142,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi β€” the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum <image>. Input The only line contains integer n (1 ≀ n ≀ 5Β·105). Output Print 2n integers β€” the permuted array a that minimizes the value of the sum s. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 Submitted Solution: ``` import sys n = int(input()) a = [n]*(n*2) def solve(i, x): if x == 0: return i if x & 1: for num in range(1, x+1, 2): a[i] = num i += 1 for num in range(x, 0, -2): a[i] = num i += 1 else: for num in range(2, x+1, 2): a[i] = num i += 1 i += 1 for num in range(x, 1, -2): a[i] = num i += 1 return i i = solve(0, n-1) solve(i, n-2) sys.stdout.buffer.write((' '.join(map(str, a))).encode('utf-8')) ```
instruction
0
71,232
12
142,464
No
output
1
71,232
12
142,465
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,293
12
142,586
Tags: implementation Correct Solution: ``` n=int(input()) s=list(map(int, input().split())) i=0 a=0 while i<n and s[i]>a: a=s[i] i+=1 while i<n and s[i]==a: i+=1 while i<n and s[i]<a: a=s[i] i+=1 if i==n: print("YES") else: print("NO") ```
output
1
71,293
12
142,587
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,294
12
142,588
Tags: implementation Correct Solution: ``` def int_map(): return map(int, input().split(' ')) n = int(input()) if n == 1: print('YES') exit() v, r, u = False, False, False a = list(int_map()) a.append(0) i = 0 while a[i] < a[i+1] and i < n - 1: i += 1 while a[i] == a[i+1] and i < n - 1: i += 1 while a[i] > a[i+1] and i < n - 1: i += 1 if i == n-1: print('YES') else: print('NO') # print(i) ```
output
1
71,294
12
142,589
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,295
12
142,590
Tags: implementation Correct Solution: ``` def main(): read = lambda: tuple(map(int, input().split())) n = read()[0] l = read() if len(l) == 1: return "YES" lv = l[0] ss = [] for v in l[1:]: state = "inc" if v > lv else "dec" if v < lv else "norm" if len(ss) == 0: if state == "dec": ss += ["norm"] ss += [state] elif ss[-1] != state: if ss[-1] == "inc" and state == "dec": ss += ["norm"] ss += [state] lv = v for state in ('inc', 'dec', 'norm'): if ss.count(state) > 1: return "NO" if len(ss) == 1: return "YES" if len(ss) == 2: return "YES" if ss == ["norm", "dec"] or ss == ["inc", "norm"] else "NO" return "YES" if ss == ['inc', 'norm', 'dec'] else "NO" print(main()) ```
output
1
71,295
12
142,591
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,296
12
142,592
Tags: implementation Correct Solution: ``` n = int(input()) a = [int(x) for x in input().split(' ')] m = 'YES' s = 0 v = 0 for i in range(n): if s == 0: if v >= a[i]: s = 1 if s == 1: if v < a[i]: m = 'NO' break elif v > a[i]: s = 2 if s == 2: if v <= a[i]: m = 'NO' break v = a[i] print(m) ```
output
1
71,296
12
142,593
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,297
12
142,594
Tags: implementation Correct Solution: ``` import sys n = int(sys.stdin.readline()) array = [int(i) for i in sys.stdin.readline().split()] state = 0 good = True last = array[0] for i in array[1:]: if last < i : #increasing if state > 0 : good = False break elif last == i: if state > 1 : good = False break state = 1 else: # i lower decreasing state = 2 last = i if good: print('YES') else: print('NO') ```
output
1
71,297
12
142,595
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,298
12
142,596
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() n = int(input()) a = list(rint()) if n == 1: print("YES") exit() stage = 0 for i in range(n-1): diff = a[i+1] - a[i] if stage == 0: if diff > 0: pass elif diff == 0: stage = 1 else: stage = 2 elif stage == 1: if diff > 0 : print("NO") exit() elif diff == 0: pass else: stage = 2 elif stage == 2: if diff > 0 or diff == 0: print("NO") exit() else: pass print("YES") ```
output
1
71,298
12
142,597
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,299
12
142,598
Tags: implementation Correct Solution: ``` num, arr = int(input()), input().split() arr = [int(x) for x in arr] def problem8(num,arr): i = 1 for i in range(i, num): if not (arr[i - 1] < arr[i]): break else: return "YES" for i in range(i, num): if not (arr[i - 1] == arr[i]): break else: return "YES" for i in range(i, num): if not (arr[i - 1] > arr[i]): return "NO" else: return "YES" print(problem8(num,arr)) ```
output
1
71,299
12
142,599
Provide tags and a correct Python 3 solution for this coding contest problem. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
instruction
0
71,300
12
142,600
Tags: implementation Correct Solution: ``` import itertools as it sign = lambda x: (x > 0) - (x < 0) n, arr = input(), [int(x) for x in input().split()] diff = (sign(a-b) for a, b in zip(arr, arr[1:])) diff = (set(g) for k, g in it.groupby(diff)) diff = list(it.chain.from_iterable(diff)) if all(a < b for a, b in zip(diff, diff[1:])): print('YES') else: print('NO') ```
output
1
71,300
12
142,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) flag = True f =f3 = True for i in range(1,n): if flag==True: if a[i]==a[i-1]: flag = False prev = a[i-1] elif a[i]<a[i-1]: flag = False f3 = False else: if f3==True and a[i]==prev: f = True else: f3 = False if a[i]>=a[i-1]: f = False break if f==True: print("YES") else: print("NO") ```
instruction
0
71,301
12
142,602
Yes
output
1
71,301
12
142,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` size = int(input()) array = list(map(int, input().split())) index = 0 value = 0 while index < size and array[index] > value: value = array[index] index += 1 while index < size and array[index] == value: index += 1 while index < size and array[index] < value: value = array[index] index += 1 print("YES" if index == size else "NO") ```
instruction
0
71,302
12
142,604
Yes
output
1
71,302
12
142,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` x=int(input()) a=list(map(int,input().split())) b=[] a.append(0) for i in range(x): if a[i]<a[i+1]: b.append(a[i]) else: break for t in range(i,x): if a[t]==a[t+1]: b.append(a[t]) else: break for p in range(t,x): if a[p]>a[p+1]: b.append(a[p]) else: break del a[-1] if b==a: print('YES') else: print('NO') #author:SK__Shanto__γ‹› #code__define__your__smartness ```
instruction
0
71,303
12
142,606
Yes
output
1
71,303
12
142,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` #!/bin/python3 import sys n=int(input()) num=list(map(int,input().split())) i=0 while(i<n-1 and num[i]<num[i+1]): i+=1 while(i<n-1 and num[i]==num[i+1]): i+=1 while(i<n-1 and num[i]>num[i+1]): i+=1 if(i==n-1): print("YES") else: print("NO") ```
instruction
0
71,304
12
142,608
Yes
output
1
71,304
12
142,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` n = int(input()) a = [int(i) for i in input().split()] i = 0 l = len(a) while i < l and a[i] > a[i + 1]: i += 1 while i < l and a[i] == a[i + 1]: i += 1 while i < l and a[i] < a[i + 1]: i += 1 if i == l - 1: print("YES") else: print("NO") ```
instruction
0
71,305
12
142,610
No
output
1
71,305
12
142,611
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` import sys n = int(input()) data = [int(x) for x in input().split()] if len(data) > 1: flgVV = data[0] < data[1] flgVn = data[-2] > data[-1] if flgVV: i = 0 while i < len(data) - 1 and data[i] < data[i + 1]: i += 1 if i == len(data) - 1: print('NO') sys.exit() while i < len(data) - 1 and data[i] == data[i + 1]: i += 1 if i == len(data) - 1 and not flgVn: print('YES') sys.exit() while flgVn and i < len(data) - 1 and data[i] > data[i + 1]: i += 1 if i < len(data) - 1: print('NO') sys.exit() print('YES') else: i = 0 while i < len(data) - 1 and data[i] == data[i + 1]: i += 1 if i == len(data) - 1 and not flgVn: print('YES') sys.exit() while flgVn and i < len(data) - 1 and data[i] > data[i + 1]: i += 1 if i < len(data) - 1: print('NO') sys.exit() print('YES') else: print('YES') ```
instruction
0
71,306
12
142,612
No
output
1
71,306
12
142,613
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` if __name__ == '__main__': n=int(input()) a =list(map(int,input().split())) flag=0 fl=0 for i in range(1,n): if flag==0: if a[i]>a[i-1]: continue elif a[i]==a[i-1]: flag=1 elif a[i]<a[i-1]: flag=2 elif flag==1: if a[i]>a[i-1]: fl=1 break elif a[i]==a[i-1]: continue if a[i]<a[i-1]: flag=2 elif flag==2: if a[i] > a[i - 1]: fl = 1 break if fl: print('NO') else: print('YES') ```
instruction
0
71,307
12
142,614
No
output
1
71,307
12
142,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 1 000) β€” the elements of the array. Output Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Examples Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES Note In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). Submitted Solution: ``` from sys import maxsize, stdout, stdin,stderr mod = int(1e9 + 7) import re #can use multiple splits def tup():return map(int,stdin.readline().split()) def I(): return int(stdin.readline()) def lint(): return [int(x) for x in stdin.readline().split()] def S(): return input().strip() def grid(r, c): return [lint() for i in range(r)] def debug(*args, c=6): print('\033[3{}m'.format(c), *args, '\033[0m', file=stderr) from math import log2,sqrt from collections import defaultdict # s= S().split() # n = I() # # d='^>v<' # if n%2==0:print('undefined') # else: # st =d.find(s[0]).__index__() # en = d[(st+n)%4] # if en==s[1]:print('cw') # elif d[(st-n)%4]==s[1]:print('ccw') # else:print('undefined') # # #when k it is even it will end up in the same position so direction can't be determined # # # k = I() # n =S() # arr = sorted(list(map(int,n))) # cnt =sum(arr) # ans = 0 # #print(arr,cnt) # for i in arr: # if cnt < k: # cnt+=9 - i # ans+=1 # print(ans) # #increasing sum by 9-d n,ls = I(),lint() d = defaultdict(int) for i in ls: d[i]+=1 f =1;ans = 1;cnt =0; i =0 while i < n -1: if f==1: if ls[i] < ls[i+1]:pass #elif ls[i]==ls[i+1]:pass elif ls[i] > ls[i+1]: f =0 elif f==0: if ls[i] > ls[i+1]:pass elif ls[i] <= ls[i+1]: ans =0 break i+=1 print("YES") if ans else print("NO") ```
instruction
0
71,308
12
142,616
No
output
1
71,308
12
142,617
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,367
12
142,734
Tags: implementation Correct Solution: ``` n = int(input()) l = list(map(int, input().split())) s = '' d = {} cnt = 0 for i in range(len(l)-1, -1, -1): if l[i] not in d: s = str(l[i]) + ' ' + s d[l[i]] = i cnt += 1 print(cnt) print(s) ```
output
1
71,367
12
142,735
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,368
12
142,736
Tags: implementation Correct Solution: ``` n = input() l = list(map(int, input().split(" ") )) l = l[::-1] ans = [] for i in l: if i in ans: continue else: ans.append(i) ans = ans[::-1] print(len(ans)) print(*ans) ```
output
1
71,368
12
142,737
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,369
12
142,738
Tags: implementation Correct Solution: ``` n = int(input()) l = input().split() l.reverse() temp = [] for i in l: if i not in temp: temp.append(i) print(len(temp)) print(" ".join(temp[::-1])) ```
output
1
71,369
12
142,739
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,370
12
142,740
Tags: implementation Correct Solution: ``` n = int(input()) ar = list(map(int, input().split())) dic = {} ar.reverse() nar = [] for x in ar: if dic.get(x) is None: nar.append(x) dic[x] = True nar.reverse() print(len(nar)) print(*nar) ```
output
1
71,370
12
142,741
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,371
12
142,742
Tags: implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) ans = [] for i in range(n): if a[i] not in a[i+1:]: ans.append(a[i]) print(len(ans)) print(*ans, sep=" ") ```
output
1
71,371
12
142,743
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,372
12
142,744
Tags: implementation Correct Solution: ``` n=int(input()) li=list(map(int,input().split())) s=[] for i in range(n): if li[n-1-i] not in s: s.append(li[n-1-i]) n=len(s) print(n) for i in range(n): print(s[n-1-i],end=" ") ```
output
1
71,372
12
142,745
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,373
12
142,746
Tags: implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) a.reverse() l = [] d = {} for i in a: if i not in d: l.append(str(i)) d[i]=1 print(len(l)) l.reverse() print(" ".join(l)) ```
output
1
71,373
12
142,747
Provide tags and a correct Python 3 solution for this coding contest problem. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
instruction
0
71,374
12
142,748
Tags: implementation Correct Solution: ``` """ CODEFORCES user: julianloaiza1999 problem Restoring Three numbers """ import sys from sys import stdin def main(): N = int(stdin.readline()) A = [int(x) for x in stdin.readline().strip().split()] R = set() i = N-1 while(i >= 0): if A[i] in R: A.pop(i) else: R.add(A[i]) i -= 1 print(len(A)) for i in range(len(A)-1): print(A[i], end = ' ') print(A[-1]) main() ```
output
1
71,374
12
142,749
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` n=int(input()) L=list(map(int,input().split())) L1=[True]*1001 L2=[] for k in L[::-1]: if(L1[k]): L2.append(str(k)) L1[k]=False print(len(L2)) print(" ".join(L2[::-1])) ```
instruction
0
71,375
12
142,750
Yes
output
1
71,375
12
142,751
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` import sys from math import sqrt, floor, factorial from collections import deque, Counter inp = sys.stdin.readline read = lambda: list(map(int, inp().strip().split())) def solve(): n = int(inp()); arr = read(); sett = set(); ans = [] for i in range(-1, -n-1, -1): if not arr[i] in sett: sett.add(arr[i]); ans.append(arr[i]) ans.reverse() print(len(ans)) print(*ans) if __name__ == "__main__": solve() ```
instruction
0
71,376
12
142,752
Yes
output
1
71,376
12
142,753
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) c = 0 l = a[:] for i in a: if(l.count(i)>1): l.remove(i) else: pass print(len(l)) print(*l) ```
instruction
0
71,377
12
142,754
Yes
output
1
71,377
12
142,755
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` n = int(input()) sequencia = input().split() dic = {} for e in range(n -1, -1, -1): dic[sequencia[e]] = 0 resp = [] for e in dic: resp.append(e) resp.reverse() print(len(resp)) print(" ".join(resp)) ```
instruction
0
71,378
12
142,756
Yes
output
1
71,378
12
142,757
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` n = int(input()) numbers = list(map(int, input().split())) print(numbers) numbers.reverse() result = [] for x in numbers: if x not in result: result.insert(0, x) print(len(result)) for i in result: print(i, end=" ") ```
instruction
0
71,379
12
142,758
No
output
1
71,379
12
142,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` n = int(input()) nums = list(map(int, input().split(' '))) answer = [] for i in range(len(nums)-1, -1, -1): if nums[i] not in answer: answer.append(nums[i]) answer.reverse() print(*answer, sep = ' ') ```
instruction
0
71,380
12
142,760
No
output
1
71,380
12
142,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` def answer(): n = int(input()) a = [int(x) for x in input().split()] c = [] a.reverse() for x in a: if x not in c: c.append(x) i=0 ans="" while i<len(c): ans+=str(c[i]) i+=1 if i!=len(c): ans+=" " return ans print(answer()) ```
instruction
0
71,381
12
142,762
No
output
1
71,381
12
142,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input The first line contains a single integer n (1 ≀ n ≀ 50) β€” the number of elements in Petya's array. The following line contains a sequence a_1, a_2, ..., a_n (1 ≀ a_i ≀ 1 000) β€” the Petya's array. Output In the first line print integer x β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print x integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Examples Input 6 1 5 5 1 6 1 Output 3 5 6 1 Input 5 2 4 2 4 4 Output 2 2 4 Input 5 6 6 6 6 6 Output 1 6 Note In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2. In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4. In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) b=[] while a: r=a.pop(0) b.append(r) while r in a: a.remove(r) print(*b) ```
instruction
0
71,382
12
142,764
No
output
1
71,382
12
142,765