codeforces-scrape

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

353A.md (1895B)


      1 Source: https://codeforces.com/problemset/problem/353/A
      2 
      3 A. Domino
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
     22 
     23 To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
     24 
     25 Input
     26 
     27 The first line contains integer *n* (1 ≤ *n* ≤ 100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*, *y**i* (1 ≤ *x**i*, *y**i* ≤ 6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
     28 
     29 Output
     30 
     31 Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print  - 1.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 2  
     39 4 2  
     40 6 4
     41 ```
     42 
     43 Output
     44 
     45 ```
     46 0
     47 ```
     48 
     49 Input
     50 
     51 ```
     52 1  
     53 2 3
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 -1
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 3  
     66 1 4  
     67 2 3  
     68 4 4
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 1
     75 ```
     76 
     77 Note
     78 
     79 In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
     80 
     81 In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
     82 
     83 In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.