人生如棋,走错一步,满盘皆输。

A. Elections

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.

The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.

At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.

Determine who will win the elections.

Input

The first line of the input contains two integers n,m (1≤n,m≤100) — the number of candidates and of cities, respectively.

Each of the next m lines contains n non-negative integers, the j-th number in thei-th line aij (1≤j≤n,1≤i≤m, 0≤aij≤109) denotes the number of votes for candidatej in city i.

It is guaranteed that the total number of people in all the cities does not exceed109.

Output

Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.

Sample test(s)

Input

3 31 2 32 3 11 2 1

Output

2

Input

3 410 10 35 1 62 2 21 5 7

Output

1

Note

Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.

Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.

题意很坑,大意就是每个城市给每个候选人投票,行是城市,列是候选人。每次投票只选最大的,并且编号小的,对于候选人票数相同的情况,也一样,选编号小的。

#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>#include <queue>using namespace std;typedef long long ll;int main(){int n,m;ll a[105][105];int b[105];while(cin>>m>>n){memset(a,0,sizeof(a));memset(b,0,sizeof(b));int i,j;for(i=1; i<=n; i++)for(j=1; j<=m; j++){cin>>a[i][j];}int k;int max1;for(i=1; i<=n; i++){max1=-1;for(j=1; j<=m; j++){if(a[i][j]>max1){max1=a[i][j];k=j;}}b[k]++;}max1=-1;for(i=1; i<=100; i++)if(b[i]>max1){k=i;max1=b[i];}cout<<k<<endl;}return 0;}

B. Simple Game

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from1 to n. Let’s assume that Misha chose numberm, and Andrew chose number a.

Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer toc. The boys agreed that if m and a are located on the same distance fromc, Misha wins.

Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and numbern. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.

More formally, you need to find such integer a (1≤a≤n), that the probability that is maximal, wherec is the equiprobably chosen integer from 1 to n (inclusive).

Input

唯有斯人面上簌簌流下的,是点点无声无行的热泪。

人生如棋,走错一步,满盘皆输。

相关文章:

你感兴趣的文章:

标签云: