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've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up down """ n, k = I() a = sorted(I()) cnt = dd(int) for i in a: cnt[i] += 1 cur = 0 for i in sorted(cnt.keys()): cur += cnt[i] * n if cur < k: continue ans = [0, 0] cur -= cnt[i] * n r = k - cur ans[0] = i ans[1] = a[(r - 1) // cnt[i]] break print(*ans) ```
instruction
0
71,923
12
143,846
Yes
output
1
71,923
12
143,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` n,k=map(int,input().split()) ar=list(map(int,input().split())) ar=sorted(ar) summ=0 flag=True for i in range(n): if (i+1)*n>=k: break x=ar.count(ar[i]) c=ar.index(ar[i]) y=((k-1)-c*n)//x print(ar[i],ar[y]) ```
instruction
0
71,924
12
143,848
Yes
output
1
71,924
12
143,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` from sys import stdin, stdout def read_ints(): return map(int, stdin.readline().split(' ')) n, k = read_ints() a = list(read_ints()) a.sort() l = (k - 1) // n lo = l while lo > 0 and a[lo - 1] == a[lo]: lo -= 1 hi = l while hi + 1 < n and a[hi + 1] == a[hi]: hi += 1 length = hi - lo + 1 acc = k - lo * n r = (acc - 1) // length stdout.write('{} {}'.format(a[l], a[r])) ```
instruction
0
71,925
12
143,850
Yes
output
1
71,925
12
143,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` # your code goes here n, k = map(int, input().split()) series = list(map(int, input().split())) series.sort() digit1 = series[(k-1)//n] ind, cnt = series.index(digit1), series.count(digit1) digit2_ind = ((k-1) - ind * n)//cnt digit2 = series[digit2_ind] print(digit1,digit2) ```
instruction
0
71,926
12
143,852
Yes
output
1
71,926
12
143,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` import math from os import curdir, startfile import random from queue import Queue import time import heapq import sys def main(arr,k): n=len(arr) arr.sort() val=1 first=k//n-val if k%n==0 else k//n second=k%n-1 if second==-1: second=first print(arr[first],arr[second]) n,k=list(map(int,input().split())) arr=list(map(int,input().split())) main(arr,k) ```
instruction
0
71,927
12
143,854
No
output
1
71,927
12
143,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` n,b=map(int,input().split()) l=list(map(int,input().split())) b-=1 l.sort() c=b//n e=b%n print(l[c],l[e]) ```
instruction
0
71,928
12
143,856
No
output
1
71,928
12
143,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` # https://codeforces.com/contest/160/problem/C """ Sort the list. The lexicographic order will look like (a1, a1), ..., (a1, an) ... (an, a1), ..., (an, an) Hence we simply need to find the quotient remainder theorem form on k-1 and n. k-1 = p*n + q. (k-1 as counting from 0.) """ n, k = map(int, input().split()) a = sorted(map(int, input().split())) q = (k - 1) % n p = (k - 1 - q) // n print(a[p], a[q]) ```
instruction
0
71,929
12
143,858
No
output
1
71,929
12
143,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≀ i, j ≀ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (3, 3), (3, 1), (3, 5), (1, 3), (1, 1), (1, 5), (5, 3), (5, 1), (5, 5). Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (p1, q1) is lexicographically less than pair (p2, q2) only if either p1 < p2, or p1 = p2 and q1 < q2. Then the sequence, mentioned above, will be sorted like that: (1, 1), (1, 3), (1, 5), (3, 1), (3, 3), (3, 5), (5, 1), (5, 3), (5, 5) Let's number all the pair in the sorted list from 1 to n2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given. Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout, streams or the %I64d specificator instead. Output In the single line print two numbers β€” the sought k-th pair. Examples Input 2 4 2 1 Output 2 2 Input 3 2 3 1 5 Output 1 3 Note In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). Submitted Solution: ``` from math import ceil,floor n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() x = ceil(k/n) m = k%n print(a[x-1],a[m-1]) ```
instruction
0
71,930
12
143,860
No
output
1
71,930
12
143,861
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,987
12
143,974
Tags: brute force, implementation, math Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) k,t=0,0 for i in range(n): if i == l[i]:k+=1 elif i == l[l[i]]:t=1 print(min(k+1+t,n)) ```
output
1
71,987
12
143,975
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,988
12
143,976
Tags: brute force, implementation, math Correct Solution: ``` def main(): n = map(int,input().split()) a = list(map(int,input().split())) cnt = 0 for i in range(len(a)): if a[i]==i: cnt+=1 if cnt==len(a): print(cnt) return for i in range(len(a)): if a[i]!=i: if i==a[a[i]]: print(cnt+2) return print(cnt+1) return main() ```
output
1
71,988
12
143,977
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,989
12
143,978
Tags: brute force, implementation, math Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) c=0 f=0 for i in range(n): if a[i]==i: c+=1 for i in range(n): if a[i]!=i: if a[a[i]]==i: f=1 break if f==0 and c!=n: c+=1 elif f==1 and c!=n: c+=2 print(c) ```
output
1
71,989
12
143,979
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,990
12
143,980
Tags: brute force, implementation, math Correct Solution: ``` n = int(input()) a = [int(i) for i in input().split()] count = 0 add = 0 for i in range(n): if (a[i] == i): count += 1 else: if (a[a[i]] == i): add = 1 if (count != n): add += 1 print (count + add) ```
output
1
71,990
12
143,981
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,991
12
143,982
Tags: brute force, implementation, math Correct Solution: ``` n=int(input());a=list(map(int,input().split()));o,ot=0,0 for i in range(n): if(a[i]==i):o+=1 for i in range(n): if(a[i]!=i): if(i==a[a[i]]):ot=2 else:ot=max(ot,1) print(ot+o) ```
output
1
71,991
12
143,983
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,992
12
143,984
Tags: brute force, implementation, math Correct Solution: ``` n=int(input()) a=[int(num) for num in input().split()] max=0 flag=0 for i in range(0,n): if a[i]==i: max=max+1 elif a[a[i]]==i and flag!=1: temp=a[i] a[i]=a[temp] a[temp]=temp max=max+1 flag=1 elif flag!=1: flag=2 if flag==2: max=max+1 print(max) ```
output
1
71,992
12
143,985
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,993
12
143,986
Tags: brute force, implementation, math Correct Solution: ``` def fixed_points(n, a): count = 0 fixed = 0 for i, j in enumerate(a): if i == j: fixed += 1 elif a[j] == i: count = 2 elif count == 0: count = 1 return fixed + count if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) result = fixed_points(n, a) print(result) ```
output
1
71,993
12
143,987
Provide tags and a correct Python 3 solution for this coding contest problem. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3
instruction
0
71,994
12
143,988
Tags: brute force, implementation, math Correct Solution: ``` s, k, n = 0, 0, int(input()) t = list(map(int, input().split())) for i in range(n): if i == t[i]: s += 1 elif k < 2: if t[t[i]] == i: k = 2 else: k = 1 print(s + k) ```
output
1
71,994
12
143,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` n = int(input()) l = list(map(int, input().split(' '))) certos = 0 achou_2 = False errados = 0 for i in range(len(l)): if l[i] == i: certos += 1 else: errados += 1 if l[l[i]] == i: achou_2 = True if errados > 1: if achou_2: certos += 2 else: certos += 1 print(certos) # 1518733072890 ```
instruction
0
71,995
12
143,990
Yes
output
1
71,995
12
143,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) ans = 0 ans1 = 0 for i in range(len(a)): if a[i] == i: ans += 1 ans1 += 1 if ans != n: for i in range(len(a)): if a[i] != i: if a[a[i]] == i: ans += 2 break if ans == ans1: ans += 1 print(ans) ```
instruction
0
71,996
12
143,992
Yes
output
1
71,996
12
143,993
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` from sys import stdin def max_nb_fixed_points(n, permutation): pos_for_val = {} initial_fixed = 0 double_swap = False single_swap = False for i in range(n): if i == permutation[i]: initial_fixed += 1 continue if not double_swap: if i in pos_for_val: j = pos_for_val[i] if permutation[i] == j: double_swap = True else: single_swap = True pos_for_val[permutation[i]] = i if double_swap: return initial_fixed + 2 if single_swap: return initial_fixed + 1 return initial_fixed if __name__ == "__main__": n = int(stdin.readline()) permutation = [int(c) for c in stdin.readline().split(" ")] print(max_nb_fixed_points(n, permutation)) ```
instruction
0
71,997
12
143,994
Yes
output
1
71,997
12
143,995
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` def solve (n,seq) : times = 0 temp_fixed = 0 done = 0 s = list(enumerate(seq)) for i,j in s : if i == j : times += 1 elif done == 0 : if s[j][1] == i and j == s[j][0] : temp_fixed = 2 done = 1 elif s[j][1] == i or j == s[j][0] : temp_fixed = 1 return times + temp_fixed n = int(input()) seq = list(map(int,input().split())) print (solve(n,seq)) ```
instruction
0
71,998
12
143,996
Yes
output
1
71,998
12
143,997
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` n = int(input()) ai = list(map(int,input().split())) cnt = 0 for i in range(0,len(ai)): if ai[i] <= i: cnt += 1 print(cnt) ```
instruction
0
71,999
12
143,998
No
output
1
71,999
12
143,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` n = int(input()) a = [] inp = input() a = [int(x) for x in inp.split(' ')] result = 0 swaped = False for i in range(len(a)): if i == a[i]: result += 1 if a[a[i]] == i: result += 2 swaped = True break if swaped: pass else: result +=1 print(result) ```
instruction
0
72,000
12
144,000
No
output
1
72,000
12
144,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` # import math # import bisect import sys from collections import Counter input = sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(s[:len(s)-1]) def invr(): return(map(int,input().split())) # list1, list2 = zip(*sorted(zip(list1, list2))) N = inp() L = inlt() out = 0 fl = True for n in range(N): if n == L[n]: out += 1 if fl and L[L[n]] == n: out += 1 fl = False print(out) ```
instruction
0
72,001
12
144,002
No
output
1
72,001
12
144,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points. You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input The first line contains a single integer n (1 ≀ n ≀ 105). The second line contains n integers a0, a1, ..., an - 1 β€” the given permutation. Output Print a single integer β€” the maximum possible number of fixed points in the permutation after at most one swap operation. Examples Input 5 0 1 3 4 2 Output 3 Submitted Solution: ``` x=int(input()) x=input().split() y=[int(p) for p in x] fpts=[] nfpts=[] for x in y: if( x==y.index(x)): fpts.append(x) else:nfpts.append(x) for x in nfpts : if(y[x]==y.index(x)): print(len(fpts)+2) break; else: print(len(fpts)+1) if(len(nfpts)==0): print(len(fpts)) ```
instruction
0
72,002
12
144,004
No
output
1
72,002
12
144,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of length n is a sequence of distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n). A permutation is an identity permutation, if for any i the following equation holds pi = i. A swap (i, j) is the operation that swaps elements pi and pj in the permutation. Let's assume that f(p) is the minimum number of swaps that you need to make the permutation p an identity permutation. Valera wonders, how he can transform permutation p into any permutation q, such that f(q) = m, using the minimum number of swaps. Help him do that. Input The first line contains integer n (1 ≀ n ≀ 3000) β€” the length of permutation p. The second line contains n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) β€” Valera's initial permutation. The last line contains integer m (0 ≀ m < n). Output In the first line, print integer k β€” the minimum number of swaps. In the second line, print 2k integers x1, x2, ..., x2k β€” the description of the swap sequence. The printed numbers show that you need to consecutively make swaps (x1, x2), (x3, x4), ..., (x2k - 1, x2k). If there are multiple sequence swaps of the minimum length, print the lexicographically minimum one. Examples Input 5 1 2 3 4 5 2 Output 2 1 2 1 3 Input 5 2 1 4 5 3 2 Output 1 1 2 Note Sequence x1, x2, ..., xs is lexicographically smaller than sequence y1, y2, ..., ys, if there is such integer r (1 ≀ r ≀ s), that x1 = y1, x2 = y2, ..., xr - 1 = yr - 1 and xr < yr. Submitted Solution: ``` n=int(input()) L=list(map(int,input().split())) Pos=[0]*n y=0 for i in range(n): L[i]-=1 Pos[L[i]]=i if(L[i]!=i): y+=1 Ans=[] m=int(input()) Ans=[] if(y>m+1 and n!=1): e=y-m-1 while(e>=1): q1=0 while(L[q1]==q1): q1+=1 q2=q1+1 cont=False while(cont or L[q2]==q2): cont=False q2+=1 if(q2!=L[q2] and L[q2]==q1 and e==1): cont=True numx=L[q1] posx=q1 numy=L[q2] posy=q2 if(posx==numy): e-=2 Ans.append((posx,posy)) L[numx]=numx Pos[numx]=numx L[numy]=numy Pos[numy]=numy else: e-=1 Ans.append((posx,posy)) L[numx]=numx Pos[numx]=numx L[posx]=numy Pos[numy]=posx if(y<m+1 and n!=1): e=m+1-y while(e>=1): q1=0 while(L[q1]!=q1): q1+=1 q2=q1+1 cont=True q2=0 while(1): if(q2==q1): q2+=1 continue if(L[q2]==q2 and e==1): q2+=1 continue break numx=L[q1] posx=q1 numy=L[q2] posy=q2 b=min(posx,posy) c=max(posx,posy) Ans.append((b,c)) L[posx],L[posy]=L[posy],L[posx] Pos[numx],Pos[numy]=Pos[numy],Pos[numx] e-=2 print(len(Ans)) for i in range(len(Ans)): print(Ans[i][0]+1,Ans[i][1]+1,end=" ") ```
instruction
0
72,033
12
144,066
No
output
1
72,033
12
144,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A permutation p of length n is a sequence of distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n). A permutation is an identity permutation, if for any i the following equation holds pi = i. A swap (i, j) is the operation that swaps elements pi and pj in the permutation. Let's assume that f(p) is the minimum number of swaps that you need to make the permutation p an identity permutation. Valera wonders, how he can transform permutation p into any permutation q, such that f(q) = m, using the minimum number of swaps. Help him do that. Input The first line contains integer n (1 ≀ n ≀ 3000) β€” the length of permutation p. The second line contains n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) β€” Valera's initial permutation. The last line contains integer m (0 ≀ m < n). Output In the first line, print integer k β€” the minimum number of swaps. In the second line, print 2k integers x1, x2, ..., x2k β€” the description of the swap sequence. The printed numbers show that you need to consecutively make swaps (x1, x2), (x3, x4), ..., (x2k - 1, x2k). If there are multiple sequence swaps of the minimum length, print the lexicographically minimum one. Examples Input 5 1 2 3 4 5 2 Output 2 1 2 1 3 Input 5 2 1 4 5 3 2 Output 1 1 2 Note Sequence x1, x2, ..., xs is lexicographically smaller than sequence y1, y2, ..., ys, if there is such integer r (1 ≀ r ≀ s), that x1 = y1, x2 = y2, ..., xr - 1 = yr - 1 and xr < yr. Submitted Solution: ``` def ID(L): x=0 for i in range(n): Pos[L[i]]=i for i in range(n): if(Pos[i]==i): continue e=Pos[i] q=L[i] L[i],L[Pos[i]]=L[Pos[i]],L[i] Pos[i],Pos[q]=i,e x+=1 return x n=int(input()) L=list(map(int,input().split())) Pos=[0]*3001 for i in range(n): L[i]-=1 y=ID(list(L)) for i in range(n): Pos[L[i]]=i Ans=[] m=int(input()) Ans=[] if(y>m and n!=1): e=y-m while(e>=1): q1=0 while(L[q1]==q1): q1+=1 q2=q1+1 while(L[q2]==q2): q2+=1 numx=L[q1] posx=q1 numy=L[q2] posy=q2 if(posx==numy): e-=1 Ans.append((posx,posy)) L[numx]=numx Pos[numx]=numx L[numy]=numy Pos[numy]=numy else: e-=1 Ans.append((posx,posy)) L[numx]=numx Pos[numx]=numx L[posx]=numy Pos[numy]=posx if(y<m and n!=1): e=m-y #print(L) while(e>=1): q1=0 while(L[q1]!=q1): q1+=1 q2=q1+1 cont=True q2=0 while(1): if(q2==q1): q2+=1 continue if(L[q2]!=q2 and e>1): q2+=1 continue break numx=L[q1] posx=q1 numy=L[q2] posy=q2 b=min(posx,posy) c=max(posx,posy) Ans.append((b,c)) L[posx],L[posy]=L[posy],L[posx] Pos[numx],Pos[numy]=Pos[numy],Pos[numx] e-=1 print(len(Ans)) for i in range(len(Ans)): print(Ans[i][0]+1,Ans[i][1]+1,end=" ") ```
instruction
0
72,034
12
144,068
No
output
1
72,034
12
144,069
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,137
12
144,274
Tags: dp, greedy, implementation Correct Solution: ``` for _ in range(1): n=int(input()) # n,k=map(int,input().split()) a=list(map(int,input().split())) mn=1 mx=1 i=0 while(i<n-1): if(a[i]<a[i+1]): mn=mn+1 i=i+1 else: i=i+1 mn=1 if(mn>mx): mx=mn print(mx) ```
output
1
72,137
12
144,275
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,138
12
144,276
Tags: dp, greedy, implementation Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) big=1 c=1 for i in range(n-1): if a[i+1]>a[i]: c+=1 else: big=max(big,c) c=1 print(max(big,c)) ```
output
1
72,138
12
144,277
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,139
12
144,278
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) a = list([int(x) for x in input().split()]) i = 1 res = 1 ans = 1 while i != n: if a[i-1] < a[i]: res += 1 else: ans = max(res, ans) res = 1 i += 1 ans = max(res, ans) print(ans) ```
output
1
72,139
12
144,279
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,140
12
144,280
Tags: dp, greedy, implementation Correct Solution: ``` n, a, b, c = input(), 0, 0, 0 for x in list(map(int, input().split())): c = c + 1 if x > a else 1 b = max(c, b) a = x print(b) ```
output
1
72,140
12
144,281
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,141
12
144,282
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) a = input().split() b = [1 for i in range(n)] a[0] = int(a[0]) for i in range(1, n): a[i] = int(a[i]) if a[i] > a[i-1]: b[i] += b[i-1] k = b[0] for i in range(n): k = max(k, b[i]) print(k) ```
output
1
72,141
12
144,283
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,142
12
144,284
Tags: dp, greedy, implementation Correct Solution: ``` import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[:len(s) - 1]) def invr(): return map(int, input().split()) def solve(ip): i = 0 j = i + 1 max = 1 while (i <= j) and j < len(ip): current = 1 while i < j < len(ip) and (ip[i] < ip[j]) : current = current + 1 j = j + 1 i = i+1 if current > max: max = current i = i + 1 j = j + 1 print(max) n = inp() ip = inlt() solve(ip) ```
output
1
72,142
12
144,285
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,143
12
144,286
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) l = list(map(int, input().split())) ans = 0 tmp = 1 for i in range(1, n): if l[i] > l[i - 1]: tmp += 1 else: if tmp > ans: ans = tmp tmp = 1 if tmp > ans: ans = tmp print (ans) ```
output
1
72,143
12
144,287
Provide tags and a correct Python 3 solution for this coding contest problem. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3
instruction
0
72,144
12
144,288
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) v = list(map(int, input().split())) mx = 1 dp = [0]*n dp[0] = 1 for i in range(1, n): if v[i] > v[i-1]: dp[i] = dp[i-1]+1 else: dp[i] = 1 mx = max(dp[i], mx) print(mx) ```
output
1
72,144
12
144,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) max_l = 1 l = 1 for i in range(n-1): if(a[i+1] > a[i]): l += 1 if(l > max_l): max_l=l else: l = 1 print(max_l) ```
instruction
0
72,145
12
144,290
Yes
output
1
72,145
12
144,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` n=int(input()) s=str(input()).split() l=list() for i in s: l.append(int(i)) nl=list() c=1 for k in range(len(l)-1): if l[k]<l[k+1]: c=c+1 nl.append(c) else: c=1 if len(nl)!=0: print(max(nl)) else: print(1) ```
instruction
0
72,146
12
144,292
Yes
output
1
72,146
12
144,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` import math x = list(map(int, input().split())) s = [] s = list(map(int, input().split())) q_temp = 1 q = 1 for i in range(1,x[0]): if s[i] <= s[i-1]: q_temp = 1 else: q_temp += 1 q = max(q,q_temp) print(q) ```
instruction
0
72,147
12
144,294
Yes
output
1
72,147
12
144,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` n=int(input());j=1;r=0 L=list(map(int,input().split()))+[-1] for k in range(n): if(L[k]<L[k+1]): j+=1 else: if(j>r): r=j j=1 print(r) ```
instruction
0
72,148
12
144,296
Yes
output
1
72,148
12
144,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` str = int(input()) str = input() Array = [int(x) for x in str.split()] pred = Array[0] count=1 for i in Array[1:]: if i>pred: count+=1 pred = i else: count = 1 print(count) ```
instruction
0
72,149
12
144,298
No
output
1
72,149
12
144,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` input() #cons = [int(x) for x in input().split()] cons = list(map(int, input().split())) backitem = 0 count = 1 for item in cons: if item > backitem: count += 1 else: count = 1 backitem = item print(count) ```
instruction
0
72,150
12
144,300
No
output
1
72,150
12
144,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` n=int(input()) z=list(map(int,input().split())) arr=[] count=1 for i in range(n-1) : if z[i]<z[i+1] : count+=1 else : arr.append(count) count=1 print(max(arr)) ```
instruction
0
72,151
12
144,302
No
output
1
72,151
12
144,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line contains single positive integer n (1 ≀ n ≀ 105) β€” the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). Output Print the maximum length of an increasing subarray of the given array. Examples Input 5 1 7 2 11 15 Output 3 Input 6 100 100 100 100 100 100 Output 1 Input 3 1 2 3 Output 3 Submitted Solution: ``` n = int(input()) count = 1 maxCount = 1 nums = [int(num) for num in input().split()] for i in range(1,n): if nums[i] > nums[i-1]: count += 1 else: maxCount = max(maxCount,count) count = 1 print(maxCount) ```
instruction
0
72,152
12
144,304
No
output
1
72,152
12
144,305
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,153
12
144,306
Tags: brute force, greedy, implementation, math Correct Solution: ``` import sys def swapC(c1, c2): for r in range(n): swap(r, c1, c2) def swap(r, c1, c2): nums[r][c1], nums[r][c2] = nums[r][c2], nums[r][c1] def checkRow(r): bad = [] for i in range(m): if nums[r][i] != i: bad.append(i) if len(bad) == 0: return True if len(bad) != 2: return False x0, x1 = nums[r][bad[0]], nums[r][bad[1]] return bad[0] == x1 and bad[1] == x0 def checkAll(): for r in range(n): if not checkRow(r): return False return True n, m = map(int, input().split()) nums = [list(map(lambda x: int(x) - 1, input().split())) for i in range(n)] flag = False for c1 in range(m): for c2 in range(c1, m): swapC(c1, c2) if checkAll(): print("YES") flag = True break swapC(c1, c2) if flag: break else: print("NO") ```
output
1
72,153
12
144,307
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,154
12
144,308
Tags: brute force, greedy, implementation, math Correct Solution: ``` n, m = map(int, input().split()) a = [input().split() for _ in range(n)] for l in range(m): for r in range(l, m): for s in a: s1 = s.copy() s1[l], s1[r] = s1[r], s1[l] if sum(int(s1[i]) != i + 1 for i in range(m)) > 2: break else: print('YES') exit() print('NO') ```
output
1
72,154
12
144,309
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,155
12
144,310
Tags: brute force, greedy, implementation, math Correct Solution: ``` def solve(): n, m = map(int, input().split()) tab = [list(map(int, input().split())) for _ in range(n)] def ordered(l): for i in range(len(l) - 1): if l[i] > l[i + 1]: return False return True def canswap(l): if ordered(l): return True for i in range(len(l)): for j in range(i + 1, len(l)): lc = list(l) lc[i], lc[j] = lc[j], lc[i] if ordered(lc): return True return False works = True for row in tab: if not canswap(row): works = False if works: return True for coli in range(m): for colj in range(coli, m): works = True for rowref in tab: row = list(rowref) row[coli], row[colj] = row[colj], row[coli] if ordered(row): continue good = False for i in range(m): if good: break for j in range(m): row = list(rowref) row[i], row[j] = row[j], row[i] row[coli], row[colj] = row[colj], row[coli] if ordered(row): good = True break row = list(rowref) row[coli], row[colj] = row[colj], row[coli] row[i], row[j] = row[j], row[i] if ordered(row): good = True break if not good: works = False break if works: return True return False res = solve() print("YES" if res else "NO") ```
output
1
72,155
12
144,311
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,156
12
144,312
Tags: brute force, greedy, implementation, math Correct Solution: ``` import copy n,m = map(int,input().split()) l = [] for i in range(n) : l.append(list(map(int,input().split()))) def test_matrix(l) : test = 1 for i in range(n) : rem = 0 k = 1 for j in range(m) : if l[i][j] != j+1 and rem == 0 : rem = {j+1,l[i][j]} elif l[i][j] != j+1 and (l[i][j] not in rem) : k = 0 break if k == 0 : test = 0 break if test == 0 : return False else : return True ola = 0 if test_matrix(l) == True : ola = 1 for i in range(m) : for j in range(i+1,m) : b = copy.deepcopy(l) for p in range(n) : b[p][i],b[p][j] = b[p][j],b[p][i] if test_matrix(b) == True : ola = 1 break if ola == 1 : break if ola == 1 : print('YES') else : print('NO') ```
output
1
72,156
12
144,313
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,157
12
144,314
Tags: brute force, greedy, implementation, math Correct 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 f=-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 h==-1 and f==-1: 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()) ```
output
1
72,157
12
144,315
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,158
12
144,316
Tags: brute force, greedy, implementation, math Correct Solution: ``` n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input().split()))) def check(x, y): for i in range(n): k = 0 for j in range(m): if (j == x): if (a[i][y] != j + 1): k += 1 elif (j == y): if (a[i][x] != j + 1): k += 1 elif (a[i][j] != j + 1): k += 1 if k > 2: return False return True for e in range(m): for r in range(m): if check(e, r): print('YES') exit() print('NO') ```
output
1
72,158
12
144,317
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,159
12
144,318
Tags: brute force, greedy, implementation, math Correct Solution: ``` def check(matrix, getindex = False, isfirst = False): indices = set() canbe = True for row in matrix: count = 0 for i, value in enumerate(row): if value != i+1 : indices.update([i]) count += 1 if count >2: canbe = False if count >4 and isfirst: print("NO") exit() if getindex: return list(indices) return canbe n, m = map(int, input().split()) matrix = [] for i in range(n): row = [int(x) for x in input().split()] matrix.append(row) indices = check(matrix, True, True) canbesort = check(matrix) for i in indices: if canbesort: break for j in indices[1:]: for k in range(n): matrix[k][i], matrix[k][j] = matrix[k][j], matrix[k][i] canbesort = check(matrix) if canbesort: break for k in range(n): matrix[k][i], matrix[k][j] = matrix[k][j], matrix[k][i] print(canbesort and 'YES' or 'NO') ```
output
1
72,159
12
144,319
Provide tags and a correct Python 3 solution for this coding contest problem. 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
instruction
0
72,160
12
144,320
Tags: brute force, greedy, implementation, math Correct Solution: ``` n, m = map(int, input().split(' ')) a = [] for i in range(n): a.append(list(map(int, input().split(' ')))) p = [] possible = True col_swap = False #print('swaps:') for r in a: x = [] j = 0 swaps = [] while j < len(r) and len(swaps) < 3: if r[j] != j + 1: tmp = r[j] r[j] = r[tmp - 1] r[tmp - 1] = tmp swaps.append((j, tmp - 1)) else: j += 1 #print(swaps) if len(swaps) > 2: possible = False break if len(swaps) == 2: col_swap = True if len(swaps) > 0: x = swaps if len(swaps) == 2 and swaps[0][0] == swaps[1][0]: x.append(( min(swaps[0][1], swaps[1][1]), max(swaps[0][1], swaps[1][1]) )) p.append(x) #print('possible:', possible, 'p:', p, 'col_swap:', col_swap) if possible and col_swap and p: c = set(p[0]) for x in p: c = c.intersection(x) possible = bool(c) #print('c:', c) if possible: print('YES') else: print('NO') ```
output
1
72,160
12
144,321