
import java.net.*;
import java.io.*;
import java.util.*;

//The deer will visit the feeders in random order (waiting 1-3 seconds between visits),
//and they will eat a given amount of food (the amount is different for each deer).
//If there is not enough food in the chosen feeder, the deer eats it all, and prints a message that he is still hungry;
//otherwise, he prints a message that he is happy.
//
//The deer make 5 visits to the feeders, then they exit.
class Deer {
  public static void main(String[] args) throws Exception {
    String host = "localhost";
    int port = 12345;
    Socket s = new Socket(host, port);

    PrintWriter pw = new PrintWriter(s.getOutputStream());
    Scanner sc = new Scanner(s.getInputStream());
    Random rnd = new Random();

    for (int i = 0; i < 5; i++) {
      int sleep_sec = rnd.nextInt(2) + 1; //rnd(0-1) + 1
      if (sleep_sec < 3) {
        sleep_sec += rnd.nextInt(1);//1-3
      }
      Thread.sleep(sleep_sec * 1000); // second to milisecond conversion
      int val = rnd.nextInt(10) + 1;
      pw.println(-val);
      int index = rnd.nextInt(10) + 1;
      pw.println(index);
      pw.flush();
      System.out.println("The deer visited feeder #" + index
                         + " and tried to eat " + val + " food from it.");

      String response = sc.nextLine();
      if ("success".equals(response)) {
        System.out.println("Success. I'm a happy deer.");
      } else {
        System.out.println("There wasn't enough food. I'm still hungry.");
      }
    }

    pw.close();
    sc.close();
    s.close();
  }
}