#!/usr/bin/env python2.7

import sys, os
from math import *

def raw_input_checked(str_ = ""):
    done = False
    value = 0
    while done == False:
        done = True
        try:
            data = raw_input(str_)
            value = (int(data))
            if (value < 0):
                raise ValueError("Negative Number")
        except (ValueError):
            print("error: [{}] must be a number and positive".format(data))
            done = False
    return value



def buy(portefeuille, cours):
 buy_actions = floor((portefeuille[0]) / cours)
 commission = cours * buy_actions + ceil((0.15 / 100.0 * (cours * buy_actions)))
 if (portefeuille[0] - commission < 0):
  buy_actions = buy_actions - 1
 if (buy_actions > 0):
  portefeuille[0] = portefeuille[0] - cours * buy_actions - ceil((0.15 / 100.0 * (cours * buy_actions)))
  portefeuille[1] = portefeuille[1] + buy_actions
  os.write(1, "buy {}\n".format(buy_actions))
 else:
  os.write(1, "wait\n")

def wait():
 os.write(1, "wait\n")

def sell(portefeuille, cours):
 if (portefeuille[1] > 0):
  os.write(1, "sell {}\n".format(portefeuille[1]))
  portefeuille[0] = portefeuille[0] + portefeuille[1] * cours - ceil((0.15 / 100.0 * (portefeuille[1] * cours)))
  portefeuille[1] = 0
 else:
  os.write(1, "wait\n")

# Calcul de la moyenne mobile exponentielle
def calcul_mme(prev_mme, cours, day):
 C = 2.0 / (day + 1.0)
 return (C * cours + (1.0 - C) * prev_mme)

def analyse(informations, portefeuille, cours):
 if (informations.get("mme_50") > informations.get("mme_150")):
  buy(portefeuille, cours)
 elif (informations.get("mme_50") < informations.get("mme_150")):
  sell(portefeuille, cours)

def getIn(portefeuille, max_day):
 info = raw_input()
 day = 1
 informations = {}
 informations["mme_50"] = 0.0
 informations["mme_150"] = 0.0
 while (info.lower() != "--end--"):
  try:
    cours = (int(info))
  except (ValueError):
    print("error: [{}] must be a number and positive".format(info))
    info = raw_input()
    continue
  if (day == max_day and portefeuille[1] > 0):
   sell(portefeuille, cours)
  else:
   informations["mme_50"] = calcul_mme(informations.get("mme_50"), cours, 50)
   informations["mme_150"] = calcul_mme(informations.get("mme_150"), cours, 150)
   analyse(informations, portefeuille, cours)
  day = day + 1
  info = raw_input()

def main():
 capital = raw_input_checked()
 day = raw_input_checked()
 portefeuille = []
 actions = 0
 portefeuille.append(capital)
 portefeuille.append(actions)
 getIn(portefeuille, day)

if __name__ == "__main__":
   main()
