### 以下是代码

#### A

```(n, k) = map(int, raw_input().split())
ll = map(int, raw_input().split())

ans = 0

for i in xrange(k):
ones = 0
twos = 0
for j in xrange(i, n, k):
if ll[j] == 1:
ones += 1
else:
twos += 1

ans += min(ones, twos)

print ans
```

#### B

```from fractions import gcd

def avail(a):
ans = 0
while a % 2 == 0:
ans += 1
a /= 2
while a % 3 == 0:
ans += 1
a /= 3
while a % 5 == 0:
ans += 1
a /= 5

if a != 1:
return -1
else:
return ans

(a, b) = map(int, raw_input().split())

c = gcd(a, b)

a /= c
b /= c

av = avail(a)
gv = avail(b)

if av != -1 and gv != -1:
print av + gv
else:
print -1
```

#### C

```#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

const int BUFFER = 128;
const int SIZE = 5;

llint need[SIZE];
llint have[SIZE];
llint cost[SIZE];
llint money;

llint calc(llint num) {
llint res = 0;
for (int i = 0; i < 3; i++) {
llint t = max(0LL, num * need[i] - have[i]);
res += t * cost[i];
}
return res;
}

llint solve()
{
llint step = 10000000000000LL;
llint now = 0;
while (step) {
llint half = step >> 1;
llint mid = now + half;

if (calc(mid) > money) {
step = half;
} else {
now = mid + 1;
step = step - half - 1;
}
}
return now;
}

int main()
{
freopen("input.txt", "r", stdin);
char buffer[BUFFER];

while (input(buffer)) {
memset(need, 0, sizeof(need));
memset(have, 0, sizeof(have));
memset(cost, 0, sizeof(money));

for (int i = 0; buffer[i]; i++) {
switch (buffer[i]) {
case 'B': need[0]++; break;
case 'S': need[1]++; break;
case 'C': need[2]++; break;
default: break;
}
}

for (int i = 0; i < 3; i++) {
input(have[i]);
}
for (int i = 0; i < 3; i++) {
input(cost[i]);
}

input(money);

llint ans = solve() - 1;
print(max(0LL, ans));
}
return 0;
}
```

#### D

```#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

const int SIZE = 200100;

int n, m;
llint cap[SIZE];
llint vessel[SIZE];

int father[SIZE];

int find_father(int x)
{
if (father[x] == x) return x;
else return father[x] = find_father(father[x]);
}

void pour(int pos, llint value) {
vessel[pos] += value;
if (vessel[pos] > cap[pos]) {
if (pos == n - 1) {
vessel[pos] = cap[pos];
return;
} else {
llint overflow = vessel[pos] - cap[pos];
father[pos] = find_father(pos + 1);
vessel[pos] = cap[pos];
pour(father[pos], overflow);
}
}
}

llint query(int pos)
{
return vessel[pos];
}

int main()
{
freopen("input.txt", "r", stdin);
llint a, b, c;
input(n);

for (int i = 0; i < SIZE; i++) {
father[i] = i;
}

memset(cap, 0, sizeof(cap));
memset(vessel, 0, sizeof(vessel));

for (int i = 0; i < n; i++) {
input(cap[i]);
}

input(m);
while (m--) {
input(a);
if (a == 1) {
input(b >> c);
pour(--b, c);
} else {
input(b);
print(query(--b));
}
}

return 0;
}
```

#### E

```#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

struct node {
int pos, nr;
node(){}
node(int ipos, int inr):
pos(ipos), nr(inr) {}

bool operator < (const node& x) const
{
return pos < x.pos;
}
};

const int SIZE = 300008;

node station[SIZE];
llint leftsum[SIZE];

llint n, k;

int main()
{
input(n);
for (int i = 0; i < n; i++) {
input(station[i].pos);
station[i].nr = i + 1;
}
input(k);
sort(station, station + n);
for (int i = 1; i < n; i++) {
leftsum[i] = leftsum[i-1] + station[i].pos;
}

llint f = 0;
for (int i = 1; i <= k; i++) {
f += (llint)station[i].pos * i - leftsum[i-1];
}

llint res = f;
int pos = 0;
k--;
for (int i = 1; i < n - k; i++) {
f += station[i+k].pos * k;
f -= leftsum[i+k-1] * 2;
f += leftsum[i-1] * 2 ;
f += station[i-1].pos * k;
if (f < res) {
res = f;
pos = i;
}
}
for (int i=0; i<=k; i++) {
printf("%d ", station[pos + i].nr);
}
return 0;
}
```