Psp98

Untitled

May 24th, 2017
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.86 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*;
  4. import java.lang.*;
  5. import static java.lang.Math.*;
  6.  
  7. public class Sol
  8. {
  9.    
  10.     static long mod=1000000007;
  11.    
  12.     public static void main(String args[]) throws Exception
  13.     {
  14.         InputReader in;
  15.         PrintWriter w;
  16.         boolean online = false;
  17.         String fileName = "input";
  18.  
  19.         if (online)
  20.         {
  21.             in = new InputReader(new FileInputStream(new File(fileName + ".in")));
  22.             w = new PrintWriter(new FileWriter("out.txt"));
  23.         }
  24.         else
  25.         {
  26.             in = new InputReader(System.in);
  27.             w = new PrintWriter(System.out);
  28.         }
  29.        
  30.         //int T = in.nextInt();
  31.         int T=1;
  32.        
  33.         for (int t = 1; t <= T; t++)
  34.         {
  35.             char c[]=in.next().toCharArray();
  36.             int t1=0, t2=0, c1=0, c2=0, flag=0, max=0;
  37.            
  38.             if(c[0]==':') flag=1;
  39.            
  40.             for(int i=0;i<c.length-1;i++)
  41.             {
  42.                 if(c[i]==':' && c[i+1]==')') t1++;
  43.                 else if(c[i]=='(' && c[i+1]==':') t2++;
  44.             }
  45.            
  46.             max=max(t1,t2);
  47.            
  48.             for(int i=0;i<c.length-1;i++)
  49.             {
  50.                 if(c[i]==':' && c[i+1]==')') c1++;
  51.                
  52.                 else if(c[i]=='(' && c[i+1]==':')
  53.                 {
  54.                     c2++;
  55.                     if(i+2<=c.length-1 && c[i+2]==')') {
  56.                         c1++;
  57.                         if(flag==1) c2++;
  58.                     }
  59.                     max=max(max, (c2 + (t1 - c1)));
  60.                     if(flag==1 && i+2<=c.length-1 && c[i+2]==')') c2--;
  61.                     i++;
  62.                 }
  63.             }
  64.            
  65.             w.println(max);
  66.         }
  67.        
  68.         w.close();
  69.     }
  70.    
  71.     static int arr[];
  72.     static int size[];
  73.    
  74.     static void initialize(int n)
  75.     {
  76.         for(int i=0;i<=n;i++)
  77.         {
  78.             arr[i]=i;
  79.             size[i]=1;
  80.         }
  81.     }
  82.    
  83.     static int root(int r)
  84.     {
  85.         while(arr[r]!=r)
  86.         {
  87.             arr[r]=arr[arr[r]];
  88.             r=arr[r];
  89.         }
  90.        
  91.         return r;
  92.     }
  93.    
  94.     static void union(int u,int v)
  95.     {
  96.         int r1=root(u);
  97.         int r2=root(v);
  98.  
  99.         if(r1!=r2)
  100.         {
  101.             if(size[r1]<size[r2])
  102.             {
  103.                 arr[r1]=arr[r2];
  104.                 size[r2]+=size[r1];
  105.             }
  106.  
  107.             else
  108.             {
  109.                 arr[r2]=arr[r1];
  110.                 size[r1]+=size[r2];
  111.             }
  112.         }
  113.     }
  114.    
  115.     private static long gcd(long a, long b)
  116.     {
  117.         while (b > 0)
  118.         {
  119.             long temp = b;
  120.             b = a % b; // % is remainder
  121.             a = temp;
  122.         }
  123.         return a;
  124.     }
  125.  
  126.     private static long gcd(long[] input)
  127.     {
  128.         long result = input[0];
  129.        
  130.         for(int i = 1; i < input.length; i++)
  131.             result = gcd(result, input[i]);
  132.        
  133.         return result;
  134.     }
  135.    
  136.     private static long lcm(long a, long b)
  137.     {
  138.         return a * (b / gcd(a, b));
  139.     }
  140.  
  141.     private static long lcm(long[] input)
  142.     {
  143.         long result = input[0];
  144.        
  145.         for(int i = 1; i < input.length; i++)
  146.             result = lcm(result, input[i]);
  147.        
  148.         return result;
  149.     }
  150.    
  151.     public static void Array_2dsort(Integer[][] a)
  152.     {
  153.         Arrays.sort(a, new Comparator<Integer[]>()
  154.         {
  155.             public int compare(Integer[] int1, Integer[] int2)
  156.             {
  157.                 Integer numOfKeys1 = int1[1];       //about which column u want to sort
  158.                 Integer numOfKeys2 = int2[1];
  159.                 return numOfKeys1.compareTo(numOfKeys2);
  160.             }
  161.         });
  162.     }
  163.      
  164.     static long powmod(long x,long n,long m)        //(a/b)%mod = (a * (b^(m-2))%mod  here --> x=a, n=mod-2, m=mod  
  165.     {
  166.     if (n == 0)
  167.             return 1;
  168.         else if (n%2==0)
  169.             return powmod(((x%m)*(x%m))%m,n/2,m);
  170.     else if(n%2==1)
  171.             return (((x%m)*powmod(((x%m)*(x%m))%m,(n-1)/2,m))%m);
  172.     else
  173.             return 0;
  174.     }
  175.        
  176.    
  177.     static class InputReader
  178.     {
  179.    
  180.                 private InputStream stream;
  181.         private byte[] buf = new byte[1024];
  182.         private int curChar;
  183.         private int numChars;
  184.         private SpaceCharFilter filter;
  185.        
  186.         public InputReader(InputStream stream)
  187.         {
  188.             this.stream = stream;
  189.         }
  190.        
  191.         public int read()
  192.         {
  193.             if (numChars==-1)
  194.                 throw new InputMismatchException();
  195.            
  196.             if (curChar >= numChars)
  197.             {
  198.                 curChar = 0;
  199.                 try
  200.                 {
  201.                     numChars = stream.read(buf);
  202.                 }
  203.                 catch (IOException e)
  204.                 {
  205.                     throw new InputMismatchException();
  206.                 }
  207.                
  208.                 if(numChars <= 0)              
  209.                     return -1;
  210.             }
  211.             return buf[curChar++];
  212.         }
  213.      
  214.         public String nextLine()
  215.         {
  216.             BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  217.             String str = "";
  218.             try
  219.             {
  220.                 str = br.readLine();
  221.             }
  222.             catch (IOException e)
  223.             {
  224.                 e.printStackTrace();
  225.             }
  226.             return str;
  227.         }
  228.         public int nextInt()
  229.         {
  230.             int c = read();
  231.            
  232.             while(isSpaceChar(c))
  233.                 c = read();
  234.            
  235.             int sgn = 1;
  236.            
  237.             if (c == '-')
  238.             {
  239.                 sgn = -1;
  240.                 c = read();
  241.             }
  242.            
  243.             int res = 0;
  244.             do
  245.             {
  246.                 if(c<'0'||c>'9')
  247.                     throw new InputMismatchException();
  248.                 res *= 10;
  249.                 res += c - '0';
  250.                 c = read();
  251.             }
  252.             while (!isSpaceChar(c));
  253.            
  254.             return res * sgn;
  255.         }
  256.        
  257.         public long nextLong()
  258.         {
  259.             int c = read();
  260.             while (isSpaceChar(c))
  261.                 c = read();
  262.             int sgn = 1;
  263.             if (c == '-')
  264.             {
  265.                 sgn = -1;
  266.                 c = read();
  267.             }
  268.             long res = 0;
  269.            
  270.             do
  271.             {
  272.                 if (c < '0' || c > '9')
  273.                     throw new InputMismatchException();
  274.                 res *= 10;
  275.                 res += c - '0';
  276.                 c = read();
  277.             }
  278.             while (!isSpaceChar(c));
  279.                 return res * sgn;
  280.         }
  281.        
  282.         public double nextDouble()
  283.         {
  284.             int c = read();
  285.             while (isSpaceChar(c))
  286.                 c = read();
  287.             int sgn = 1;
  288.             if (c == '-')
  289.             {
  290.                 sgn = -1;
  291.                 c = read();
  292.             }
  293.             double res = 0;
  294.             while (!isSpaceChar(c) && c != '.')
  295.             {
  296.                 if (c == 'e' || c == 'E')
  297.                     return res * Math.pow(10, nextInt());
  298.                 if (c < '0' || c > '9')
  299.                     throw new InputMismatchException();
  300.                 res *= 10;
  301.                 res += c - '0';
  302.                 c = read();
  303.             }
  304.             if (c == '.')
  305.             {
  306.                 c = read();
  307.                 double m = 1;
  308.                 while (!isSpaceChar(c))
  309.                 {
  310.                     if (c == 'e' || c == 'E')
  311.                         return res * Math.pow(10, nextInt());
  312.                     if (c < '0' || c > '9')
  313.                         throw new InputMismatchException();
  314.                     m /= 10;
  315.                     res += (c - '0') * m;
  316.                     c = read();
  317.                 }
  318.             }
  319.             return res * sgn;
  320.         }
  321.        
  322.         public String readString()
  323.         {
  324.             int c = read();
  325.             while (isSpaceChar(c))
  326.                 c = read();
  327.             StringBuilder res = new StringBuilder();
  328.             do
  329.             {
  330.                 res.appendCodePoint(c);
  331.                 c = read();
  332.             }
  333.             while (!isSpaceChar(c));
  334.            
  335.             return res.toString();
  336.         }
  337.      
  338.         public boolean isSpaceChar(int c)
  339.         {
  340.             if (filter != null)
  341.                 return filter.isSpaceChar(c);
  342.             return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  343.         }
  344.      
  345.         public String next()
  346.         {
  347.             return readString();
  348.         }
  349.        
  350.         public interface SpaceCharFilter
  351.         {
  352.             public boolean isSpaceChar(int ch);
  353.         }
  354.     }
  355.    
  356. }
Add Comment
Please, Sign In to add comment