1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>

int main() {
  unsigned long long ret = 0ll;
  int l = -1, ac = 0, bc = 0;
  char c = 0;
  int in[200010];
  while(c != '\n') {
    l++;
    scanf("%c", &c);
    in[l] = c - 'a';
    if(in[l] == 0) {
      ac++;
    } else if(in[l] == 1) {
      bc++;
    }
  }
  if(ac % 2 == 1 && bc % 2 == 1) {
    printf("-1");
    return 0;
  }
  // 0 na srodku
  if(bc % 2 == 1) {
    for(int i = 0; i < l; i++) {
      in[i] = 1 - in[i];
    }
  }
  for(int i = 0; i < l / 2; i++) {
    if (in[i] == in[l - i -1]) {
//      printf("cont  %d %d    ", i, l- i -1);
      continue;
    }
//    printf("nie-cont   %d    ", i);
    if(in[i] == 0) {
//      printf("xx  ");
      int j = i;
      while(in[j] == 0) {
        j++;
        ret++;
      }
      in[j] = 0;
      in[i] = 1;
    } else {
      int j = l - i - 1;
      while(in[j] == 0) {
        j--;
        ret++;
      }
      in[j] = 0;
      in[i] = 1;
    }
  }

//  printf("%i = %i + %i   ", l, ac, bc);
//  printf("\n\n");
  printf("%llu", ret);
  return 0;
}