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
Provide tags and a correct Python 3 solution for this coding contest problem. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
instruction
0
25,211
12
50,422
Tags: sortings Correct Solution: ``` n = int(input()) mex = 1 for num in sorted(map(int, input().split())): if num >= mex: mex += 1 print(mex) ```
output
1
25,211
12
50,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` n = int(input()) A = [int(x) for x in input().split()] A.sort() mex = 1 for i in range(n): if A[i] >= mex: A[i] = mex mex += 1 print(mex) ```
instruction
0
25,212
12
50,424
Yes
output
1
25,212
12
50,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` n = int(input()) ai = list(map(int,input().split())) ai.sort() num = n ans = 0 for i in ai: num -= 1 ans += 1 ans = min(i,ans) print(ans+1) ```
instruction
0
25,213
12
50,426
Yes
output
1
25,213
12
50,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` input() m=1 for i in sorted(list(map(int,input().split()))): m+=i>=m print(m) ```
instruction
0
25,214
12
50,428
Yes
output
1
25,214
12
50,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` # Author Kmoussai import sys import math import random if len(sys.argv) >= 2: if sys.argv[1] == 'LOCAL': sys.stdin = open('input.in', 'r') n = int(input()) l = map(int, input().split()) l = sorted(l) mex = 1 for i in l: if i >= mex: mex += 1 print(mex) ```
instruction
0
25,215
12
50,430
Yes
output
1
25,215
12
50,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` n=int(input()) a=sorted(list(map(int,input().split()))) f=0 ans=0 for i in range(0,len(a)-1): if abs(a[i]-a[i+1])>1: f=1 ans=a[i+1]-1 if f==0: print(a[-1]+1) else: print(ans) ```
instruction
0
25,216
12
50,432
No
output
1
25,216
12
50,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) a = sorted(a) num = 1 i = 0 while i < n: if i < n and num <= a[i]: num += 1 i += 1 i += 1 print(num + 1) ```
instruction
0
25,217
12
50,434
No
output
1
25,217
12
50,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` def fun(numbers): numbers.sort() le = len(numbers) if numbers[le-1]==le: return le+1 else: return le # return ''.join([str(elem) for elem in li]) # var1, var2 = [int(x) for x in input().split()] # # var1, var2,var3 = [int(x) for x in input().split()] # user_input = input().split(' ') # numbers = [int(x.strip()) for x in user_input] # st = input() # # print(fun(st)) # print(fun(st)) st = input() user_input = input().split(' ') numbers = [int(x.strip()) for x in user_input] print(fun(numbers)) # var1, var2 = [int(x) for x in input().split()] # # # fun(st,var1,var2) # # # var2 = input() # print(fun(var1,var2)) # ############################################################3############################### # # user_input = input().split(' ') # # numbers = [int(x.strip()) for x in user_input] # # print(fun(numbers)) # ###################################################################################### ```
instruction
0
25,218
12
50,436
No
output
1
25,218
12
50,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≀ bi ≀ ai for every 1 ≀ i ≀ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print one positive integer β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Examples Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 Note In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. Submitted Solution: ``` # Author: Maharshi Gor def read(type=int): return type(input()) def read_arr(type=int): return [type(token) for token in input().split()] def solution(a, b, c, A, B): A.sort() B.sort() aa = min(a, len(A)) bb = min(b, len(B)) s = 0 for i in range(aa): s += A[i] for i in range(bb): s += B[i] def run(): n = read() A = read_arr() A.sort() B = [i for i in range(1, n+1)] cnt = 0 for i in range(n): if A[i] < B[i]: cnt += 1 print(n + 1 - cnt) run() ```
instruction
0
25,219
12
50,438
No
output
1
25,219
12
50,439
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,266
12
50,532
Tags: combinatorics, dp, math Correct Solution: ``` n,k =map(int,input().split()) ans=[1,0] #dearrangment [0,1,2,9] #D(n) = nCx* (d(n-1)+d(n-2)) #n choose 2 ans.append(n*(n-1)//2) #n choose 3 ans.append(n*(n-1)*(n-2)//3) #n choose 4 ans.append(n*(n-1)*(n-2)*(n-3)*3//8) print(sum(ans[:k+1])) ```
output
1
25,266
12
50,533
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,267
12
50,534
Tags: combinatorics, dp, math Correct Solution: ``` n, k = map(int, input().split()); ans = 1; ct = n spoils = [0, 1, 1, 2, 9] for i in range(2, k + 1): ct = ct*(n - i + 1) // i ans += ct*spoils[i] print(ans) ```
output
1
25,267
12
50,535
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,268
12
50,536
Tags: combinatorics, dp, math Correct Solution: ``` import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def fact(n): if n==0: return(1) p=1 for i in range(1,n+1): p=p*i return(p) def de(n): o=0 a=fact(n) for i in range(n+1): o=o + (a*((-1)**i))/fact(i) return(o) n,k=invr() out=0 for i in range(n-k,n+1): out=out+(fact(n)/(fact(i)*fact(n-i)))*de(n-i) print(int(out)) ```
output
1
25,268
12
50,537
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,269
12
50,538
Tags: combinatorics, dp, math Correct Solution: ``` def C(n, k): res = 1 for i in range(1, k + 1): res *= (n - i + 1) for i in range(2, k + 1): res //= i return res if __name__ == "__main__": n, k = map(int, input().split()) ans = 1 val = { 1: 1, 2: 2, 3: 9, } for i in range(k, 1, -1): ans += val[(i - 1)] * C(n, i) print(ans) ```
output
1
25,269
12
50,539
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,270
12
50,540
Tags: combinatorics, dp, math Correct Solution: ``` a,b=map(int,input().split()) s=1 if b>=2: s+=a*(a-1)>>1 if b>=3: s+=a*(a-1)*(a-2)/3 if b==4: s+=3*a*(a-1)*(a-2)*(a-3)>>3 print(int(s)) ```
output
1
25,270
12
50,541
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,271
12
50,542
Tags: combinatorics, dp, math Correct Solution: ``` from sys import stdin, stdout def solve(n): ret = factor[n] for i in range(1, n+1): ret += (-1 if i % 2 == 1 else 1) * C[n][i] * factor[n-i] return ret n, k = map(int, input().split()) C = [[0 for j in range(n+1)] for i in range(n+1)] for i in range(n+1): C[i][0] = C[i][i] = 1 for j in range(1, i): C[i][j] = C[i-1][j-1] + C[i-1][j] factor = [0] * 10 factor[0] = 1 for i in range(1, 10): factor[i] = factor[i-1] * i cnt = [0] * 5 cnt[0] = 1 for d in range(2, 5): cnt[d] = C[n][d] * solve(d) ans = 0 for d in range(k+1): ans += cnt[d] print(ans) ```
output
1
25,271
12
50,543
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,272
12
50,544
Tags: combinatorics, dp, math Correct Solution: ``` import math from sys import stdin string = stdin.readline().strip().split() n=int(string[0]) k=int(string[1]) def factorial(N): result=1 for i in range(1,N+1): result*=i return result output=1 for i in range(2,k+1): if i==2: output=output+factorial(n)/factorial(n-2)/2 if i==3: output=output+2*(factorial(n)/factorial(n-3)/6) if i==4: output=output+9*(factorial(n)/factorial(n-4)/24) print(int(output)) ```
output
1
25,272
12
50,545
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76
instruction
0
25,273
12
50,546
Tags: combinatorics, dp, math Correct Solution: ``` def nCr(n,r): p = 1 for i in range(n,n-r,-1): p*=i for i in range(1,r+1): p//=i return p n,k = list(map(int,input().split())) out = 1 if k>=2: out += nCr(n,2) if k>=3: out += 2*nCr(n,3) if k==4: out += 9*nCr(n,4) print(out) ```
output
1
25,273
12
50,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def main(): n,k=map(int,input().split()) su=1 if k>=2: su+=n*(n-1)//2 if k>=3: su+=n*(n-1)*(n-2)//3 if k>=4: su+=3*n*(n-1)*(n-2)*(n-3)//8 print(su) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
instruction
0
25,274
12
50,548
Yes
output
1
25,274
12
50,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?########################################################### def isPrime(x): for i in range(2, x): if i*i > x: break if (x % i == 0): return False return True #?############################################################ def ncr(n, r): num = den = 1 for i in range(r): num = (num * (n - i)) den = (den * (i + 1)) return (num//den) #?############################################################ def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: l.append(int(i)) n = n / i if n > 2: l.append(n) return list(set(l)) #?############################################################ def power(x, y, p): res = 1 x = x % p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): res = (res * x) % p y = y >> 1 x = (x * x) % p return res #?############################################################ def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #?############################################################ def digits(n): c = 0 while (n > 0): n //= 10 c += 1 return c #?############################################################ def ceil(n, x): if (n % x == 0): return n//x return n//x+1 #?############################################################ def mapin(): return map(int, input().split()) #?############################################################ def fact(n): ans = 1 for i in range(n): ans = ans*(i+1) return ans def de(k): if(k == 0): return 0 temp = fact(k) aa = 0 for i in range(k-1): if(i &1): aa-= (temp//fact(i+2)) else: aa += (temp//fact(i+2)) return aa input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # python3 15.py<in>op n, k = map(int, input().split()) ans = 0 for i in range(k): a = ncr(n, k-i) b = de(k-i) ans+=a*b print(ans+1) ```
instruction
0
25,275
12
50,550
Yes
output
1
25,275
12
50,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` def C(n, k): result = 1 for i in range(n - k + 1, n + 1): result *= i for i in range(2, k + 1): result //= i return result n, k = map(int, input().split()) derangements = { 2: 1, 3: 2, 4: 9 } result = 1 for a, n_derang in derangements.items(): if a <= k: result += C(n, a) * n_derang print(result) ```
instruction
0
25,276
12
50,552
Yes
output
1
25,276
12
50,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` n, k = map(int, input().split()) dg = [0, 0, 1, 2, 9] def getCombinationValue(r): if r == 0: return 1 elif r == 1: return n elif r == 2: return ((n - 1) * n)// 2 elif r == 3: return ((n - 1) * n * (n - 2)) // 6 elif r == 4: return ((n - 1) * n * (n - 2) * (n - 3)) // 24 ans = 1 for m in range(k + 1): ans += getCombinationValue(m) * dg[m] print(ans) ```
instruction
0
25,277
12
50,554
Yes
output
1
25,277
12
50,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` from math import factorial n, k = map(int, input().split()) q = 0 if k == 1: print(1) elif k == 2: print(n*(n-1) - n*(n-1)//2 + 1) elif k == 3: print(n*(n-1)*(n-2) - n*(n-1) - n*(n-1)*(n-2)//6+1) else: print(n*(n-1)*(n-2)*(n-3) - n*(n-1)*(n-2) - n*(n-1)*(n-2)*(n-3)//24+1) ```
instruction
0
25,278
12
50,556
No
output
1
25,278
12
50,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` from math import factorial n, k = map(int, input().split()) q = 0 if k == 1: print(1) elif k == 2: print(n*(n-1) - n*(n-1)/2 + 1) elif k == 3: print(n*(n-1)*(n-2) - n*(n-1) - n*(n-1)*(n-2)/6+1) else: print(n*(n-1)*(n-2)*(n-3) - n*(n-1)*(n-2) - n*(n-1)*(n-2)*(n-3)/24+1) ```
instruction
0
25,279
12
50,558
No
output
1
25,279
12
50,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` import math s = input().split(' ') n = int(s[0]) m = int(s[1]) ans = int(0) sgn = int(0) if m == 3: print(int(int(int(math.factorial(n))/int(math.factorial(n - m)))/2 +1)) if m == 2: print(int(2*n - 1)) if m == 1: print(1) if m == 4: while m >= 0: d = int(int(math.factorial(n))/int(math.factorial(n - m))) ans = int(ans +(1 - 2*sgn)*d) m-=1 sgn = int(1) - sgn print(ans) ```
instruction
0
25,280
12
50,560
No
output
1
25,280
12
50,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≀ i ≀ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers n and k. Input The first line contains two integers n and k (4 ≀ n ≀ 1000, 1 ≀ k ≀ 4). Output Print the number of almost identity permutations for given n and k. Examples Input 4 1 Output 1 Input 4 2 Output 7 Input 5 3 Output 31 Input 5 4 Output 76 Submitted Solution: ``` n, k = map(int, input().split()) if k == 1: ans = 1 elif k == 2: ans = n*(n-1)//2 + 1 elif k == 3: ans = n*(n-1)*(n-2)//2 + 1 elif k == 4: ans = n*(n-1)*(n-2)*(n-3)//2 + 1 print(ans) ```
instruction
0
25,281
12
50,562
No
output
1
25,281
12
50,563
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,701
12
51,402
Tags: constructive algorithms, greedy, math Correct Solution: ``` test_cases = [(input(), list(map(int, input().split())))[1] for _ in range(int(input()))] for case in test_cases: flag = True for i in range(1, len(case)): if abs(case[i] - case[i - 1]) > 1: print('YES') print(i, i + 1) flag = False break if flag: print('NO') ```
output
1
25,701
12
51,403
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,702
12
51,404
Tags: constructive algorithms, greedy, math Correct Solution: ``` for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) found=0 for i in range(n-1): if abs(ar[i]-ar[i+1])>1: print("YES") print(i+1,i+2) found=1 break if found==0: print("NO") ```
output
1
25,702
12
51,405
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,703
12
51,406
Tags: constructive algorithms, greedy, math Correct Solution: ``` if __name__ == '__main__': ans = [] for t in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] for i in range(len(a) - 1): if abs(a[i] - a[i + 1]) >= 2: ans.append("YES") ans.append([i + 1, i + 2]) break else: ans.append("NO") print("\n".join([ans[i] if isinstance(ans[i], str) else str(ans[i][0]) + " " + str(ans[i][1]) for i in range(len(ans))])) ```
output
1
25,703
12
51,407
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,704
12
51,408
Tags: constructive algorithms, greedy, math Correct Solution: ``` t= int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) f = -1 for i in range(n-1): if abs(a[i] - a[i+1]) >= 2: f = i+1 break if f == -1: print("NO") else: print("YES") print(f,f+1) ```
output
1
25,704
12
51,409
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,705
12
51,410
Tags: constructive algorithms, greedy, math Correct Solution: ``` from sys import stdin,stdout for a in range(int(stdin.readline())): n=int(stdin.readline()) L=list(map(int,input().split())) f=False for a in range(len(L)-1): if(max(L[a],L[a+1])-min(L[a],L[a+1])>=2): f=True print("YES") print(a+1,a+2) break if(f==False): print("NO") ```
output
1
25,705
12
51,411
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,706
12
51,412
Tags: constructive algorithms, greedy, math Correct Solution: ``` t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) for i in range(n-1): if abs(l[i]-l[i+1]) > 1: print('YES') print(i+1, i+2, sep=' ') break else: print('NO') ```
output
1
25,706
12
51,413
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,707
12
51,414
Tags: constructive algorithms, greedy, math Correct Solution: ``` for i in range(int(input())): n=int(input()) arr=list(map(int,input().split())) f=0 for i in range(n-1): if abs(arr[i]-arr[i+1])>=2: print("YES") print(i+1, i+2) f=1 break if f==0: print("NO") ```
output
1
25,707
12
51,415
Provide tags and a correct Python 3 solution for this coding contest problem. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4.
instruction
0
25,708
12
51,416
Tags: constructive algorithms, greedy, math Correct Solution: ``` for i in range(int(input())): n = int(input()) l = list(map(int,input().split())) i = 1 flag = 0 while i < len(l): if abs(l[i]-l[i-1])>=2: print("YES") print(i,i+1) flag = 1 break i+=1 if not flag: print("NO") ```
output
1
25,708
12
51,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` import math from math import ceil from math import factorial from collections import Counter from operator import itemgetter import bisect ii = lambda: int(input()) iia = lambda: list(map(int,input().split())) isa = lambda: list(input().split()) t = ii() for _ in range(t): n = ii() a = iia() flag = 0 for i in range(n-1): if(abs(a[i]-a[i+1])>=2): print('YES') print(i+1,i+2) flag=1 break if(flag==0): print('NO') ```
instruction
0
25,709
12
51,418
Yes
output
1
25,709
12
51,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) l = list(map(int,input().split())) flag = 0 for j in range(n-1): if abs(l[j]-l[j+1])>=2: print("YES") print(j+1,j+2) flag = 1 break if flag==0: print("NO") ```
instruction
0
25,710
12
51,420
Yes
output
1
25,710
12
51,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) a = list(map(int,input().split())) ans = -1 for i in range(n-1): if abs(a[i] - a[i+1]) >1: ans = i + 1 break if ans != -1: print("YES") print(ans, ans + 1) else: print("NO") ```
instruction
0
25,711
12
51,422
Yes
output
1
25,711
12
51,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` for i in range(int(input())): n = int(input()) l = [int(x) for x in input().split()] flag = 1 for i in range((len(l)-1)): if(abs(l[i]-l[i+1])>=2): print("YES") print(i+1, i+2) flag =0 break if(flag): print("NO") ```
instruction
0
25,712
12
51,424
Yes
output
1
25,712
12
51,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) li = list(map(int, input().split())) i, j = 0, 0 f = 0 while i < n or j < n: if i >= n and j >= n: break if j >= n: if abs(li[i] - li[j]) >= abs(i-j)+1: print('YES') print(min(i, j)+1, max(i, j)+1) f = 1 break i += 1 if i >= n: break else: if abs(li[i] - li[j]) >= abs(i-j)+1: print('YES') print(min(i, j)+1, max(i, j)+1) f = 1 break j += 1 if j >= n: break if f == 0: print('NO') ```
instruction
0
25,713
12
51,426
No
output
1
25,713
12
51,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` N = int(input()) for _ in range(N): k = int(input()) b = list(map(int,input().split())) mx = max(b) mm = min(b) posx = poxm = 0 for i in range(k): if mx == b[i]: posx = i+1 if mm == b[i]: posm = i+1 k = min(k, posx-posm+1) if mx-mm >= k: print("YES") print(min(posm,posx), max(posm,posx)) else: sim = 0 for i in range(posx): if (b[posx-1]-b[i] >= posx-i): print("YES") print(i,posx) sim = 1 break if not sim: print("NO") ```
instruction
0
25,714
12
51,428
No
output
1
25,714
12
51,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` from collections import * import sys input=sys.stdin.readline # "". join(strings) def ri(): return int(input()) def rl(): return list(map(int, input().split())) t = ri() for _ in range(t): n = ri() aa = rl() for i in range(1, n): if aa[i] > aa[i - 1] + 1: print("YES") print(i, i + 1) break else: print("NO") ```
instruction
0
25,715
12
51,430
No
output
1
25,715
12
51,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) β‰₯ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 β‰₯ 5. You are given an array a of n integers. Find some interesting nonempty subarray of a, or tell that it doesn't exist. An array b is a subarray of an array a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. Input The first line contains integer number t (1 ≀ t ≀ 10 000). Then t test cases follow. The first line of each test case contains a single integer n (2≀ n ≀ 2β‹… 10^5) β€” the length of the array. The second line of each test case contains n integers a_1, a_2, ..., a_n (0≀ a_i ≀ 10^9) β€” the elements of the array. It is guaranteed that the sum of n over all test cases does not exceed 2 β‹… 10^5. Output For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in a. Otherwise, output "YES" in a separate line. In the next line, output two integers l and r (1≀ l ≀ r ≀ n) β€” bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower). Example Input 3 5 1 2 3 4 5 4 2 0 1 9 2 2019 2020 Output NO YES 1 4 NO Note In the second test case of the example, one of the interesting subarrays is a = [2, 0, 1, 9]: max(a) - min(a) = 9 - 0 = 9 β‰₯ 4. Submitted Solution: ``` def f(a): mx=max(a) mn=min(a) if mx-mn>=len(a): print("YES") print(*sorted([a.index(mx)+1,a.index(mn)+1])) return '' else: print("NO") return '' for _ in range(int(input())): a=input() l=list(map(int,input().strip().split())) print(f(l)) ```
instruction
0
25,716
12
51,432
No
output
1
25,716
12
51,433
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,750
12
51,500
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` #!/usr/bin/python3 n = int(input()) a = list(map(int, input().split())) b = sorted([(a[i], i) for i in range(n)]) res = [] for _ in range(n): for i in range(n - 1): if b[i][1] > b[i + 1][1]: res.append((b[i + 1][1], b[i][1])) b[i], b[i + 1] = b[i + 1], b[i] print(len(res)) for i, j in res: print(i + 1, j + 1) ```
output
1
25,750
12
51,501
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,751
12
51,502
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n=int(input()) arr=list(map(int,input().split())) brr=[] for i in range(n): for j in range(i+1,n): if arr[i]>arr[j]: brr.append((arr[i],i+1,j+1)) brr.sort();brr.sort(reverse=True,key=lambda x:x[2]) print(len(brr)) for a,b,c in brr: print(b,c) ```
output
1
25,751
12
51,503
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,752
12
51,504
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n=int(input()) li=list(map(int,input().split())) lp=li.copy() j=1 lf=[] c=max(lp) while j<=n: a=min(lp) i=lp.index(a) li[i]=j lp[i]=c+j j+=1 while n>1: a=li.pop() while a<n: i=li.index(a+1) li[i]=a lf+=[f'{i+1} {n}'] a=a+1 n-=1 print(len(lf)) for v in lf: print(v) ```
output
1
25,752
12
51,505
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,753
12
51,506
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` # from math import factorial as fac from collections import defaultdict # from copy import deepcopy import sys, math f = None try: f = open('q1.input', 'r') except IOError: f = sys.stdin if 'xrange' in dir(__builtins__): range = xrange # print(f.readline()) sys.setrecursionlimit(10**2) def print_case_iterable(case_num, iterable): print("Case #{}: {}".format(case_num," ".join(map(str,iterable)))) def print_case_number(case_num, iterable): print("Case #{}: {}".format(case_num,iterable)) def print_iterable(A): print (' '.join(A)) def read_int(): return int(f.readline().strip()) def read_int_array(): return [int(x) for x in f.readline().strip().split(" ")] def rns(): a = [x for x in f.readline().split(" ")] return int(a[0]), a[1].strip() def read_string(): return list(f.readline().strip()) def ri(): return int(f.readline().strip()) def ria(): return [int(x) for x in f.readline().strip().split(" ")] def rns(): a = [x for x in f.readline().split(" ")] return int(a[0]), a[1].strip() def rs(): return list(f.readline().strip()) def bi(x): return bin(x)[2:] from collections import deque import math NUMBER = 10**9 + 7 # NUMBER = 998244353 def factorial(n) : M = NUMBER f = 1 for i in range(1, n + 1): f = (f * i) % M # Now f never can # exceed 10^9+7 return f def mult(a,b): return (a * b) % NUMBER def minus(a , b): return (a - b) % NUMBER def plus(a , b): return (a + b) % NUMBER def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def modinv(a): m = NUMBER g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def choose(n,k): if n < k: assert false return mult(factorial(n), modinv(mult(factorial(k),factorial(n-k)))) % NUMBER from collections import deque, defaultdict import heapq from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def dfs(g, timeIn, timeOut,depths,parents): # assign In-time to node u cnt = 0 # node, neig_i, parent, depth stack = [[1,0,0,0]] while stack: v,neig_i,parent,depth = stack[-1] parents[v] = parent depths[v] = depth # print (v) if neig_i == 0: timeIn[v] = cnt cnt+=1 while neig_i < len(g[v]): u = g[v][neig_i] if u == parent: neig_i+=1 continue stack[-1][1] = neig_i + 1 stack.append([u,0,v,depth+1]) break if neig_i == len(g[v]): stack.pop() timeOut[v] = cnt cnt += 1 # def isAncestor(u: int, v: int, timeIn: list, timeOut: list) -> str: # return timeIn[u] <= timeIn[v] and timeOut[v] <= timeOut[u] cnt = 0 @bootstrap def dfs(v,adj,timeIn, timeOut,depths,parents,parent=0,depth=0): global cnt parents[v] = parent depths[v] = depth timeIn[v] = cnt cnt+=1 for u in adj[v]: if u == parent: continue yield dfs(u,adj,timeIn,timeOut,depths,parents,v,depth+1) timeOut[v] = cnt cnt+=1 yield def gcd(a,b): if a == 0: return b return gcd(b % a, a) # Function to return LCM of two numbers def lcm(a,b): return (a*b) / gcd(a,b) def get_num_2_5(n): twos = 0 fives = 0 while n>0 and n%2 == 0: n//=2 twos+=1 while n>0 and n%5 == 0: n//=5 fives+=1 return (twos,fives) def shift(a,i,num): for _ in range(num): a[i],a[i+1],a[i+2] = a[i+2],a[i],a[i+1] def find_mex(a,m): b = sorted([x-m for x in a]) # print('sorted a',b) if b[0] > 0: return m last = 0 for i in range(len(b)): if b[i] > last+1: return last+1 + m last = b[i] return b[len(b)-1]+m+1 def solution(a,n): sol = [] b = sorted([(a[i],i) for i in range(n)], reverse=True) for x,i in b: for j in range(i): if a[j] > a[i]: sol.append(f'{j+1} {i+1}') sol = [f'{len(sol)}'] + sol return '\n'.join(sol) def main(): T = 1 # T = ri() for i in range(T): n = ri() # s = rs() # data = [] # n,m = ria() a = ria() # b = ria() x = solution(a,n) # continue if 'xrange' not in dir(__builtins__): print(x) else: print >>output,str(x)# "Case #"+str(i+1)+':', if 'xrange' in dir(__builtins__): print(output.getvalue()) output.close() if 'xrange' in dir(__builtins__): import cStringIO output = cStringIO.StringIO() #example usage: # for l in res: # print >>output, str(len(l)) + ' ' + ' '.join(l) if __name__ == '__main__': main() ```
output
1
25,753
12
51,507
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,754
12
51,508
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n=int(input()) a=[int(i) for i in input().split()] ans=0 dc=[[] for i in range(n)] for i in range(n): for j in range(i): if(a[i]<a[j]): dc[i].append((a[j],j)) ans+=1 print(ans) for i in range(n-1,-1,-1): dc[i].sort() for j in dc[i]: print(j[1]+1,i+1) ```
output
1
25,754
12
51,509
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,755
12
51,510
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) aWithIndex = [] for i in range(n): aWithIndex.append((a[i],i)) aWithIndex.sort(key = lambda x: x[0]) aOrder = [-1] * n for i in range(n): aOrder[aWithIndex[i][1]] = i aOrderInverse = [-1] * n for i in range(n): aOrderInverse[aOrder[i]] = i result = [] for i in range(n): for j in range(aOrder[i] - 1, i - 1, -1): result.append(str(i + 1) + ' ' + str(aOrderInverse[j] + 1)) tmp = aOrder[i] aOrder[i] = aOrder[aOrderInverse[j]] aOrder[aOrderInverse[j]] = tmp for j in range(n): aOrderInverse[aOrder[j]] = j print(len(result)) if len(result) != 0: print('\n'.join(result)) ```
output
1
25,755
12
51,511
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,756
12
51,512
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` it = lambda: list(map(int, input().strip().split())) def solve(): N = int(input()) A = it() inversions = [] for i in range(N): inversion = [] for j in range(i): if A[j] > A[i]: inversion.append(j) inversions.append(inversion) R = [] B = [[a, i] for i, a in enumerate(A)] for i in range(N - 1, -1, -1): inversion = inversions[i] inversion.sort(key=lambda x:B[x]) for j in inversion: R.append([j + 1, i + 1]) B[i], B[j] = B[j], B[i] print(len(R)) for i, j in R: print(i, j) if __name__ == '__main__': solve() ```
output
1
25,756
12
51,513
Provide tags and a correct Python 3 solution for this coding contest problem. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted.
instruction
0
25,757
12
51,514
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n = int(input()) l = list(map(int, input().split())) order = [(l[i],i) for i in range(n)] order.sort(reverse = True) out = [] for v, ind in order: for i in range(ind): if v < l[i]: out.append(str(i + 1)+' '+str(ind + 1)) print(len(out)) print('\n'.join(out)) ```
output
1
25,757
12
51,515
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≀ u < v ≀ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with the following conditions: * all the pairs in the list are distinct and form an inversion in a. * all the pairs that form an inversion in a are in the list. * Starting from the given array, if you swap the values at indices u_1 and v_1, then the values at indices u_2 and v_2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order. Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the length of the array. Next line contains n integers a_1,a_2,...,a_n (1 ≀ a_i ≀ 10^9) β€” elements of the array. Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≀ m ≀ (n(n-1))/(2)) β€” number of pairs in the list. The i-th of the following m lines should contain two integers u_i, v_i (1 ≀ u_i < v_i≀ n). If there are multiple possible answers, you may find any of them. Examples Input 3 3 1 2 Output 2 1 3 1 2 Input 4 1 8 1 6 Output 2 2 4 2 3 Input 5 1 1 1 2 2 Output 0 Note In the first sample test case the array will change in this order [3,1,2] β†’ [2,1,3] β†’ [1,2,3]. In the second sample test case it will be [1,8,1,6] β†’ [1,6,1,8] β†’ [1,1,6,8]. In the third sample test case the array is already sorted. Submitted Solution: ``` import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n = mint() a = list(mints()) inv = [] for i in range(1,n): for j in range(i): if a[i] < a[j]:inv.append((i,-a[j],-j)) inv.sort(reverse=True) r = list(range(len(inv))) if r is not None: print(len(r)) for z in r:v, _, u = inv[z];u = -u;print(u+1,v+1) else: print("wut") ```
instruction
0
25,758
12
51,516
Yes
output
1
25,758
12
51,517