Cod sursa(job #2672198)

Utilizator Botzki17Botocan Cristian-Alexandru Botzki17 Data 13 noiembrie 2020 13:36:23
Problema A+B Scor 60
Compilator java Status done
Runda teme_upb Marime 14.98 kb
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));//bagam citire de la tastatura :)
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            String string = new String();
            try {
                string = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return string;
        }
    }//FastReader Class

    static class Nod {
        private ArrayList<Integer> vecini;
        // private int size;

        public Nod() {
            vecini = new ArrayList<Integer>();
        }

        public int getSize() {
            return vecini.size();
        }

        public ArrayList<Integer> getVecini() {
            return vecini;
        }

        public void addMuchie(int nod) {
            vecini.add(nod);
        }

        public int getNod(int i) {
            return vecini.get(i);
        }
    }//NOD

    static class Poz {
        private int diagonala;
        private int column;
        private int linie;

        public Poz(int diagonala, int column, int linie) {
            this.column = column;
            this.diagonala = diagonala;
            this.linie = linie;
        }

        public int getColumn() {
            return column;
        }

        public int getDiagonala() {
            return diagonala;
        }

        public int getLinie() {
            return linie;
        }
    }

    public static void dfs(int nod, boolean[] viz, List<Nod> g) {
        viz[nod] = true;
        for (int i = 0; i < g.get(nod).getSize(); i++) {
            if (viz[g.get(nod).getNod(i)] == false)
                dfs(g.get(nod).getNod(i), viz, g);
        }
    }

    static class Structure {
        Set<String> set;

        public Structure() {
            set = new HashSet<>();
        }

        public int getSize() {
            return set.size();
        }

        public void add(String s) {
            set.add(s);
        }
    }

    /*public static void main(String [] args) {
       FastReader fr = new FastReader();
        int n = fr.nextInt();
        int m = fr.nextInt();
        int i, j;
        Map<String, Poz> map= new HashMap<String, Poz>();
       Structure[] column = new Structure[n + 1];
       Structure[] line = new Structure[n+1];
       Structure[] diag = new Structure[2];
       for(i =0 ; i<=n ;i++)
       {
           column[i] = new Structure();
           line[i] = new Structure();
       }




        for(i = 1; i <=n;i++)
        {
            for(j = 1; j<=n;j++)
            {
                String s = fr.next();
                int diagonala = -1;
                if(i==j)
                    diagonala = 0;
                if(i+j == n+1)
                    diagonala = 1;
                if(i+j== n+1 && i == j)
                {
                    diag[1] = new Structure();
                    diag[0] = new Structure();
                    diag[0].add(s);
                    diag[1].add(s);
                }
                Poz aux = new Poz(diagonala, j, i);
                map.put(s, aux);
            }
        }
        for(i =1; i<=m;i++)
        {
            String s = fr.next();
            if(map.containsKey(s)) {
                Poz aux = map.get(s);
                if(aux.getDiagonala() != -1)
                {
                    diag[aux.getDiagonala()].add(s);
                    if(diag[aux.getDiagonala()].getSize() == n)
                    {
                     System.out.println(i);
                     return;
                    }
                }
                column[aux.getColumn()].add(s);
                if(column[aux.getColumn()].getSize() == n)
                {
                    System.out.println(i);
                    return;
                }
                line[aux.getLinie()].add(s);
                if(line[aux.getLinie()].getSize() == n)
                {
                    System.out.println(i);
                    return;
                }
            }

        }
        System.out.println(":-(");

    }*/
 /*   static class Node implements Comparator<Node> {
        private int nr;
        private long cost;

        public Node() // for comparator
        {

        }

        public Node(int nr, long cost) {
            this.cost = cost;
            this.nr = nr;
        }

        public int compare(Node a, Node b) {
            if (a.cost < b.cost)
                return -1;
            if (a.cost > b.cost)
                return 1;
            return 0;
        }

        public long getCost() {
            return cost;
        }

        public int getNr() {
            return nr;
        }

        public void setCost(long cost) {
            this.cost = cost;
        }
    }

     static class DijkstraPQ {
        private long dist[];
        private Set<Integer> set;
        private PriorityQueue<Node> pq;
        private int v_number;
        private List<List<Node>> graf;

        public DijkstraPQ(int v_number, List<List<Node>> graf) {
            this.graf = graf;
            this.v_number = v_number;
            dist = new long[v_number + 1];
            for (int i = 1; i <= v_number; i++) {
                dist[i] = Long.MAX_VALUE;
            }
            set = new HashSet<>();
            pq = new PriorityQueue<>(v_number, new Node());
        }

        public void dijkstra(int start) {
            Node node = new Node(start, 0);
            Node aux;
            dist[start] = 0;
            pq.add(node);
            while (!pq.isEmpty()) {
                node = pq.peek();
                pq.remove();
                if (node.getCost() > dist[node.getNr()])
                    continue;
                for (int i = 0; i < graf.get(node.getNr()).size(); i++) {
                    aux = graf.get(node.getNr()).get(i);
                    if (dist[aux.getNr()] > dist[node.getNr()] + aux.getCost()) {
                        dist[aux.getNr()] = dist[node.getNr()] + aux.getCost();
                        aux.setCost(dist[aux.getNr()]);
                        pq.add(aux);
                    }
                }

            }
        }

        public Node answer(List<Integer> shops) {
            long d = Long.MAX_VALUE;
            Node node = new Node();
            for (int i = 0; i < shops.size(); i++) {
                if (d > dist[shops.get(i)]) {
                    Node aux = new Node(shops.get(i), dist[shops.get(i)]);
                    node = aux;
                    d = dist[shops.get(i)];
                }
            }
            return node;
        }
    }
    /*public static void main(String[] args)
    {
        FastReader fr = new FastReader();
        int n = fr.nextInt();
        int m = fr.nextInt();
        List <List <Node>> graf = new ArrayList<List<Node>>();
        for(int i =0 ; i<= n; i++)
        {
            List <Node> list = new ArrayList<Node>();
            graf.add(list);
        }
        for(int i =0; i < m; i++)
        {
            int nod1 = fr.nextInt();
            int nod2 = fr.nextInt();
            long  cost = fr.nextLong();
            Node node = new Node(nod1, cost);
            graf.get(nod2).add(node);
            node = new Node(nod2, cost);
            graf.get(nod1).add(node);
        }
        List <Integer> shops = new ArrayList<>();
        m = fr.nextInt();
        for( int i =0 ; i <m; i++)
        {
            int x = fr.nextInt();
            shops.add(x);
        }
        DijkstraPQ program = new DijkstraPQ(n, graf);
        program.dijkstra(1);
        Node node = program.answer(shops);
        System.out.println(node.getNr() + " " +  node.getCost());

    }*/


    public static int countWords(String s)
    {
        String [] words = s.split("\\s+");
        return words.length;
    }

/*    public static void main(String [] args){

        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        List <String> team1 = new ArrayList<>();
        List <String> team2 = new ArrayList<>();
        Queue<String> queue = new LinkedList<>();

        boolean ok = true;
        int steps = countWords(s);

        int n = sc.nextInt();
        
        for(int i = 0; i < n; i++)
        {
            s = sc.next();
            queue.add(s);
        }

        while(queue.size() != 0)
        {
            int c = steps / queue.size();
            int csteps = steps - queue.size() * (c-1);
            while(csteps != 1)
            {
                s = queue.remove();
                csteps--;
                queue.add(s);
            }
            s = queue.remove();
            if(ok == true)
                team1.add(s);
            else
                team2.add(s);
            ok = !ok;
        }
        System.out.println(team1.size());
        for (int i = 0; i < team1.size(); i++) {
            System.out.println(team1.get(i));
        }

        System.out.println(team2.size());
        for (int i = 0; i < team2.size(); i++) {
            System.out.println(team2.get(i));
        }


    }*/
   public static void main(String[] args) throws IOException {
       File in = new File("adunare.in");
       Scanner sc = new Scanner(in);
       long a = sc.nextLong();
       long b = sc.nextLong();
       long c = a + b;
       BufferedWriter outw = new BufferedWriter(new FileWriter("adunare.out"));
       outw.write(Long.toString(c));
       outw.close();


  }
    
    public static double[] merge(double [] list1, double[] list2)
    {
        double [] sol = new double[list1.length + list2.length];
        int i, k, j;
        i = 0;
        k = 0;
        j = 0;
        for(;k < sol.length; k++)
        {
            if(i == list1.length)
            {
                sol[k] = list2[j];
                k++;
                j++;
                continue;
            }
            if(j == list2.length)
            {
                sol[k] = list1[i];
                k++;
                i++;
                continue;
            }
            if(list1[i] <= list2[j])
            {
                sol[k] = list1[i];
                i++;
            }else{
                sol[k] = list2[j];
                j++;
            }
            k++;

        }
        return sol;
    }
    public static double [] mergeSort(double [] list)
    {
        if(list.length == 1 || list.length == 0)
            return list;
        int k1 = list.length >>1;
        int k2 = list.length - k1;
        double [] list1 = new double[k1];
        double [] list2 = new double[k2];
        for(int i =0; i < k1; i++)
            list1[i] =list[i];
        for(int i = k1; i < list.length; i++)
            list2[i - k1] = list[i];
        list1 = mergeSort(list1);
        list2 = mergeSort(list2);
        list = merge(list1, list2);
        return list;
    }
    class Node {

        List<Node> outgoingEdges;

        int value;



        boolean marked;

        public Node(int value) {
            this.outgoingEdges = new ArrayList<>();
            this.value = value;
            this.marked = false;
        }
    }
    class sortInt implements Comparator<Integer>{

        public int compare(Integer a, Integer b)
        {
            if(a > b)
                return 1;
            if(a == b)
                return 0;
            else return -1;

        }

    }
    boolean dfs(Node node)
    {

        node.marked = true;

        for (int i = 0; i < node.outgoingEdges.size(); i++) {

            Node v = node.outgoingEdges.get(i);
            if (v.marked == true)
                return true;
           boolean ok = dfs(v);
           if(ok == true)
               return true;
        }
        return false;
    }

    boolean bfs(Node start, Node t)
    {
        Queue <Node> q = new LinkedList<>();
        q.add(start);
        start.marked = true;
        while(!q.isEmpty()){
            Node u = q.remove();
            for(Node n : u.outgoingEdges)
            {
                if(n.marked == false)
                {
                    n.marked = true;
                    q.add(n);
                }

            }
        }
        return t.marked;
    }



    public String solve(InputStream in) {
        boolean ok = false;


        Scanner sc = new Scanner(in);




        int n, m, s, t;
        n = sc.nextInt();
        m = sc.nextInt();
        s = sc.nextInt();
        t = sc.nextInt();
        Node[] graph = new Node[n+1];
        for(int i =0; i < n + 1;i++) {
            graph[i] = new Node(i);
        }
        for (int i = 0; i < m; i++) {
            int u, v;
            u = sc.nextInt();
            v = sc.nextInt();
            int w = sc.nextInt();
            Node nodev = graph[v];
            graph[u].outgoingEdges.add(nodev);
        }


        ok = bfs(graph[s], graph[t]);



        if(ok == false)
            return "no";
        else
            return "yes";

    }
    int minAmountOfTrucks(int n, int[] weights, int maxWeight) {

        if(weights == null || weights.length == 0)
            return 0;

        //Integer[] w = new Integer[weights.length];

        //for(int i =0; i < w.length; i++)
        //{
         //   w [i] =Integer.valueOf(weights[i]);
       // }

       // Arrays.sort(w, new sortInt());

        Arrays.sort(weights, 0, weights.length);


        int sum = 0;
        int cnt =0;
        LinkedList <Integer> st =  new LinkedList<>();

        st.push(weights[1]);

        for(int i =1; i < weights.length; i++)
        {
            int x = st.peek();
            if(x + weights[i] <= maxWeight)
            {
                x += weights[i];
                st.pop();
                st.push(x);
            }
            else{
                if(weights[i] > maxWeight)
                       break;
                else
                    st.push(weights[i]);
            }
        }
        return st.size();

    }



}