message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` n, m = map(int,input().split()) g = [list(map(int,input().split())) for _ in range(n)] for c1 in range(m): for c2 in range(c1, m): ok = True for row in g: row[c1], row[c2] = row[c2], row[c1] cnt = 0 for i in range(m): if row[i] != i + 1: cnt += 1 if cnt > 2: break row[c1], row[c2] = row[c2], row[c1] if cnt > 2: ok = False break if ok: print('YES') exit(0) print('NO') ```
instruction
0
72,161
12
144,322
Yes
output
1
72,161
12
144,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` I=lambda:map(int,input().split()) R=range n,m=I() t=[[]for _ in R(m)] e=list(R(1,m+1)) r='NO' for _ in R(n): for i,v in zip(R(m),I()):t[i]+=[v] for i in R(m): for j in R(i,m): t[i],t[j]=t[j],t[i] if all(3>sum(t[i][j]!=e[i]for i in R(m))for j in R(n)):r='YES' t[i],t[j]=t[j],t[i] print(r) ```
instruction
0
72,162
12
144,324
Yes
output
1
72,162
12
144,325
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` read = lambda: map(int, input().split()) n, m = read() a = [list(read()) for i in range(n)] b = [a[i][:] for i in range(n)] flag = True for i in range(n): c = sorted(b[i]) d = b[i][:] dif = sum(c[j] != d[j] for j in range(m)) if dif > 2: flag = False if flag: print('YES') exit() for k1 in range(m): for k2 in range(k1 + 1, m): b = [a[i][:] for i in range(n)] for i in range(n): b[i][k1], b[i][k2] = b[i][k2], b[i][k1] flag = True for i in range(n): c = sorted(b[i]) d = b[i][:] dif = sum(c[j] != d[j] for j in range(m)) if dif > 2: flag = False if flag: print('YES') exit() print('NO') ```
instruction
0
72,163
12
144,326
Yes
output
1
72,163
12
144,327
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` n, m = [int(x) for x in input().split()] L = [[int(x) for x in input().split()] for i in range(n)] def solve(L): D = {i:set() for i in range(n)} for i in range(n): for j in range(m): if L[i][j] != j+1: D[i].add((min(j+1, L[i][j]), max(j+1, L[i][j]))) if len(D[i]) > 3 or len(D[i]) == 3 and L[i][L[i][j]-1] == j+1: return False if all((len(D[i]) < 2) for i in range(n)): return True for x in range(m): for y in range(x,m): for i in range(n): if not ((x+1,y+1) in D[i] or len(D[i]) == 0): break else: return True return False print('YES') if solve(L) else print('NO') ```
instruction
0
72,164
12
144,328
Yes
output
1
72,164
12
144,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` def no(k): s=[] for j in range (len(k)): if k[j]!=j+1: s.append(j) return(s) def summ(k,n,i): s=0 for j in range(n): s+=k[j][i] return(s) def numcol(k,n): d=0 s=no(k[0]) for i in s: if summ(k,n,i)==n*k[0][i]: d+=1 return(d) def notin(k,m): s=0 for j in range(m): if k[j]!=j+1: s+=1 return(s) def somme(k,n,m): g=0 for i in range(n): g+=notin(k[i],m) return(g) def op(k,n,m): for i in range(n): if notin(k[i],m)>2: return(False) return(True) def tr(l,n,m,i,j): c=l.copy() for s in range(n): c[s][i],c[s][j]=c[s][j],c[s][i] f=op(c,n,m) for s in range(n): c[s][i],c[s][j]=c[s][j],c[s][i] return(f) def main (): n,m=map(int,input().split()) k=[] for i in range (n): k.append(list(map(int,input().split(' ')))) g=somme(k,n,m) h=-1 for i in range(n): if notin(k[i],m) > 4 : return("NO") elif notin(k[i],m) == 4: f=i elif notin(k[i],m) == 3: h=i if n <3 and m<3: return("YES") elif g==0: return("NO") elif (g<=2*n): return("YES") elif h !=-1: p=no(k[h]) if tr(k,n,m,p[0],p[1])or tr(k,n,m,p[0],p[2])or tr(k,n,m,p[1],p[2]): return("YES") else : return("NO") elif h==-1: p=no(k[f]) if tr(k,n,m,p[0],p[1])or tr(k,n,m,p[0],p[2])or tr(k,n,m,p[0],p[3])or tr(k,n,m,p[1],p[2])or tr(k,n,m,p[1],p[3])or tr(k,n,m,p[2],p[3]): return("YES") else : return("NO") print(main()) ```
instruction
0
72,165
12
144,330
No
output
1
72,165
12
144,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` #!/usr/bin/env python3 n,m= tuple(map(int, input().split())) lista = [list(map(int, input().split())) for _ in range(n)] for k,numeros in enumerate(lista): contadur=0 for i,n in enumerate(numeros): if n!=(i+1): if contadur<k+2: contadur+=1 else: print("NO") quit() print("YES") ```
instruction
0
72,166
12
144,332
No
output
1
72,166
12
144,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` def no(k): s=[] for j in range (len(k)): if k[j]!=j+1: s.append(j) return(s) def summ(k,n,i): s=0 for j in range(n): s+=k[j][i] return(s) def numcol(k,n): d=0 s=no(k[0]) for i in s: if summ(k,n,i)==n*k[0][i]: d+=1 return(d) def notin(k,m): s=0 for j in range(m): if k[j]!=j+1: s+=1 return(s) def somme(k,n,m): g=0 for i in range(n): g+=notin(k[i],m) return(g) def op(k,n,m): for i in range(n): if notin(k[i],m)>2: return(False) return(True) def tr(l,n,m,i,j): c=l.copy() for s in range(n): c[s][i],c[s][j]=c[s][j],c[s][i] f=op(c,n,m) for s in range(n): c[s][i],c[s][j]=c[s][j],c[s][i] return(f) def main (): n,m=map(int,input().split()) k=[] for i in range (n): k.append(list(map(int,input().split(' ')))) g=somme(k,n,m) h=-1 for i in range(n): if notin(k[i],m) > 4 : return("NO") elif notin(k[i],m) == 4: f=i elif notin(k[i],m) == 3: h=i if g==0: return("NO") elif n <3 and m<3: return("YES") elif (g<=2*n): return("YES") elif h !=-1: p=no(k[h]) if tr(k,n,m,p[0],p[1])or tr(k,n,m,p[0],p[2])or tr(k,n,m,p[1],p[2]): return("YES") else : return("NO") elif h==-1: p=no(k[f]) if tr(k,n,m,p[0],p[1])or tr(k,n,m,p[0],p[2])or tr(k,n,m,p[0],p[3])or tr(k,n,m,p[1],p[2])or tr(k,n,m,p[1],p[3])or tr(k,n,m,p[2],p[3]): return("YES") else : return("NO") print(main()) ```
instruction
0
72,167
12
144,334
No
output
1
72,167
12
144,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. Output If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Examples Input 2 4 1 3 2 4 1 3 4 2 Output YES Input 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Output NO Input 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Output YES Note In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4 Submitted Solution: ``` #!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() r, c = rint() mat = [[] for i in range(r)] disorder = [] for i in range(r): mat[i] = list(rint()) tmp = set() for j in range(c): if j+1 != mat[i][j]: tmp.add((j+1, mat[i][j])) if len(tmp) != 0: disorder.append(tmp) max_cap = max([len(e) for e in disorder]) num_cap = len(set.intersection(*disorder)) if max_cap > 4: print("NO") else: if max_cap - num_cap <= 2: print("YES") else: print("NO") ```
instruction
0
72,168
12
144,336
No
output
1
72,168
12
144,337
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,494
12
144,988
Tags: greedy Correct Solution: ``` from sys import stdin import pprint input_string = list(map(int,stdin.readline().split())) mediana = input_string[1] array = list(map(int,stdin.readline().split())) array.sort() change = 0 if array[array.__len__() // 2] > mediana: for i in range(0, (array.__len__() // 2) + 1): if array[i] > mediana: change += array[i] - mediana elif array[array.__len__() // 2] < mediana: for i in range(array.__len__() // 2, array.__len__()): if array[i] < mediana: change += mediana - array[i] print(change) ```
output
1
72,494
12
144,989
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,495
12
144,990
Tags: greedy Correct Solution: ``` import bisect n,s=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() tot,cnt=0,0 if s>=arr[n//2]: ind=bisect.bisect_left(arr,s) for i in range(n//2,ind): tot+=s-arr[i] cnt+=1 if cnt==0: tot+=s-arr[n//2] print(tot) else: ind=bisect.bisect_left(arr,s) for i in range(ind,(n//2)+1): tot+=arr[i]-s cnt+=1 if cnt==0: tot+=arr[n//2]-s print(tot) ```
output
1
72,495
12
144,991
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,496
12
144,992
Tags: greedy Correct Solution: ``` n,s = [ int(i) for i in input().split()] a = [ int(i) for i in input().split()] a.sort(); o = 0; if a[-(n//2)-1] < s: for i in range (n-1,n//2-1,-1): if a[i] < s: o = o+ s-a[i]; else: for i in range (n//2+1): if a[i] > s: o = o- (s-a[i]); print (o) ```
output
1
72,496
12
144,993
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,497
12
144,994
Tags: greedy Correct Solution: ``` n, s = map(int, input().split(' ')) aa = sorted(list(map(int, input().split(' ')))) res = 0 m = n // 2 for i in range(m): if aa[i] > s: res += aa[i] - s res += abs(aa[m] - s) for i in range(m+1, n): if aa[i] < s: res += s - aa[i] print(res) ```
output
1
72,497
12
144,995
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,498
12
144,996
Tags: greedy Correct Solution: ``` def main(): n, s = map(int, input().split()) a = sorted(int(c) for c in input().split()) i = n // 2 median = a[i] if median == s: res = 0 elif median < s: res = s - median i += 1 while 1 <= i < n and a[i] < s: res += s - a[i] i += 1 else: res = median - s i -= 1 while 0 <= i < n - 1 and a[i] > s: res += a[i] - s i -= 1 print(res) if __name__ == '__main__': main() ```
output
1
72,498
12
144,997
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,499
12
144,998
Tags: greedy Correct Solution: ``` n, median = input().split() n=int(n) median=int(median) myArr = [int(i) for i in input().split()] myArr.sort() midIndex =int( n/2) cost=0 k=midIndex if myArr[midIndex]!=median: while(k>=0): if myArr[k]>median: cost=cost+myArr[k]-median k=k-1 for j in range(midIndex,n): if myArr[j]<median: cost = cost + median-myArr[j] print(cost) ```
output
1
72,499
12
144,999
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,500
12
145,000
Tags: greedy Correct Solution: ``` n, s = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) result = 0 med = (n-1)//2 while (med in range(n) and arr[med] < s): result += s - arr[med] med = med + 1 med = (n-1)//2 while (med in range(n) and arr[med] > s): result += arr[med] - s med = med - 1 print(result) ```
output
1
72,500
12
145,001
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
instruction
0
72,501
12
145,002
Tags: greedy Correct Solution: ``` n,res=list(map(int,input().split())) s=list(map(int,input().split())) count=0 s.sort() for i in range(n//2+1): if(s[i]>res): count+=s[i]-res if(s[n-1-i]<res): count+=res-s[n-1-i] print(count) ```
output
1
72,501
12
145,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` #!/usr/bin/env python3 n, s = map(int, input().split()) xs = [int(x) for x in input().split()] xs.sort() c = 0 if xs[n//2] < s: for i in range(n//2, n): c += max(0, s - xs[i]) elif xs[n//2] > s: for i in range(0, n//2+1): c += max(0, xs[i] - s) print(c) ```
instruction
0
72,502
12
145,004
Yes
output
1
72,502
12
145,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` n, s = list(map(int,input().strip().split(' '))) a = sorted(list(map(int,input().strip().split(' ')))) i = n // 2 inc = 0 if a[i] < s: while True: if i == n or a[i] >= s: break else: inc += s - a[i] i += 1 elif a[i] > s: while True: if i == -1 or a[i] <= s: break else: inc += a[i] - s i -= 1 else: inc = 0 print(inc) ```
instruction
0
72,503
12
145,006
Yes
output
1
72,503
12
145,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` import bisect n,s=map(int,input().split()) A=list(map(int,input().split())) A.sort() r=bisect.bisect_left(A,s) l=bisect.bisect_right(A,s) #n//2個目がsになればよい #sより小:r個 #sより大:n-l個 #s:l-r個 ANS=float("inf") ANS2=float("inf") if r>n//2: ANS=(r-n//2)*s-sum(A[n//2:r]) if n-l>n//2: ANS2=sum(A[l:n//2+1])-(n//2+1-l)*s x=min(ANS,ANS2) if x!=float("inf"): print(x) else: print(0) ```
instruction
0
72,504
12
145,008
Yes
output
1
72,504
12
145,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` t=list(map(int,input().rstrip().split())) m=list(map(int,input().rstrip().split())) s=sorted(m) j=int((len(s)-1)/2) k=0 if s[j]<t[1]: k+=t[1]-s[j] if s[j]>t[1]: k+=s[j]-t[1] for i in s: s[j]=t[1] for i in range(0,j): if s[j]<=s[i]: k+=s[i]-s[j] for i in range(j+1,len(s)): if s[j]>=s[i]: k+=s[j]-s[i] print(k) ```
instruction
0
72,505
12
145,010
Yes
output
1
72,505
12
145,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` n,m=map(int,input().split()) s=list(map(int,input().split())) s.sort() i,j=n//2,0 if s[n//2]<m: while s[i]<m: j+=(m-s[i]) i+=1 else: while s[j]>m: j+=(s[i]-m) i-=1 print(j) ```
instruction
0
72,506
12
145,012
No
output
1
72,506
12
145,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` a,b=map(int,input().split()) s=sorted(list(map(int,input().split()))) l=-1 z=[] for n in s: if n!=l: z.append(n) l=n if len(z)%2==0: x1=z[len(z)//2] x2=z[len(z)//2-1] print(2*b-x1-x2) else: x1=z[len(z)//2] print(b-x1) ```
instruction
0
72,507
12
145,014
No
output
1
72,507
12
145,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` import bisect n,s=map(int,input().split()) A=list(map(int,input().split())) A.sort() r=bisect.bisect_left(A,s) l=bisect.bisect_right(A,s) #n//2個目がsになればよい #sより小:r個 #sより大:n-l個 #s:l-r個 ANS=float("inf") ANS2=float("inf") if r>=n//2: ANS=(r-n//2)*s-sum(A[n//2:r]) if n-l>=n//2: ANS2=sum(A[l:n//2+1])-(n//2+1-l)*s x=min(ANS,ANS2) if x!=float("inf"): print(x) else: print(0) ```
instruction
0
72,508
12
145,016
No
output
1
72,508
12
145,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position. Input The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median. The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a. It is guaranteed that n is odd. Output In a single line output the minimum number of operations to make the median being equal to s. Examples Input 3 8 6 5 8 Output 2 Input 7 20 21 15 12 11 20 19 12 Output 6 Note In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8. In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. Submitted Solution: ``` n, s = map(int, input().split()) H = list(map(int, input().split())) H.sort(); ans = 0 #print(H) for i in range(n // 2 + 1): #print('0', H[n//2 + i], '1', H[n // 2 - i]) if H[n//2 + i] == s: for j in range(n // 2 + i - 1, n // 2 - 1, -1): ans += s - H[j] print(ans) exit() elif H[n // 2 - i] == s: for t in range(n // 2 - i + 1, n // 2 + 1): ans += H[t] - s print(ans) exit() ```
instruction
0
72,509
12
145,018
No
output
1
72,509
12
145,019
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,608
12
145,216
Tags: brute force, sortings Correct Solution: ``` n,m=map(int,input().split()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] l=sorted(b) A=sorted(list(set(a))) B=sorted(list(set(b))) #print(A) #print(B) ans=m-1 for i in range(0,len(B)): k=abs(B[i]-A[0]) #print(k) h=[] for j in range(0,len(a)): h.append((a[j]+k)%m) if(sorted(h)==l): ans=min(ans,k) k2=m-abs(B[i]-A[0]) #print(k) h=[] for j in range(0,len(a)): h.append((a[j]+k2)%m) if(sorted(h)==l): ans=min(ans,k2) print(ans) ```
output
1
72,608
12
145,217
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,609
12
145,218
Tags: brute force, sortings Correct Solution: ``` n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() pos=[(b[i]-a[0])%m for i in range(n)] for i in pos: s=[(j+i)%m for j in a] s.sort() if s==b: l=[] l.append(i) print(min(l)) ```
output
1
72,609
12
145,219
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,610
12
145,220
Tags: brute force, sortings Correct Solution: ``` def shift(): a=A.pop(0) A.append(a) a=A1.pop(0) A1.append(a) def count(A): c=A[0] n=0 A0=[] A1=[A[0]] for i in range(len(A)): if c==A[i]: n+=1 else: A0.append(n) A1.append(A[i]) n=1 c=A[i] A0.append(n) return A0,A1 def check(x): for i in range(len(A1)): if (A1[i]+x)%m!=B1[i]: return False return True n,m=map(int,input().split()) turns=0 A0=sorted(list(map(int,input().split()))) B0=sorted(list(map(int,input().split()))) if A0==B0: print(0) else: A,A1=count(A0) B,B1=count(B0) turns=0 x=m+1 while turns<n: if A==B: x1=(m+B1[-1]-A1[-1])%m if x1<x and check(x1): x=x1 shift() turns+=1 print(x) ```
output
1
72,610
12
145,221
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,611
12
145,222
Tags: brute force, sortings Correct Solution: ``` n,m=tuple(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() x=[] for i in range(n): x.append((b[0]-a[i])%m) x=list(set(x)) for i in range(len(x)): k=[] for j in range(n): k.append((a[j]+x[i])%m) k.sort() if(k==b): print(x[i]) break ```
output
1
72,611
12
145,223
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,612
12
145,224
Tags: brute force, sortings Correct Solution: ``` import sys import math def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() n,m = MI() a = LI() b = sorted(LI()) if a == b: print(0) else: c = [(b[i]-a[0])%m for i in range(n)] for i in sorted(c): s = [(a[j]+i)%m for j in range(n)] if sorted(s) == b: print(i) break ```
output
1
72,612
12
145,225
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,613
12
145,226
Tags: brute force, sortings Correct Solution: ``` ''' n, m = input().split() n = int(n); m = int(m) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) for x in range(m): c = sorted([(i+x) % m for i in a]) if c == b: print(x) break ''' n, m = input().split() n = int(n); m = int(m) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) for index in range(n): c = a[ : n - index] d = b[index: n] for i in range(n-index): if d[i] - c[i] != d[0] - c[0]: break else: x = (d[0] - c[0] + m) % m break print(x) ```
output
1
72,613
12
145,227
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,614
12
145,228
Tags: brute force, sortings Correct Solution: ``` import math n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() min_x = math.inf for i in range(len(b)): x = (b[i] - a[0]) % m if x < min_x: new_a = [(y + x) % m for y in a] new_a.sort() if new_a == b: min_x = x print(min_x) ```
output
1
72,614
12
145,229
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0
instruction
0
72,615
12
145,230
Tags: brute force, sortings Correct Solution: ``` import sys import math def run(i, dif): global m for j in range(len(a)): indB = (j + i) % len(a) if b[indB] < a[j]: newDif = m - a[j] + b[indB] else: newDif = b[indB] - a[j] if newDif != dif: return False return True n, m = list(map(int, sys.stdin.readline().split())) a = list(map(int, sys.stdin.readline().split())) b = list(map(int, sys.stdin.readline().split())) a = sorted(a) b = sorted(b) ans = math.inf for i in range(len(b)): if a[0] > b[i]: dif = m - a[0] + b[i] else: dif = b[i] - a[0] if run(i, dif): ans = min(ans, dif) print(ans) ```
output
1
72,615
12
145,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` from collections import Counter (n,m), a, b = (list(map(int, input().split())) for _ in '012') c = Counter(b) for x in sorted((m + i - a[0]) % m for i in c): if Counter((i+x)%m for i in a) == c: print(x) exit(0) ```
instruction
0
72,616
12
145,232
Yes
output
1
72,616
12
145,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` ''' Hey stalker :) ''' INF = 10**10 def main(): #print = out.append ''' Cook your dish here! ''' n, m = get_list() a = get_list() b = get_list() cnta = Counter(a) cntb = Counter(b) keys = list(sorted(cntb.keys())) def chk(x): for i in keys: try: if cntb[i]!=cnta[(i-x)%m]: return False except : return False return True key1 = list(sorted(cnta.keys()))[0] res = INF for ele in keys: if cnta[key1]==cntb[ele] and chk(ele-key1): res = min(res, (ele-key1)%m) print(res) ''' Pythonista fLite 1.1 ''' import sys from collections import defaultdict, Counter from bisect import bisect_left, bisect_right #from functools import reduce import math input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ out = [] get_int = lambda: int(input()) get_list = lambda: list(map(int, input().split())) main() #[main() for _ in range(int(input()))] print(*out, sep='\n') ```
instruction
0
72,617
12
145,234
Yes
output
1
72,617
12
145,235
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` import sys import math input = sys.stdin.readline n,m = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) a.sort() b.sort() best = 10**12 for i in range(len(a)): x = b[0] - a[i] if x<0: x += m ok = 1 #print(x) c = [] for j in range(len(a)): c.append((a[j] + x) % m) #print(c) if sorted(c) == b: best = min(best, x) print(best) ```
instruction
0
72,618
12
145,236
Yes
output
1
72,618
12
145,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` from collections import Counter n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(len(b)): b[i] = b[i] % m for i in range(len(a)): a[i] = a[i] % m b = sorted(b) a = sorted(a) # print('a', a, 'b', b) counterb = Counter(b) temp = a[:] for i in range(len(temp)): temp[i] = (m + b[0] - a[i]) % m temp = list(set(sorted(temp))) # print('temp', temp) for x in temp: # print('x', x, 'a', a) newa = [(i + x) % m for i in a] # print('newa', newa) countera = Counter(newa) # print(newa, countera, counterb) if countera == counterb: print(x) break ```
instruction
0
72,619
12
145,238
Yes
output
1
72,619
12
145,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() count_a = [1] value_a = [a[0]] count_b = [1] value_b = [b[0]] for i in range(1, n): if a[i] == a[i-1]: count_a[-1] += 1 else: count_a.append(1) value_a.append(a[i]) if b[i] == b[i-1]: count_b[-1] += 1 else: count_b.append(1) value_b.append(b[i]) for i in range(len(count_a)): if count_a == count_b: print(value_b[i] - a[0]) break value_a = list(map(lambda x: (x+1) % m, value_a)) if value_a[-1] == 0: count_a.insert(0, count_a.pop()) value_a = [0] + value_a[0:-1] ```
instruction
0
72,620
12
145,240
No
output
1
72,620
12
145,241
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) min1=[] dic={} b.sort() length=len(a) for i in range(length): dic[b[i]]=dic.get(b[i],0)+1 if a[i]>b[i]: min1.append(m-(a[i]-b[i])) else: min1.append(b[i]-a[i]) l=[] for i in min1: l=[(a[j]+i)%m for j in range(n)] l.sort() if l==b: print(i) break ```
instruction
0
72,621
12
145,242
No
output
1
72,621
12
145,243
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() x=[] for i in range(n): x.append((b[0]-a[i])%m) for i in x: q=[] for j in range(n): q.append((a[j]+i)%m) q.sort() if q==b: print(i) break ```
instruction
0
72,622
12
145,244
No
output
1
72,622
12
145,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n. Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3]. You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x. In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m. For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b. Input The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m. The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m). The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m). It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}. Output Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n. Examples Input 4 3 0 0 2 1 2 0 1 1 Output 1 Input 3 2 0 0 0 1 1 1 Output 1 Input 5 10 0 0 0 1 2 2 1 0 0 0 Output 0 Submitted Solution: ``` n,m=map(int,input().split()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] b.sort() x=[(i-b[0])%m for i in a] x.sort() for i in x: c=[(e+i)%m for e in a] c.sort() if c==b: break print(i) ```
instruction
0
72,623
12
145,246
No
output
1
72,623
12
145,247
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,624
12
145,248
Tags: greedy, implementation Correct Solution: ``` t = int(input()) ans=[] for i in range(t): n = int(input()) a = list(map(int, input().split())) inc_state, dec_state = False, False min_inc, min_dec = 0, n-1 for i in range(n): if (a[i] < i) and (inc_state == False): min_inc = i-1 inc_state = True if (a[n-1-i] < i) and (dec_state == False): min_dec = n-i dec_state = True if (inc_state == False): min_inc = n-1 if (dec_state == False): min_dec = 0 if (min_dec <= min_inc): ans.append('Yes') else: ans.append('No') for i in ans: print(i) ```
output
1
72,624
12
145,249
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,625
12
145,250
Tags: greedy, implementation Correct Solution: ``` def solve(n, a_s): left = [True] * n right = [True] * n # Strict relationship invariant for i, a in enumerate(a_s): if a < i: left[i] = False if a < n - 1 - i: right[i] = False l_max = n - 1 for i, l in enumerate(left): if not l: l_max = i - 1 break r_max = n - 1 for i, r in enumerate(reversed(right)): if not r: r_max = i - 1 break if l_max + r_max + 2 < n: return "No" if l_max != r_max: return "Yes" # l_max == r_max # Even elements & same max number at middle if l_max + r_max + 2 == n and l_max == r_max and a_s[l_max] == a_s[n - 1 - r_max]: return "No" return "Yes" if __name__ == "__main__": t = int(input()) for _ in range(t): n = int(input()) a_s = [int(ch) for ch in input().split(' ')] print(solve(n, a_s)) ```
output
1
72,625
12
145,251
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,626
12
145,252
Tags: greedy, implementation Correct Solution: ``` for _ in range(int(input())) : n = int(input()) a = list(map(int, input().split())) can = False pos, mx = 0, 0 l = [0 for i in range(n)]; r = [0 for i in range(n)] l[0] = 1; r[n - 1] = 1 for i in range(1, n) : if l[i - 1] == 1 and a[i] >= i : l[i] = 1 for i in range(n - 2, -1, -1) : if r[i + 1] == 1 and a[i] >= n - 1 - i : r[i] = 1 for i, j in zip(l, r) : if i == 1 and j == 1 : can = True if can : print('Yes') else : print('No') ```
output
1
72,626
12
145,253
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,627
12
145,254
Tags: greedy, implementation Correct Solution: ``` #from sys import maxsize #from collections import Counter as cnt, defaultdict as dic #import string #from decimal import Decimal as de get_int = lambda: int(input()) get_mul_int = lambda: map(int, input().rstrip().split()) get_list = lambda: list(map(int, input().rstrip().split())) TEST_CASES = True def main(): n = get_int() a = get_list() i, j = 0, n-1 while i<n: if a[i]<i: break i+=1 while j>-1: if a[j]<n-j-1: break j-=1 j+=1; i-=1 print('YES') if i>=j else print('NO') # START if not TEST_CASES: main() else: [main() for _ in range(int(input()))] ```
output
1
72,627
12
145,255
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,628
12
145,256
Tags: greedy, implementation Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict, deque, Counter from bisect import * from math import sqrt, pi, ceil, log, inf,gcd from itertools import permutations from copy import deepcopy from heapq import * from sys import setrecursionlimit def solve(): n = int(input()) a = list(map(int,input().split())) if n == 1: return "Yes" else: dp=[1]*n for i in range(n-2,-1,-1): if a[i]<n-i-1: dp[i]=0 dp[i]=dp[i]&dp[i+1] for i in range(n-1): if a[i]<i: return "No" if dp[i+1] and not(n%2==0 and i==n//2-1 and a[i]==a[i+1]==i): return "Yes" return "No" def main(): for _ in range(int(input())): print(solve()) # 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() ```
output
1
72,628
12
145,257
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,629
12
145,258
Tags: greedy, implementation Correct Solution: ``` import sys import math import collections import heapq input=sys.stdin.readline t=int(input()) for w in range(t): n=int(input()) l=[int(i) for i in input().split()] c1,c2=0,n-1 while(c1<n and l[c1]>=c1): c1+=1 while(c2>=0 and l[c2]>=n-1-c2): c2-=1 if(c1>c2+1): print("Yes") else: print("No") ```
output
1
72,629
12
145,259
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,630
12
145,260
Tags: greedy, implementation Correct Solution: ``` import os import sys from io import BytesIO, IOBase import math def main(): pass # 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") import os import sys from io import BytesIO, IOBase def main(): pass # 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") for xyz in range(0,int(input())): n=int(input()) l=list(map(int,input().split())) cp=n-1 for i in range(0,n): if(l[i]<i): cp=i-1 break if(cp==n-1): print("Yes") else: cp2=0 for i in range(n-1,-1,-1): if(l[i]<(n-i-1)): cp2=i+1 break #print(cp,cp2) if(cp>=cp2): print("Yes") else: print("No") ```
output
1
72,630
12
145,261
Provide tags and a correct Python 3 solution for this coding contest problem. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened.
instruction
0
72,631
12
145,262
Tags: greedy, implementation Correct Solution: ``` T = int(input()) answer = "" for t in range(T): n = int(input()) arr = list(map(int, input().split(' '))) end = False can = 0 if n == 1: answer += "Yes\n" continue for i in range(n-1, -1, -1): if arr[i] >= n - i - 1: can += 1 else: break l = -1 r = n for i in range(n): if i > 0: if arr[i-1] < i-1: answer += "No\n" end = True break r -= 1 l += 1 if l <= arr[i] and r <= arr[i] and r <= can: answer += "Yes\n" end = True break if not end: answer += "No\n" print(answer) ```
output
1
72,631
12
145,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened. Submitted Solution: ``` from sys import stdin for _ in range(int(input())): n=int(input()) l=list(map(int,stdin.readline().split())) ind = -1 for i in range(n): if l[i]>=i: pass else: ind = i break if ind == -1: print("Yes") else: f=0 if ind == n-1: if l[ind]==l[ind-1] and l[-1]==0: print("No") f=1 else: print("Yes") f=1 if f==0: if l[ind]==n-ind-1 and l[ind-1]==l[ind]: print("No") f=1 if f==0: for i in range(ind,n): if l[i]>=n-i-1: pass else: f=1 break if f==0: print("Yes") else: print("No") ```
instruction
0
72,632
12
145,264
Yes
output
1
72,632
12
145,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You're given an array a_1, …, a_n of n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: * The arrays [4], [0, 1], [12, 10, 8] and [3, 11, 15, 9, 7, 4] are sharpened; * The arrays [2, 8, 2, 8, 6, 5], [0, 1, 1, 0] and [2, 5, 6, 9, 8, 8] are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any i (1 ≤ i ≤ n) such that a_i>0 and assign a_i := a_i - 1. Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. Input The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 15\ 000) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5). The second line of each test case contains a sequence of n non-negative integers a_1, …, a_n (0 ≤ a_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5. Output For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. Example Input 10 1 248618 3 12 10 8 6 100 11 15 9 7 8 4 0 1 1 0 2 0 0 2 0 1 2 1 0 2 1 1 3 0 1 0 3 1 0 1 Output Yes Yes Yes No No Yes Yes Yes Yes No Note In the first and the second test case of the first test, the given array is already sharpened. In the third test case of the first test, we can transform the array into [3, 11, 15, 9, 7, 4] (decrease the first element 97 times and decrease the last element 4 times). It is sharpened because 3 < 11 < 15 and 15 > 9 > 7 > 4. In the fourth test case of the first test, it's impossible to make the given array sharpened. Submitted Solution: ``` from functools import reduce import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import * from io import BytesIO, IOBase input = lambda: sys.stdin.readline().rstrip("\r\n") def value(): return tuple(map(int, input().split())) # multiple values def arr(): return [int(i) for i in input().split()] # array input def sarr(): return [int(i) for i in input()] #array from string def starr(): return [str(x) for x in input().split()] #string array def inn(): return int(input()) # integer input def svalue(): return tuple(map(str, input().split())) #multiple string values def parr(): return [(value()) for i in range(n)] # array of pairs mo = 1000000007 # ----------------------------CODE------------------------------# for _ in range(inn()): n=inn() a=arr() if(min(a)>=n): print("YES") continue ans='No' flag=0 for i in range(n): if(a[i]<i): flag=1 if(flag==0): print("Yes") continue flag=0 for i in range(n): if(a[i]<n-i-1): flag=1 if(flag==0): print("Yes") continue flag=0 for i in range(n): if(a[i]<i and a[i]<n-i-1): flag=1 if(n%2==0): res=n//2 if(a[res]==a[res-1]==res-1): flag=1 if(flag==0): print("Yes") continue print(ans) ```
instruction
0
72,633
12
145,266
Yes
output
1
72,633
12
145,267