## Algorithm

Problem Name: 2 AD-HOC - beecrowd | 1414

# World Cup

By Alessandro Luna de Almeida Brasil

Timelimit: 1

A Button Soccer World Cup is being held with teams from around the world. The classification is based on the number of points earned by the teams, and the distribution of points is done in the usual way. That is, when a team wins a game, it gets 3 points if the game ends in a draw, both teams get 1 point, and the loser no points.

Given the current standings of the teams and the number of participating teams in the World Cup, his task is to determine how many games ended in draws so far.

## Input

The input contains several test cases. The first line of a test case contains two integers T and N, respectively indicating the number of participating teams (2 ≤ T ≤ 200) and the number of matches played (0 ≤ N ≤ 10000). Each of the next T lines contains the name of a team (a string of up to 10 letters and digits), a space, and the number of points the team got so far. The end of input is indicated by T = 0.

## Output

For each test case your program must print a single line containing an integer representing the amount of games ended in draws.

 Sample Input Sample Output 3 3 Brasil 3 Australia 3 Croacia 3 3 3 Brasil 5 Japao 1 Australia 1 0 0 02

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <iostream>
#include <string>

using namespace std;

int main()
{
ios::sync_with_stdio(false);
int t, n, p;
for (cin >> t >> n; t != 0; cin >> t >> n) {
string time;
cin.ignore();
int sum = 0;
for (int i = 0; i  <  t; ++i) {
cin >> time >> p;
sum += p;
}
cout << n * 3 - sum << "\n";
}
return 0;
}
``````
Copy The Code &

Input

cmd
3 3
Brasil 3
Australia 3
Croacia 3
3 3
Brasil 5
Japao 1
Australia 1
0 0

Output

cmd
0
2

### #2 Code Example with Java Programming

```Code - Java Programming```

``````
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
static Writer out = new Writer(System.out);

public static void main(String[] args) throws IOException {
int T, N, points;
while (true) {
T = in.nextInt();
N = in.nextInt();
if (T + N == 0) {
break;
}
points = 0;
while (T-- > 0) {
in.next();
points += in.nextInt();
}
out.println(N * 3 - points);
}
in.close();
out.flush();
out.close();
}

////////////////////////////////////////////////////////////////////////////
/////////////////////////////  INPUT / OUTPUT  /////////////////////////////
////////////////////////////////////////////////////////////////////////////
static class Reader implements Closeable {

private StringTokenizer tokenizer;

tokenizer = new StringTokenizer("");
}

private StringTokenizer getTokenizer() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
String line = nextLine();
if (line == null) {
return null;
}
tokenizer = new StringTokenizer(line);
}
}

public boolean hasNext() throws IOException {
return getTokenizer() != null;
}

public String next() throws IOException {
return hasNext() ? tokenizer.nextToken() : null;
}

public String nextLine() throws IOException {
tokenizer = null;
}

public int nextInt() throws IOException {
return Integer.parseInt(next());
}

public long nextLong() throws IOException {
return Long.parseLong(next());
}

public float nextFloat() throws IOException {
return Float.parseFloat(next());
}

public double nextDouble() throws IOException {
return Double.parseDouble(next());
}

public String[] nextStringArray(int size) throws IOException {
String[] array = new String[size];
for (int i = 0; i  <  size; i++) {
array[i] = next();
}
return array;
}

public int[] nextIntArray(int size) throws IOException {
int[] array = new int[size];
for (int i = 0; i  <  size; i++) {
array[i] = nextInt();
}
return array;
}

public long[] nextLongArray(int size) throws IOException {
long[] array = new long[size];
for (int i = 0; i  <  size; i++) {
array[i] = nextLong();
}
return array;
}

public double[] nextDoubleArray(int size) throws IOException {
double[] array = new double[size];
for (int i = 0; i  <  size; i++) {
array[i] = nextDouble();
}
return array;
}

@Override
public void close() throws IOException {
tokenizer = null;
}
}

static class Writer {

private final PrintWriter writer;

public Writer(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}

public void print(Object... objects) {
for (int i = 0; i  <  objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}

public void println(Object... objects) {
print(objects);
writer.println();
}

public void close() {
writer.close();
}

public void flush() {
writer.flush();
}

}
}
``````
Copy The Code &

Input

cmd
3 3
Brasil 3
Australia 3
Croacia 3
3 3
Brasil 5
Japao 1
Australia 1
0 0

Output

cmd
0
2