686A : FREE ICE CREAM

//686A : FREE ICE CREAM

/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Basic mathematics
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {  
  
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
            //Take the necessary inputs
            int n=in.nextInt();
            long total=in.nextInt();
            int distress=0;
          
            //Evaluate for the result
            /*
             * Algorithm:
             *     - Evaluate with each inputs depending on +/-
             */
            while(n-- > 0){
                String sign=in.next();
                int num=in.nextInt();
                if(sign.charAt(0)=='+')total+=num;
                else{
                    if(num>total)++distress;
                    else total-=num;
                }
            }
            out.print(total+" "+distress);
        }
    }
  
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
      
    }
  
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);      
        out.close();      
    }

}

454A : LITTLE PONY AND CRYSTAL MINE

//454A : LITTLE PONY AND CRYSTAL MINE


/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Simple string manipulation
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
            //Take the input
            int n=in.nextInt();
           
            //Declare the necessary variables
            char[][] crystal=new char[n][n];
            int increment=0;
            String s="";
            for(int i=0;i<n;++i){
                s=s.concat("*");
            }
           
            //Evaluate the given problem
            /*
             * Algorithm:
             *     - Fill all the arrays with * first
             *     - Then symmetrically fill up the arrays
             */
            for(int i=0;i<=n/2;++i,++increment){
                crystal[i]=s.toCharArray();
                crystal[n-1-i]=s.toCharArray();
                for(int j=0;j<=increment;++j){
                    crystal[i][n/2-j]='D';
                    crystal[i][n/2+j]='D';
                    crystal[n-1-i][n/2-j]='D';
                    crystal[n-1-i][n/2+j]='D';
                }
            }
           
            //Display the result
            for(int i=0;i<n;++i){
                for(int j=0;j<n;++j)out.print(crystal[i][j]);
                out.println();
            }
           
        }                   
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}

732B : CORMEN THE BEST FRIEND OF A MAN

//732B : CORMEN THE BEST FRIEND OF A MAN


/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Greedy Algorithm
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
           
            //Taking necessary inputs and evaluating the result
            int n=in.nextInt();
            int k=in.nextInt();
            int[] walks=new int[n];
           
            /*
             * Hint:
             *     - Ensure that the sum of the present and 
             *       the previous input doesn't exceed the
             *       total number of walks
             */
            int total=0;
            walks[0]=in.nextInt();
            for(int i=1;i<n;++i){
                walks[i]=in.nextInt();
                if(walks[i]+walks[i-1]>=k)continue;
                else{
                    int extra=(k-walks[i-1]-walks[i]);
                    total+=extra;
                    walks[i]+=extra;
                 }
            }
           
            //Display the result
            out.println(total);           
            for(int i=0;i<n;++i)out.print(walks[i]+" ");
        }                   
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}

688B : LOVELY PALINDROMES

//688B : LOVELY PALINDROMES


/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Concept of Palindromes
 *     - Basic string manipulation
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
            /*
             * Logic:
             *     - The first half of the palindrome is
             *       the input itself
             */
           
            //Take the input
            String s=in.next();
           
            //Compute the result and display the output
            out.print(s);
            int i=s.length()-1;
            while(i>=0)out.print(s.charAt(i--));
        }                   
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}

688A : OPPONENTS

//688A : OPPONENTS


/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Basic Mathematics
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
           
            //Take the necessary inputs and declare the variables
            int n=in.nextInt();
            n=in.nextInt();
            String present;
            int consecutive=0;
            int count=0;
           
            //Evaluate the expression
            /*
             * Algorithm:
             *     - If a child is absent in any day then increment the
             *       number of wins
             *     - Else see whether the numbers of wins till then
             *       is the maximum or not
             */
            for(int i=0;i<n;++i){
                present=in.next();
                if(present.contains("0"))++count;
                else{
                    consecutive=Math.max(count, consecutive);
                    count=0;
                }
            }
           
            //Display the result
            out.print(Math.max(consecutive, count));
        }
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}

749A : BACHGOLD PROBLEM

//749A : BACHGOLD PROBLEM


/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Reasoning
 *     - Concept of prime numbers
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
            //Take the input
            int n=in.nextInt();
           
            //Evaluate the solution
            /*
             * Algorithm:
             *     - A number greater than 2 is:
             *         ~ number = (2*n) + 3; or
             *         ~ number = (2*n)
             */
            if(n%2==0){
                n/=2;
                out.println(n);
                while(n-->0)out.print("2 ");
            }else{
                n/=2;
                n-=1;
                out.println(n+1);
                while(n-->0)out.print("2 ");
                out.print("3");
            }
        }                   
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}

742A : ARPA'S HARD EXAM AND MEHRDAD'S NAIVE CHEAT

//742A : ARPA'S HARD EXAM AND MEHRDAD'S NAIVE CHEAT

/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Basic mathematics
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
           
            //Take the necessary inputs
            int n=in.nextInt();
           
            //Take care of the base cases
            if(n==0){
                out.print(1);
                return;
            }
                       
            //Display the result
            /*
             * Hint:
             *     - The number at the end repeats in certain intervals
             */
            int res=n%4;
            if(res==1)out.print(8);
            else if(res==2)out.print(4);
            else if(res==3)out.print(2);
            else out.print(6);
        }                   
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}