Description
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds.
The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi, ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
Output
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Sample Input
3 3 5 2 1 4 2
Mishka
2 6 1 1 6
Friendship is magic!^^
3 1 5 3 3 2 2
Chris
Hint
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
int n;
int main()
{
int t1,t2;
int win1,win2;
while(scanf("%d",&n)==1)
{
win1 = 0;
win2 = 0;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&t1,&t2);
if(t1>t2)
{
win1++;
continue;
}
if(t2>t1)
{
win2++;
continue;
}
}
if(win1 > win2)
{
printf("Mishka\n");
}
else if(win1<win2)
{
printf("Chris\n");
}
else
printf("Friendship is magic!^^\n");
}
return 0;
}
Description
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.
Here are some interesting facts about XXX:
- XXX consists of n cities, k of whose (just imagine!) are capital cities.
- All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
- All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
- Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 ≤ i ≤ n, i ≠ x, there is a road between cities x and i.
- There is at most one road between any two cities.
- Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ci·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road betweena and b you are to find sum of products ca·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.
Output
Print the only integer — summary price of passing each of the roads in XXX.
Sample Input
4 1 2 3 1 2 3
17
5 2 3 5 2 2 4 1 4
71
Hint
This image describes first sample case:
It is easy to see that summary price is equal to 17.
This image describes second sample case:
It is easy to see that summary price is equal to 71.
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<conio.h>
typedef long long ll;
using namespace std;
ll n,k;
ll c[100005];
ll mid[100005];
int main()
{
while(scanf("%lld %lld",&n,&k)==2)
{
ll re = 0;
ll sum1 =0;
memset(c,0,sizeof(c));
memset(mid,0,sizeof(mid));
for(int i=1;i<=n;i++)
{
scanf("%lld",&c[i]);
sum1 += c[i];
}
for(int i=1;i<=k;i++)
{
scanf("%lld",&mid[i]);
}
for(int i=1;i<=k;i++)//先计算出首都到其他点的和
{
re += (sum1-c[mid[i]])*c[mid[i]];
sum1 -= c[mid[i]]; //防止首都间重复,
c[mid[i]] = 0; //设置为0,防止相邻间重复
}
for(int i=1;i<n;i++)
{
re += c[i]*c[i+1];
}
re += c[1]*c[n];
printf("%lld\n",re);
}
return 0;
}