import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.regex.Pattern;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_A
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
    
    public static String shuffle(String original, int h) {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    }
} import java.io.InputStreamReader; InputStreamReader java.io import java.io.LineNumberReader; LineNumberReader java.io import java.util.regex.Pattern; Pattern java.util.regex public class Main {
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
    
    public static String shuffle(String original, int h) {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    }
} Main public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    } main {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    } try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        } catch (Exception e) {
            System.exit(-1);
        } Exception e {
            System.exit(-1);
        } System.exit(-1) System.exit System -1 1 {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in)); lineNumReader new LineNumberReader(
                    new InputStreamReader(System.in)) String inputStr = null; inputStr null String pile = null; pile null long lineNum = 0; lineNum 0 long resultShowLine = 0; resultShowLine 0 Pattern p = Pattern.compile("^[0-9]*$"); p Pattern.compile("^[0-9]*$") Pattern.compile Pattern "^[0-9]*$" while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            } (inputStr = lineNumReader.readLine()) != null (inputStr = lineNumReader.readLine()) inputStr lineNumReader.readLine() lineNumReader.readLine lineNumReader null {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            } if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                } "-".equals(inputStr) "-".equals "-" inputStr {
                    // do nothing.
                    break;
                } break; if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                } p.matcher(inputStr).find() p.matcher(inputStr).find p.matcher(inputStr) p.matcher p inputStr {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    } lineNumReader.getLineNumber() == lineNum + 1 lineNumReader.getLineNumber() lineNumReader.getLineNumber lineNumReader lineNum + 1 lineNum 1 {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2 resultShowLine resultShowLine
                                + Integer.parseInt(inputStr) + 2 resultShowLine
                                + Integer.parseInt(inputStr) + 2 resultShowLine Integer.parseInt(inputStr) Integer.parseInt Integer inputStr 2 continue; {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    } int h = Integer.parseInt(inputStr); h Integer.parseInt(inputStr) Integer.parseInt Integer inputStr pile = shuffle(pile, h) pile shuffle(pile, h) shuffle pile h {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                } pile = inputStr pile inputStr lineNum = lineNumReader.getLineNumber() lineNum lineNumReader.getLineNumber() lineNumReader.getLineNumber lineNumReader if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                } lineNumReader.getLineNumber() == resultShowLine lineNumReader.getLineNumber() lineNumReader.getLineNumber lineNumReader resultShowLine {
                    // ??¢???????????????
                    System.out.println(pile);
                } System.out.println(pile) System.out.println System.out System System.out pile lineNumReader.close() lineNumReader.close lineNumReader String[] args args public static String shuffle(String original, int h) {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    } shuffle {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    } StringBuilder shuffledStr = new StringBuilder(original); shuffledStr new StringBuilder(original) String temp = shuffledStr.substring(0, h); temp shuffledStr.substring(0, h) shuffledStr.substring shuffledStr 0 h shuffledStr.delete(0, h) shuffledStr.delete shuffledStr 0 h shuffledStr.append(temp) shuffledStr.append shuffledStr temp return shuffledStr.toString(); shuffledStr.toString() shuffledStr.toString shuffledStr String original original int h h public class Main {
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
    
    public static String shuffle(String original, int h) {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    }
} public class Main {
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
    
    public static String shuffle(String original, int h) {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    }
} Main
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.regex.Pattern;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_A
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String pile = null;
            long lineNum = 0;
            long resultShowLine = 0;
            
            // ??????????????????
            Pattern p = Pattern.compile("^[0-9]*$");
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????¶.
                if ("-".equals(inputStr)) {
                    // do nothing.
                    break;
                }
                
                // ??±??°?????????????????????.
                if (p.matcher(inputStr).find()) {
                    if (lineNumReader.getLineNumber() == lineNum + 1) {
                        // ?????£??????????????°???????????????????????¨?????????????????°????¨????.
                        resultShowLine = resultShowLine
                                + Integer.parseInt(inputStr) + 2;
                        continue;
                    } else {
                        // ?????£?????????????????????
                        int h = Integer.parseInt(inputStr);
                        pile = shuffle(pile, h);
                    }
                } else {
                    pile = inputStr;
                    lineNum = lineNumReader.getLineNumber();
                }
                
                if (lineNumReader.getLineNumber() == resultShowLine) {
                    // ??¢???????????????
                    System.out.println(pile);
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
    
    public static String shuffle(String original, int h) {
        StringBuilder shuffledStr = new StringBuilder(original);
        String temp = shuffledStr.substring(0, h);
        shuffledStr.delete(0, h);
        shuffledStr.append(temp);
        return shuffledStr.toString();
        
    }
}