codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1373C.md (1306B)


      1 Source: https://codeforces.com/problemset/problem/1373/C
      2 
      3 C. Pluses and Minuses
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given a string $s$ consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode:
     22 
     23 ```
     24 res = 0  
     25 for init = 0 to inf  
     26     cur = init  
     27     ok = true  
     28     for i = 1 to |s|  
     29         res = res + 1  
     30         if s[i] == '+'  
     31             cur = cur + 1  
     32         else  
     33             cur = cur - 1  
     34         if cur < 0  
     35             ok = false  
     36             break  
     37     if ok  
     38         break
     39 ```
     40 
     41 Note that the $inf$ denotes infinity, and the characters of the string are numbered from $1$ to $|s|$.
     42 
     43 You have to calculate the value of the $res$ after the process ends.
     44 
     45 Input
     46 
     47 The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.
     48 
     49 The only lines of each test case contains string $s$ ($1 \le |s| \le 10^6$) consisting only of characters + and -.
     50 
     51 It's guaranteed that sum of $|s|$ over all test cases doesn't exceed $10^6$.
     52 
     53 Output
     54 
     55 For each test case print one integer — the value of the $res$ after the process ends.
     56 
     57 Example
     58 
     59 Input
     60 
     61 ```
     62 3
     63 --+-
     64 ---
     65 ++--+-
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 7
     72 9
     73 6
     74 ```