#include <stdio.h>
using namespace std;
#define ll long long
#define maxN 50010
#define F(i,j,n) for (int i=j; i<=n; i++)
int n,m,P;
ll check[maxN];
ll p[maxN],a[maxN],b[maxN],k[maxN];
int tot;
void prime(int n)
{
tot=0;
F(i,2,n)
{
if (!check[i]) p[++tot]=i;
F(j,1,tot)
{
if (i*p[j]>=maxN) break;
check[i*p[j]]=1;
if (i%p[j]==0) break;
}
}
}
ll ask(ll x,ll z)
{
ll sum=1,x1=x;
for (int i=0; (1<<i)<=z; i++)
{
if (z&(1<<i)) sum=(sum*x1)%P;
x1*=x1;
}
return sum;
}
int main()
{
freopen("2066.in","r",stdin);
freopen("2066.out","w",stdout);
scanf("%d%d%d",&n,&m,&P);
if (m>n-m) m=n-m;
F(i,0,m-1) a[i]=n-i;
F(i,1,m) b[i]=i;
prime(n);
F(i,0,m-1)
F(j,1,tot)
{
while (a[i]%p[j]==0) a[i]/=p[j],k[j]++;
if (a[i]==1) break;
}
F(i,2,m)
F(j,1,tot)
{
while (b[i]%p[j]==0) b[i]/=p[j],k[j]--;
if (b[i]==1) break;
}
ll ans=1;
F(i,1,tot)
ans=(ans*ask(p[i],k[i]))%P;
printf("%lld\n",ans);
return 0;
}
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxN 200010
#define ll long long
#define F(i,j,n) for (int i=j; i<=n; i++)
int n;
ll tr[maxN*4],a[maxN*2],f[maxN];
void update(int l,int r,int root,int pos)
{
if (l==r)
{
tr[root]++;
return ;
}
int mid=(l+r)/2;
if (l<=pos && pos<=mid) update(l,mid,root*2,pos);
if (mid<pos && pos<=r) update(mid+1,r,root*2+1,pos);
tr[root]=tr[root*2]+tr[root*2+1];
}
ll query(int L,int R,int root,int l,int r)
{
if (l>R || L>r) return 0;
if (l<=L && R<=r) return tr[root];
return query(L,(L+R)/2,root*2,l,r)+query((L+R)/2+1,R,root*2+1,l,r);
}
int main()
{
freopen("2067.in","r",stdin);
freopen("2067.out","w",stdout);
scanf("%d",&n);
ll ans=0;
memset(tr,0,sizeof tr);
memset(f,0,sizeof f);
int cnt=0;
F(i,1,n*2)
{
scanf("%d",&a[i]);
if (!f[a[i]]) f[a[i]]=++cnt;
}
F(i,1,n*2)
{
a[i]=f[a[i]];
update(1,n,1,a[i]);
ans+=query(1,n,1,a[i]+1,n);
}
printf("%lld",ans);
return 0;
}
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxN 200010
#define F(i,j,n) for (int i=j; i<=n; i++)
struct Tnode{
int v,w,nxt;
}edge[maxN];
struct Tpoint{
int w,bh;
}p[maxN][4];
int first[maxN],tot;
int du[maxN],used[maxN];
int n;
void init() { memset(first,-1,sizeof first); tot=0;}
void add(int u,int v,int w) { edge[++tot].v=v,edge[tot].w=w,edge[tot].nxt=first[u],first[u]=tot;}
void insert(int v,int max_v,int u)
{
if (max_v>p[u][0].w){
p[u][3]=p[u][2],p[u][2]=p[u][1],p[u][1]=p[u][0];
p[u][0].bh=v,p[u][0].w=max_v;
}else
if (max_v>p[u][1].w){
p[u][3]=p[u][2],p[u][2]=p[u][1];
p[u][1].bh=v,p[u][1].w=max_v;
}else
if (max_v>p[u][2].w){
p[u][3]=p[u][2];
p[u][2].bh=v,p[u][2].w=max_v;
}else
if (max_v>p[u][3].w){
p[u][3].bh=v,p[u][3].w=max_v;
}
}
void dfs(int u)
{
used[u]=1;
for (int i=first[u]; i!=-1; i=edge[i].nxt)
{
int v=edge[i].v;
if (!used[v])
{
dfs(v);
int max_v=p[v][0].w+edge[i].w;
insert(v,max_v,u);
}
}
}
void ask(int u)
{
used[u]=1;
for (int i=first[u]; i!=-1; i=edge[i].nxt)
{
int v=edge[i].v;
if (!used[v])
{
F(j,0,3)
if (p[u][j].bh!=v)
{
int max_u=p[u][j].w+edge[i].w;
insert(u,max_u,v);
break;
}
ask(v);
}
}
}
int main()
{
freopen("2068.in","r",stdin);
freopen("2068.out","w",stdout);
scanf("%d",&n);
init();
F(i,1,n-1)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
du[u]++,du[v]++;
add(u,v,w);
add(v,u,w);
}
dfs(1);
memset(used,0,sizeof used);
ask(1);
int ans=-1;
F(i,1,n)
if (du[i]>=4) ans=max(ans,p[i][0].w+p[i][1].w+p[i][2].w+p[i][3].w);
printf("%d\n",ans);
return 0;
}