---
# System prepended metadata

title: 114 程式設計實習I (資訊一乙) Week08 上課練習

---

# 114 程式設計實習I (資訊一乙) Week08 上課練習
password: qweqwheidasd
## 1. Vito's family

### 題目敘述

The world-known gangster Vito Deadstone is moving to New York. He has a very big family there, all of them living in Lamafia Avenue. Since he will visit all his relatives very often, he is trying to find a house close to them. Vito wants to minimize the total distance to all of them and has blackmailed you to write a program that solves his problem.

---

### 題目輸入

The input consists of several test cases. The first line contains the number of test cases. For each test case you will be given the integer number of relatives r (0 < r < 500) and the street numbers (also integers) s1, s2, . . . , si, . . . , sr where they live (0 < si < 30000 ). Note that several relatives could live in the same street number.

---

### 題目輸出

For each test case your program must write the minimal sum of distances from the optimal Vito’s house to each one of his relatives. The distance between two street numbers si and sj is dij = |si − sj|.

---

### 範例輸入1

```
2
2 2 4
3 2 4 6
```

### 範例輸出1

```
2
4
```

## 2. Parity

### 題目敘述

We define the parity of an integer n as the sum of the bits in binary representation computed modulo two. As an example, the number 21 = 101012 has three 1s in its binary representation so it has parity 3(mod2), or 1. 
In this problem you have to calculate the parity of an integer 1 ≤ I ≤ 2147483647.

---

### 題目輸入

Each line of the input has an integer I and the end of the input is indicated by a line where I = 0 that should not be processed.

---

### 題目輸出

For each integer I in the inputt you should print a line ‘The parity of B is P (mod 2).’, where B is the binary representation of I.

---

### 範例輸入1

```
1
2
10
21
0
```

### 範例輸出1

```
The parity of 1 is 1 (mod 2).
The parity of 10 is 1 (mod 2).
The parity of 1010 is 2 (mod 2).
The parity of 10101 is 3 (mod 2).
```