/******************************************************************/
/* ACM ICPC 2012-2013                                             */
/* Northeastern European Regional Contest                         */
/* St Petersburg - Barnaul - Tashkent - Tbilisi, December 2, 2012 */
/******************************************************************/
/* Problem B. Blind Problem Solving                               */
/*                                                                */
/* Original idea         Maxim Buzdalov                           */
/* Problem statement     Maxim Buzdalov                           */
/* Test set              Maxim Buzdalov                           */
/******************************************************************/
/* Interactor                                                     */
/*                                                                */
/* Author                Maxim Buzdalov                           */
/******************************************************************/

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

public class Interact {
    static final int COMMAND_LIMIT = 1000;

    static int weight(int mask, int[] weights) {
        int n = weights.length;
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            if (((mask >>> j) & 1) == 1) {
                sum += weights[j];
            }
        }
        return sum;
    }

    static int solve(int c, int[] weights) {
        int optimalW = 0;
        int optimalA = 0;
        int n = weights.length;
        for (int i = 0, max = 1 << n; i < max; ++i) {
            int sum = weight(i, weights);
            if (sum <= c && sum > optimalW) {
                optimalW = sum;
                optimalA = i;
            }
        }
        return optimalA;
    }

    public static void main(String[] args) throws IOException {
        String testData = args.length >= 2 ? args[0] : "blind.in";
        String logFile = args.length >= 2 ? args[1] : "blind.out";

        Scanner in = new Scanner(new File(testData));
        int n = in.nextInt();
        int c = in.nextInt();
        Random random = new Random(in.nextLong());
        String initAlg = in.next();
        int[] weights = new int[n];
        for (int i = 0; i < n; ++i) {
            weights[i] = in.nextInt();
        }
        in.close();

        int optimalA = solve(c, weights);
        int optimal = weight(optimalA, weights);

        int curr;
        if (initAlg.equals("optimal")) {
            curr = optimalA;
        } else if (initAlg.equals("worst")) {
            curr = ((1 << n) - 1) & ~optimalA;
        } else {
            curr = random.nextInt(1 << n);
        }
        int next = curr ^ (1 << random.nextInt(n));

        BufferedReader pipeIn = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pipeOut = new PrintWriter(System.out, true); // auto-flush
        PrintWriter log = new PrintWriter(new FileWriter(logFile), true); // auto-flush

        String init = n + " " + c + " " + weight(next, weights);
        pipeOut.println(init);
        log.println("< " + init);

        boolean ok = false;

        try {
            for (int commands = 1; ; ++commands) {
                // log timestamps
                log.println("% " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss").format(new Date()));
                // read and parse command
                String command = pipeIn.readLine();
                log.println("> " + command);
                if (command == null) {
                    log.println("WA unexpected termination");
                    break;
                } else if (command.equals("stop")) {
                    int cw = weight(next, weights);
                    if (cw == optimal) {
                        ok = true;
                        log.println("OK weight = " + optimal + ". " + commands + " commands used");
                        break;
                    } else {
                        log.println("WA weight expected " + optimal + ", found " + cw + ". " + commands + " commands used");
                        break;
                    }
                } else if (command.equals("accept")) {
                    curr = next;
                } else if (command.equals("decline")) {
                    //
                } else {
                    log.println("WA illegal command '" + command + "'");
                    break;
                }
                if (commands == COMMAND_LIMIT) {
                    log.println("WA 'stop' not issued after " + COMMAND_LIMIT + " commands");
                    break;
                }
                next = curr;
                next ^= 1 << random.nextInt(n);
                int nw = weight(next, weights);
                log.println("< " + nw);
                pipeOut.println(nw);
            }
        } finally {
            log.close();
            pipeOut.close();
            pipeIn.close();
        }
        // Exit code 10 signals to invoker that we know the outcome, user program must be terminated and its outcome must be ignored
        System.exit(ok ? 0 : 10);
    }
}

