Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 11 to nn and then 3n3n times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation. He generates a random permutation just like Petr but swaps elements 7n+17n+1 times instead of 3n3n times. Because it is more random, OK?!
You somehow get a test from one of these problems and now you want to know from which one.
In the first line of input there is one integer nn (103≤n≤106103≤n≤106).
In the second line there are nn distinct integers between 11 and nn — the permutation of size nn from the test.
It is guaranteed that all tests except for sample are generated this way: First we choose nn — the size of the permutation. Then we randomly choose a method to generate a permutation — the one of Petr or the one of Alex. Then we generate a permutation using chosen method.
If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).
5 2 4 5 1 3
Petr
Please note that the sample is not a valid test (because of limitations for nn) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.
Due to randomness of input hacks in this problem are forbidden.
分析:比赛的时候因为卡测评机了,导致D题提交了以后一直在in queue,再加上大晚上的困了,所以就没有开E做,结果第二天一看,这道题比D还容易啊,敲了一发提交就直接过了,看到这道题看到3n和7n+1之后随便带了几个数进去以后发现奇偶是不同的,每个序列交换的奇偶性肯定是 固定,然后就将大乱的序列重新交换位置得到原序列,用从cnt记录一下总共做了几次交换,然后直接比较cnt和3n的奇偶性,相同则输出Peter否则输出Um_nik。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000000+100;
int n;
int a[maxn];
int main(){
cin>>n;
for(int i=1; i<=n; i++){
cin>>a[i];
}
int cnt = 0;
for(int i=1; i<=n; i++){
if(a[i] == i) continue;
while(a[i] != i){
cnt++;
int t = a[i];
swap(a[i], a[t]);
}
}
// for(int i=1; i<=n; i++){
// cout<<a[i]<<" ";
// }
// cout<<endl;
if(n & 1){
if(cnt & 1) cout<<"Petr"<<endl;
else cout<<"Um_nik"<<endl;
}
else {
if(cnt & 1) cout<<"Um_nik"<<endl;
else cout<<"Petr"<<endl;
}
}