## Algorithm

Problem Name: beecrowd | 2554

# Pizza Before BH

By Ricardo Oliveira, UFPR Brazil

Timelimit: 1

The Nlogonian Aquatic Surf Championship, to be hosted in Bonita Horeleninha (BH) city, is about to start! Before going to BH, you and your N-1 friends decided to go for a pizza, so you can relax and have some fun (and, of course, eat!).

At this moment you are choosing the date for the event. To make sure everyone can enjoy it, it was decided that the meeting is to be set in a day so that all the N people can show up at the pizzeria on that date.

Given the list of dates considered for the event and the information about which people can show up at which dates, determine if the event can happen and, if it can, its date. If more than one date is possible, the event must occur as early as possible.

## Input

The input contains several test cases. The first line of each test case contains integers N and D (1 ≤ N, D ≤ 50), the number of people and the number of considered dates. People are numbered from 1 to N. Next D lines describe the considered dates. Each line begins with a date in the format day∕month∕year. The line is followed by N integers p1,p2,...,pN. The integer pi is 1 if the i-th person can show up at the considered date, or 0 otherwise. It is guaranteed that dates are always valid, and there aren’t leading zeros. Also, all dates are given in order, from the earliest to the latest day.

The input ends with end-of-file (EOF).

## Output

For each test case, print one line with the date in the format day∕month∕year, exactly as it appears in the input. If it is not possible to hold the event, print “Pizza antes de FdI” (without quotes).

 Input Sample Output Sample 4 4 1/6/2016 0 0 1 0 12/7/2016 1 1 1 0 5/10/2016 1 1 1 1 25/12/2016 0 0 0 0 5 3 20/9/2016 0 1 1 1 1 30/9/2016 1 0 1 1 1 1/10/2016 1 1 0 1 1 5/10/2016 Pizza antes de FdI

## Code Examples

### #1 Code Example with C Programming

```Code - C Programming```

``````
#include <stdio.h>

struct date
{
int day;
int month;
int year;
};

int main(void)

{
int a, b, i, j, x, y, z=0, c=1;

while (scanf("%d %d", &a, &b) != EOF)
{
struct date d[b];

z=-1;
c=1;

for (i = 0; i  <  b; ++i)
{
scanf("%d/%d/%d", &d[i].day, &d[i].month, &d[i].year);

y=0;

for (j = 0; j  <  a; ++j)
{
scanf("%d", &x);

if (x==1)
++y;
}

if (y==a && c)
{
z=i;
c=0;
}
}

if (z>=0)
printf("%d/%d/%d\n", d[z].day, d[z].month, d[z].year);

else
printf("Pizza antes de FdI\n");
}

return 0;
}

``````
Copy The Code &

### #2 Code Example with Java Programming

```Code - Java Programming```

``````
import java.util.Scanner;
import java.util.Locale;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useLocale(Locale.ENGLISH);
Locale.setDefault(new Locale("en", "US"));

while(sc.hasNext()) {
String[] P = sc.nextLine().split(" ");
int N = Integer.parseInt(P[0]); //numero de pessoas
int D = Integer.parseInt(P[1]); //datas consideradas
int soma=0, c=0;
String[] entrada = new String[N+1];

for(int x = 0 ; x  <  D ; x++) {
soma=0;
entrada = sc.nextLine().split(" ");
//data[0][x] = Integer.toString(x);
for (int i = 1 ; i  <  entrada.length ; i++)
if (entrada[i].equals("1"))
soma++;
if (soma == N && c!=1) {
System.out.println(entrada[0]);
c=1;
}
}
if (c==0)
System.out.println("Pizza antes de FdI");
}
sc.close();
}
}

``````
Copy The Code &
Advertisements